libcm is a C development framework with an emphasis on audio signal processing applications.
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

cmScore.h 11KB

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