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.

198 lines
7.7KB

  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. struct BridgeTimeInfo {
  71. bool playing;
  72. uint64_t frame;
  73. uint64_t usecs;
  74. uint valid;
  75. // bbt
  76. int32_t bar, beat, tick;
  77. float beatsPerBar, beatType;
  78. double barStartTick, ticksPerBeat, beatsPerMinute;
  79. };
  80. // -----------------------------------------------------------------------
  81. struct BridgeShmControl {
  82. union {
  83. void* runServer;
  84. char _padServer[32];
  85. };
  86. union {
  87. void* runClient;
  88. char _padClient[32];
  89. };
  90. StackRingBuffer ringBuffer;
  91. };
  92. // -----------------------------------------------------------------------
  93. static inline
  94. const char* PluginBridgeInfoType2str(const PluginBridgeInfoType type) noexcept
  95. {
  96. switch (type)
  97. {
  98. case kPluginBridgePong:
  99. return "kPluginBridgePong";
  100. case kPluginBridgePluginInfo1:
  101. return "kPluginBridgePluginInfo1";
  102. case kPluginBridgePluginInfo2:
  103. return "kPluginBridgePluginInfo2";
  104. case kPluginBridgeAudioCount:
  105. return "kPluginBridgeAudioCount";
  106. case kPluginBridgeMidiCount:
  107. return "kPluginBridgeMidiCount";
  108. case kPluginBridgeParameterCount:
  109. return "kPluginBridgeParameterCount";
  110. case kPluginBridgeProgramCount:
  111. return "kPluginBridgeProgramCount";
  112. case kPluginBridgeMidiProgramCount:
  113. return "kPluginBridgeMidiProgramCount";
  114. case kPluginBridgeParameterData:
  115. return "kPluginBridgeParameterData";
  116. case kPluginBridgeParameterRanges1:
  117. return "kPluginBridgeParameterRanges1";
  118. case kPluginBridgeParameterRanges2:
  119. return "kPluginBridgeParameterRanges2";
  120. case kPluginBridgeParameterMidiCC:
  121. return "kPluginBridgeParameterMidiCC";
  122. case kPluginBridgeParameterMidiChannel:
  123. return "kPluginBridgeParameterMidiChannel";
  124. case kPluginBridgeParameterValue:
  125. return "kPluginBridgeParameterValue";
  126. case kPluginBridgeDefaultValue:
  127. return "kPluginBridgeDefaultValue";
  128. case kPluginBridgeCurrentProgram:
  129. return "kPluginBridgeCurrentProgram";
  130. case kPluginBridgeCurrentMidiProgram:
  131. return "kPluginBridgeCurrentMidiProgram";
  132. case kPluginBridgeProgramName:
  133. return "kPluginBridgeProgramName";
  134. case kPluginBridgeMidiProgramData:
  135. return "kPluginBridgeMidiProgramData";
  136. case kPluginBridgeConfigure:
  137. return "kPluginBridgeConfigure";
  138. case kPluginBridgeSetCustomData:
  139. return "kPluginBridgeSetCustomData";
  140. case kPluginBridgeSetChunkData:
  141. return "kPluginBridgeSetChunkData";
  142. case kPluginBridgeUpdateNow:
  143. return "kPluginBridgeUpdateNow";
  144. case kPluginBridgeError:
  145. return "kPluginBridgeError";
  146. }
  147. carla_stderr("CarlaBackend::PluginBridgeInfoType2str(%i) - invalid type", type);
  148. return nullptr;
  149. }
  150. static inline
  151. const char* PluginBridgeOpcode2str(const PluginBridgeOpcode opcode) noexcept
  152. {
  153. switch (opcode)
  154. {
  155. case kPluginBridgeOpcodeNull:
  156. return "kPluginBridgeOpcodeNull";
  157. case kPluginBridgeOpcodeSetAudioPool:
  158. return "kPluginBridgeOpcodeSetAudioPool";
  159. case kPluginBridgeOpcodeSetBufferSize:
  160. return "kPluginBridgeOpcodeSetBufferSize";
  161. case kPluginBridgeOpcodeSetSampleRate:
  162. return "kPluginBridgeOpcodeSetSampleRate";
  163. case kPluginBridgeOpcodeSetParameter:
  164. return "kPluginBridgeOpcodeSetParameter";
  165. case kPluginBridgeOpcodeSetProgram:
  166. return "kPluginBridgeOpcodeSetProgram";
  167. case kPluginBridgeOpcodeSetMidiProgram:
  168. return "kPluginBridgeOpcodeSetMidiProgram";
  169. case kPluginBridgeOpcodeMidiEvent:
  170. return "kPluginBridgeOpcodeMidiEvent";
  171. case kPluginBridgeOpcodeProcess:
  172. return "kPluginBridgeOpcodeProcess";
  173. case kPluginBridgeOpcodeQuit:
  174. return "kPluginBridgeOpcodeQuit";
  175. }
  176. carla_stderr("CarlaBackend::PluginBridgeOpcode2str(%i) - invalid opcode", opcode);
  177. return nullptr;
  178. }
  179. // -----------------------------------------------------------------------
  180. #endif // CARLA_BRIDGE_UTILS_HPP_INCLUDED