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.

200 lines
7.8KB

  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 "CarlaBackend.h"
  20. #include "CarlaEngine.hpp"
  21. #include "CarlaRingBuffer.hpp"
  22. // -----------------------------------------------------------------------
  23. enum PluginBridgeInfoType {
  24. kPluginBridgePong = 0,
  25. kPluginBridgePluginInfo1, // uuh => category, hints, uniqueId
  26. kPluginBridgePluginInfo2, // ssss => realName, label, maker, copyright
  27. kPluginBridgeAudioCount, // uu => ins, outs
  28. kPluginBridgeMidiCount, // uu => ins, outs
  29. kPluginBridgeParameterCount, // uu => ins, outs
  30. kPluginBridgeProgramCount, // u => count
  31. kPluginBridgeMidiProgramCount, // u => count
  32. kPluginBridgeParameterData, // uiuuss => index, rindex, type, hints, name, unit
  33. kPluginBridgeParameterRanges1, // ufff => index, def, min, max
  34. kPluginBridgeParameterRanges2, // ufff => index, step, stepSmall, stepLarge
  35. kPluginBridgeParameterMidiCC, // ui => index, cc
  36. kPluginBridgeParameterMidiChannel, // uu => index, channel
  37. kPluginBridgeParameterValue, // uf => index, value
  38. kPluginBridgeDefaultValue, // uf => index, value
  39. kPluginBridgeCurrentProgram, // i => index
  40. kPluginBridgeCurrentMidiProgram, // i => index
  41. kPluginBridgeProgramName, // us => index, name
  42. kPluginBridgeMidiProgramData, // uuus => index, bank, program, name
  43. kPluginBridgeConfigure, // ss => key, value
  44. kPluginBridgeSetCustomData, // sss => type, key, value
  45. kPluginBridgeSetChunkData, // s => chunkFile
  46. kPluginBridgeUpdateNow, //
  47. kPluginBridgeError //
  48. };
  49. enum PluginBridgeOpcode {
  50. kPluginBridgeOpcodeNull = 0,
  51. kPluginBridgeOpcodeSetAudioPool = 1, // long
  52. kPluginBridgeOpcodeSetBufferSize = 2, // int
  53. kPluginBridgeOpcodeSetSampleRate = 3, // float
  54. kPluginBridgeOpcodeSetParameter = 4, // int, float
  55. kPluginBridgeOpcodeSetProgram = 5, // int
  56. kPluginBridgeOpcodeSetMidiProgram = 6, // int
  57. kPluginBridgeOpcodeMidiEvent = 7, // long, int, char[] (long = timeFrame, int = size max 4)
  58. kPluginBridgeOpcodeProcess = 8,
  59. kPluginBridgeOpcodeQuit = 9
  60. };
  61. const char* const CARLA_BRIDGE_MSG_HIDE_GUI = "CarlaBridgeHideGUI"; //!< Plugin -> Host call, tells host GUI is now hidden
  62. const char* const CARLA_BRIDGE_MSG_SAVED = "CarlaBridgeSaved"; //!< Plugin -> Host call, tells host state is saved
  63. #if 0
  64. const char* const CARLA_BRIDGE_MSG_SAVE_NOW = "CarlaBridgeSaveNow"; //!< Host -> Plugin call, tells plugin to save state now
  65. const char* const CARLA_BRIDGE_MSG_SET_CHUNK = "CarlaBridgeSetChunk"; //!< Host -> Plugin call, tells plugin to set chunk in file \a value
  66. const char* const CARLA_BRIDGE_MSG_SET_CUSTOM = "CarlaBridgeSetCustom"; //!< Host -> Plugin call, tells plugin to set a custom data set using \a value ("type·key·rvalue").
  67. //If \a type is 'chunk' or 'binary' \a rvalue refers to chunk file.
  68. #endif
  69. // -----------------------------------------------------------------------
  70. PRE_PACKED_STRUCTURE
  71. struct BridgeTimeInfo {
  72. bool playing;
  73. uint64_t frame;
  74. uint64_t usecs;
  75. uint valid;
  76. // bbt
  77. int32_t bar, beat, tick;
  78. float beatsPerBar, beatType;
  79. double barStartTick, ticksPerBeat, beatsPerMinute;
  80. } POST_PACKED_STRUCTURE;
  81. // -----------------------------------------------------------------------
  82. PRE_PACKED_STRUCTURE
  83. struct BridgeShmControl {
  84. union {
  85. void* runServer;
  86. char _padServer[32];
  87. };
  88. union {
  89. void* runClient;
  90. char _padClient[32];
  91. };
  92. StackRingBuffer ringBuffer;
  93. } POST_PACKED_STRUCTURE;
  94. // -----------------------------------------------------------------------
  95. static inline
  96. const char* PluginBridgeInfoType2str(const PluginBridgeInfoType type) noexcept
  97. {
  98. switch (type)
  99. {
  100. case kPluginBridgePong:
  101. return "kPluginBridgePong";
  102. case kPluginBridgePluginInfo1:
  103. return "kPluginBridgePluginInfo1";
  104. case kPluginBridgePluginInfo2:
  105. return "kPluginBridgePluginInfo2";
  106. case kPluginBridgeAudioCount:
  107. return "kPluginBridgeAudioCount";
  108. case kPluginBridgeMidiCount:
  109. return "kPluginBridgeMidiCount";
  110. case kPluginBridgeParameterCount:
  111. return "kPluginBridgeParameterCount";
  112. case kPluginBridgeProgramCount:
  113. return "kPluginBridgeProgramCount";
  114. case kPluginBridgeMidiProgramCount:
  115. return "kPluginBridgeMidiProgramCount";
  116. case kPluginBridgeParameterData:
  117. return "kPluginBridgeParameterData";
  118. case kPluginBridgeParameterRanges1:
  119. return "kPluginBridgeParameterRanges1";
  120. case kPluginBridgeParameterRanges2:
  121. return "kPluginBridgeParameterRanges2";
  122. case kPluginBridgeParameterMidiCC:
  123. return "kPluginBridgeParameterMidiCC";
  124. case kPluginBridgeParameterMidiChannel:
  125. return "kPluginBridgeParameterMidiChannel";
  126. case kPluginBridgeParameterValue:
  127. return "kPluginBridgeParameterValue";
  128. case kPluginBridgeDefaultValue:
  129. return "kPluginBridgeDefaultValue";
  130. case kPluginBridgeCurrentProgram:
  131. return "kPluginBridgeCurrentProgram";
  132. case kPluginBridgeCurrentMidiProgram:
  133. return "kPluginBridgeCurrentMidiProgram";
  134. case kPluginBridgeProgramName:
  135. return "kPluginBridgeProgramName";
  136. case kPluginBridgeMidiProgramData:
  137. return "kPluginBridgeMidiProgramData";
  138. case kPluginBridgeConfigure:
  139. return "kPluginBridgeConfigure";
  140. case kPluginBridgeSetCustomData:
  141. return "kPluginBridgeSetCustomData";
  142. case kPluginBridgeSetChunkData:
  143. return "kPluginBridgeSetChunkData";
  144. case kPluginBridgeUpdateNow:
  145. return "kPluginBridgeUpdateNow";
  146. case kPluginBridgeError:
  147. return "kPluginBridgeError";
  148. }
  149. carla_stderr("CarlaBackend::PluginBridgeInfoType2str(%i) - invalid type", type);
  150. return nullptr;
  151. }
  152. static inline
  153. const char* PluginBridgeOpcode2str(const PluginBridgeOpcode opcode) noexcept
  154. {
  155. switch (opcode)
  156. {
  157. case kPluginBridgeOpcodeNull:
  158. return "kPluginBridgeOpcodeNull";
  159. case kPluginBridgeOpcodeSetAudioPool:
  160. return "kPluginBridgeOpcodeSetAudioPool";
  161. case kPluginBridgeOpcodeSetBufferSize:
  162. return "kPluginBridgeOpcodeSetBufferSize";
  163. case kPluginBridgeOpcodeSetSampleRate:
  164. return "kPluginBridgeOpcodeSetSampleRate";
  165. case kPluginBridgeOpcodeSetParameter:
  166. return "kPluginBridgeOpcodeSetParameter";
  167. case kPluginBridgeOpcodeSetProgram:
  168. return "kPluginBridgeOpcodeSetProgram";
  169. case kPluginBridgeOpcodeSetMidiProgram:
  170. return "kPluginBridgeOpcodeSetMidiProgram";
  171. case kPluginBridgeOpcodeMidiEvent:
  172. return "kPluginBridgeOpcodeMidiEvent";
  173. case kPluginBridgeOpcodeProcess:
  174. return "kPluginBridgeOpcodeProcess";
  175. case kPluginBridgeOpcodeQuit:
  176. return "kPluginBridgeOpcodeQuit";
  177. }
  178. carla_stderr("CarlaBackend::PluginBridgeOpcode2str(%i) - invalid opcode", opcode);
  179. return nullptr;
  180. }
  181. // -----------------------------------------------------------------------
  182. #endif // CARLA_BRIDGE_UTILS_HPP_INCLUDED