Browse Source

cmDspKr.c Changes to _cmDspMidiFilePlaySeekMsgIdx() and _cmDspMidiFilePlayExec() to validate MIDI file handle prior to using it.

master
kevin 12 years ago
parent
commit
0fcfebb1cd
1 changed files with 25 additions and 3 deletions
  1. 25
    3
      dsp/cmDspKr.c

+ 25
- 3
dsp/cmDspKr.c View File

604
   unsigned      startSymId;
604
   unsigned      startSymId;
605
   unsigned      stopSymId;
605
   unsigned      stopSymId;
606
   unsigned      contSymId;
606
   unsigned      contSymId;
607
+  bool          errFl;
607
 } cmDspMidiFilePlay_t;
608
 } cmDspMidiFilePlay_t;
608
 
609
 
609
 /*
610
 /*
657
 }
658
 }
658
 
659
 
659
 // return the index of the msg following smpIdx
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
   unsigned                 i;
671
   unsigned                 i;
663
   unsigned                 n     = cmMidiFileMsgCount(p->mfH);
672
   unsigned                 n     = cmMidiFileMsgCount(p->mfH);
664
   const cmMidiTrackMsg_t** a     = cmMidiFileMsgArray(p->mfH);
673
   const cmMidiTrackMsg_t** a     = cmMidiFileMsgArray(p->mfH);
676
   const cmChar_t*      fn = cmDspStrcz(inst,kFnMfId);
685
   const cmChar_t*      fn = cmDspStrcz(inst,kFnMfId);
677
   cmDspMidiFilePlay_t* p  = (cmDspMidiFilePlay_t*)inst;
686
   cmDspMidiFilePlay_t* p  = (cmDspMidiFilePlay_t*)inst;
678
 
687
 
688
+  p->errFl = false;
689
+
679
   if( fn==NULL || strlen(fn)==0 )
690
   if( fn==NULL || strlen(fn)==0 )
680
     return rc;
691
     return rc;
681
 
692
 
687
     p->bsi       = cmDspInt(inst,kBsiMfId);
698
     p->bsi       = cmDspInt(inst,kBsiMfId);
688
     p->esi       = cmDspInt(inst,kEsiMfId);
699
     p->esi       = cmDspInt(inst,kEsiMfId);
689
     p->csi       = 0;
700
     p->csi       = 0;
690
-
701
+    
691
     // force the first msg to occurr one quarter note into the file
702
     // force the first msg to occurr one quarter note into the file
692
     cmMidiFileSetDelay(p->mfH, cmMidiFileTicksPerQN(p->mfH) );
703
     cmMidiFileSetDelay(p->mfH, cmMidiFileTicksPerQN(p->mfH) );
693
 
704
 
711
   cmDspMidiFilePlay_t* p   = (cmDspMidiFilePlay_t*)inst;
722
   cmDspMidiFilePlay_t* p   = (cmDspMidiFilePlay_t*)inst;
712
   unsigned             sPc = cmDspSamplesPerCycle(ctx);
723
   unsigned             sPc = cmDspSamplesPerCycle(ctx);
713
 
724
 
725
+
714
   if( cmDspSymbol(inst,kSelMfId) != p->stopSymId )
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
     const cmMidiTrackMsg_t** mpp   = cmMidiFileMsgArray(p->mfH);
738
     const cmMidiTrackMsg_t** mpp   = cmMidiFileMsgArray(p->mfH);
717
     unsigned                 msgN  = cmMidiFileMsgCount(p->mfH);
739
     unsigned                 msgN  = cmMidiFileMsgCount(p->mfH);
718
   
740
   
754
         if( cmDspSymbol(inst,kSelMfId)==p->startSymId ) 
776
         if( cmDspSymbol(inst,kSelMfId)==p->startSymId ) 
755
         {
777
         {
756
           p->csi       = cmDspInt(inst,kBsiMfId);
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
         break;
781
         break;
760
       }
782
       }

Loading…
Cancel
Save