From 403b85eff47c36bc7d9c61c36b543a2682b24ff8 Mon Sep 17 00:00:00 2001 From: kevin Date: Thu, 16 Jun 2016 12:51:55 -0400 Subject: [PATCH] cmScore.h/c : Added cmScoreIdToEvt() and add 'vel' field to cmScoreEvt_t structure. --- app/cmScore.c | 21 +++++++++++++++++++-- app/cmScore.h | 6 +++++- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/app/cmScore.c b/app/cmScore.c index 6010cb8..a88f032 100644 --- a/app/cmScore.c +++ b/app/cmScore.c @@ -723,6 +723,7 @@ cmScRC_t _cmScParseNoteOn( cmSc_t* p, unsigned rowIdx, cmScoreEvt_t* s, unsigned unsigned dynVal = kInvalidDynScId; const cmChar_t* sciPitch; cmMidiByte_t midiPitch; + cmMidiByte_t midiVel; const cmChar_t* attr; double secs; double durSecs; @@ -742,6 +743,9 @@ cmScRC_t _cmScParseNoteOn( cmSc_t* p, unsigned rowIdx, cmScoreEvt_t* s, unsigned if((midiPitch = cmSciPitchToMidi(sciPitch)) == kInvalidMidiPitch) return cmErrMsg(&p->err,kSyntaxErrScRC,"Unable to convert the scientific pitch '%s' to a MIDI value. "); + + if((midiVel = cmCsvCellUInt( p->cH,rowIdx,kD1ColScIdx)) >= kInvalidMidiVelocity ) + return cmErrMsg(&p->err,kSyntaxErrScRC,"An invalid MIDI velocity (%i) was encountered.",midiVel); // get the sec's field - or DBL_MAX if it is not set if((secs = cmCsvCellDouble(p->cH, rowIdx, kSecsColScIdx )) == DBL_MAX) // Returns DBL_MAX on error. @@ -812,6 +816,7 @@ cmScRC_t _cmScParseNoteOn( cmSc_t* p, unsigned rowIdx, cmScoreEvt_t* s, unsigned s->type = kNonEvtScId; s->secs = secs; s->pitch = midiPitch; + s->vel = midiVel; s->flags = flags; s->dynVal = dynVal; s->barNumb = barNumb; @@ -1513,7 +1518,7 @@ cmScRC_t _cmScInitLocArray( cmSc_t* p ) for(i=1; icnt; ++i ) { if( p->array[i].secs < p->array[i-1].secs ) - rc = cmErrMsg(&p->err,kSyntaxErrScRC,"The time associated with the score entry on line %i is less than the previous line.",p->array[i].csvRowNumb); + rc = cmErrMsg(&p->err,kSyntaxErrScRC,"The time (%f) associated with the score entry on line %i is less than the previous line (%f).",p->array[i].csvRowNumb,p->array[i].secs,p->array[i-1].secs); if( (p->array[i].secs - p->array[i-1].secs) > maxDSecs ) ++p->locCnt; @@ -1673,7 +1678,7 @@ cmScoreEvt_t* cmScoreEvt( cmScH_t h, unsigned idx ) return p->array + idx; } -cmScoreEvt_t* cmScoreBarEvt( cmScH_t h, unsigned barNumb ) +const cmScoreEvt_t* cmScoreBarEvt( cmScH_t h, unsigned barNumb ) { cmSc_t* p = _cmScHandleToPtr(h); unsigned i = 0; @@ -1684,6 +1689,18 @@ cmScoreEvt_t* cmScoreBarEvt( cmScH_t h, unsigned barNumb ) return NULL; } +const cmScoreEvt_t* cmScoreIdToEvt( cmScH_t h, unsigned csvEventId ) +{ + cmSc_t* p = _cmScHandleToPtr(h); + unsigned i = 0; + for(; icnt; ++i) + if( p->array[i].csvEventId==csvEventId ) + return p->array + i; + + return NULL; +} + + unsigned cmScoreSectionCount( cmScH_t h ) { cmSc_t* p = _cmScHandleToPtr(h); diff --git a/app/cmScore.h b/app/cmScore.h index d8cda18..8b94537 100644 --- a/app/cmScore.h +++ b/app/cmScore.h @@ -87,6 +87,7 @@ extern "C" { unsigned index; // Index of this event in the event array. unsigned locIdx; // Index of the location containing this event cmMidiByte_t pitch; // MIDI pitch of this note or the MIDI pedal id of pedal down/up msg (64=sustain 65=sostenuto 66=soft) + cmMidiByte_t vel; // MIDI velocity of this note unsigned flags; // Attribute flags for this event unsigned dynVal; // Dynamcis value pppp to ffff (1 to 11) for this note. double frac; // Note's time value for tempo and non-grace evenness notes. @@ -185,7 +186,10 @@ extern "C" { cmScoreEvt_t* cmScoreEvt( cmScH_t h, unsigned idx ); // Given a bar number return the associated 'bar' event record. - cmScoreEvt_t* cmScoreBarEvt( cmScH_t h, unsigned barNumb ); + const cmScoreEvt_t* cmScoreBarEvt( cmScH_t h, unsigned barNumb ); + + // Given a csvEventId return the associated event + const cmScoreEvt_t* cmScoreIdToEvt( cmScH_t h, unsigned csvEventId ); // Access section records unsigned cmScoreSectionCount( cmScH_t h );