libcm is a C development framework with an emphasis on audio signal processing applications.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

cmScore.h 7.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. kInvalidScFl = 0x10 // This note has a calculated time
  39. };
  40. // Id's used by cmScoreSet_t.varId and as indexes into
  41. // cmScoreSection_t.vars[].
  42. enum
  43. {
  44. kEvenVarScId,
  45. kDynVarScId,
  46. kTempoVarScId,
  47. kScVarCnt
  48. };
  49. struct cmScoreLoc_str;
  50. struct cmScoreSet_str;
  51. // The score can be divided into arbitrary non-overlapping sections.
  52. typedef struct
  53. {
  54. const cmChar_t* label; // section label
  55. unsigned index; // index of this record in the internal section array
  56. struct cmScoreLoc_str* locPtr; // location where this section starts
  57. unsigned begEvtIndex; // score element index where this section starts
  58. unsigned setCnt; // Count of elements in setArray[]
  59. struct cmScoreSet_str** setArray; // Ptrs to sets which are applied to this section.
  60. double vars[ kScVarCnt ]; // Set to DBL_MAX by default.
  61. } cmScoreSection_t;
  62. typedef struct
  63. {
  64. unsigned type; // Event type
  65. double secs; // Time location in seconds
  66. double durSecs; // Duration in seconds
  67. unsigned index; // Index of this event in the event array.
  68. unsigned locIdx; // Index of the location containing this event
  69. cmMidiByte_t pitch; // MIDI pitch of this note
  70. unsigned flags; // Attribute flags for this event
  71. unsigned dynVal; // Dynamcis value pppp to ffff (1 to 11) for this note.
  72. unsigned barNumb; // Bar id of the measure containing this event.
  73. unsigned barNoteIdx; // Index of this note in this bar
  74. unsigned csvRowNumb; // File row number (not index) from which this record originated
  75. unsigned perfSmpIdx; // Time this event was performed or cmInvalidIdx if the event was not performed.
  76. unsigned perfVel; // Velocity of the performed note or 0 if the note was not performed.
  77. unsigned perfDynLvl; // Index into dynamic level ref. array assoc'd with perfVel
  78. } cmScoreEvt_t;
  79. typedef struct cmScoreSet_str
  80. {
  81. unsigned varId; // See kXXXVarScId flags above
  82. cmScoreEvt_t** eleArray; // Events that make up this set in time order
  83. unsigned eleCnt; //
  84. bool doneFl;
  85. double value;
  86. struct cmScoreSet_str* llink; // cmScoreLoc_t setList link
  87. } cmScoreSet_t;
  88. // All events which are simultaneous are collected into a single
  89. // cmScoreLoc_t record.
  90. typedef struct cmScoreLoc_str
  91. {
  92. unsigned index; // index of this location record
  93. double secs; // Time of this location
  94. unsigned evtCnt; // Count of events in evtArray[].
  95. cmScoreEvt_t** evtArray; // Events which occur at this time.
  96. unsigned barNumb; // Bar number this event is contained by.
  97. cmScoreSet_t* setList; // Set's which end on this time location (linked through cmScoreSet_t.llink)
  98. cmScoreSection_t* begSectPtr; // NULL if this location does not start a section
  99. } cmScoreLoc_t;
  100. typedef void (*cmScCb_t)( void* arg, const void* data, unsigned byteCnt );
  101. typedef cmRC_t cmScRC_t;
  102. typedef cmHandle_t cmScH_t;
  103. typedef void (*cmScCb_t)( void* arg, const void* data, unsigned byteCnt );
  104. extern cmScH_t cmScNullHandle;
  105. const cmChar_t* cmScEvtTypeIdToLabel( unsigned id );
  106. const cmChar_t* cmScDynIdToLabel( unsigned id );
  107. // Initialize a score object from a CSV File generated from a score spreadsheet.
  108. // The dynRefArray[dynRefCnt] and cbFunc(cbArg) are optional if these
  109. // features are not used.
  110. // If provided the dynRefArray[] is copied into an internal array.
  111. // The physical array passed here therefore does not need to remain valid.
  112. cmScRC_t cmScoreInitialize( cmCtx_t* ctx, cmScH_t* hp, const cmChar_t* fn, const unsigned* dynRefArray, unsigned dynRefCnt, cmScCb_t cbFunc, void* cbArg );
  113. cmScRC_t cmScoreFinalize( cmScH_t* hp );
  114. // Filename of last successfuly loaded score file.
  115. const cmChar_t* cmScoreFileName( cmScH_t h );
  116. // Validate the score handle
  117. bool cmScoreIsValid( cmScH_t h );
  118. // Access the score data.
  119. unsigned cmScoreEvtCount( cmScH_t h );
  120. cmScoreEvt_t* cmScoreEvt( cmScH_t h, unsigned idx );
  121. // Access section records
  122. unsigned cmScoreSectionCount( cmScH_t h );
  123. cmScoreSection_t* cmScoreSection( cmScH_t h, unsigned idx );
  124. // Access the score location data
  125. unsigned cmScoreLocCount( cmScH_t h );
  126. cmScoreLoc_t* cmScoreLoc( cmScH_t h, unsigned idx );
  127. void cmScorePrintLoc( cmScH_t h );
  128. // Make callbacks for all events in the score. The callbacks
  129. // contain cmScMsg_t records serialized as a byte stream.
  130. // Use cmScoreDecode() to convert the byte string to a
  131. // cmScMsg_t record.
  132. cmScRC_t cmScoreSeqNotify( cmScH_t h );
  133. void cmScoreClearPerfInfo( cmScH_t h );
  134. // Assign 'smpIdx' and 'vel' to the event matching 'pitch' at 'locIdx'
  135. // but do not trigger any variable calculations. Return true if as a
  136. // result of this call all events assigned to 'locIdx' have been received
  137. // otherwise return false.
  138. bool cmScoreSetPerfEvent( cmScH_t h, unsigned locIdx, unsigned smpIdx, unsigned pitch, unsigned vel );
  139. // Assign 'smpIdx' and 'vel' to the event matching 'pitch' at 'locIdx'
  140. // but and trigger any variable calculations which may happen on, or before, 'locIdx'.
  141. void cmScoreExecPerfEvent( cmScH_t h, unsigned locIdx, unsigned smpIdx, unsigned pitch, unsigned vel );
  142. // Assign 'value' to the section at, or before, 'locIdx'.
  143. void cmScoreSetPerfValue( cmScH_t h, unsigned locIdx, unsigned varId, double value );
  144. // Set the performed dynamic level of a score event.
  145. void cmScoreSetPerfDynLevel( cmScH_t h, unsigned evtIdx, unsigned dynLvl );
  146. typedef enum
  147. {
  148. kInvalidMsgScId,
  149. kBeginMsgScId,
  150. kEventMsgScId,
  151. kSectionMsgScId,
  152. kEndMsgScId,
  153. kVarMsgScId,
  154. kDynMsgScId
  155. } cmScMsgTypeId_t;
  156. typedef struct
  157. {
  158. unsigned varId; // see kXXXVarScId from cmScoreSet_t.varId
  159. double value; // value of a variable
  160. } cmScMeas_t;
  161. typedef struct
  162. {
  163. unsigned evtIdx;
  164. unsigned dynLvl;
  165. } cmScDyn_t;
  166. typedef struct
  167. {
  168. cmScMsgTypeId_t typeId;
  169. union
  170. {
  171. cmScoreEvt_t evt; // only used when typeId == kEventMsgScId
  172. cmScMeas_t meas; // only used when typeId == kVarMsgScId
  173. cmScoreSection_t sect; // only used when typeId == kSectionMsgScId
  174. cmScDyn_t dyn; // only used when typeId == kDynLvlMsgScId
  175. } u;
  176. } cmScMsg_t;
  177. // Decode a serialized cmScMsg_t from a byte stream as passed to the
  178. // cmScCb_t function.
  179. cmScRC_t cmScoreDecode( const void* msg, unsigned msgByteCnt, cmScMsg_t* );
  180. void cmScorePrint( cmScH_t h, cmRpt_t* rpt );
  181. void cmScoreTest( cmCtx_t* ctx, const cmChar_t* fn );
  182. #ifdef __cplusplus
  183. }
  184. #endif
  185. #endif