libcm is a C development framework with an emphasis on audio signal processing applications.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

cmTimeLine.h 9.9KB

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