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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. #ifndef cmTimeLine_h
  2. #define cmTimeLine_h
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. typedef cmHandle_t cmTlH_t;
  7. typedef cmRC_t cmTlRC_t;
  8. enum
  9. {
  10. kOkTlRC = cmOkRC,
  11. kLHeapFailTlRC,
  12. kParseFailTlRC,
  13. kJsonFailTlRC,
  14. kDuplNameTlRC,
  15. kRefNotFoundTlRC,
  16. kAudioFileFailTlRC,
  17. kMidiFileFailTlRC,
  18. kTypeCvtFailTlRC,
  19. kUnknownRecdTypeTlRC,
  20. kFinalizeFailTlRC,
  21. kInvalidSeqIdTlRC,
  22. kOnsetFailTlRC,
  23. kAssertFailTlRC
  24. };
  25. typedef enum
  26. {
  27. kMidiFileTlId = 0x01,
  28. kMidiEvtTlId = 0x02,
  29. kAudioFileTlId = 0x03,
  30. kAudioEvtTlId = 0x04,
  31. kMarkerTlId = 0x05
  32. } cmTlObjTypeId_t;
  33. enum
  34. {
  35. kReservedTlFl = 0x01,
  36. kNoWriteTlFl = 0x02 // do not write this object in cmTimeLineWrite()
  37. };
  38. // marker types
  39. enum
  40. {
  41. kAudioMarkTlId,
  42. kAudioOnsetMarkTlId,
  43. kMidiOnsetMarkTlId
  44. };
  45. typedef void (*cmTlCb_t)( void* arg, const void* data, unsigned byteCnt );
  46. typedef struct cmTlObj_str
  47. {
  48. void* reserved; // pt's to _cmTlObj_t
  49. unsigned seqId; // sequence this object is assigned to
  50. const cmChar_t* name; // text name of this object
  51. unsigned uid; // generated unique id for this object
  52. cmTlObjTypeId_t typeId; // type of the object
  53. struct cmTlObj_str* ref; // time reference object
  54. int begSmpIdx; // start time of this object as an offset from the start time of the reference object
  55. unsigned durSmpCnt; // duration of this object
  56. int seqSmpIdx; // absolute start time of this object within the sequence
  57. const cmChar_t* text; // points to text assoc'd with this node (file name for audio/midi file, marker text)
  58. unsigned flags; // see kXXXTlFl
  59. void* userDataPtr; // user customizable data pointer
  60. } cmTlObj_t;
  61. typedef struct
  62. {
  63. cmTlObj_t obj;
  64. cmMidiFileH_t h;
  65. unsigned noteOnCnt;
  66. cmChar_t* fn;
  67. } cmTlMidiFile_t;
  68. // MIDI events generated from MIDI files reference the previous
  69. // MIDI event and the first event in the file references the
  70. // file object. The 'begSmpIdx' is therefore a delta value
  71. // from the previous event.
  72. typedef struct
  73. {
  74. cmTlObj_t obj; //
  75. unsigned midiFileObjId;
  76. const cmMidiTrackMsg_t* msg; // w/ dticks converted to samples
  77. } cmTlMidiEvt_t;
  78. typedef struct
  79. {
  80. cmTlObj_t obj;
  81. cmAudioFileH_t h;
  82. cmAudioFileInfo_t info;
  83. cmChar_t* fn;
  84. } cmTlAudioFile_t;
  85. typedef struct
  86. {
  87. cmTlObj_t obj;
  88. cmAudioFileH_t h;
  89. unsigned smpIdx;
  90. unsigned smpCnt;
  91. cmChar_t* text;
  92. } cmTlAudioEvt_t;
  93. typedef struct
  94. {
  95. cmTlObj_t obj;
  96. unsigned typeId; // marker type see kXXXMarkTlId above.
  97. const cmChar_t* text;
  98. unsigned bar; // measure (bar) in which this marker starts
  99. const cmChar_t* sectionStr; // the section in which this marker starts
  100. } cmTlMarker_t;
  101. extern cmTlH_t cmTimeLineNullHandle;
  102. //
  103. cmTlRC_t cmTimeLineInitialize( cmCtx_t* ctx, cmTlH_t* hp, cmTlCb_t cbFunc, void* cbArg, const cmChar_t* prefixPath );
  104. cmTlRC_t cmTimeLineInitializeFromFile( cmCtx_t* ctx, cmTlH_t* hp, cmTlCb_t cbFunc, void* cbArg, const cmChar_t* fn, const cmChar_t* prefixPath );
  105. const cmChar_t* cmTimeLineFileName( cmTlH_t h );
  106. cmTlRC_t cmTimeLineFinalize( cmTlH_t* hp );
  107. bool cmTimeLineIsValid( cmTlH_t h );
  108. double cmTimeLineSampleRate( cmTlH_t h );
  109. // Convert global (sequence) time to a time relative to an object.
  110. int cmTimeLineSeqToLocalSampleIndex( int seqSmpIdx, cmTlObj_t* localObjPtr );
  111. // Given cmTlObj_t.uid return a pointer to the associated record.
  112. // seqId is optional (dflt:cmInvalidId)
  113. cmTlObj_t* cmTimeLineIdToObj( cmTlH_t h, unsigned seqId, unsigned uid );
  114. // Return the object following 'p' assigned to 'seqId'.
  115. // If 'p' is NULL then return the first object assigned to seqId.
  116. // If 'seqId' is set to cmInvalidId then return the next object on any seq.
  117. // If no objects follow 'p' on the specified sequence then return NULL.
  118. cmTlObj_t* cmTimeLineNextObj( cmTlH_t h, cmTlObj_t* p, unsigned seqId );
  119. // Same as cmTimeLineNextObj() but returns next object whose type matches 'typeId'.
  120. cmTlObj_t* cmTimeLineNextTypeObj( cmTlH_t h, cmTlObj_t* p, unsigned seqId, unsigned typeId );
  121. cmTlMidiFile_t* cmTlNextMidiFileObjPtr( cmTlH_t h, cmTlObj_t* op, unsigned seqId );
  122. cmTlAudioFile_t* cmTlNextAudioFileObjPtr( cmTlH_t h, cmTlObj_t* op, unsigned seqId );
  123. cmTlMidiEvt_t* cmTlNextMidiEvtObjPtr( cmTlH_t h, cmTlObj_t* op, unsigned seqId );
  124. cmTlAudioEvt_t* cmTlNextAudioEvtObjPtr( cmTlH_t h, cmTlObj_t* op, unsigned seqId );
  125. cmTlMarker_t* cmTlNextMarkerObjPtr( cmTlH_t h, cmTlObj_t* op, unsigned seqId );
  126. cmTlObj_t* cmTlIdToObjPtr( cmTlH_t h, unsigned uid );
  127. // Cast a genereic cmTlObj_t pointer to a specific type.
  128. cmTlMidiFile_t* cmTimeLineMidiFileObjPtr( cmTlH_t h, cmTlObj_t* op );
  129. cmTlAudioFile_t* cmTimeLineAudioFileObjPtr( cmTlH_t h, cmTlObj_t* op );
  130. cmTlMidiEvt_t* cmTimeLineMidiEvtObjPtr( cmTlH_t h, cmTlObj_t* op );
  131. cmTlAudioEvt_t* cmTimeLineAudioEvtObjPtr( cmTlH_t h, cmTlObj_t* op );
  132. cmTlMarker_t* cmTimeLineMarkerObjPtr( cmTlH_t h, cmTlObj_t* op );
  133. // Same as cmTimeLineXXXObjPtr() but does not generate an error when
  134. // 'op' does not point to the correct type. These function quietly
  135. // return NULL if the requested type does not match or 'op' == NULL.
  136. cmTlMidiFile_t* cmTlMidiFileObjPtr( cmTlH_t h, cmTlObj_t* op );
  137. cmTlAudioFile_t* cmTlAudioFileObjPtr( cmTlH_t h, cmTlObj_t* op );
  138. cmTlMidiEvt_t* cmTlMidiEvtObjPtr( cmTlH_t h, cmTlObj_t* op );
  139. cmTlAudioEvt_t* cmTlAudioEvtObjPtr( cmTlH_t h, cmTlObj_t* op );
  140. cmTlMarker_t* cmTlMarkerObjPtr( cmTlH_t h, cmTlObj_t* op );
  141. cmTlAudioFile_t* cmTimeLineFindAudioFile( cmTlH_t h, const cmChar_t* fn );
  142. cmTlMidiFile_t* cmTimeLineFindMidiFile( cmTlH_t h, const cmChar_t* fn );
  143. cmTlAudioFile_t* cmTimeLineAudioFileAtTime( cmTlH_t h, unsigned seqId, unsigned seqSmpIdx );
  144. cmTlMidiFile_t* cmTimeLineMidiFileAtTime( cmTlH_t h, unsigned seqId, unsigned seqSmpIdx );
  145. cmTlMidiEvt_t* cmTimeLineMidiEvtAtTime( cmTlH_t h, unsigned seqId, unsigned seqSmpIdx );
  146. cmTlMarker_t* cmTimeLineMarkerAtTime( cmTlH_t h, unsigned seqId, unsigned seqSmpIdx );
  147. cmTlAudioFile_t* cmTimeLineAudioFileAtTime( cmTlH_t h, unsigned seqId, unsigned seqSmpIdx );
  148. cmTlMidiFile_t* cmTimeLineMidiFileAtTime( cmTlH_t h, unsigned seqId, unsigned seqSmpIdx );
  149. cmTlMidiEvt_t* cmTimeLineMidiEvtAtTime( cmTlH_t h, unsigned seqId, unsigned seqSmpIdx );
  150. cmTlMarker_t* cmTimeLineMarkerAtTime( cmTlH_t h, unsigned seqId, unsigned seqSmpIdx );
  151. cmTlMarker_t* cmTimeLineMarkerFind( cmTlH_t h, const cmChar_t* markText );
  152. // 'typeId' = kAudioFileTlId, kMidiFileTId, kMarkerTlId.
  153. // 'nameStr' and 'refObjNameStr' may be NULL.
  154. cmTlRC_t cmTimeLineInsert(
  155. cmTlH_t h,
  156. const cmChar_t* nameStr,
  157. unsigned typeId,
  158. const cmChar_t* fn_or_markerStr,
  159. int begSmpIdx,
  160. unsigned durSmpCnt,
  161. const cmChar_t* refObjNameStr,
  162. unsigned seqId );
  163. // See src/data/tl0.json for an example JSON file.
  164. cmTlRC_t cmTimeLineReadJson( cmTlH_t* hp, const cmChar_t* ifn );
  165. // Return a count of sequences contained within this timeline.
  166. unsigned cmTimeLineSeqCount( cmTlH_t h );
  167. // Make notifications for all records belonging to the sequence.
  168. cmTlRC_t cmTimeLineSeqNotify( cmTlH_t h, unsigned seqId );
  169. // Create and make notification for audio/MIDI onset marks.
  170. cmTlRC_t cmTimeLineGenOnsetMarks( cmTlH_t h, unsigned seqId );
  171. cmTlRC_t cmTimeLineDeleteOnsetMarks( cmTlH_t h, unsigned seqId );
  172. cmTlRC_t cmTimeLineWrite( cmTlH_t h, const cmChar_t* fn );
  173. cmTlRC_t cmTimeLinePrint( cmTlH_t h, cmRpt_t* rpt );
  174. cmTlRC_t cmTimeLinePrintFn( cmCtx_t* ctx, const cmChar_t* tlFn, const cmChar_t* prefixPath, cmRpt_t* rpt );
  175. cmTlRC_t cmTimeLineTest( cmCtx_t* ctx, const cmChar_t* tlFn, const cmChar_t* prefixPath );
  176. // The time-line notifies listeners of initialization and finalization
  177. // events via calling a cmTlCbFunc_t function. The argument to this
  178. // function is a serialized cmTlUiMsg_t. The recipient of the callback
  179. // can extract information from this message using cmTimeLineDecode()
  180. // to form a cmTlUiMsg_t record. Note that all pointers internal to the
  181. // cmTlUiMsg_t point into the message buffer itself.
  182. // id's used to indicate the type of a serialized object
  183. typedef enum
  184. {
  185. kInvalidMsgTlId,
  186. kInitMsgTlId, // A a set of time-line objects is about to be transmitted
  187. kFinalMsgTlId, // A time-line object is being finalized.
  188. kDoneMsgTlId, // All the objects assoc'd with a time line seq-notify have been sent.
  189. kInsertMsgTlId, // A time-line object was inserted.
  190. } cmTlUiMsgTypeId_t;
  191. typedef struct
  192. {
  193. cmTlUiMsgTypeId_t msgId; // See cmTlUiMsgTypeId_t.
  194. unsigned objId; // Set to cmTlObj_t.uid
  195. unsigned seqId; // Sequence id
  196. double srate; // Only valid with kInitMsgTlId.
  197. unsigned seqCnt; // Only valid with kInitMsgTlId.
  198. } cmTlUiMsg_t;
  199. // Decode a serialized cmTlObj_t as passed to the cmTlCb_t listener
  200. // callback function.
  201. cmTlRC_t cmTimeLineDecode( const void* msg, unsigned msgByteCnt, cmTlUiMsg_t* uiMsg );
  202. #ifdef __cplusplus
  203. }
  204. #endif
  205. #endif