Browse Source

cmScore.h/c : Added cmScoreIdToEvt() and add 'vel' field to cmScoreEvt_t structure.

master
kevin 8 years ago
parent
commit
403b85eff4
2 changed files with 24 additions and 3 deletions
  1. 19
    2
      app/cmScore.c
  2. 5
    1
      app/cmScore.h

+ 19
- 2
app/cmScore.c View File

@@ -723,6 +723,7 @@ cmScRC_t _cmScParseNoteOn( cmSc_t* p, unsigned rowIdx, cmScoreEvt_t* s, unsigned
723 723
   unsigned        dynVal = kInvalidDynScId;
724 724
   const cmChar_t* sciPitch;
725 725
   cmMidiByte_t    midiPitch;
726
+  cmMidiByte_t    midiVel;
726 727
   const cmChar_t* attr;
727 728
   double          secs;
728 729
   double          durSecs;
@@ -742,6 +743,9 @@ cmScRC_t _cmScParseNoteOn( cmSc_t* p, unsigned rowIdx, cmScoreEvt_t* s, unsigned
742 743
           
743 744
   if((midiPitch = cmSciPitchToMidi(sciPitch)) == kInvalidMidiPitch)
744 745
     return cmErrMsg(&p->err,kSyntaxErrScRC,"Unable to convert the scientific pitch '%s' to a MIDI value. ");
746
+
747
+  if((midiVel = cmCsvCellUInt( p->cH,rowIdx,kD1ColScIdx)) >= kInvalidMidiVelocity )
748
+    return cmErrMsg(&p->err,kSyntaxErrScRC,"An invalid MIDI velocity (%i) was encountered.",midiVel);
745 749
   
746 750
   // get the sec's field - or DBL_MAX if it is not set
747 751
   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
812 816
   s->type       = kNonEvtScId;
813 817
   s->secs       = secs;
814 818
   s->pitch      = midiPitch;
819
+  s->vel        = midiVel;
815 820
   s->flags      = flags;
816 821
   s->dynVal     = dynVal; 
817 822
   s->barNumb    = barNumb;
@@ -1513,7 +1518,7 @@ cmScRC_t _cmScInitLocArray( cmSc_t* p )
1513 1518
   for(i=1; i<p->cnt; ++i )
1514 1519
   {
1515 1520
     if( p->array[i].secs < p->array[i-1].secs )
1516
-      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);
1521
+      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);
1517 1522
 
1518 1523
     if( (p->array[i].secs - p->array[i-1].secs) > maxDSecs )
1519 1524
       ++p->locCnt;
@@ -1673,7 +1678,7 @@ cmScoreEvt_t* cmScoreEvt( cmScH_t h, unsigned idx )
1673 1678
   return p->array + idx;
1674 1679
 }
1675 1680
 
1676
-cmScoreEvt_t* cmScoreBarEvt( cmScH_t h, unsigned barNumb )
1681
+const cmScoreEvt_t* cmScoreBarEvt( cmScH_t h, unsigned barNumb )
1677 1682
 {
1678 1683
   cmSc_t* p = _cmScHandleToPtr(h);
1679 1684
   unsigned i = 0;
@@ -1684,6 +1689,18 @@ cmScoreEvt_t* cmScoreBarEvt( cmScH_t h, unsigned barNumb )
1684 1689
   return NULL;
1685 1690
 }
1686 1691
 
1692
+const cmScoreEvt_t* cmScoreIdToEvt( cmScH_t h, unsigned csvEventId )
1693
+{
1694
+  cmSc_t* p = _cmScHandleToPtr(h);
1695
+  unsigned i = 0;
1696
+  for(; i<p->cnt; ++i)
1697
+    if( p->array[i].csvEventId==csvEventId )
1698
+      return p->array + i;
1699
+
1700
+  return NULL;
1701
+}
1702
+
1703
+
1687 1704
 unsigned      cmScoreSectionCount( cmScH_t h )
1688 1705
 { 
1689 1706
   cmSc_t* p = _cmScHandleToPtr(h);

+ 5
- 1
app/cmScore.h View File

@@ -87,6 +87,7 @@ extern "C" {
87 87
     unsigned     index;        // Index of this event in the event array.
88 88
     unsigned     locIdx;       // Index of the location containing this event
89 89
     cmMidiByte_t pitch;        // MIDI pitch of this note or the MIDI pedal id of pedal down/up msg (64=sustain 65=sostenuto 66=soft)
90
+    cmMidiByte_t vel;          // MIDI velocity of this note
90 91
     unsigned     flags;        // Attribute flags for this event
91 92
     unsigned     dynVal;       // Dynamcis value pppp to ffff (1 to 11) for this note.
92 93
     double       frac;         // Note's time value for tempo and non-grace evenness notes.
@@ -185,7 +186,10 @@ extern "C" {
185 186
   cmScoreEvt_t* cmScoreEvt( cmScH_t h, unsigned idx );
186 187
 
187 188
   // Given a bar number return the associated 'bar' event record.
188
-  cmScoreEvt_t* cmScoreBarEvt( cmScH_t h, unsigned barNumb );
189
+  const cmScoreEvt_t* cmScoreBarEvt( cmScH_t h, unsigned barNumb );
190
+
191
+  // Given a csvEventId return the associated event
192
+  const cmScoreEvt_t* cmScoreIdToEvt( cmScH_t h, unsigned csvEventId );
189 193
 
190 194
   // Access section records
191 195
   unsigned      cmScoreSectionCount( cmScH_t h );

Loading…
Cancel
Save