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.

199 lines
7.9KB

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