libcm is a C development framework with an emphasis on audio signal processing applications.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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