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.

304 lines
12KB

  1. /*
  2. * Carla Bridge utils
  3. * Copyright (C) 2013-2014 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 "CarlaRingBuffer.hpp"
  20. // -----------------------------------------------------------------------
  21. // carla-plugin receives these via osc
  22. enum PluginBridgeOscInfoType {
  23. kPluginBridgeOscNull = 0,
  24. kPluginBridgeOscPong,
  25. kPluginBridgeOscPluginInfo1, // uuuuh => category, hints, optionsAvailable, optionsEnabled, uniqueId
  26. kPluginBridgeOscPluginInfo2, // ssss => realName, label, maker, copyright
  27. kPluginBridgeOscAudioCount, // uu => ins, outs
  28. kPluginBridgeOscMidiCount, // uu => ins, outs
  29. kPluginBridgeOscParameterCount, // uu => ins, outs
  30. kPluginBridgeOscProgramCount, // u => count
  31. kPluginBridgeOscMidiProgramCount, // u => count
  32. kPluginBridgeOscParameterData1, // uiuui => index, rindex, type, hints, cc
  33. kPluginBridgeOscParameterData2, // uss => index, name, unit
  34. kPluginBridgeOscParameterRanges1, // ufff => index, def, min, max
  35. kPluginBridgeOscParameterRanges2, // ufff => index, step, stepSmall, stepLarge
  36. kPluginBridgeOscParameterValue, // uf => index, value
  37. kPluginBridgeOscDefaultValue, // uf => index, value
  38. kPluginBridgeOscCurrentProgram, // i => index
  39. kPluginBridgeOscCurrentMidiProgram, // i => index
  40. kPluginBridgeOscProgramName, // us => index, name
  41. kPluginBridgeOscMidiProgramData, // uuus => index, bank, program, name
  42. kPluginBridgeOscConfigure, // ss => key, value
  43. kPluginBridgeOscSetCustomData, // sss => type, key, value
  44. kPluginBridgeOscSetChunkDataFile, // s => chunkFile
  45. kPluginBridgeOscLatency, // u => value
  46. kPluginBridgeOscReady,
  47. kPluginBridgeOscError
  48. };
  49. // carla-plugin sends these during RT
  50. enum PluginBridgeRtOpcode {
  51. kPluginBridgeRtNull = 0,
  52. kPluginBridgeRtSetAudioPool, // ulong/ptr
  53. kPluginBridgeRtSetCVPool, // ulong/ptr
  54. kPluginBridgeRtControlEventParameter, // uint/frame, byte/chan, ushort, float
  55. kPluginBridgeRtControlEventMidiBank, // uint/frame, byte/chan, ushort
  56. kPluginBridgeRtControlEventMidiProgram, // uint/frame, byte/chan, ushort
  57. kPluginBridgeRtControlEventAllSoundOff, // uint/frame, byte/chan
  58. kPluginBridgeRtControlEventAllNotesOff, // uint/frame, byte/chan
  59. kPluginBridgeRtMidiEvent, // uint/frame, byte/port, byte/size, byte[]/data
  60. kPluginBridgeRtProcess,
  61. kPluginBridgeRtQuit
  62. };
  63. // carla-plugin sends these during non-RT
  64. enum PluginBridgeNonRtOpcode {
  65. kPluginBridgeNonRtNull = 0,
  66. kPluginBridgeNonRtPing,
  67. kPluginBridgeNonRtActivate,
  68. kPluginBridgeNonRtDeactivate,
  69. kPluginBridgeNonRtSetBufferSize, // uint
  70. kPluginBridgeNonRtSetSampleRate, // double
  71. kPluginBridgeNonRtSetOffline,
  72. kPluginBridgeNonRtSetOnline,
  73. kPluginBridgeNonRtSetParameterValue, // uint, float
  74. kPluginBridgeNonRtSetParameterMidiChannel, // uint, byte
  75. kPluginBridgeNonRtSetParameterMidiCC, // uint, short
  76. kPluginBridgeNonRtSetProgram, // int
  77. kPluginBridgeNonRtSetMidiProgram, // int
  78. kPluginBridgeNonRtSetCustomData, // uint/size, str[], uint/size, str[], uint/size, str[] TODO plugin
  79. kPluginBridgeNonRtSetChunkDataFile, // uint/size, str[]/file
  80. kPluginBridgeNonRtSetCtrlChannel, // short
  81. kPluginBridgeNonRtSetOscURL, // uint/size, str[]/url
  82. kPluginBridgeNonRtSetOption, // uint/option, bool
  83. kPluginBridgeNonRtPrepareForSave,
  84. kPluginBridgeNonRtShowUI,
  85. kPluginBridgeNonRtHideUI,
  86. kPluginBridgeNonRtUiParameterChange, // uint, float
  87. kPluginBridgeNonRtUiProgramChange, // uint
  88. kPluginBridgeNonRtUiMidiProgramChange, // uint
  89. kPluginBridgeNonRtUiNoteOn, // byte, byte, byte
  90. kPluginBridgeNonRtUiNoteOff, // byte, byte
  91. kPluginBridgeNonRtQuit
  92. };
  93. // -----------------------------------------------------------------------
  94. const char* const CARLA_BRIDGE_MSG_HIDE_GUI = "CarlaBridgeHideGUI"; //!< Plugin -> Host configure, tells host GUI is now hidden
  95. const char* const CARLA_BRIDGE_MSG_SAVED = "CarlaBridgeSaved"; //!< Plugin -> Host configure, tells host state is saved
  96. // -----------------------------------------------------------------------
  97. struct BridgeSemaphore {
  98. union {
  99. void* server;
  100. char _padServer[64];
  101. };
  102. union {
  103. void* client;
  104. char _padClient[64];
  105. };
  106. };
  107. // needs to be 64bit aligned
  108. struct BridgeTimeInfo {
  109. uint64_t playing;
  110. uint64_t frame;
  111. uint64_t usecs;
  112. uint32_t valid;
  113. // bbt
  114. int32_t bar, beat, tick;
  115. float beatsPerBar, beatType;
  116. double barStartTick, ticksPerBeat, beatsPerMinute;
  117. };
  118. struct BridgeRtData {
  119. BridgeSemaphore sem;
  120. BridgeTimeInfo timeInfo;
  121. StackBuffer ringBuffer;
  122. };
  123. struct BridgeNonRtData {
  124. BigStackBuffer ringBuffer;
  125. };
  126. // -----------------------------------------------------------------------
  127. static inline
  128. const char* PluginBridgeOscInfoType2str(const PluginBridgeOscInfoType type) noexcept
  129. {
  130. switch (type)
  131. {
  132. case kPluginBridgeOscNull:
  133. return "kPluginBridgeOscNull";
  134. case kPluginBridgeOscPong:
  135. return "kPluginBridgeOscPong";
  136. case kPluginBridgeOscPluginInfo1:
  137. return "kPluginBridgeOscPluginInfo1";
  138. case kPluginBridgeOscPluginInfo2:
  139. return "kPluginBridgeOscPluginInfo2";
  140. case kPluginBridgeOscAudioCount:
  141. return "kPluginBridgeOscAudioCount";
  142. case kPluginBridgeOscMidiCount:
  143. return "kPluginBridgeOscMidiCount";
  144. case kPluginBridgeOscParameterCount:
  145. return "kPluginBridgeOscParameterCount";
  146. case kPluginBridgeOscProgramCount:
  147. return "kPluginBridgeOscProgramCount";
  148. case kPluginBridgeOscMidiProgramCount:
  149. return "kPluginBridgeOscMidiProgramCount";
  150. case kPluginBridgeOscParameterData1:
  151. return "kPluginBridgeOscParameterData1";
  152. case kPluginBridgeOscParameterData2:
  153. return "kPluginBridgeOscParameterData2";
  154. case kPluginBridgeOscParameterRanges1:
  155. return "kPluginBridgeOscParameterRanges1";
  156. case kPluginBridgeOscParameterRanges2:
  157. return "kPluginBridgeOscParameterRanges2";
  158. case kPluginBridgeOscParameterValue:
  159. return "kPluginBridgeOscParameterValue";
  160. case kPluginBridgeOscDefaultValue:
  161. return "kPluginBridgeOscDefaultValue";
  162. case kPluginBridgeOscCurrentProgram:
  163. return "kPluginBridgeOscCurrentProgram";
  164. case kPluginBridgeOscCurrentMidiProgram:
  165. return "kPluginBridgeOscCurrentMidiProgram";
  166. case kPluginBridgeOscProgramName:
  167. return "kPluginBridgeOscProgramName";
  168. case kPluginBridgeOscMidiProgramData:
  169. return "kPluginBridgeOscMidiProgramData";
  170. case kPluginBridgeOscConfigure:
  171. return "kPluginBridgeOscConfigure";
  172. case kPluginBridgeOscSetCustomData:
  173. return "kPluginBridgeOscSetCustomData";
  174. case kPluginBridgeOscSetChunkDataFile:
  175. return "kPluginBridgeOscSetChunkDataFile";
  176. case kPluginBridgeOscLatency:
  177. return "kPluginBridgeOscLatency";
  178. case kPluginBridgeOscReady:
  179. return "kPluginBridgeOscReady";
  180. case kPluginBridgeOscError:
  181. return "kPluginBridgeOscError";
  182. }
  183. carla_stderr("CarlaBackend::PluginBridgeOscInfoType2str(%i) - invalid type", type);
  184. return nullptr;
  185. }
  186. static inline
  187. const char* PluginBridgeRtOpcode2str(const PluginBridgeRtOpcode opcode) noexcept
  188. {
  189. switch (opcode)
  190. {
  191. case kPluginBridgeRtNull:
  192. return "kPluginBridgeRtNull";
  193. case kPluginBridgeRtSetAudioPool:
  194. return "kPluginBridgeRtSetAudioPool";
  195. case kPluginBridgeRtSetCVPool:
  196. return "kPluginBridgeRtSetCVPool";
  197. case kPluginBridgeRtControlEventParameter:
  198. return "kPluginBridgeRtControlEventParameter";
  199. case kPluginBridgeRtControlEventMidiBank:
  200. return "kPluginBridgeRtControlEventMidiBank";
  201. case kPluginBridgeRtControlEventMidiProgram:
  202. return "kPluginBridgeRtControlEventMidiProgram";
  203. case kPluginBridgeRtControlEventAllSoundOff:
  204. return "kPluginBridgeRtControlEventAllSoundOff";
  205. case kPluginBridgeRtControlEventAllNotesOff:
  206. return "kPluginBridgeRtControlEventAllNotesOff";
  207. case kPluginBridgeRtMidiEvent:
  208. return "kPluginBridgeRtMidiEvent";
  209. case kPluginBridgeRtProcess:
  210. return "kPluginBridgeRtProcess";
  211. case kPluginBridgeRtQuit:
  212. return "kPluginBridgeRtQuit";
  213. }
  214. carla_stderr("CarlaBackend::PluginBridgeRtOpcode2str(%i) - invalid opcode", opcode);
  215. return nullptr;
  216. }
  217. static inline
  218. const char* PluginBridgeNonRtOpcode2str(const PluginBridgeNonRtOpcode opcode) noexcept
  219. {
  220. switch (opcode)
  221. {
  222. case kPluginBridgeNonRtNull:
  223. return "kPluginBridgeNonRtNull";
  224. case kPluginBridgeNonRtPing:
  225. return "kPluginBridgeNonRtPing";
  226. case kPluginBridgeNonRtActivate:
  227. return "kPluginBridgeNonRtActivate";
  228. case kPluginBridgeNonRtDeactivate:
  229. return "kPluginBridgeNonRtDeactivate";
  230. case kPluginBridgeNonRtSetBufferSize:
  231. return "kPluginBridgeNonRtSetBufferSize";
  232. case kPluginBridgeNonRtSetSampleRate:
  233. return "kPluginBridgeNonRtSetSampleRate";
  234. case kPluginBridgeNonRtSetOffline:
  235. return "kPluginBridgeNonRtSetOffline";
  236. case kPluginBridgeNonRtSetOnline:
  237. return "kPluginBridgeNonRtSetOnline";
  238. case kPluginBridgeNonRtSetParameterValue:
  239. return "kPluginBridgeNonRtSetParameterValue";
  240. case kPluginBridgeNonRtSetParameterMidiChannel:
  241. return "kPluginBridgeNonRtSetParameterMidiChannel";
  242. case kPluginBridgeNonRtSetParameterMidiCC:
  243. return "kPluginBridgeNonRtSetParameterMidiCC";
  244. case kPluginBridgeNonRtSetProgram:
  245. return "kPluginBridgeNonRtSetProgram";
  246. case kPluginBridgeNonRtSetMidiProgram:
  247. return "kPluginBridgeNonRtSetMidiProgram";
  248. case kPluginBridgeNonRtSetCustomData:
  249. return "kPluginBridgeNonRtSetCustomData";
  250. case kPluginBridgeNonRtSetChunkDataFile:
  251. return "kPluginBridgeNonRtSetChunkDataFile";
  252. case kPluginBridgeNonRtSetCtrlChannel:
  253. return "kPluginBridgeNonRtSetCtrlChannel";
  254. case kPluginBridgeNonRtSetOscURL:
  255. return "kPluginBridgeNonRtSetOscURL";
  256. case kPluginBridgeNonRtSetOption:
  257. return "kPluginBridgeNonRtSetOption";
  258. case kPluginBridgeNonRtPrepareForSave:
  259. return "kPluginBridgeNonRtPrepareForSave";
  260. case kPluginBridgeNonRtShowUI:
  261. return "kPluginBridgeNonRtShowUI";
  262. case kPluginBridgeNonRtHideUI:
  263. return "kPluginBridgeNonRtHideUI";
  264. case kPluginBridgeNonRtUiParameterChange:
  265. return "kPluginBridgeNonRtUiParameterChange";
  266. case kPluginBridgeNonRtUiProgramChange:
  267. return "kPluginBridgeNonRtUiProgramChange";
  268. case kPluginBridgeNonRtUiMidiProgramChange:
  269. return "kPluginBridgeNonRtUiMidiProgramChange";
  270. case kPluginBridgeNonRtUiNoteOn:
  271. return "kPluginBridgeNonRtUiNoteOn";
  272. case kPluginBridgeNonRtUiNoteOff:
  273. return "kPluginBridgeNonRtUiNoteOff";
  274. case kPluginBridgeNonRtQuit:
  275. return "kPluginBridgeNonRtQuit";
  276. }
  277. carla_stderr("CarlaBackend::PluginBridgeNonRtOpcode2str(%i) - invalid opcode", opcode);
  278. return nullptr;
  279. }
  280. // -----------------------------------------------------------------------
  281. #endif // CARLA_BRIDGE_UTILS_HPP_INCLUDED