libcm is a C development framework with an emphasis on audio signal processing applications.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

cmScore.h 11KB

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