libcm is a C development framework with an emphasis on audio signal processing applications.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

cmTimeLine.h 9.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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. const cmChar_t* cmTimeLinePrefixPath( cmTlH_t h );
  107. cmTlRC_t cmTimeLineFinalize( cmTlH_t* hp );
  108. bool cmTimeLineIsValid( cmTlH_t h );
  109. double cmTimeLineSampleRate( cmTlH_t h );
  110. // Convert global (sequence) time to a time relative to an object.
  111. int cmTimeLineSeqToLocalSampleIndex( int seqSmpIdx, cmTlObj_t* localObjPtr );
  112. // Given cmTlObj_t.uid return a pointer to the associated record.
  113. // seqId is optional (dflt:cmInvalidId)
  114. cmTlObj_t* cmTimeLineIdToObj( cmTlH_t h, unsigned seqId, unsigned uid );
  115. // Return the object following 'p' assigned to 'seqId'.
  116. // If 'p' is NULL then return the first object assigned to seqId.
  117. // If 'seqId' is set to cmInvalidId then return the next object on any seq.
  118. // If no objects follow 'p' on the specified sequence then return NULL.
  119. cmTlObj_t* cmTimeLineNextObj( cmTlH_t h, cmTlObj_t* p, unsigned seqId );
  120. // Same as cmTimeLineNextObj() but returns next object whose type matches 'typeId'.
  121. cmTlObj_t* cmTimeLineNextTypeObj( cmTlH_t h, cmTlObj_t* p, unsigned seqId, unsigned typeId );
  122. cmTlMidiFile_t* cmTlNextMidiFileObjPtr( cmTlH_t h, cmTlObj_t* op, unsigned seqId );
  123. cmTlAudioFile_t* cmTlNextAudioFileObjPtr( cmTlH_t h, cmTlObj_t* op, unsigned seqId );
  124. cmTlMidiEvt_t* cmTlNextMidiEvtObjPtr( cmTlH_t h, cmTlObj_t* op, unsigned seqId );
  125. cmTlAudioEvt_t* cmTlNextAudioEvtObjPtr( cmTlH_t h, cmTlObj_t* op, unsigned seqId );
  126. cmTlMarker_t* cmTlNextMarkerObjPtr( cmTlH_t h, cmTlObj_t* op, unsigned seqId );
  127. cmTlObj_t* cmTlIdToObjPtr( cmTlH_t h, unsigned uid );
  128. // Cast a genereic cmTlObj_t pointer to a specific type.
  129. cmTlMidiFile_t* cmTimeLineMidiFileObjPtr( cmTlH_t h, cmTlObj_t* op );
  130. cmTlAudioFile_t* cmTimeLineAudioFileObjPtr( cmTlH_t h, cmTlObj_t* op );
  131. cmTlMidiEvt_t* cmTimeLineMidiEvtObjPtr( cmTlH_t h, cmTlObj_t* op );
  132. cmTlAudioEvt_t* cmTimeLineAudioEvtObjPtr( cmTlH_t h, cmTlObj_t* op );
  133. cmTlMarker_t* cmTimeLineMarkerObjPtr( cmTlH_t h, cmTlObj_t* op );
  134. // Same as cmTimeLineXXXObjPtr() but does not generate an error when
  135. // 'op' does not point to the correct type. These function quietly
  136. // return NULL if the requested type does not match or 'op' == NULL.
  137. cmTlMidiFile_t* cmTlMidiFileObjPtr( cmTlH_t h, cmTlObj_t* op );
  138. cmTlAudioFile_t* cmTlAudioFileObjPtr( cmTlH_t h, cmTlObj_t* op );
  139. cmTlMidiEvt_t* cmTlMidiEvtObjPtr( cmTlH_t h, cmTlObj_t* op );
  140. cmTlAudioEvt_t* cmTlAudioEvtObjPtr( cmTlH_t h, cmTlObj_t* op );
  141. cmTlMarker_t* cmTlMarkerObjPtr( cmTlH_t h, cmTlObj_t* op );
  142. cmTlAudioFile_t* cmTimeLineFindAudioFile( cmTlH_t h, const cmChar_t* fn );
  143. cmTlMidiFile_t* cmTimeLineFindMidiFile( cmTlH_t h, const cmChar_t* fn );
  144. cmTlAudioFile_t* cmTimeLineAudioFileAtTime( cmTlH_t h, unsigned seqId, unsigned seqSmpIdx );
  145. cmTlMidiFile_t* cmTimeLineMidiFileAtTime( cmTlH_t h, unsigned seqId, unsigned seqSmpIdx );
  146. cmTlMidiEvt_t* cmTimeLineMidiEvtAtTime( cmTlH_t h, unsigned seqId, unsigned seqSmpIdx );
  147. cmTlMarker_t* cmTimeLineMarkerAtTime( cmTlH_t h, unsigned seqId, unsigned seqSmpIdx );
  148. cmTlAudioFile_t* cmTimeLineAudioFileAtTime( cmTlH_t h, unsigned seqId, unsigned seqSmpIdx );
  149. cmTlMidiFile_t* cmTimeLineMidiFileAtTime( cmTlH_t h, unsigned seqId, unsigned seqSmpIdx );
  150. cmTlMidiEvt_t* cmTimeLineMidiEvtAtTime( cmTlH_t h, unsigned seqId, unsigned seqSmpIdx );
  151. cmTlMarker_t* cmTimeLineMarkerAtTime( cmTlH_t h, unsigned seqId, unsigned seqSmpIdx );
  152. cmTlMarker_t* cmTimeLineMarkerFind( cmTlH_t h, const cmChar_t* markText );
  153. // 'typeId' = kAudioFileTlId, kMidiFileTId, kMarkerTlId.
  154. // 'nameStr' and 'refObjNameStr' may be NULL.
  155. cmTlRC_t cmTimeLineInsert(
  156. cmTlH_t h,
  157. const cmChar_t* nameStr,
  158. unsigned typeId,
  159. const cmChar_t* fn_or_markerStr,
  160. int begSmpIdx,
  161. unsigned durSmpCnt,
  162. const cmChar_t* refObjNameStr,
  163. unsigned seqId );
  164. // See src/data/tl0.json for an example JSON file.
  165. cmTlRC_t cmTimeLineReadJson( cmTlH_t* hp, const cmChar_t* ifn );
  166. // Return a count of sequences contained within this timeline.
  167. unsigned cmTimeLineSeqCount( cmTlH_t h );
  168. // Make notifications for all records belonging to the sequence.
  169. cmTlRC_t cmTimeLineSeqNotify( cmTlH_t h, unsigned seqId );
  170. // Create and make notification for audio/MIDI onset marks.
  171. cmTlRC_t cmTimeLineGenOnsetMarks( cmTlH_t h, unsigned seqId );
  172. cmTlRC_t cmTimeLineDeleteOnsetMarks( cmTlH_t h, unsigned seqId );
  173. cmTlRC_t cmTimeLineWrite( cmTlH_t h, const cmChar_t* fn );
  174. cmTlRC_t cmTimeLinePrint( cmTlH_t h, cmRpt_t* rpt );
  175. cmTlRC_t cmTimeLinePrintFn( cmCtx_t* ctx, const cmChar_t* tlFn, const cmChar_t* prefixPath, cmRpt_t* rpt );
  176. cmTlRC_t cmTimeLineTest( cmCtx_t* ctx, const cmChar_t* tlFn, const cmChar_t* prefixPath );
  177. // The time-line notifies listeners of initialization and finalization
  178. // events via calling a cmTlCbFunc_t function. The argument to this
  179. // function is a serialized cmTlUiMsg_t. The recipient of the callback
  180. // can extract information from this message using cmTimeLineDecode()
  181. // to form a cmTlUiMsg_t record. Note that all pointers internal to the
  182. // cmTlUiMsg_t point into the message buffer itself.
  183. // id's used to indicate the type of a serialized object
  184. typedef enum
  185. {
  186. kInvalidMsgTlId,
  187. kInitMsgTlId, // A a set of time-line objects is about to be transmitted
  188. kFinalMsgTlId, // A time-line object is being finalized.
  189. kDoneMsgTlId, // All the objects assoc'd with a time line seq-notify have been sent.
  190. kInsertMsgTlId, // A time-line object was inserted.
  191. } cmTlUiMsgTypeId_t;
  192. typedef struct
  193. {
  194. cmTlUiMsgTypeId_t msgId; // See cmTlUiMsgTypeId_t.
  195. unsigned objId; // Set to cmTlObj_t.uid
  196. unsigned seqId; // Sequence id
  197. double srate; // Only valid with kInitMsgTlId.
  198. unsigned seqCnt; // Only valid with kInitMsgTlId.
  199. } cmTlUiMsg_t;
  200. // Decode a serialized cmTlObj_t as passed to the cmTlCb_t listener
  201. // callback function.
  202. cmTlRC_t cmTimeLineDecode( const void* msg, unsigned msgByteCnt, cmTlUiMsg_t* uiMsg );
  203. #ifdef __cplusplus
  204. }
  205. #endif
  206. #endif