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 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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 releives 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 cmAudioSysArgs_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. cmChar_t* devLabelStr; // Midi device label.
  61. cmChar_t* portLabelStr; // Midi device port label.
  62. bool inputFl; // 'True' if this is an input port.
  63. unsigned devIdx; // Midi device index.
  64. unsigned portIdx; // Midi port index.
  65. } cmDcmMidi_t;
  66. typedef struct
  67. {
  68. cmChar_t* inDevLabelStr; // Input audio device label.
  69. cmChar_t* outDevLabelStr; // Output audio device label.
  70. cmAudioSysArgs_t audioSysArgs; // Audio system cfg recd
  71. bool dfltFl; // true if this is the default audio cfg.
  72. } cmDcmAudio_t;
  73. typedef struct
  74. {
  75. cmChar_t* sockAddr; // Remote socket address.
  76. unsigned portNumber; // Remote socket port number
  77. } cmDcmNet_t;
  78. extern cmDevCfgH_t cmDevCfgNullHandle;
  79. cmDcRC_t cmDevCfgAlloc( cmCtx_t* c, cmDevCfgH_t* hp, const cmChar_t* fn );
  80. cmDcRC_t cmDevCfgFree( cmDevCfgH_t* hp );
  81. bool cmDevCfgIsValid( cmDevCfgH_t h );
  82. // Return the count of cfg records for the given type in the current location.
  83. unsigned cmDevCfgCount( cmDevCfgH_t h, cmTypeDcmId_t typeId );
  84. // Return the label for a each cfg record of a given type in the current location.
  85. const cmChar_t* cmDevCfgLabel( cmDevCfgH_t h, cmTypeDcmId_t typeId, unsigned index );
  86. // Return the description for a give cfg. record.
  87. const cmChar_t* cmDevCfgDesc( cmDevCfgH_t h, cmTypeDcmId_t typeId, unsigned index );
  88. // Return the cfg index assoc'd with a given label in the current location.
  89. unsigned cmDevCfgLabelToIndex( cmDevCfgH_t h, cmTypeDcmId_t typeId, const cmChar_t* label );
  90. // Delete a cfg record created by cmDevCfgNameMidiPort(), cmDevCfgNameAudioPort(), etc.
  91. cmDcRC_t cmDevCfgDeleteCfg( cmDevCfgH_t h, cmTypeDcmId_t typeId, const cmChar_t* dcLabelStr );
  92. // Create a map record to associate a app/dev id with a cfg. record.
  93. // Note that multiple app/dev id's may be assoc'd with the same cfg. record.
  94. cmDcRC_t cmDevCfgCreateMap( cmDevCfgH_t h, cmTypeDcmId_t typeId, const cmChar_t* dcLabelStr, unsigned usrAppId, unsigned usrMapId );
  95. // Delete a map record created by cmDevCfgCreateMap().
  96. cmDcRC_t cmDevCfgDeleteMap( cmDevCfgH_t h, cmTypeDcmId_t typeId, unsigned usrAppId, unsigned usrMapId );
  97. // Create a MIDI cfg. record.
  98. cmDcRC_t cmDevCfgNameMidiPort(
  99. cmDevCfgH_t h,
  100. const cmChar_t* dcLabelStr,
  101. const cmChar_t* devNameStr,
  102. const cmChar_t* portNameStr,
  103. bool inputFl );
  104. const cmDcmMidi_t* cmDevCfgMidiCfg( cmDevCfgH_t h, unsigned cfgIdx );
  105. const cmDcmMidi_t* cmDevCfgMidiMap( cmDevCfgH_t h, unsigned usrAppId, unsigned usrMapId );
  106. cmDcRC_t cmDevCfgNameAudioPort(
  107. cmDevCfgH_t h,
  108. const cmChar_t* dcLabelStr,
  109. const cmChar_t* inDevNameStr,
  110. const cmChar_t* outDevNameStr,
  111. bool syncInputFl,
  112. unsigned msgQueueByteCnt,
  113. unsigned devFramesPerCycle,
  114. unsigned dspFramesPerCycle,
  115. unsigned audioBufCnt,
  116. double srate );
  117. cmDcRC_t cmDevCfgAudioSetDefaultCfgIndex( cmDevCfgH_t h, unsigned cfgIdx );
  118. unsigned cmDevCfgAudioGetDefaultCfgIndex( cmDevCfgH_t h );
  119. const cmDcmAudio_t* cmDevCfgAudioCfg( cmDevCfgH_t h, unsigned cfgIdx );
  120. const cmDcmAudio_t* cmDevCfgAudioMap( cmDevCfgH_t h, unsigned usrAppId, unsigned usrMapId );
  121. const struct cmAudioSysArgs_str* cmDevCfgAudioSysArgs( cmDevCfgH_t h, unsigned usrAppId, unsigned usrMapId );
  122. cmDcRC_t cmDevCfgNameNetPort(
  123. cmDevCfgH_t h,
  124. const cmChar_t* dcLabelStr,
  125. const cmChar_t* sockAddr,
  126. unsigned portNumber );
  127. const cmDcmNet_t* cmDevCfgNetCfg( cmDevCfgH_t h, unsigned cfgIdx );
  128. const cmDcmNet_t* cmDevCfgNetMap( cmDevCfgH_t h, unsigned usrAppId, unsigned usrMapId );
  129. //---------------------------------------------------------------------------------------
  130. // Location Management Functions:
  131. // Store and recall groups of cfg records.
  132. // Return a count of the current number of locations.
  133. unsigned cmDevCfgLocCount( cmDevCfgH_t h );
  134. // Given a location index (0 to cmDevCfgLocCount()-1) return the locations label.
  135. const cmChar_t* cmDevCfgLocLabel( cmDevCfgH_t h, unsigned locIdx );
  136. // If 'locLabelStr' has already been used then this function does nothing and returns.
  137. // otherwise the current location is duplicated and the duplicate is named 'locLabelStr'.
  138. cmDcRC_t cmDevCfgLocStore( cmDevCfgH_t h, const cmChar_t* locLabelStr );
  139. // Make the location named 'locLabelStr' the current location.
  140. cmDcRC_t cmDevCfgLocRecall( cmDevCfgH_t h, const cmChar_t* locLabelStr );
  141. // Delete the location named by 'locLabelStr'.
  142. cmDcRC_t cmDevCfgLocDelete( cmDevCfgH_t h, const cmChar_t* locLabelStr );
  143. // Return the current location index
  144. unsigned cmDevCfgLocCurIndex( cmDevCfgH_t h );
  145. // Set 'fn' to NULL to use filename from cmDevCfgAlloc()
  146. cmDcRC_t cmDevCfgWrite( cmDevCfgH_t h, const cmChar_t* fn );
  147. #ifdef __cplusplus
  148. }
  149. #endif
  150. #endif