libcm is a C development framework with an emphasis on audio signal processing applications.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

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