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.8KB

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