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

This commit is contained in:
kpl 2012-11-26 23:03:35 -08:00
parent fdf1a7c15a
commit d32c47be4c
2 changed files with 19 additions and 10 deletions

View File

@ -365,8 +365,8 @@ cmMfRC_t _cmMidiFileReadTrack( _cmMidiFile_t* mfp, unsigned short trkIdx )
break;
default:
// handle channel msg
rc = _cmMidiFileReadChannelMsg(mfp,&runstatus,status,tmp);
// handle channel msg
rc = _cmMidiFileReadChannelMsg(mfp,&runstatus,status,tmp);
}
}
@ -454,11 +454,15 @@ cmMfRC_t _cmMidiFileClose( _cmMidiFile_t* mfp )
cmMfRC_t cmMidiFileOpen( const char* fn, cmMidiFileH_t* hPtr, cmCtx_t* ctx )
{
cmMfRC_t rc = kOkMfRC;
cmMfRC_t rc = kOkMfRC;
_cmMidiFile_t* mfp = NULL;
unsigned short trkIdx = 0;
cmErr_t err;
if( cmMidiFileIsValid(*hPtr) )
if((rc = _cmMidiFileClose(_cmMidiFileHandleToPtr(*hPtr))) != kOkMfRC )
return rc;
cmErrSetup(&err,&ctx->rpt,"MIDI File");
// allocate the midi file object
@ -575,13 +579,13 @@ cmMfRC_t cmMidiFileOpen( const char* fn, cmMidiFileH_t* hPtr, cmCtx_t* ctx )
errLabel:
if( cmFileClose(&mfp->fh) != kOkFileRC )
rc = _cmMidiFileError(&mfp->err,kCloseFailFileRC);
if( cmFileClose(&mfp->fh) != kOkFileRC )
rc = _cmMidiFileError(&mfp->err,kCloseFailFileRC);
if( rc != kOkMfRC )
_cmMidiFileClose(mfp);
if( rc != kOkMfRC )
_cmMidiFileClose(mfp);
return rc;
return rc;
}
@ -600,6 +604,9 @@ cmMfRC_t cmMidiFileClose( cmMidiFileH_t* h )
return rc;
}
bool cmMidiFileIsValid( cmMidiFileH_t h )
{ return !cmMidiFileIsNull(h); }
unsigned cmMidiFileTrackCount( cmMidiFileH_t h )
{
_cmMidiFile_t* mfp;
@ -648,7 +655,7 @@ cmMidiByte_t cmMidiFileTicksPerSmpteFrame( cmMidiFileH_t h )
if( mfp->ticksPerQN != 0 )
return 0;
return mfp->smpteTicksPerFrame;
return mfp->smpteTicksPerFrame;
}
cmMidiByte_t cmMidiFileSmpteFormatId( cmMidiFileH_t h )
@ -661,7 +668,7 @@ cmMidiByte_t cmMidiFileSmpteFormatId( cmMidiFileH_t h )
if( mfp->ticksPerQN != 0 )
return 0;
return mfp->smpteFmtId;
return mfp->smpteFmtId;
}
unsigned cmMidiFileTrackMsgCount( cmMidiFileH_t h, unsigned trackIdx )

View File

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