Ver código fonte

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

master
kevin 8 anos atrás
pai
commit
403b85eff4
2 arquivos alterados com 24 adições e 3 exclusões
  1. 19
    2
      app/cmScore.c
  2. 5
    1
      app/cmScore.h

+ 19
- 2
app/cmScore.c Ver arquivo

723
   unsigned        dynVal = kInvalidDynScId;
723
   unsigned        dynVal = kInvalidDynScId;
724
   const cmChar_t* sciPitch;
724
   const cmChar_t* sciPitch;
725
   cmMidiByte_t    midiPitch;
725
   cmMidiByte_t    midiPitch;
726
+  cmMidiByte_t    midiVel;
726
   const cmChar_t* attr;
727
   const cmChar_t* attr;
727
   double          secs;
728
   double          secs;
728
   double          durSecs;
729
   double          durSecs;
742
           
743
           
743
   if((midiPitch = cmSciPitchToMidi(sciPitch)) == kInvalidMidiPitch)
744
   if((midiPitch = cmSciPitchToMidi(sciPitch)) == kInvalidMidiPitch)
744
     return cmErrMsg(&p->err,kSyntaxErrScRC,"Unable to convert the scientific pitch '%s' to a MIDI value. ");
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
   // get the sec's field - or DBL_MAX if it is not set
750
   // get the sec's field - or DBL_MAX if it is not set
747
   if((secs =  cmCsvCellDouble(p->cH, rowIdx, kSecsColScIdx )) == DBL_MAX) // Returns DBL_MAX on error.
751
   if((secs =  cmCsvCellDouble(p->cH, rowIdx, kSecsColScIdx )) == DBL_MAX) // Returns DBL_MAX on error.
812
   s->type       = kNonEvtScId;
816
   s->type       = kNonEvtScId;
813
   s->secs       = secs;
817
   s->secs       = secs;
814
   s->pitch      = midiPitch;
818
   s->pitch      = midiPitch;
819
+  s->vel        = midiVel;
815
   s->flags      = flags;
820
   s->flags      = flags;
816
   s->dynVal     = dynVal; 
821
   s->dynVal     = dynVal; 
817
   s->barNumb    = barNumb;
822
   s->barNumb    = barNumb;
1513
   for(i=1; i<p->cnt; ++i )
1518
   for(i=1; i<p->cnt; ++i )
1514
   {
1519
   {
1515
     if( p->array[i].secs < p->array[i-1].secs )
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
     if( (p->array[i].secs - p->array[i-1].secs) > maxDSecs )
1523
     if( (p->array[i].secs - p->array[i-1].secs) > maxDSecs )
1519
       ++p->locCnt;
1524
       ++p->locCnt;
1673
   return p->array + idx;
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
   cmSc_t* p = _cmScHandleToPtr(h);
1683
   cmSc_t* p = _cmScHandleToPtr(h);
1679
   unsigned i = 0;
1684
   unsigned i = 0;
1684
   return NULL;
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
 unsigned      cmScoreSectionCount( cmScH_t h )
1704
 unsigned      cmScoreSectionCount( cmScH_t h )
1688
 { 
1705
 { 
1689
   cmSc_t* p = _cmScHandleToPtr(h);
1706
   cmSc_t* p = _cmScHandleToPtr(h);

+ 5
- 1
app/cmScore.h Ver arquivo

87
     unsigned     index;        // Index of this event in the event array.
87
     unsigned     index;        // Index of this event in the event array.
88
     unsigned     locIdx;       // Index of the location containing this event
88
     unsigned     locIdx;       // Index of the location containing this event
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)
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
     unsigned     flags;        // Attribute flags for this event
91
     unsigned     flags;        // Attribute flags for this event
91
     unsigned     dynVal;       // Dynamcis value pppp to ffff (1 to 11) for this note.
92
     unsigned     dynVal;       // Dynamcis value pppp to ffff (1 to 11) for this note.
92
     double       frac;         // Note's time value for tempo and non-grace evenness notes.
93
     double       frac;         // Note's time value for tempo and non-grace evenness notes.
185
   cmScoreEvt_t* cmScoreEvt( cmScH_t h, unsigned idx );
186
   cmScoreEvt_t* cmScoreEvt( cmScH_t h, unsigned idx );
186
 
187
 
187
   // Given a bar number return the associated 'bar' event record.
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
   // Access section records
194
   // Access section records
191
   unsigned      cmScoreSectionCount( cmScH_t h );
195
   unsigned      cmScoreSectionCount( cmScH_t h );

Carregando…
Cancelar
Salvar