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 8.6KB

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