From cf8c6af27f978aa5f1adb75e283e12123bacd343 Mon Sep 17 00:00:00 2001 From: Kevin Larke Date: Wed, 25 Feb 2015 15:17:10 -0800 Subject: [PATCH] cmProc4.h/c : The cmMidiTrackMsg_t.uid identifier of note-on messages fed to cmScMatcher are now tracked along with the note. This allows score events to be definitevly matched to a particular note-on event when the event comes from a MIDI file. --- cmProc4.c | 9 +++++---- cmProc4.h | 6 +++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/cmProc4.c b/cmProc4.c index 6de6ad6..e27dbf0 100644 --- a/cmProc4.c +++ b/cmProc4.c @@ -1275,7 +1275,7 @@ cmRC_t cmScMatcherReset( cmScMatcher* p, unsigned scLocIdx ) return cmOkRC; } -bool cmScMatcherInputMidi( cmScMatcher* p, unsigned smpIdx, unsigned status, cmMidiByte_t d0, cmMidiByte_t d1 ) +bool cmScMatcherInputMidi( cmScMatcher* p, unsigned smpIdx, unsigned muid, unsigned status, cmMidiByte_t d0, cmMidiByte_t d1 ) { if( (status&0xf0) != kNoteOnMdId) return false; @@ -1293,6 +1293,7 @@ bool cmScMatcherInputMidi( cmScMatcher* p, unsigned smpIdx, unsigned status, cm p->midiBuf[mi].scEvtIdx = cmInvalidIdx; p->midiBuf[mi].mni = p->mni++; p->midiBuf[mi].smpIdx = smpIdx; + p->midiBuf[mi].muid = muid; p->midiBuf[mi].pitch = d0; p->midiBuf[mi].vel = d1; if( p->mbi > 0 ) @@ -1503,7 +1504,7 @@ cmRC_t cmScMatcherStep( cmScMatcher* p ) return cmOkRC; } -cmRC_t cmScMatcherExec( cmScMatcher* p, unsigned smpIdx, unsigned status, cmMidiByte_t d0, cmMidiByte_t d1, unsigned* scLocIdxPtr ) +cmRC_t cmScMatcherExec( cmScMatcher* p, unsigned smpIdx, unsigned muid, unsigned status, cmMidiByte_t d0, cmMidiByte_t d1, unsigned* scLocIdxPtr ) { bool fl = p->mbi > 0; cmRC_t rc = cmOkRC; @@ -1513,7 +1514,7 @@ cmRC_t cmScMatcherExec( cmScMatcher* p, unsigned smpIdx, unsigned status, c *scLocIdxPtr = cmInvalidIdx; // update the MIDI buffer with the incoming note - if( cmScMatcherInputMidi(p,smpIdx,status,d0,d1) == false ) + if( cmScMatcherInputMidi(p,smpIdx,muid,status,d0,d1) == false ) return rc; // if the MIDI buffer transitioned to full then perform an initial scan sync. @@ -2485,7 +2486,7 @@ cmRC_t cmScAlignScanToTimeLineEvent( cmScMatcher* p, cmTlH_t tlH, cmTlObj_t* top // if the time line MIDI msg a note-on if( (mep->msg->status&0xf0) == kNoteOnMdId ) { - rc = cmScMatcherExec(p, mep->obj.seqSmpIdx, mep->msg->status, mep->msg->u.chMsgPtr->d0, mep->msg->u.chMsgPtr->d1, NULL ); + rc = cmScMatcherExec(p, mep->obj.seqSmpIdx, mep->msg->uid, mep->msg->status, mep->msg->u.chMsgPtr->d0, mep->msg->u.chMsgPtr->d1, NULL ); switch( rc ) { diff --git a/cmProc4.h b/cmProc4.h index d10f0bf..a2c5c44 100644 --- a/cmProc4.h +++ b/cmProc4.h @@ -145,6 +145,7 @@ extern "C" { typedef struct { unsigned mni; // unique identifier for this MIDI note - used to recognize when the cmScMatcher backtracks. + unsigned muid; // MIDI file event msg unique id (See cmMidiTrackMsg_t.uid) unsigned smpIdx; // time stamp of this event unsigned pitch; // MIDI note pitch unsigned vel; // " " velocity @@ -208,6 +209,7 @@ extern "C" { unsigned scEvtIdx; // score event index unsigned mni; // index of the performed MIDI event associated with this score location unsigned smpIdx; // sample time index of performed MIDI event + unsigned muid; // MIDI file event msg unique id (See cmMidiTrackMsg_t.uid) unsigned pitch; // performed pitch unsigned vel; // performed velocity unsigned flags; // smTruePosFl | smFalsePosFl @@ -297,12 +299,14 @@ extern "C" { // will be set with the matched scLocIdx of the match. // If this call does not result in a successful match *scLocIdxPtr is set // to cmInvalidIdx. + // 'muid' is the unique id associated with this MIDI event under the circumstances + // that the event came from a MIDI file. See cmMidiFile.h cmMidiTrackMsg_t.uid. // Return: // cmOkRC - Continue processing MIDI events. // cmEofRC - The end of the score was encountered. // cmInvalidArgRC - scan failed or the object was in an invalid state to attempt a match. // cmSubSysFailRC - a scan resync failed in cmScMatcherStep(). - cmRC_t cmScMatcherExec( cmScMatcher* p, unsigned smpIdx, unsigned status, cmMidiByte_t d0, cmMidiByte_t d1, unsigned* scLocIdxPtr ); + cmRC_t cmScMatcherExec( cmScMatcher* p, unsigned smpIdx, unsigned muid, unsigned status, cmMidiByte_t d0, cmMidiByte_t d1, unsigned* scLocIdxPtr ); void cmScMatcherPrint( cmScMatcher* p );