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.

297 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. kPluginBridgeRtControlEventParameter, // uint/frame, byte/chan, ushort, float
  54. kPluginBridgeRtControlEventMidiBank, // uint/frame, byte/chan, ushort
  55. kPluginBridgeRtControlEventMidiProgram, // uint/frame, byte/chan, ushort
  56. kPluginBridgeRtControlEventAllSoundOff, // uint/frame, byte/chan
  57. kPluginBridgeRtControlEventAllNotesOff, // uint/frame, byte/chan
  58. kPluginBridgeRtMidiEvent, // uint/frame, byte/port, byte/size, byte[]/data
  59. kPluginBridgeRtProcess
  60. };
  61. // carla-plugin sends these during non-RT
  62. enum PluginBridgeNonRtOpcode {
  63. kPluginBridgeNonRtNull = 0,
  64. kPluginBridgeNonRtPing,
  65. kPluginBridgeNonRtActivate,
  66. kPluginBridgeNonRtDeactivate,
  67. kPluginBridgeNonRtSetBufferSize, // uint
  68. kPluginBridgeNonRtSetSampleRate, // double
  69. kPluginBridgeNonRtSetOffline,
  70. kPluginBridgeNonRtSetOnline,
  71. kPluginBridgeNonRtSetParameterValue, // uint, float
  72. kPluginBridgeNonRtSetParameterMidiChannel, // uint, byte
  73. kPluginBridgeNonRtSetParameterMidiCC, // uint, short
  74. kPluginBridgeNonRtSetProgram, // int
  75. kPluginBridgeNonRtSetMidiProgram, // int
  76. kPluginBridgeNonRtSetCustomData, // uint/size, str[], uint/size, str[], uint/size, str[] TODO plugin
  77. kPluginBridgeNonRtSetChunkDataFile, // uint/size, str[]/file
  78. kPluginBridgeNonRtSetCtrlChannel, // short
  79. kPluginBridgeNonRtSetOscURL, // uint/size, str[]/url
  80. kPluginBridgeNonRtSetOption, // uint/option, bool
  81. kPluginBridgeNonRtPrepareForSave,
  82. kPluginBridgeNonRtShowUI,
  83. kPluginBridgeNonRtHideUI,
  84. kPluginBridgeNonRtUiParameterChange, // uint, float
  85. kPluginBridgeNonRtUiProgramChange, // uint
  86. kPluginBridgeNonRtUiMidiProgramChange, // uint
  87. kPluginBridgeNonRtUiNoteOn, // byte, byte, byte
  88. kPluginBridgeNonRtUiNoteOff, // byte, byte
  89. kPluginBridgeNonRtQuit
  90. };
  91. // -----------------------------------------------------------------------
  92. const char* const CARLA_BRIDGE_MSG_HIDE_GUI = "CarlaBridgeHideGUI"; //!< Plugin -> Host configure, tells host GUI is now hidden
  93. const char* const CARLA_BRIDGE_MSG_SAVED = "CarlaBridgeSaved"; //!< Plugin -> Host configure, tells host state is saved
  94. // -----------------------------------------------------------------------
  95. struct BridgeSemaphore {
  96. union {
  97. void* server;
  98. char _padServer[32];
  99. };
  100. union {
  101. void* client;
  102. char _padClient[32];
  103. };
  104. };
  105. struct BridgeTimeInfo {
  106. bool playing;
  107. uint64_t frame;
  108. uint64_t usecs;
  109. uint valid;
  110. // bbt
  111. int32_t bar, beat, tick;
  112. float beatsPerBar, beatType;
  113. double barStartTick, ticksPerBeat, beatsPerMinute;
  114. };
  115. struct BridgeRtData {
  116. BridgeSemaphore sem;
  117. BridgeTimeInfo timeInfo;
  118. StackBuffer ringBuffer;
  119. };
  120. struct BridgeNonRtData {
  121. BigStackBuffer ringBuffer;
  122. };
  123. // -----------------------------------------------------------------------
  124. static inline
  125. const char* PluginBridgeOscInfoType2str(const PluginBridgeOscInfoType type) noexcept
  126. {
  127. switch (type)
  128. {
  129. case kPluginBridgeOscNull:
  130. return "kPluginBridgeOscNull";
  131. case kPluginBridgeOscPong:
  132. return "kPluginBridgeOscPong";
  133. case kPluginBridgeOscPluginInfo1:
  134. return "kPluginBridgeOscPluginInfo1";
  135. case kPluginBridgeOscPluginInfo2:
  136. return "kPluginBridgeOscPluginInfo2";
  137. case kPluginBridgeOscAudioCount:
  138. return "kPluginBridgeOscAudioCount";
  139. case kPluginBridgeOscMidiCount:
  140. return "kPluginBridgeOscMidiCount";
  141. case kPluginBridgeOscParameterCount:
  142. return "kPluginBridgeOscParameterCount";
  143. case kPluginBridgeOscProgramCount:
  144. return "kPluginBridgeOscProgramCount";
  145. case kPluginBridgeOscMidiProgramCount:
  146. return "kPluginBridgeOscMidiProgramCount";
  147. case kPluginBridgeOscParameterData1:
  148. return "kPluginBridgeOscParameterData1";
  149. case kPluginBridgeOscParameterData2:
  150. return "kPluginBridgeOscParameterData2";
  151. case kPluginBridgeOscParameterRanges1:
  152. return "kPluginBridgeOscParameterRanges1";
  153. case kPluginBridgeOscParameterRanges2:
  154. return "kPluginBridgeOscParameterRanges2";
  155. case kPluginBridgeOscParameterValue:
  156. return "kPluginBridgeOscParameterValue";
  157. case kPluginBridgeOscDefaultValue:
  158. return "kPluginBridgeOscDefaultValue";
  159. case kPluginBridgeOscCurrentProgram:
  160. return "kPluginBridgeOscCurrentProgram";
  161. case kPluginBridgeOscCurrentMidiProgram:
  162. return "kPluginBridgeOscCurrentMidiProgram";
  163. case kPluginBridgeOscProgramName:
  164. return "kPluginBridgeOscProgramName";
  165. case kPluginBridgeOscMidiProgramData:
  166. return "kPluginBridgeOscMidiProgramData";
  167. case kPluginBridgeOscConfigure:
  168. return "kPluginBridgeOscConfigure";
  169. case kPluginBridgeOscSetCustomData:
  170. return "kPluginBridgeOscSetCustomData";
  171. case kPluginBridgeOscSetChunkDataFile:
  172. return "kPluginBridgeOscSetChunkDataFile";
  173. case kPluginBridgeOscLatency:
  174. return "kPluginBridgeOscLatency";
  175. case kPluginBridgeOscReady:
  176. return "kPluginBridgeOscReady";
  177. case kPluginBridgeOscError:
  178. return "kPluginBridgeOscError";
  179. }
  180. carla_stderr("CarlaBackend::PluginBridgeOscInfoType2str(%i) - invalid type", type);
  181. return nullptr;
  182. }
  183. static inline
  184. const char* PluginBridgeRtOpcode2str(const PluginBridgeRtOpcode opcode) noexcept
  185. {
  186. switch (opcode)
  187. {
  188. case kPluginBridgeRtNull:
  189. return "kPluginBridgeRtNull";
  190. case kPluginBridgeRtSetAudioPool:
  191. return "kPluginBridgeRtSetAudioPool";
  192. case kPluginBridgeRtControlEventParameter:
  193. return "kPluginBridgeRtControlEventParameter";
  194. case kPluginBridgeRtControlEventMidiBank:
  195. return "kPluginBridgeRtControlEventMidiBank";
  196. case kPluginBridgeRtControlEventMidiProgram:
  197. return "kPluginBridgeRtControlEventMidiProgram";
  198. case kPluginBridgeRtControlEventAllSoundOff:
  199. return "kPluginBridgeRtControlEventAllSoundOff";
  200. case kPluginBridgeRtControlEventAllNotesOff:
  201. return "kPluginBridgeRtControlEventAllNotesOff";
  202. case kPluginBridgeRtMidiEvent:
  203. return "kPluginBridgeRtMidiEvent";
  204. case kPluginBridgeRtProcess:
  205. return "kPluginBridgeRtProcess";
  206. }
  207. carla_stderr("CarlaBackend::PluginBridgeRtOpcode2str(%i) - invalid opcode", opcode);
  208. return nullptr;
  209. }
  210. static inline
  211. const char* PluginBridgeNonRtOpcode2str(const PluginBridgeNonRtOpcode opcode) noexcept
  212. {
  213. switch (opcode)
  214. {
  215. case kPluginBridgeNonRtNull:
  216. return "kPluginBridgeNonRtNull";
  217. case kPluginBridgeNonRtPing:
  218. return "kPluginBridgeNonRtPing";
  219. case kPluginBridgeNonRtActivate:
  220. return "kPluginBridgeNonRtActivate";
  221. case kPluginBridgeNonRtDeactivate:
  222. return "kPluginBridgeNonRtDeactivate";
  223. case kPluginBridgeNonRtSetBufferSize:
  224. return "kPluginBridgeNonRtSetBufferSize";
  225. case kPluginBridgeNonRtSetSampleRate:
  226. return "kPluginBridgeNonRtSetSampleRate";
  227. case kPluginBridgeNonRtSetOffline:
  228. return "kPluginBridgeNonRtSetOffline";
  229. case kPluginBridgeNonRtSetOnline:
  230. return "kPluginBridgeNonRtSetOnline";
  231. case kPluginBridgeNonRtSetParameterValue:
  232. return "kPluginBridgeNonRtSetParameterValue";
  233. case kPluginBridgeNonRtSetParameterMidiChannel:
  234. return "kPluginBridgeNonRtSetParameterMidiChannel";
  235. case kPluginBridgeNonRtSetParameterMidiCC:
  236. return "kPluginBridgeNonRtSetParameterMidiCC";
  237. case kPluginBridgeNonRtSetProgram:
  238. return "kPluginBridgeNonRtSetProgram";
  239. case kPluginBridgeNonRtSetMidiProgram:
  240. return "kPluginBridgeNonRtSetMidiProgram";
  241. case kPluginBridgeNonRtSetCustomData:
  242. return "kPluginBridgeNonRtSetCustomData";
  243. case kPluginBridgeNonRtSetChunkDataFile:
  244. return "kPluginBridgeNonRtSetChunkDataFile";
  245. case kPluginBridgeNonRtSetCtrlChannel:
  246. return "kPluginBridgeNonRtSetCtrlChannel";
  247. case kPluginBridgeNonRtSetOscURL:
  248. return "kPluginBridgeNonRtSetOscURL";
  249. case kPluginBridgeNonRtSetOption:
  250. return "kPluginBridgeNonRtSetOption";
  251. case kPluginBridgeNonRtPrepareForSave:
  252. return "kPluginBridgeNonRtPrepareForSave";
  253. case kPluginBridgeNonRtShowUI:
  254. return "kPluginBridgeNonRtShowUI";
  255. case kPluginBridgeNonRtHideUI:
  256. return "kPluginBridgeNonRtHideUI";
  257. case kPluginBridgeNonRtUiParameterChange:
  258. return "kPluginBridgeNonRtUiParameterChange";
  259. case kPluginBridgeNonRtUiProgramChange:
  260. return "kPluginBridgeNonRtUiProgramChange";
  261. case kPluginBridgeNonRtUiMidiProgramChange:
  262. return "kPluginBridgeNonRtUiMidiProgramChange";
  263. case kPluginBridgeNonRtUiNoteOn:
  264. return "kPluginBridgeNonRtUiNoteOn";
  265. case kPluginBridgeNonRtUiNoteOff:
  266. return "kPluginBridgeNonRtUiNoteOff";
  267. case kPluginBridgeNonRtQuit:
  268. return "kPluginBridgeNonRtQuit";
  269. }
  270. carla_stderr("CarlaBackend::PluginBridgeNonRtOpcode2str(%i) - invalid opcode", opcode);
  271. return nullptr;
  272. }
  273. // -----------------------------------------------------------------------
  274. #endif // CARLA_BRIDGE_UTILS_HPP_INCLUDED