Browse Source

cmMidiFile.h/c _cmMidiFileClose() is now called by cmMidiFileOpen() on the incoming handle.

master
kpl 12 years ago
parent
commit
d32c47be4c
2 changed files with 19 additions and 10 deletions
  1. 17
    10
      cmMidiFile.c
  2. 2
    0
      cmMidiFile.h

+ 17
- 10
cmMidiFile.c View File

@@ -365,8 +365,8 @@ cmMfRC_t _cmMidiFileReadTrack( _cmMidiFile_t* mfp, unsigned short trkIdx )
365 365
         break;
366 366
 
367 367
       default:
368
-          // handle channel msg
369
-          rc = _cmMidiFileReadChannelMsg(mfp,&runstatus,status,tmp);
368
+        // handle channel msg
369
+        rc = _cmMidiFileReadChannelMsg(mfp,&runstatus,status,tmp);
370 370
 
371 371
     }
372 372
   }
@@ -454,11 +454,15 @@ cmMfRC_t _cmMidiFileClose( _cmMidiFile_t* mfp )
454 454
 
455 455
 cmMfRC_t cmMidiFileOpen( const char* fn, cmMidiFileH_t* hPtr, cmCtx_t* ctx )
456 456
 {
457
-  cmMfRC_t         rc     = kOkMfRC;
457
+  cmMfRC_t       rc     = kOkMfRC;
458 458
   _cmMidiFile_t* mfp    = NULL;
459 459
   unsigned short trkIdx = 0;
460 460
   cmErr_t        err;
461 461
 
462
+  if( cmMidiFileIsValid(*hPtr) )
463
+    if((rc = _cmMidiFileClose(_cmMidiFileHandleToPtr(*hPtr))) != kOkMfRC )
464
+      return rc;
465
+
462 466
   cmErrSetup(&err,&ctx->rpt,"MIDI File");
463 467
 
464 468
   // allocate the midi file object 
@@ -575,13 +579,13 @@ cmMfRC_t cmMidiFileOpen( const char* fn, cmMidiFileH_t* hPtr, cmCtx_t* ctx )
575 579
 
576 580
  errLabel:
577 581
 
578
-    if( cmFileClose(&mfp->fh) != kOkFileRC )
579
-      rc = _cmMidiFileError(&mfp->err,kCloseFailFileRC);
582
+  if( cmFileClose(&mfp->fh) != kOkFileRC )
583
+    rc = _cmMidiFileError(&mfp->err,kCloseFailFileRC);
580 584
 
581
-    if( rc != kOkMfRC )
582
-      _cmMidiFileClose(mfp);
585
+  if( rc != kOkMfRC )
586
+    _cmMidiFileClose(mfp);
583 587
 
584
-    return rc;
588
+  return rc;
585 589
 }
586 590
 
587 591
 
@@ -600,6 +604,9 @@ cmMfRC_t        cmMidiFileClose( cmMidiFileH_t* h )
600 604
   return rc;
601 605
 }
602 606
 
607
+bool   cmMidiFileIsValid( cmMidiFileH_t h )
608
+{ return !cmMidiFileIsNull(h); }
609
+
603 610
 unsigned    cmMidiFileTrackCount( cmMidiFileH_t h )
604 611
 {
605 612
   _cmMidiFile_t* mfp;
@@ -648,7 +655,7 @@ cmMidiByte_t  cmMidiFileTicksPerSmpteFrame( cmMidiFileH_t h )
648 655
   if( mfp->ticksPerQN != 0 )
649 656
     return 0;
650 657
  
651
- return mfp->smpteTicksPerFrame;
658
+  return mfp->smpteTicksPerFrame;
652 659
 } 
653 660
 
654 661
 cmMidiByte_t  cmMidiFileSmpteFormatId( cmMidiFileH_t h )
@@ -661,7 +668,7 @@ cmMidiByte_t  cmMidiFileSmpteFormatId( cmMidiFileH_t h )
661 668
   if( mfp->ticksPerQN != 0 )
662 669
     return 0;
663 670
  
664
- return mfp->smpteFmtId;
671
+  return mfp->smpteFmtId;
665 672
 }
666 673
     
667 674
 unsigned    cmMidiFileTrackMsgCount( cmMidiFileH_t h, unsigned trackIdx )

+ 2
- 0
cmMidiFile.h View File

@@ -107,6 +107,8 @@ extern "C" {
107 107
   cmMfRC_t              cmMidiFileOpen( const char* fn, cmMidiFileH_t* hPtr, cmCtx_t* ctx );
108 108
   cmMfRC_t              cmMidiFileClose( cmMidiFileH_t* hp );
109 109
 
110
+  bool                  cmMidiFileIsValid( cmMidiFileH_t h );
111
+
110 112
   // Returns track count or kInvalidCnt if 'h' is invalid.
111 113
   unsigned              cmMidiFileTrackCount( cmMidiFileH_t h );
112 114
 

Loading…
Cancel
Save