libcm is a C development framework with an emphasis on audio signal processing applications.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

cmDevCfg.h 7.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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* ipAddr; // local network addr or NULL for localhost
  74. cmUdpPort_t ipPort; // local network port
  75. bool activeFl;
  76. } cmDcmAudio_t;
  77. typedef struct
  78. {
  79. const cmChar_t* label; // cfg label
  80. cmChar_t* sockAddr; // socket address.
  81. unsigned portNumber; // socket port number
  82. bool activeFl; // this port is active/inactive
  83. } cmDcmNet_t;
  84. extern cmDevCfgH_t cmDevCfgNullHandle;
  85. cmDcRC_t cmDevCfgAlloc( cmCtx_t* c, cmDevCfgH_t* hp, const cmChar_t* fn );
  86. cmDcRC_t cmDevCfgFree( cmDevCfgH_t* hp );
  87. bool cmDevCfgIsValid( cmDevCfgH_t h );
  88. // Return the count of cfg records for the given type in the current location.
  89. unsigned cmDevCfgCount( cmDevCfgH_t h, cmTypeDcmId_t typeId );
  90. // Return the label for a each cfg record of a given type in the current location.
  91. const cmChar_t* cmDevCfgLabel( cmDevCfgH_t h, cmTypeDcmId_t typeId, unsigned index );
  92. // Return the description for a give cfg. record.
  93. const cmChar_t* cmDevCfgDesc( cmDevCfgH_t h, cmTypeDcmId_t typeId, unsigned index );
  94. // Return the cfg index assoc'd with a given label in the current location.
  95. unsigned cmDevCfgLabelToIndex( cmDevCfgH_t h, cmTypeDcmId_t typeId, const cmChar_t* label );
  96. // Delete a cfg record created by cmDevCfgNameMidiPort(), cmDevCfgNameAudioPort(), etc.
  97. cmDcRC_t cmDevCfgDeleteCfg( cmDevCfgH_t h, cmTypeDcmId_t typeId, const cmChar_t* dcLabelStr );
  98. // Create a map record to associate a app/dev id with a cfg. record.
  99. // Note that multiple app/dev id's may be assoc'd with the same cfg. record.
  100. cmDcRC_t cmDevCfgCreateMap( cmDevCfgH_t h, cmTypeDcmId_t typeId, const cmChar_t* dcLabelStr, unsigned usrAppId, unsigned usrMapId );
  101. // Delete a map record created by cmDevCfgCreateMap().
  102. cmDcRC_t cmDevCfgDeleteMap( cmDevCfgH_t h, cmTypeDcmId_t typeId, unsigned usrAppId, unsigned usrMapId );
  103. // Create a MIDI cfg. record.
  104. cmDcRC_t cmDevCfgNameMidiPort(
  105. cmDevCfgH_t h,
  106. const cmChar_t* dcLabelStr,
  107. const cmChar_t* devNameStr,
  108. const cmChar_t* portNameStr,
  109. bool inputFl );
  110. const cmDcmMidi_t* cmDevCfgMidiCfg( cmDevCfgH_t h, unsigned cfgIdx );
  111. const cmDcmMidi_t* cmDevCfgMidiMap( cmDevCfgH_t h, unsigned usrAppId, unsigned usrMapId );
  112. const cmDcmMidi_t* cmDevCfgMidiCfgFromLabel( cmDevCfgH_t h, const cmChar_t* cfgLabel );
  113. cmDcRC_t cmDevCfgNameAudioPort(
  114. cmDevCfgH_t h,
  115. const cmChar_t* dcLabelStr,
  116. const cmChar_t* inDevNameStr,
  117. const cmChar_t* outDevNameStr,
  118. bool syncInputFl,
  119. unsigned msgQueueByteCnt,
  120. unsigned devFramesPerCycle,
  121. unsigned dspFramesPerCycle,
  122. unsigned audioBufCnt,
  123. double srate,
  124. const cmChar_t* ipAddr,
  125. cmUdpPort_t ipPort,
  126. bool activeFl );
  127. bool cmDevCfgAudioIsDeviceActive( cmDevCfgH_t h, const cmChar_t* devNameStr, bool inputFl );
  128. unsigned cmDevCfgAudioActiveCount( cmDevCfgH_t h );
  129. const cmChar_t* cmDevCfgAudioActiveLabel( cmDevCfgH_t h, unsigned idx );
  130. const cmDcmAudio_t* cmDevCfgAudioActiveCfg( cmDevCfgH_t h, unsigned idx );
  131. unsigned cmDevCfgAudioActiveIndex( cmDevCfgH_t h, const cmChar_t* cfgLabel );
  132. const cmDcmAudio_t* cmDevCfgAudioCfg( cmDevCfgH_t h, unsigned cfgIdx );
  133. const cmDcmAudio_t* cmDevCfgAudioMap( cmDevCfgH_t h, unsigned usrAppId, unsigned usrMapId );
  134. const struct cmRtSysArgs_str* cmDevCfgRtSysArgs( cmDevCfgH_t h, unsigned usrAppId, unsigned usrMapId );
  135. cmDcRC_t cmDevCfgNameNetPort(
  136. cmDevCfgH_t h,
  137. const cmChar_t* dcLabelStr,
  138. const cmChar_t* sockAddr,
  139. unsigned portNumber,
  140. bool activeFl);
  141. unsigned cmDevCfgNetActiveCount( cmDevCfgH_t h );
  142. const cmDcmNet_t* cmDevCfgNetActiveCfg( cmDevCfgH_t h, unsigned idx );
  143. const cmDcmNet_t* cmDevCfgNetCfg( cmDevCfgH_t h, unsigned cfgIdx );
  144. const cmDcmNet_t* cmDevCfgNetMap( cmDevCfgH_t h, unsigned usrAppId, unsigned usrMapId );
  145. //---------------------------------------------------------------------------------------
  146. // Location Management Functions:
  147. // Store and recall groups of cfg records.
  148. // Return a count of the current number of locations.
  149. unsigned cmDevCfgLocCount( cmDevCfgH_t h );
  150. // Given a location index (0 to cmDevCfgLocCount()-1) return the locations label.
  151. const cmChar_t* cmDevCfgLocLabel( cmDevCfgH_t h, unsigned locIdx );
  152. // If 'locLabelStr' has already been used then this function does nothing and returns.
  153. // otherwise the current location is duplicated and the duplicate is named 'locLabelStr'.
  154. cmDcRC_t cmDevCfgLocStore( cmDevCfgH_t h, const cmChar_t* locLabelStr );
  155. // Make the location named 'locLabelStr' the current location.
  156. cmDcRC_t cmDevCfgLocRecall( cmDevCfgH_t h, const cmChar_t* locLabelStr );
  157. // Delete the location named by 'locLabelStr'.
  158. cmDcRC_t cmDevCfgLocDelete( cmDevCfgH_t h, const cmChar_t* locLabelStr );
  159. // Return the current location index
  160. unsigned cmDevCfgLocCurIndex( cmDevCfgH_t h );
  161. // Set 'fn' to NULL to use filename from cmDevCfgAlloc()
  162. cmDcRC_t cmDevCfgWrite( cmDevCfgH_t h, const cmChar_t* fn );
  163. #ifdef __cplusplus
  164. }
  165. #endif
  166. #endif