libcm is a C development framework with an emphasis on audio signal processing applications.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cmDevCfg.h 7.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. #ifndef cmDevCfg_h
  2. #define cmDevCfg_h
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. /*
  7. IMPLEMENTATION:
  8. 1) A 'cfg' record is a device reference with a 'cfg label'.
  9. There are three kinds of cfg records MIDI,Audio,Net.
  10. The device record identifies a particlar device
  11. end-point or pre-configured setup. The 'cfg label'
  12. associated with this setup allows an application
  13. to refer to the setup by name. This relieves the
  14. application from having to handle the details of
  15. forming, storing, and maintaining device configurations.
  16. 2) A 'map' record is a record which links an
  17. application and reference id to a cfg record.
  18. The goal of this is to allow applications to refer to
  19. pre-configured device setups by name and then to
  20. associate a numeric id with this setup.
  21. The application can then send data to the device using
  22. only the numeric id. Likewise data arriving from the
  23. device to the application is tagged with
  24. id of the of the device.
  25. NOTES:
  26. 1) usrAppId's must be unique among all app.s'.
  27. 2) usrDevId's must be unique among all usrDevId's for particular app.
  28. In other words the same 'usrDevId' may not be used by devices
  29. of different types.
  30. 3) The usrAppId's and usrDevIds' are used internally as index
  31. locations. They should therefore be low numbers and
  32. densely packed.
  33. */
  34. struct cmRtSysArgs_str;
  35. enum
  36. {
  37. kOkDcRC = cmOkRC,
  38. kLHeapFailDcRC,
  39. kLabelNotFoundDcRC,
  40. kDuplLabelDcRC,
  41. kBlankLabelDcRC,
  42. kInvalidUserAppIdRC,
  43. kInvalidUserMapIdRC,
  44. kInvalidArgDcRC,
  45. kInvalidCfgIdxDcRC,
  46. kJsonFailDcRC,
  47. kInvalidFnDcRC
  48. };
  49. typedef enum
  50. {
  51. kInvalidDcmTId, // kInvalidDcmTId must be zero
  52. kMidiDcmTId,
  53. kAudioDcmTId,
  54. //kNetDcmTId
  55. } cmTypeDcmId_t;
  56. typedef cmRC_t cmDcRC_t;
  57. typedef cmHandle_t cmDevCfgH_t;
  58. typedef struct
  59. {
  60. const cmChar_t* label; // cfg label
  61. cmChar_t* devLabelStr; // Midi device label.
  62. cmChar_t* portLabelStr; // Midi device port label.
  63. bool inputFl; // 'True' if this is an input port.
  64. unsigned devIdx; // Midi device index.
  65. unsigned portIdx; // Midi port index.
  66. } cmDcmMidi_t;
  67. typedef struct
  68. {
  69. const cmChar_t* label; // cfg label
  70. cmChar_t* inDevLabelStr; // Input audio device label.
  71. cmChar_t* outDevLabelStr; // Output audio device label.
  72. cmRtSysArgs_t rtSysArgs; // RT system cfg recd
  73. const cmChar_t* netNodeLabel;
  74. const cmChar_t* bcastAddr; // network broadcast address
  75. const cmChar_t* ipAddr; // local network addr or NULL for localhost
  76. cmUdpPort_t ipPort; // local network port
  77. bool activeFl;
  78. } cmDcmAudio_t;
  79. /*
  80. typedef struct
  81. {
  82. const cmChar_t* label; // cfg label
  83. cmChar_t* sockAddr; // socket address.
  84. unsigned portNumber; // socket port number
  85. bool activeFl; // this port is active/inactive
  86. } cmDcmNet_t;
  87. */
  88. extern cmDevCfgH_t cmDevCfgNullHandle;
  89. cmDcRC_t cmDevCfgAlloc( cmCtx_t* c, cmDevCfgH_t* hp, const cmChar_t* fn );
  90. cmDcRC_t cmDevCfgFree( cmDevCfgH_t* hp );
  91. bool cmDevCfgIsValid( cmDevCfgH_t h );
  92. // Return the count of cfg records for the given type in the current location.
  93. unsigned cmDevCfgCount( cmDevCfgH_t h, cmTypeDcmId_t typeId );
  94. // Return the label for a each cfg record of a given type in the current location.
  95. const cmChar_t* cmDevCfgLabel( cmDevCfgH_t h, cmTypeDcmId_t typeId, unsigned index );
  96. // Return the description for a give cfg. record.
  97. const cmChar_t* cmDevCfgDesc( cmDevCfgH_t h, cmTypeDcmId_t typeId, unsigned index );
  98. // Return the cfg index assoc'd with a given label in the current location.
  99. unsigned cmDevCfgLabelToIndex( cmDevCfgH_t h, cmTypeDcmId_t typeId, const cmChar_t* label );
  100. // Delete a cfg record created by cmDevCfgNameMidiPort(), cmDevCfgNameAudioPort(), etc.
  101. cmDcRC_t cmDevCfgDeleteCfg( cmDevCfgH_t h, cmTypeDcmId_t typeId, const cmChar_t* dcLabelStr );
  102. // Create a map record to associate a app/dev id with a cfg. record.
  103. // Note that multiple app/dev id's may be assoc'd with the same cfg. record.
  104. cmDcRC_t cmDevCfgCreateMap( cmDevCfgH_t h, cmTypeDcmId_t typeId, const cmChar_t* dcLabelStr, unsigned usrAppId, unsigned usrMapId );
  105. // Delete a map record created by cmDevCfgCreateMap().
  106. cmDcRC_t cmDevCfgDeleteMap( cmDevCfgH_t h, cmTypeDcmId_t typeId, unsigned usrAppId, unsigned usrMapId );
  107. // Create a MIDI cfg. record.
  108. cmDcRC_t cmDevCfgNameMidiPort(
  109. cmDevCfgH_t h,
  110. const cmChar_t* dcLabelStr,
  111. const cmChar_t* devNameStr,
  112. const cmChar_t* portNameStr,
  113. bool inputFl );
  114. const cmDcmMidi_t* cmDevCfgMidiCfg( cmDevCfgH_t h, unsigned cfgIdx );
  115. const cmDcmMidi_t* cmDevCfgMidiMap( cmDevCfgH_t h, unsigned usrAppId, unsigned usrMapId );
  116. const cmDcmMidi_t* cmDevCfgMidiCfgFromLabel( cmDevCfgH_t h, const cmChar_t* cfgLabel );
  117. cmDcRC_t cmDevCfgNameAudioPort(
  118. cmDevCfgH_t h,
  119. const cmChar_t* dcLabelStr,
  120. const cmChar_t* inDevNameStr,
  121. const cmChar_t* outDevNameStr,
  122. bool syncInputFl,
  123. unsigned msgQueueByteCnt,
  124. unsigned devFramesPerCycle,
  125. unsigned dspFramesPerCycle,
  126. unsigned audioBufCnt,
  127. double srate,
  128. const cmChar_t* netNodeLabel,
  129. const cmChar_t* bcastAddr,
  130. const cmChar_t* ipAddr,
  131. cmUdpPort_t ipPort,
  132. bool activeFl );
  133. bool cmDevCfgAudioIsDeviceActive( cmDevCfgH_t h, const cmChar_t* devNameStr, bool inputFl );
  134. unsigned cmDevCfgAudioActiveCount( cmDevCfgH_t h );
  135. const cmChar_t* cmDevCfgAudioActiveLabel( cmDevCfgH_t h, unsigned idx );
  136. const cmDcmAudio_t* cmDevCfgAudioActiveCfg( cmDevCfgH_t h, unsigned idx );
  137. unsigned cmDevCfgAudioActiveIndex( cmDevCfgH_t h, const cmChar_t* cfgLabel );
  138. const cmDcmAudio_t* cmDevCfgAudioCfg( cmDevCfgH_t h, unsigned cfgIdx );
  139. const cmDcmAudio_t* cmDevCfgAudioMap( cmDevCfgH_t h, unsigned usrAppId, unsigned usrMapId );
  140. const struct cmRtSysArgs_str* cmDevCfgRtSysArgs( cmDevCfgH_t h, unsigned usrAppId, unsigned usrMapId );
  141. /*
  142. cmDcRC_t cmDevCfgNameNetPort(
  143. cmDevCfgH_t h,
  144. const cmChar_t* dcLabelStr,
  145. const cmChar_t* sockAddr,
  146. unsigned portNumber,
  147. bool activeFl);
  148. unsigned cmDevCfgNetActiveCount( cmDevCfgH_t h );
  149. const cmDcmNet_t* cmDevCfgNetActiveCfg( cmDevCfgH_t h, unsigned idx );
  150. const cmDcmNet_t* cmDevCfgNetCfg( cmDevCfgH_t h, unsigned cfgIdx );
  151. const cmDcmNet_t* cmDevCfgNetMap( cmDevCfgH_t h, unsigned usrAppId, unsigned usrMapId );
  152. */
  153. //---------------------------------------------------------------------------------------
  154. // Location Management Functions:
  155. // Store and recall groups of cfg records.
  156. // Return a count of the current number of locations.
  157. unsigned cmDevCfgLocCount( cmDevCfgH_t h );
  158. // Given a location index (0 to cmDevCfgLocCount()-1) return the locations label.
  159. const cmChar_t* cmDevCfgLocLabel( cmDevCfgH_t h, unsigned locIdx );
  160. // If 'locLabelStr' has already been used then this function does nothing and returns.
  161. // otherwise the current location is duplicated and the duplicate is named 'locLabelStr'.
  162. cmDcRC_t cmDevCfgLocStore( cmDevCfgH_t h, const cmChar_t* locLabelStr );
  163. // Make the location named 'locLabelStr' the current location.
  164. cmDcRC_t cmDevCfgLocRecall( cmDevCfgH_t h, const cmChar_t* locLabelStr );
  165. // Delete the location named by 'locLabelStr'.
  166. cmDcRC_t cmDevCfgLocDelete( cmDevCfgH_t h, const cmChar_t* locLabelStr );
  167. // Return the current location index
  168. unsigned cmDevCfgLocCurIndex( cmDevCfgH_t h );
  169. // Set 'fn' to NULL to use filename from cmDevCfgAlloc()
  170. cmDcRC_t cmDevCfgWrite( cmDevCfgH_t h, const cmChar_t* fn );
  171. #ifdef __cplusplus
  172. }
  173. #endif
  174. #endif