libcm is a C development framework with an emphasis on audio signal processing applications.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

cmScore.h 10KB

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