libcm is a C development framework with an emphasis on audio signal processing applications.
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

cmDevCfg.h 8.0KB

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