libcm is a C development framework with an emphasis on audio signal processing applications.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

cmTimeLine.h 9.7KB

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