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.

298 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[64];
  99. };
  100. union {
  101. void* client;
  102. char _padClient[64];
  103. };
  104. };
  105. // needs to be 64bit aligned
  106. struct BridgeTimeInfo {
  107. uint64_t playing;
  108. uint64_t frame;
  109. uint64_t usecs;
  110. uint32_t valid;
  111. // bbt
  112. int32_t bar, beat, tick;
  113. float beatsPerBar, beatType;
  114. double barStartTick, ticksPerBeat, beatsPerMinute;
  115. };
  116. struct BridgeRtData {
  117. BridgeSemaphore sem;
  118. BridgeTimeInfo timeInfo;
  119. StackBuffer ringBuffer;
  120. };
  121. struct BridgeNonRtData {
  122. BigStackBuffer ringBuffer;
  123. };
  124. // -----------------------------------------------------------------------
  125. static inline
  126. const char* PluginBridgeOscInfoType2str(const PluginBridgeOscInfoType type) noexcept
  127. {
  128. switch (type)
  129. {
  130. case kPluginBridgeOscNull:
  131. return "kPluginBridgeOscNull";
  132. case kPluginBridgeOscPong:
  133. return "kPluginBridgeOscPong";
  134. case kPluginBridgeOscPluginInfo1:
  135. return "kPluginBridgeOscPluginInfo1";
  136. case kPluginBridgeOscPluginInfo2:
  137. return "kPluginBridgeOscPluginInfo2";
  138. case kPluginBridgeOscAudioCount:
  139. return "kPluginBridgeOscAudioCount";
  140. case kPluginBridgeOscMidiCount:
  141. return "kPluginBridgeOscMidiCount";
  142. case kPluginBridgeOscParameterCount:
  143. return "kPluginBridgeOscParameterCount";
  144. case kPluginBridgeOscProgramCount:
  145. return "kPluginBridgeOscProgramCount";
  146. case kPluginBridgeOscMidiProgramCount:
  147. return "kPluginBridgeOscMidiProgramCount";
  148. case kPluginBridgeOscParameterData1:
  149. return "kPluginBridgeOscParameterData1";
  150. case kPluginBridgeOscParameterData2:
  151. return "kPluginBridgeOscParameterData2";
  152. case kPluginBridgeOscParameterRanges1:
  153. return "kPluginBridgeOscParameterRanges1";
  154. case kPluginBridgeOscParameterRanges2:
  155. return "kPluginBridgeOscParameterRanges2";
  156. case kPluginBridgeOscParameterValue:
  157. return "kPluginBridgeOscParameterValue";
  158. case kPluginBridgeOscDefaultValue:
  159. return "kPluginBridgeOscDefaultValue";
  160. case kPluginBridgeOscCurrentProgram:
  161. return "kPluginBridgeOscCurrentProgram";
  162. case kPluginBridgeOscCurrentMidiProgram:
  163. return "kPluginBridgeOscCurrentMidiProgram";
  164. case kPluginBridgeOscProgramName:
  165. return "kPluginBridgeOscProgramName";
  166. case kPluginBridgeOscMidiProgramData:
  167. return "kPluginBridgeOscMidiProgramData";
  168. case kPluginBridgeOscConfigure:
  169. return "kPluginBridgeOscConfigure";
  170. case kPluginBridgeOscSetCustomData:
  171. return "kPluginBridgeOscSetCustomData";
  172. case kPluginBridgeOscSetChunkDataFile:
  173. return "kPluginBridgeOscSetChunkDataFile";
  174. case kPluginBridgeOscLatency:
  175. return "kPluginBridgeOscLatency";
  176. case kPluginBridgeOscReady:
  177. return "kPluginBridgeOscReady";
  178. case kPluginBridgeOscError:
  179. return "kPluginBridgeOscError";
  180. }
  181. carla_stderr("CarlaBackend::PluginBridgeOscInfoType2str(%i) - invalid type", type);
  182. return nullptr;
  183. }
  184. static inline
  185. const char* PluginBridgeRtOpcode2str(const PluginBridgeRtOpcode opcode) noexcept
  186. {
  187. switch (opcode)
  188. {
  189. case kPluginBridgeRtNull:
  190. return "kPluginBridgeRtNull";
  191. case kPluginBridgeRtSetAudioPool:
  192. return "kPluginBridgeRtSetAudioPool";
  193. case kPluginBridgeRtControlEventParameter:
  194. return "kPluginBridgeRtControlEventParameter";
  195. case kPluginBridgeRtControlEventMidiBank:
  196. return "kPluginBridgeRtControlEventMidiBank";
  197. case kPluginBridgeRtControlEventMidiProgram:
  198. return "kPluginBridgeRtControlEventMidiProgram";
  199. case kPluginBridgeRtControlEventAllSoundOff:
  200. return "kPluginBridgeRtControlEventAllSoundOff";
  201. case kPluginBridgeRtControlEventAllNotesOff:
  202. return "kPluginBridgeRtControlEventAllNotesOff";
  203. case kPluginBridgeRtMidiEvent:
  204. return "kPluginBridgeRtMidiEvent";
  205. case kPluginBridgeRtProcess:
  206. return "kPluginBridgeRtProcess";
  207. }
  208. carla_stderr("CarlaBackend::PluginBridgeRtOpcode2str(%i) - invalid opcode", opcode);
  209. return nullptr;
  210. }
  211. static inline
  212. const char* PluginBridgeNonRtOpcode2str(const PluginBridgeNonRtOpcode opcode) noexcept
  213. {
  214. switch (opcode)
  215. {
  216. case kPluginBridgeNonRtNull:
  217. return "kPluginBridgeNonRtNull";
  218. case kPluginBridgeNonRtPing:
  219. return "kPluginBridgeNonRtPing";
  220. case kPluginBridgeNonRtActivate:
  221. return "kPluginBridgeNonRtActivate";
  222. case kPluginBridgeNonRtDeactivate:
  223. return "kPluginBridgeNonRtDeactivate";
  224. case kPluginBridgeNonRtSetBufferSize:
  225. return "kPluginBridgeNonRtSetBufferSize";
  226. case kPluginBridgeNonRtSetSampleRate:
  227. return "kPluginBridgeNonRtSetSampleRate";
  228. case kPluginBridgeNonRtSetOffline:
  229. return "kPluginBridgeNonRtSetOffline";
  230. case kPluginBridgeNonRtSetOnline:
  231. return "kPluginBridgeNonRtSetOnline";
  232. case kPluginBridgeNonRtSetParameterValue:
  233. return "kPluginBridgeNonRtSetParameterValue";
  234. case kPluginBridgeNonRtSetParameterMidiChannel:
  235. return "kPluginBridgeNonRtSetParameterMidiChannel";
  236. case kPluginBridgeNonRtSetParameterMidiCC:
  237. return "kPluginBridgeNonRtSetParameterMidiCC";
  238. case kPluginBridgeNonRtSetProgram:
  239. return "kPluginBridgeNonRtSetProgram";
  240. case kPluginBridgeNonRtSetMidiProgram:
  241. return "kPluginBridgeNonRtSetMidiProgram";
  242. case kPluginBridgeNonRtSetCustomData:
  243. return "kPluginBridgeNonRtSetCustomData";
  244. case kPluginBridgeNonRtSetChunkDataFile:
  245. return "kPluginBridgeNonRtSetChunkDataFile";
  246. case kPluginBridgeNonRtSetCtrlChannel:
  247. return "kPluginBridgeNonRtSetCtrlChannel";
  248. case kPluginBridgeNonRtSetOscURL:
  249. return "kPluginBridgeNonRtSetOscURL";
  250. case kPluginBridgeNonRtSetOption:
  251. return "kPluginBridgeNonRtSetOption";
  252. case kPluginBridgeNonRtPrepareForSave:
  253. return "kPluginBridgeNonRtPrepareForSave";
  254. case kPluginBridgeNonRtShowUI:
  255. return "kPluginBridgeNonRtShowUI";
  256. case kPluginBridgeNonRtHideUI:
  257. return "kPluginBridgeNonRtHideUI";
  258. case kPluginBridgeNonRtUiParameterChange:
  259. return "kPluginBridgeNonRtUiParameterChange";
  260. case kPluginBridgeNonRtUiProgramChange:
  261. return "kPluginBridgeNonRtUiProgramChange";
  262. case kPluginBridgeNonRtUiMidiProgramChange:
  263. return "kPluginBridgeNonRtUiMidiProgramChange";
  264. case kPluginBridgeNonRtUiNoteOn:
  265. return "kPluginBridgeNonRtUiNoteOn";
  266. case kPluginBridgeNonRtUiNoteOff:
  267. return "kPluginBridgeNonRtUiNoteOff";
  268. case kPluginBridgeNonRtQuit:
  269. return "kPluginBridgeNonRtQuit";
  270. }
  271. carla_stderr("CarlaBackend::PluginBridgeNonRtOpcode2str(%i) - invalid opcode", opcode);
  272. return nullptr;
  273. }
  274. // -----------------------------------------------------------------------
  275. #endif // CARLA_BRIDGE_UTILS_HPP_INCLUDED