Browse Source

cmDspBuiltIn.c : midi output port now notices when the device is not valid

prior to attempting to send it a midi message.
master
kevin 11 years ago
parent
commit
a8394b2814
1 changed files with 19 additions and 13 deletions
  1. 19
    13
      dsp/cmDspBuiltIn.c

+ 19
- 13
dsp/cmDspBuiltIn.c View File

1103
   cmDspInst_t inst;
1103
   cmDspInst_t inst;
1104
   unsigned    devIdx;
1104
   unsigned    devIdx;
1105
   unsigned    portIdx;
1105
   unsigned    portIdx;
1106
+  bool        enableFl;
1106
 } cmDspMidiOut_t;
1107
 } cmDspMidiOut_t;
1107
 
1108
 
1108
 cmDspRC_t _cmDspMidiOutSetDevice( cmDspCtx_t* ctx, cmDspMidiOut_t* p, const cmChar_t* deviceStr )
1109
 cmDspRC_t _cmDspMidiOutSetDevice( cmDspCtx_t* ctx, cmDspMidiOut_t* p, const cmChar_t* deviceStr )
1112
   if( deviceStr != NULL )
1113
   if( deviceStr != NULL )
1113
     if((p->devIdx = cmMpDeviceNameToIndex(deviceStr)) == cmInvalidIdx )
1114
     if((p->devIdx = cmMpDeviceNameToIndex(deviceStr)) == cmInvalidIdx )
1114
       rc = cmDspInstErr(ctx,&p->inst,kInvalidArgDspRC,"The MIDI device '%s' could not be found.",cmStringNullGuard(deviceStr));
1115
       rc = cmDspInstErr(ctx,&p->inst,kInvalidArgDspRC,"The MIDI device '%s' could not be found.",cmStringNullGuard(deviceStr));
1115
-
1116
   return rc;
1116
   return rc;
1117
 }
1117
 }
1118
 
1118
 
1166
 
1166
 
1167
   cmDspApplyAllDefaults(ctx,inst);
1167
   cmDspApplyAllDefaults(ctx,inst);
1168
 
1168
 
1169
-  _cmDspMidiOutSetDevice(ctx,p,cmDspStrcz(inst,kDeviceMoId));
1170
-  _cmDspMidiOutSetPort(  ctx,p,cmDspStrcz(inst,kPortMoId));
1169
+  p->enableFl = false;
1170
+
1171
+  if(_cmDspMidiOutSetDevice(ctx,p,cmDspStrcz(inst,kDeviceMoId)) == kOkDspRC )
1172
+    p->enableFl = _cmDspMidiOutSetPort(  ctx,p,cmDspStrcz(inst,kPortMoId)) == kOkDspRC;
1171
 
1173
 
1172
   return rc;
1174
   return rc;
1173
 } 
1175
 } 
1179
   switch( evt->dstVarId )
1181
   switch( evt->dstVarId )
1180
   {
1182
   {
1181
     case kDeviceMoId:      
1183
     case kDeviceMoId:      
1182
-      _cmDspMidiOutSetDevice(ctx, p, cmDsvStrcz(evt->valuePtr) );
1184
+      if(_cmDspMidiOutSetDevice(ctx, p, cmDsvStrcz(evt->valuePtr) ) != kOkDspRC )
1185
+        p->enableFl = false;
1183
       break;
1186
       break;
1184
 
1187
 
1185
     case kPortMoId:
1188
     case kPortMoId:
1186
-      _cmDspMidiOutSetPort(ctx, p, cmDsvStrcz(evt->valuePtr) );
1189
+      if( _cmDspMidiOutSetPort(ctx, p, cmDsvStrcz(evt->valuePtr) ) != kOkDspRC )
1190
+        p->enableFl = false;
1187
       break;
1191
       break;
1188
 
1192
 
1189
     case kStatusMoId:
1193
     case kStatusMoId:
1192
         unsigned status = cmDsvGetUInt(evt->valuePtr);
1196
         unsigned status = cmDsvGetUInt(evt->valuePtr);
1193
         unsigned d0     = cmDspUInt(inst,kD0MoId);
1197
         unsigned d0     = cmDspUInt(inst,kD0MoId);
1194
         unsigned d1     = cmDspUInt(inst,kD1MoId);
1198
         unsigned d1     = cmDspUInt(inst,kD1MoId);
1195
-        if( cmMpDeviceSend( p->devIdx, p->portIdx, status, d0, d1 ) != kOkMpRC )
1196
-          cmDspInstErr(ctx,inst,kInvalidArgDspRC,"MIDI send failed.");
1199
+        if( p->enableFl )
1200
+          if( cmMpDeviceSend( p->devIdx, p->portIdx, status, d0, d1 ) != kOkMpRC )
1201
+            cmDspInstErr(ctx,inst,kInvalidArgDspRC,"MIDI send failed.");
1197
       }
1202
       }
1198
       break;
1203
       break;
1199
 
1204
 
1201
       {
1206
       {
1202
         unsigned i;
1207
         unsigned i;
1203
         
1208
         
1204
-        for(i=0; i<kMidiChCnt; ++i)
1205
-        {          
1206
-          cmMpDeviceSend(p->devIdx,p->portIdx,kCtlMdId+i,121,0); // reset all controllers
1207
-          cmMpDeviceSend(p->devIdx,p->portIdx,kCtlMdId+i,123,0); // turn all notes off
1208
-          cmSleepMs(15);
1209
-        }
1209
+        if( p->enableFl )
1210
+          for(i=0; i<kMidiChCnt; ++i)
1211
+          {          
1212
+            cmMpDeviceSend(p->devIdx,p->portIdx,kCtlMdId+i,121,0); // reset all controllers
1213
+            cmMpDeviceSend(p->devIdx,p->portIdx,kCtlMdId+i,123,0); // turn all notes off
1214
+            cmSleepMs(15);
1215
+          }
1210
       }
1216
       }
1211
       break;
1217
       break;
1212
 
1218
 

Loading…
Cancel
Save