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

prior to attempting to send it a midi message.
This commit is contained in:
kevin 2013-11-01 18:31:29 -07:00
parent fadafa8e6b
commit a8394b2814

View File

@ -1103,6 +1103,7 @@ typedef struct
cmDspInst_t inst; cmDspInst_t inst;
unsigned devIdx; unsigned devIdx;
unsigned portIdx; unsigned portIdx;
bool enableFl;
} cmDspMidiOut_t; } cmDspMidiOut_t;
cmDspRC_t _cmDspMidiOutSetDevice( cmDspCtx_t* ctx, cmDspMidiOut_t* p, const cmChar_t* deviceStr ) cmDspRC_t _cmDspMidiOutSetDevice( cmDspCtx_t* ctx, cmDspMidiOut_t* p, const cmChar_t* deviceStr )
@ -1112,7 +1113,6 @@ cmDspRC_t _cmDspMidiOutSetDevice( cmDspCtx_t* ctx, cmDspMidiOut_t* p, const cmCh
if( deviceStr != NULL ) if( deviceStr != NULL )
if((p->devIdx = cmMpDeviceNameToIndex(deviceStr)) == cmInvalidIdx ) if((p->devIdx = cmMpDeviceNameToIndex(deviceStr)) == cmInvalidIdx )
rc = cmDspInstErr(ctx,&p->inst,kInvalidArgDspRC,"The MIDI device '%s' could not be found.",cmStringNullGuard(deviceStr)); rc = cmDspInstErr(ctx,&p->inst,kInvalidArgDspRC,"The MIDI device '%s' could not be found.",cmStringNullGuard(deviceStr));
return rc; return rc;
} }
@ -1166,8 +1166,10 @@ cmDspRC_t _cmDspMidiOutReset(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_
cmDspApplyAllDefaults(ctx,inst); cmDspApplyAllDefaults(ctx,inst);
_cmDspMidiOutSetDevice(ctx,p,cmDspStrcz(inst,kDeviceMoId)); p->enableFl = false;
_cmDspMidiOutSetPort( ctx,p,cmDspStrcz(inst,kPortMoId));
if(_cmDspMidiOutSetDevice(ctx,p,cmDspStrcz(inst,kDeviceMoId)) == kOkDspRC )
p->enableFl = _cmDspMidiOutSetPort( ctx,p,cmDspStrcz(inst,kPortMoId)) == kOkDspRC;
return rc; return rc;
} }
@ -1179,11 +1181,13 @@ cmDspRC_t _cmDspMidiOutRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t
switch( evt->dstVarId ) switch( evt->dstVarId )
{ {
case kDeviceMoId: case kDeviceMoId:
_cmDspMidiOutSetDevice(ctx, p, cmDsvStrcz(evt->valuePtr) ); if(_cmDspMidiOutSetDevice(ctx, p, cmDsvStrcz(evt->valuePtr) ) != kOkDspRC )
p->enableFl = false;
break; break;
case kPortMoId: case kPortMoId:
_cmDspMidiOutSetPort(ctx, p, cmDsvStrcz(evt->valuePtr) ); if( _cmDspMidiOutSetPort(ctx, p, cmDsvStrcz(evt->valuePtr) ) != kOkDspRC )
p->enableFl = false;
break; break;
case kStatusMoId: case kStatusMoId:
@ -1192,8 +1196,9 @@ cmDspRC_t _cmDspMidiOutRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t
unsigned status = cmDsvGetUInt(evt->valuePtr); unsigned status = cmDsvGetUInt(evt->valuePtr);
unsigned d0 = cmDspUInt(inst,kD0MoId); unsigned d0 = cmDspUInt(inst,kD0MoId);
unsigned d1 = cmDspUInt(inst,kD1MoId); unsigned d1 = cmDspUInt(inst,kD1MoId);
if( cmMpDeviceSend( p->devIdx, p->portIdx, status, d0, d1 ) != kOkMpRC ) if( p->enableFl )
cmDspInstErr(ctx,inst,kInvalidArgDspRC,"MIDI send failed."); if( cmMpDeviceSend( p->devIdx, p->portIdx, status, d0, d1 ) != kOkMpRC )
cmDspInstErr(ctx,inst,kInvalidArgDspRC,"MIDI send failed.");
} }
break; break;
@ -1201,12 +1206,13 @@ cmDspRC_t _cmDspMidiOutRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t
{ {
unsigned i; unsigned i;
for(i=0; i<kMidiChCnt; ++i) if( p->enableFl )
{ for(i=0; i<kMidiChCnt; ++i)
cmMpDeviceSend(p->devIdx,p->portIdx,kCtlMdId+i,121,0); // reset all controllers {
cmMpDeviceSend(p->devIdx,p->portIdx,kCtlMdId+i,123,0); // turn all notes off cmMpDeviceSend(p->devIdx,p->portIdx,kCtlMdId+i,121,0); // reset all controllers
cmSleepMs(15); cmMpDeviceSend(p->devIdx,p->portIdx,kCtlMdId+i,123,0); // turn all notes off
} cmSleepMs(15);
}
} }
break; break;