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.

230 lines
7.9KB

  1. /*
  2. * Carla Plugin Host
  3. * Copyright (C) 2011-2018 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_ENGINE_GRAPH_HPP_INCLUDED
  18. #define CARLA_ENGINE_GRAPH_HPP_INCLUDED
  19. #include "CarlaEngine.hpp"
  20. #include "CarlaMutex.hpp"
  21. #include "CarlaPatchbayUtils.hpp"
  22. #include "CarlaStringList.hpp"
  23. #include "CarlaThread.hpp"
  24. #include "water/processors/AudioProcessorGraph.h"
  25. #include "water/text/StringArray.h"
  26. using water::AudioProcessorGraph;
  27. using water::AudioSampleBuffer;
  28. using water::MidiBuffer;
  29. CARLA_BACKEND_START_NAMESPACE
  30. // -----------------------------------------------------------------------
  31. struct PatchbayPosition {
  32. bool active;
  33. int x1, y1, x2, y2;
  34. };
  35. // -----------------------------------------------------------------------
  36. // External Graph stuff
  37. enum ExternalGraphGroupIds {
  38. kExternalGraphGroupNull = 0,
  39. kExternalGraphGroupCarla = 1,
  40. kExternalGraphGroupAudioIn = 2,
  41. kExternalGraphGroupAudioOut = 3,
  42. kExternalGraphGroupMidiIn = 4,
  43. kExternalGraphGroupMidiOut = 5,
  44. kExternalGraphGroupMax = 6
  45. };
  46. enum ExternalGraphCarlaPortIds {
  47. kExternalGraphCarlaPortNull = 0,
  48. kExternalGraphCarlaPortAudioIn1 = 1,
  49. kExternalGraphCarlaPortAudioIn2 = 2,
  50. kExternalGraphCarlaPortAudioOut1 = 3,
  51. kExternalGraphCarlaPortAudioOut2 = 4,
  52. kExternalGraphCarlaPortMidiIn = 5,
  53. kExternalGraphCarlaPortMidiOut = 6,
  54. kExternalGraphCarlaPortMax = 7
  55. };
  56. enum ExternalGraphConnectionType {
  57. kExternalGraphConnectionNull = 0,
  58. kExternalGraphConnectionAudioIn1 = 1,
  59. kExternalGraphConnectionAudioIn2 = 2,
  60. kExternalGraphConnectionAudioOut1 = 3,
  61. kExternalGraphConnectionAudioOut2 = 4,
  62. kExternalGraphConnectionMidiInput = 5,
  63. kExternalGraphConnectionMidiOutput = 6
  64. };
  65. struct ExternalGraphPorts {
  66. LinkedList<PortNameToId> ins;
  67. LinkedList<PortNameToId> outs;
  68. const char* getName(bool isInput, uint portId) const noexcept;
  69. uint getPortId(bool isInput, const char portName[], bool* ok = nullptr) const noexcept;
  70. ExternalGraphPorts() noexcept;
  71. CARLA_PREVENT_HEAP_ALLOCATION
  72. CARLA_DECLARE_NON_COPY_CLASS(ExternalGraphPorts)
  73. };
  74. struct ExternalGraph {
  75. PatchbayConnectionList connections;
  76. ExternalGraphPorts audioPorts, midiPorts;
  77. PatchbayPosition positions[kExternalGraphGroupMax];
  78. mutable CharStringListPtr retCon;
  79. ExternalGraph(CarlaEngine* engine) noexcept;
  80. void clear() noexcept;
  81. bool connect(bool sendHost, bool sendOSC,
  82. uint groupA, uint portA, uint groupB, uint portB) noexcept;
  83. bool disconnect(bool sendHost, bool sendOSC,
  84. uint connectionId) noexcept;
  85. void setGroupPos(bool sendHost, bool sendOSC,
  86. uint groupId, int x1, int y1, int x2, int y2);
  87. void refresh(bool sendHost, bool sendOSC,
  88. const char* deviceName);
  89. const char* const* getConnections() const noexcept;
  90. bool getGroupFromName(const char* groupName, uint& groupId) const noexcept;
  91. bool getGroupAndPortIdFromFullName(const char* fullPortName, uint& groupId, uint& portId) const noexcept;
  92. CarlaEngine* const kEngine;
  93. CARLA_PREVENT_HEAP_ALLOCATION
  94. CARLA_DECLARE_NON_COPY_CLASS(ExternalGraph)
  95. };
  96. // -----------------------------------------------------------------------
  97. // RackGraph
  98. struct RackGraph {
  99. ExternalGraph extGraph;
  100. const uint32_t inputs;
  101. const uint32_t outputs;
  102. bool isOffline;
  103. struct Buffers {
  104. CarlaRecursiveMutex mutex;
  105. LinkedList<uint> connectedIn1;
  106. LinkedList<uint> connectedIn2;
  107. LinkedList<uint> connectedOut1;
  108. LinkedList<uint> connectedOut2;
  109. float* inBuf[2];
  110. float* inBufTmp[2];
  111. float* outBuf[2];
  112. float* unusedBuf;
  113. Buffers() noexcept;
  114. ~Buffers() noexcept;
  115. void setBufferSize(uint32_t bufferSize, bool createBuffers) noexcept;
  116. CARLA_PREVENT_HEAP_ALLOCATION
  117. CARLA_DECLARE_NON_COPY_CLASS(Buffers)
  118. } audioBuffers;
  119. RackGraph(CarlaEngine* engine, uint32_t inputs, uint32_t outputs) noexcept;
  120. ~RackGraph() noexcept;
  121. void setBufferSize(uint32_t bufferSize) noexcept;
  122. void setOffline(bool offline) noexcept;
  123. bool connect(uint groupA, uint portA, uint groupB, uint portB) noexcept;
  124. bool disconnect(uint connectionId) noexcept;
  125. void refresh(bool sendHost, bool sendOsc, bool ignored, const char* deviceName);
  126. const char* const* getConnections() const noexcept;
  127. bool getGroupAndPortIdFromFullName(const char* fullPortName, uint& groupId, uint& portId) const noexcept;
  128. // the base, where plugins run
  129. void process(CarlaEngine::ProtectedData* data, const float* inBuf[2], float* outBuf[2], uint32_t frames);
  130. // extended, will call process() in the middle
  131. void processHelper(CarlaEngine::ProtectedData* data, const float* const* inBuf, float* const* outBuf, uint32_t frames);
  132. CarlaEngine* const kEngine;
  133. CARLA_DECLARE_NON_COPY_CLASS(RackGraph)
  134. };
  135. // -----------------------------------------------------------------------
  136. // PatchbayGraph
  137. class PatchbayGraph : private CarlaThread {
  138. public:
  139. PatchbayConnectionList connections;
  140. AudioProcessorGraph graph;
  141. AudioSampleBuffer audioBuffer;
  142. AudioSampleBuffer cvInBuffer;
  143. AudioSampleBuffer cvOutBuffer;
  144. MidiBuffer midiBuffer;
  145. const uint32_t numAudioIns;
  146. const uint32_t numAudioOuts;
  147. const uint32_t numCVIns;
  148. const uint32_t numCVOuts;
  149. mutable CharStringListPtr retCon;
  150. bool usingExternalHost;
  151. bool usingExternalOSC;
  152. ExternalGraph extGraph;
  153. PatchbayGraph(CarlaEngine* engine,
  154. uint32_t audioIns, uint32_t audioOuts,
  155. uint32_t cvIns, uint32_t cvOuts);
  156. ~PatchbayGraph();
  157. void setBufferSize(uint32_t bufferSize);
  158. void setSampleRate(double sampleRate);
  159. void setOffline(bool offline);
  160. void addPlugin(CarlaPluginPtr plugin);
  161. void replacePlugin(CarlaPluginPtr oldPlugin, CarlaPluginPtr newPlugin);
  162. void renamePlugin(CarlaPluginPtr plugin, const char* newName);
  163. void switchPlugins(CarlaPluginPtr pluginA, CarlaPluginPtr pluginB);
  164. void reconfigureForCV(CarlaPluginPtr plugin, const uint portIndex, bool added);
  165. void reconfigurePlugin(CarlaPluginPtr plugin, bool portsAdded);
  166. void removePlugin(CarlaPluginPtr plugin);
  167. void removeAllPlugins();
  168. bool connect(bool external, uint groupA, uint portA, uint groupB, uint portB);
  169. bool disconnect(bool external, uint connectionId);
  170. void disconnectInternalGroup(uint groupId) noexcept;
  171. void setGroupPos(bool sendHost, bool sendOsc, bool external, uint groupId, int x1, int y1, int x2, int y2);
  172. void refresh(bool sendHost, bool sendOsc, bool external, const char* deviceName);
  173. const char* const* getConnections(bool external) const;
  174. const CarlaEngine::PatchbayPosition* getPositions(bool external, uint& count) const;
  175. bool getGroupFromName(bool external, const char* groupName, uint& groupId) const;
  176. bool getGroupAndPortIdFromFullName(bool external, const char* fullPortName, uint& groupId, uint& portId) const;
  177. void process(CarlaEngine::ProtectedData* data,
  178. const float* const* inBuf,
  179. float* const* outBuf,
  180. uint32_t frames);
  181. private:
  182. void run() override;
  183. CarlaEngine* const kEngine;
  184. CARLA_DECLARE_NON_COPY_CLASS(PatchbayGraph)
  185. };
  186. // -----------------------------------------------------------------------
  187. CARLA_BACKEND_END_NAMESPACE
  188. #endif // CARLA_ENGINE_GRAPH_HPP_INCLUDED