Audio plugin host https://kx.studio/carla
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.

222 lines
9.3KB

  1. /*
  2. * Carla Bridge utils
  3. * Copyright (C) 2013-2017 Filipe Coelho <falktx@falktx.com>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License, or any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * For a full copy of the GNU General Public License see the doc/GPL.txt file.
  16. */
  17. #ifndef CARLA_BRIDGE_UTILS_HPP_INCLUDED
  18. #define CARLA_BRIDGE_UTILS_HPP_INCLUDED
  19. #include "CarlaBridgeDefines.hpp"
  20. #include "CarlaString.hpp"
  21. #if defined(CARLA_OS_WIN) && defined(BUILDING_CARLA_FOR_WINDOWS)
  22. # define PLUGIN_BRIDGE_NAMEPREFIX_RT_CLIENT "Global\\carla-bridge_shm_rtC_"
  23. # define PLUGIN_BRIDGE_NAMEPREFIX_NON_RT_CLIENT "Global\\carla-bridge_shm_nonrtC_"
  24. # define PLUGIN_BRIDGE_NAMEPREFIX_NON_RT_SERVER "Global\\carla-bridge_shm_nonrtS_"
  25. #else
  26. # define PLUGIN_BRIDGE_NAMEPREFIX_RT_CLIENT "/crlbrdg_shm_rtC_"
  27. # define PLUGIN_BRIDGE_NAMEPREFIX_NON_RT_CLIENT "/crlbrdg_shm_nonrtC_"
  28. # define PLUGIN_BRIDGE_NAMEPREFIX_NON_RT_SERVER "/crlbrdg_shm_nonrtS_"
  29. #endif
  30. // -------------------------------------------------------------------------------------------------------------------
  31. static inline
  32. const char* PluginBridgeRtClientOpcode2str(const PluginBridgeRtClientOpcode opcode) noexcept
  33. {
  34. switch (opcode)
  35. {
  36. case kPluginBridgeRtClientNull:
  37. return "kPluginBridgeRtClientNull";
  38. case kPluginBridgeRtClientSetAudioPool:
  39. return "kPluginBridgeRtClientSetAudioPool";
  40. case kPluginBridgeRtClientControlEventParameter:
  41. return "kPluginBridgeRtClientControlEventParameter";
  42. case kPluginBridgeRtClientControlEventMidiBank:
  43. return "kPluginBridgeRtClientControlEventMidiBank";
  44. case kPluginBridgeRtClientControlEventMidiProgram:
  45. return "kPluginBridgeRtClientControlEventMidiProgram";
  46. case kPluginBridgeRtClientControlEventAllSoundOff:
  47. return "kPluginBridgeRtClientControlEventAllSoundOff";
  48. case kPluginBridgeRtClientControlEventAllNotesOff:
  49. return "kPluginBridgeRtClientControlEventAllNotesOff";
  50. case kPluginBridgeRtClientMidiEvent:
  51. return "kPluginBridgeRtClientMidiEvent";
  52. case kPluginBridgeRtClientProcess:
  53. return "kPluginBridgeRtClientProcess";
  54. case kPluginBridgeRtClientQuit:
  55. return "kPluginBridgeRtClientQuit";
  56. }
  57. carla_stderr("CarlaBackend::PluginBridgeRtClientOpcode2str(%i) - invalid opcode", opcode);
  58. return nullptr;
  59. }
  60. static inline
  61. const char* PluginBridgeNonRtClientOpcode2str(const PluginBridgeNonRtClientOpcode opcode) noexcept
  62. {
  63. switch (opcode)
  64. {
  65. case kPluginBridgeNonRtClientNull:
  66. return "kPluginBridgeNonRtClientNull";
  67. case kPluginBridgeNonRtClientPing:
  68. return "kPluginBridgeNonRtClientPing";
  69. case kPluginBridgeNonRtClientPingOnOff:
  70. return "kPluginBridgeNonRtClientPingOnOff";
  71. case kPluginBridgeNonRtClientActivate:
  72. return "kPluginBridgeNonRtClientActivate";
  73. case kPluginBridgeNonRtClientDeactivate:
  74. return "kPluginBridgeNonRtClientDeactivate";
  75. case kPluginBridgeNonRtClientSetBufferSize:
  76. return "kPluginBridgeNonRtClientSetBufferSize";
  77. case kPluginBridgeNonRtClientSetSampleRate:
  78. return "kPluginBridgeNonRtClientSetSampleRate";
  79. case kPluginBridgeNonRtClientSetOffline:
  80. return "kPluginBridgeNonRtClientSetOffline";
  81. case kPluginBridgeNonRtClientSetOnline:
  82. return "kPluginBridgeNonRtClientSetOnline";
  83. case kPluginBridgeNonRtClientSetParameterValue:
  84. return "kPluginBridgeNonRtClientSetParameterValue";
  85. case kPluginBridgeNonRtClientSetParameterMidiChannel:
  86. return "kPluginBridgeNonRtClientSetParameterMidiChannel";
  87. case kPluginBridgeNonRtClientSetParameterMidiCC:
  88. return "kPluginBridgeNonRtClientSetParameterMidiCC";
  89. case kPluginBridgeNonRtClientSetProgram:
  90. return "kPluginBridgeNonRtClientSetProgram";
  91. case kPluginBridgeNonRtClientSetMidiProgram:
  92. return "kPluginBridgeNonRtClientSetMidiProgram";
  93. case kPluginBridgeNonRtClientSetCustomData:
  94. return "kPluginBridgeNonRtClientSetCustomData";
  95. case kPluginBridgeNonRtClientSetChunkDataFile:
  96. return "kPluginBridgeNonRtClientSetChunkDataFile";
  97. case kPluginBridgeNonRtClientSetCtrlChannel:
  98. return "kPluginBridgeNonRtClientSetCtrlChannel";
  99. case kPluginBridgeNonRtClientSetOption:
  100. return "kPluginBridgeNonRtClientSetOption";
  101. case kPluginBridgeNonRtClientPrepareForSave:
  102. return "kPluginBridgeNonRtClientPrepareForSave";
  103. case kPluginBridgeNonRtClientShowUI:
  104. return "kPluginBridgeNonRtClientShowUI";
  105. case kPluginBridgeNonRtClientHideUI:
  106. return "kPluginBridgeNonRtClientHideUI";
  107. case kPluginBridgeNonRtClientUiParameterChange:
  108. return "kPluginBridgeNonRtClientUiParameterChange";
  109. case kPluginBridgeNonRtClientUiProgramChange:
  110. return "kPluginBridgeNonRtClientUiProgramChange";
  111. case kPluginBridgeNonRtClientUiMidiProgramChange:
  112. return "kPluginBridgeNonRtClientUiMidiProgramChange";
  113. case kPluginBridgeNonRtClientUiNoteOn:
  114. return "kPluginBridgeNonRtClientUiNoteOn";
  115. case kPluginBridgeNonRtClientUiNoteOff:
  116. return "kPluginBridgeNonRtClientUiNoteOff";
  117. case kPluginBridgeNonRtClientQuit:
  118. return "kPluginBridgeNonRtClientQuit";
  119. }
  120. carla_stderr("CarlaBackend::PluginBridgeNonRtClientOpcode2str(%i) - invalid opcode", opcode);
  121. return nullptr;
  122. }
  123. static inline
  124. const char* PluginBridgeNonRtServerOpcode2str(const PluginBridgeNonRtServerOpcode opcode) noexcept
  125. {
  126. switch (opcode)
  127. {
  128. case kPluginBridgeNonRtServerNull:
  129. return "kPluginBridgeNonRtServerNull";
  130. case kPluginBridgeNonRtServerPong:
  131. return "kPluginBridgeNonRtServerPong";
  132. case kPluginBridgeNonRtServerPluginInfo1:
  133. return "kPluginBridgeNonRtServerPluginInfo1";
  134. case kPluginBridgeNonRtServerPluginInfo2:
  135. return "kPluginBridgeNonRtServerPluginInfo2";
  136. case kPluginBridgeNonRtServerAudioCount:
  137. return "kPluginBridgeNonRtServerAudioCount";
  138. case kPluginBridgeNonRtServerMidiCount:
  139. return "kPluginBridgeNonRtServerMidiCount";
  140. case kPluginBridgeNonRtServerCvCount:
  141. return "kPluginBridgeNonRtServerCvCount";
  142. case kPluginBridgeNonRtServerParameterCount:
  143. return "kPluginBridgeNonRtServerParameterCount";
  144. case kPluginBridgeNonRtServerProgramCount:
  145. return "kPluginBridgeNonRtServerProgramCount";
  146. case kPluginBridgeNonRtServerMidiProgramCount:
  147. return "kPluginBridgeNonRtServerMidiProgramCount";
  148. case kPluginBridgeNonRtServerPortName:
  149. return "kPluginBridgeNonRtServerPortName";
  150. case kPluginBridgeNonRtServerParameterData1:
  151. return "kPluginBridgeNonRtServerParameterData1";
  152. case kPluginBridgeNonRtServerParameterData2:
  153. return "kPluginBridgeNonRtServerParameterData2";
  154. case kPluginBridgeNonRtServerParameterRanges:
  155. return "kPluginBridgeNonRtServerParameterRanges";
  156. case kPluginBridgeNonRtServerParameterValue:
  157. return "kPluginBridgeNonRtServerParameterValue";
  158. case kPluginBridgeNonRtServerParameterValue2:
  159. return "kPluginBridgeNonRtServerParameterValue2";
  160. case kPluginBridgeNonRtServerDefaultValue:
  161. return "kPluginBridgeNonRtServerDefaultValue";
  162. case kPluginBridgeNonRtServerCurrentProgram:
  163. return "kPluginBridgeNonRtServerCurrentProgram";
  164. case kPluginBridgeNonRtServerCurrentMidiProgram:
  165. return "kPluginBridgeNonRtServerCurrentMidiProgram";
  166. case kPluginBridgeNonRtServerProgramName:
  167. return "kPluginBridgeNonRtServerProgramName";
  168. case kPluginBridgeNonRtServerMidiProgramData:
  169. return "kPluginBridgeNonRtServerMidiProgramData";
  170. case kPluginBridgeNonRtServerSetCustomData:
  171. return "kPluginBridgeNonRtServerSetCustomData";
  172. case kPluginBridgeNonRtServerSetChunkDataFile:
  173. return "kPluginBridgeNonRtServerSetChunkDataFile";
  174. case kPluginBridgeNonRtServerSetLatency:
  175. return "kPluginBridgeNonRtServerSetLatency";
  176. case kPluginBridgeNonRtServerReady:
  177. return "kPluginBridgeNonRtServerReady";
  178. case kPluginBridgeNonRtServerSaved:
  179. return "kPluginBridgeNonRtServerSaved";
  180. case kPluginBridgeNonRtServerUiClosed:
  181. return "kPluginBridgeNonRtServerUiClosed";
  182. case kPluginBridgeNonRtServerError:
  183. return "kPluginBridgeNonRtServerError";
  184. }
  185. carla_stderr("CarlaBackend::PluginBridgeNonRtServerOpcode2str%i) - invalid opcode", opcode);
  186. return nullptr;
  187. }
  188. // -------------------------------------------------------------------------------------------------------------------
  189. struct BridgeAudioPool {
  190. float* data;
  191. std::size_t dataSize;
  192. CarlaString filename;
  193. char shm[64];
  194. BridgeAudioPool() noexcept;
  195. ~BridgeAudioPool() noexcept;
  196. bool initializeServer() noexcept;
  197. bool attachClient(const char* const fname) noexcept;
  198. void clear() noexcept;
  199. void resize(const uint32_t bufferSize, const uint32_t audioPortCount, const uint32_t cvPortCount) noexcept;
  200. CARLA_DECLARE_NON_COPY_STRUCT(BridgeAudioPool)
  201. };
  202. // -------------------------------------------------------------------------------------------------------------------
  203. #endif // CARLA_BRIDGE_UTILS_HPP_INCLUDED