|
@@ -604,6 +604,7 @@ typedef struct
|
604
|
604
|
unsigned startSymId;
|
605
|
605
|
unsigned stopSymId;
|
606
|
606
|
unsigned contSymId;
|
|
607
|
+ bool errFl;
|
607
|
608
|
} cmDspMidiFilePlay_t;
|
608
|
609
|
|
609
|
610
|
/*
|
|
@@ -657,8 +658,16 @@ cmDspRC_t _cmDspMidiFilePlayFree(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDsp
|
657
|
658
|
}
|
658
|
659
|
|
659
|
660
|
// return the index of the msg following smpIdx
|
660
|
|
-unsigned _cmDspMidiFilePlaySeekMsgIdx( cmDspCtx_t* ctx, cmDspMidiFilePlay_t* p, unsigned smpIdx )
|
|
661
|
+unsigned _cmDspMidiFilePlaySeekMsgIdx( cmDspCtx_t* ctx, cmDspInst_t* inst, unsigned smpIdx )
|
661
|
662
|
{
|
|
663
|
+ cmDspMidiFilePlay_t* p = (cmDspMidiFilePlay_t*)inst;
|
|
664
|
+
|
|
665
|
+ if( cmMidiFileIsValid(p->mfH) == false )
|
|
666
|
+ {
|
|
667
|
+ cmErrMsg(&inst->classPtr->err, kInvalidStateDspRC,"The MIDI file player has not been given a valid MIDI file.");
|
|
668
|
+ return cmInvalidIdx;
|
|
669
|
+ }
|
|
670
|
+
|
662
|
671
|
unsigned i;
|
663
|
672
|
unsigned n = cmMidiFileMsgCount(p->mfH);
|
664
|
673
|
const cmMidiTrackMsg_t** a = cmMidiFileMsgArray(p->mfH);
|
|
@@ -676,6 +685,8 @@ cmDspRC_t _cmDspMidiFilePlayOpen(cmDspCtx_t* ctx, cmDspInst_t* inst )
|
676
|
685
|
const cmChar_t* fn = cmDspStrcz(inst,kFnMfId);
|
677
|
686
|
cmDspMidiFilePlay_t* p = (cmDspMidiFilePlay_t*)inst;
|
678
|
687
|
|
|
688
|
+ p->errFl = false;
|
|
689
|
+
|
679
|
690
|
if( fn==NULL || strlen(fn)==0 )
|
680
|
691
|
return rc;
|
681
|
692
|
|
|
@@ -687,7 +698,7 @@ cmDspRC_t _cmDspMidiFilePlayOpen(cmDspCtx_t* ctx, cmDspInst_t* inst )
|
687
|
698
|
p->bsi = cmDspInt(inst,kBsiMfId);
|
688
|
699
|
p->esi = cmDspInt(inst,kEsiMfId);
|
689
|
700
|
p->csi = 0;
|
690
|
|
-
|
|
701
|
+
|
691
|
702
|
// force the first msg to occurr one quarter note into the file
|
692
|
703
|
cmMidiFileSetDelay(p->mfH, cmMidiFileTicksPerQN(p->mfH) );
|
693
|
704
|
|
|
@@ -711,8 +722,19 @@ cmDspRC_t _cmDspMidiFilePlayExec(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDsp
|
711
|
722
|
cmDspMidiFilePlay_t* p = (cmDspMidiFilePlay_t*)inst;
|
712
|
723
|
unsigned sPc = cmDspSamplesPerCycle(ctx);
|
713
|
724
|
|
|
725
|
+
|
714
|
726
|
if( cmDspSymbol(inst,kSelMfId) != p->stopSymId )
|
715
|
727
|
{
|
|
728
|
+ if( cmMidiFileIsValid(p->mfH) == false )
|
|
729
|
+ {
|
|
730
|
+ if( p->errFl==false )
|
|
731
|
+ {
|
|
732
|
+ rc = cmErrMsg(&inst->classPtr->err, kInvalidStateDspRC,"The MIDI file player has not been given a valid MIDI file.");
|
|
733
|
+ p->errFl = true;
|
|
734
|
+ }
|
|
735
|
+ return rc;
|
|
736
|
+ }
|
|
737
|
+
|
716
|
738
|
const cmMidiTrackMsg_t** mpp = cmMidiFileMsgArray(p->mfH);
|
717
|
739
|
unsigned msgN = cmMidiFileMsgCount(p->mfH);
|
718
|
740
|
|
|
@@ -754,7 +776,7 @@ cmDspRC_t _cmDspMidiFilePlayRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDsp
|
754
|
776
|
if( cmDspSymbol(inst,kSelMfId)==p->startSymId )
|
755
|
777
|
{
|
756
|
778
|
p->csi = cmDspInt(inst,kBsiMfId);
|
757
|
|
- p->curMsgIdx = _cmDspMidiFilePlaySeekMsgIdx(ctx, p, p->csi );
|
|
779
|
+ p->curMsgIdx = _cmDspMidiFilePlaySeekMsgIdx(ctx, inst, p->csi );
|
758
|
780
|
}
|
759
|
781
|
break;
|
760
|
782
|
}
|