diff --git a/cwMidi.h b/cwMidi.h index 3e7353b..9e41826 100644 --- a/cwMidi.h +++ b/cwMidi.h @@ -87,8 +87,9 @@ namespace cw template< typename T> bool isStatus( T s ) { return (kNoteOffMdId <= (s) /*&& ((unsigned)(s)) <= kSysRtResetMdId*/ ); } template< typename T> bool isChStatus( T s ) { return (kNoteOffMdId <= (s) && (s) < kSysExMdId); } - template< typename T> bool isNoteOn( T s ) { return ( kNoteOnMdId <= (s) && (s) <= (kNoteOnMdId + kMidiChCnt) ); } - template< typename T> bool isNoteOff( T s, T d1 ) { return ( (isNoteOn(s) && (d1)==0) || (kNoteOffMdId <= (s) && (s) <= (kNoteOffMdId + kMidiChCnt)) ); } + template< typename T> bool isNoteOnStatus( T s ) { return ( kNoteOnMdId <= (s) && (s) <= (kNoteOnMdId + kMidiChCnt) ); } + template< typename T> bool isNoteOn( T s, T d1 ) { return ( (isNoteOnStatus(s) && (d1)!=0) ); } + template< typename T> bool isNoteOff( T s, T d1 ) { return ( (isNoteOnStatus(s) && (d1)==0) || (kNoteOffMdId <= (s) && (s) <= (kNoteOffMdId + kMidiChCnt)) ); } template< typename T> bool isCtl( T s ) { return ( kCtlMdId <= (s) && (s) <= (kCtlMdId + kMidiChCnt) ); } template< typename T> bool isSustainPedal( T s, T d0 ) { return ( kCtlMdId <= (s) && (s) <= (kCtlMdId + kMidiChCnt) && (d0)== kSustainCtlMdId ); } diff --git a/cwMidiFile.cpp b/cwMidiFile.cpp index 977875b..6127ee8 100644 --- a/cwMidiFile.cpp +++ b/cwMidiFile.cpp @@ -1437,7 +1437,7 @@ cw::rc_t cw::midi::file::setVelocity( handle_t h, unsigned uid, uint8_t vel ) if((r = _uidToMsg(mfp,uid)) == NULL ) return cwLogError(kInvalidArgRC,"The MIDI file uid %i could not be found.",uid); - if( midi::isNoteOn(r->status) == false && midi::isNoteOff(r->status,(uint8_t)0)==false ) + if( midi::isNoteOnStatus(r->status) == false && midi::isNoteOff(r->status,(uint8_t)0)==false ) return cwLogError(kInvalidArgRC,"Cannot set velocity on a non-Note-On/Off msg."); chMsg_t* chm = (chMsg_t*)r->u.chMsgPtr; @@ -2033,7 +2033,7 @@ namespace cw tmp->u.chMsgPtr->d1); } - if( midi::isChStatus(tmp->status) && midi::isNoteOn(tmp->status) && (tmp->u.chMsgPtr->d1>0) ) + if( midi::isChStatus(tmp->status) && midi::isNoteOn(tmp->status,tmp->u.chMsgPtr->d1) ) cwLogPrintH(logH," %4s ",midi::midiToSciPitch(tmp->u.chMsgPtr->d0,NULL,0)); @@ -2082,7 +2082,7 @@ namespace cw m->u.chMsgPtr->d1); } - bool fl = midi::isChStatus(m->status) && midi::isNoteOn(m->status) && (m->u.chMsgPtr->d1>0); + bool fl = midi::isChStatus(m->status) && midi::isNoteOn(m->status,m->u.chMsgPtr->d1); cw::file::printf(fH,",%4s",fl ? midi::midiToSciPitch(m->u.chMsgPtr->d0,NULL,0) : ""); @@ -2195,7 +2195,7 @@ cw::rc_t cw::midi::file::genPlotFile( const char* midiFn, const char* outFn ) return cwLogError(rc,"Unable to create the file '%s'.",cwStringNullGuard(outFn)); for(i=0; istatus) && midi::isNoteOn(m[i]->status) && (m[i]->u.chMsgPtr->d1>0) ) + if( (m[i]!=NULL) && midi::isChStatus(m[i]->status) && midi::isNoteOn(m[i]->status,m[i]->u.chMsgPtr->d1) ) cw::file::printf(fH,"n %f %f %i %s\n",m[i]->amicro/1000000.0,m[i]->u.chMsgPtr->durMicros/1000000.0,m[i]->uid,midi::midiToSciPitch(m[i]->u.chMsgPtr->d0,NULL,0)); errLabel: diff --git a/cwMidiFile.h b/cwMidiFile.h index 684e6fd..c0eef83 100644 --- a/cwMidiFile.h +++ b/cwMidiFile.h @@ -96,7 +96,7 @@ namespace cw } u; } trackMsg_t; - inline bool isNoteOn(const trackMsg_t* m) { return midi::isNoteOn(m->status) && (m->u.chMsgPtr->d1>0); } + inline bool isNoteOn(const trackMsg_t* m) { return midi::isNoteOn( m->status,m->u.chMsgPtr->d1); } inline bool isNoteOff(const trackMsg_t* m) { return midi::isNoteOff(m->status,m->u.chMsgPtr->d1); } inline bool isPedalUp(const trackMsg_t* m) { return midi::isPedalUp( m->status, m->u.chMsgPtr->d0, m->u.chMsgPtr->d1); } diff --git a/cwPianoScore.cpp b/cwPianoScore.cpp index 3ceae5a..f54b341 100644 --- a/cwPianoScore.cpp +++ b/cwPianoScore.cpp @@ -239,9 +239,9 @@ namespace cw rc_t _parse_event_list( score_t* p, const object_t* cfg ) { rc_t rc; - const object_t* eventL; + const object_t* eventL = nullptr; - if((rc = cfg->getv( "evtL", eventL )) != kOkRC || eventL->is_list()==false ) + if((rc = cfg->getv( "evtL", eventL )) != kOkRC || eventL==nullptr || eventL->is_list()==false ) rc = cwLogError( rc, "Unable to locate the 'evtL' configuration tag."); else { @@ -494,7 +494,7 @@ unsigned cw::score::loc_to_next_note_on_measure( handle_t h, unsigned locId ) const event_t* e = _loc_to_event(p,locId); while( e != nullptr ) - if( midi::isNoteOn(e->status)) + if( midi::isNoteOn(e->status,e->d1)) return e->meas; return kInvalidId;