libcm is a C development framework with an emphasis on audio signal processing applications.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cmScore.h 9.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. #ifndef cmScore_h
  2. #define cmScore_h
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. enum
  7. {
  8. kOkScRC = cmOkRC,
  9. kCsvFailScRC,
  10. kSyntaxErrScRC,
  11. kInvalidIdxScRC,
  12. kTimeLineFailScRC,
  13. kInvalidDynRefCntScRC
  14. };
  15. enum
  16. {
  17. kInvalidEvtScId = 0,
  18. kTimeSigEvtScId,
  19. kKeySigEvtScId,
  20. kTempoEvtScId,
  21. kTrackEvtScId,
  22. kTextEvtScId,
  23. kEOTrackEvtScId,
  24. kCopyEvtScId,
  25. kBlankEvtScId,
  26. kBarEvtScId,
  27. kPgmEvtScId,
  28. kCtlEvtScId,
  29. kNonEvtScId
  30. };
  31. // Flags used by cmScoreEvt_t.flags
  32. enum
  33. {
  34. kEvenScFl = 0x01, // This note is marked for evenness measurement
  35. kDynScFl = 0x02, // This note is marked for dynamics measurement
  36. kTempoScFl = 0x04, // This note is marked for tempo measurement
  37. kSkipScFl = 0x08, // This isn't a real event (e.g. tied note) skip over it
  38. kGraceScFl = 0x10, // This is a grace note
  39. kInvalidScFl = 0x20 // This note has a calculated time
  40. };
  41. // Id's used by cmScoreSet_t.varId and as indexes into
  42. // cmScoreSection_t.vars[].
  43. enum
  44. {
  45. kEvenVarScId,
  46. kDynVarScId,
  47. kTempoVarScId,
  48. kScVarCnt
  49. };
  50. struct cmScoreLoc_str;
  51. struct cmScoreSet_str;
  52. // The score can be divided into arbitrary non-overlapping sections.
  53. typedef struct
  54. {
  55. const cmChar_t* label; // section label
  56. unsigned index; // index of this record in the internal section array
  57. struct cmScoreLoc_str* locPtr; // location where this section starts
  58. unsigned begEvtIndex; // score element index where this section starts
  59. unsigned setCnt; // Count of elements in setArray[]
  60. struct cmScoreSet_str** setArray; // Ptrs to sets which are applied to this section.
  61. double vars[ kScVarCnt ]; // Set to DBL_MAX by default.
  62. } cmScoreSection_t;
  63. typedef struct
  64. {
  65. unsigned type; // Event type
  66. double secs; // Time location in seconds
  67. double durSecs; // Duration in seconds
  68. unsigned index; // Index of this event in the event array.
  69. unsigned locIdx; // Index of the location containing this event
  70. cmMidiByte_t pitch; // MIDI pitch of this note
  71. unsigned flags; // Attribute flags for this event
  72. unsigned dynVal; // Dynamcis value pppp to ffff (1 to 11) for this note.
  73. double frac; // Note's time value for tempo and non-grace evenness notes.
  74. unsigned barNumb; // Bar id of the measure containing this event.
  75. unsigned barNoteIdx; // Index of this note in this bar
  76. unsigned csvRowNumb; // File row number (not index) from which this record originated
  77. unsigned perfSmpIdx; // Time this event was performed or cmInvalidIdx if the event was not performed.
  78. unsigned perfVel; // Velocity of the performed note or 0 if the note was not performed.
  79. unsigned perfDynLvl; // Index into dynamic level ref. array assoc'd with perfVel
  80. unsigned line; // Line number of this event in the score file.
  81. } cmScoreEvt_t;
  82. typedef struct cmScoreSet_str
  83. {
  84. unsigned varId; // See kXXXVarScId flags above
  85. cmScoreEvt_t** eleArray; // Events that make up this set in time order
  86. unsigned eleCnt; //
  87. cmScoreSection_t** sectArray; // Sections this set will be applied to
  88. unsigned sectCnt; //
  89. unsigned* symArray; // symArray[sectCnt] - symbol name of all variables represented by this set (e.g '1a-e', '1b-e', '2-t', etc)
  90. unsigned* costSymArray; // costSymArray[sectCnt] - same as symbols in symArray[] with 'c' prepended to front
  91. bool doneFl;
  92. double value;
  93. struct cmScoreSet_str* llink; // cmScoreLoc_t setList link
  94. } cmScoreSet_t;
  95. // All events which are simultaneous are collected into a single
  96. // cmScoreLoc_t record.
  97. typedef struct cmScoreLoc_str
  98. {
  99. unsigned index; // index of this location record
  100. double secs; // Time of this location
  101. unsigned evtCnt; // Count of events in evtArray[].
  102. cmScoreEvt_t** evtArray; // Events which occur at this time.
  103. unsigned barNumb; // Bar number this event is contained by.
  104. cmScoreSet_t* setList; // Set's which end on this time location (linked through cmScoreSet_t.llink)
  105. cmScoreSection_t* begSectPtr; // NULL if this location does not start a section
  106. } cmScoreLoc_t;
  107. typedef void (*cmScCb_t)( void* arg, const void* data, unsigned byteCnt );
  108. typedef cmRC_t cmScRC_t;
  109. typedef cmHandle_t cmScH_t;
  110. extern cmScH_t cmScNullHandle;
  111. const cmChar_t* cmScEvtTypeIdToLabel( unsigned id );
  112. const cmChar_t* cmScDynIdToLabel( unsigned id );
  113. // Initialize a score object from a CSV File generated from a score spreadsheet.
  114. // The dynRefArray[dynRefCnt] and cbFunc(cbArg) are optional if these
  115. // features are not used.
  116. // If provided the dynRefArray[] is copied into an internal array.
  117. // The physical array passed here therefore does not need to remain valid.
  118. // Set 'srate' to zero if the score will not be used to perform measurement calculations.
  119. // The symbol table is only necessary if valid symbols are to be assigned to the cmScoreSet_t.symArray[].
  120. cmScRC_t cmScoreInitialize( cmCtx_t* ctx, cmScH_t* hp, const cmChar_t* fn, double srate, const unsigned* dynRefArray, unsigned dynRefCnt, cmScCb_t cbFunc, void* cbArg, cmSymTblH_t stH );
  121. cmScRC_t cmScoreFinalize( cmScH_t* hp );
  122. // Filename of last successfuly loaded score file.
  123. const cmChar_t* cmScoreFileName( cmScH_t h );
  124. // Sample rate as set in cmScoreInitialize()
  125. double cmScoreSampleRate( cmScH_t h );
  126. // Validate the score handle
  127. bool cmScoreIsValid( cmScH_t h );
  128. // Access the score data.
  129. unsigned cmScoreEvtCount( cmScH_t h );
  130. cmScoreEvt_t* cmScoreEvt( cmScH_t h, unsigned idx );
  131. // Given a bar number return the associated 'bar' event record.
  132. cmScoreEvt_t* cmScoreBarEvt( cmScH_t h, unsigned barNumb );
  133. // Access section records
  134. unsigned cmScoreSectionCount( cmScH_t h );
  135. cmScoreSection_t* cmScoreSection( cmScH_t h, unsigned idx );
  136. // Access the score location data
  137. unsigned cmScoreLocCount( cmScH_t h );
  138. cmScoreLoc_t* cmScoreLoc( cmScH_t h, unsigned idx );
  139. void cmScorePrintLoc( cmScH_t h );
  140. // Return the location associated with a given score event.
  141. cmScoreLoc_t* cmScoreEvtLoc( cmScH_t h, const cmScoreEvt_t* evt );
  142. // Return the count of sets.
  143. unsigned cmScoreSetCount( cmScH_t h );
  144. // Make callbacks for all events in the score. The callbacks
  145. // contain cmScMsg_t records serialized as a byte stream.
  146. // Use cmScoreDecode() to convert the byte string to a
  147. // cmScMsg_t record.
  148. cmScRC_t cmScoreSeqNotify( cmScH_t h );
  149. void cmScoreClearPerfInfo( cmScH_t h );
  150. // Assign 'smpIdx' and 'vel' to the event matching 'pitch' at 'locIdx'
  151. // but do not trigger any variable calculations. Return true if as a
  152. // result of this call all events assigned to 'locIdx' have been received
  153. // otherwise return false.
  154. bool cmScoreSetPerfEvent( cmScH_t h, unsigned locIdx, unsigned smpIdx, unsigned pitch, unsigned vel );
  155. // Assign 'smpIdx' and 'vel' to the event matching 'pitch' at 'locIdx'
  156. // but and trigger any variable calculations which may happen on, or before, 'locIdx'.
  157. void cmScoreExecPerfEvent( cmScH_t h, unsigned locIdx, unsigned smpIdx, unsigned pitch, unsigned vel );
  158. // Assign 'value' to the section at, or before, 'locIdx'.
  159. void cmScoreSetPerfValue( cmScH_t h, unsigned locIdx, unsigned varId, double value );
  160. // Set the performed dynamic level of a score event.
  161. void cmScoreSetPerfDynLevel( cmScH_t h, unsigned evtIdx, unsigned dynLvl );
  162. typedef enum
  163. {
  164. kInvalidMsgScId,
  165. kBeginMsgScId,
  166. kEventMsgScId,
  167. kSectionMsgScId,
  168. kEndMsgScId,
  169. kVarMsgScId,
  170. kDynMsgScId
  171. } cmScMsgTypeId_t;
  172. typedef struct
  173. {
  174. unsigned varId; // see kXXXVarScId from cmScoreSet_t.varId
  175. double value; // value of a variable
  176. } cmScMeas_t;
  177. typedef struct
  178. {
  179. unsigned evtIdx;
  180. unsigned dynLvl;
  181. } cmScDyn_t;
  182. typedef struct
  183. {
  184. cmScMsgTypeId_t typeId;
  185. union
  186. {
  187. cmScoreEvt_t evt; // only used when typeId == kEventMsgScId
  188. cmScMeas_t meas; // only used when typeId == kVarMsgScId
  189. cmScoreSection_t sect; // only used when typeId == kSectionMsgScId
  190. cmScDyn_t dyn; // only used when typeId == kDynLvlMsgScId
  191. } u;
  192. } cmScMsg_t;
  193. // Decode a serialized cmScMsg_t from a byte stream as passed to the
  194. // cmScCb_t function.
  195. cmScRC_t cmScoreDecode( const void* msg, unsigned msgByteCnt, cmScMsg_t* );
  196. void cmScorePrint( cmScH_t h, cmRpt_t* rpt );
  197. void cmScoreTest( cmCtx_t* ctx, const cmChar_t* fn );
  198. #ifdef __cplusplus
  199. }
  200. #endif
  201. #endif