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.

CarlaEngineGraph.hpp 8.0KB

10 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /*
  2. * Carla Plugin Host
  3. * Copyright (C) 2011-2022 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 "CarlaRunner.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 getPortIdFromName(bool isInput, const char name[], bool* ok = nullptr) const noexcept;
  70. uint getPortIdFromIdentifier(bool isInput, const char identifier[], bool* ok = nullptr) const noexcept;
  71. ExternalGraphPorts() noexcept;
  72. CARLA_PREVENT_HEAP_ALLOCATION
  73. CARLA_DECLARE_NON_COPYABLE(ExternalGraphPorts)
  74. };
  75. struct ExternalGraph {
  76. PatchbayConnectionList connections;
  77. ExternalGraphPorts audioPorts, midiPorts;
  78. PatchbayPosition positions[kExternalGraphGroupMax];
  79. mutable CharStringListPtr retCon;
  80. ExternalGraph(CarlaEngine* engine) noexcept;
  81. void clear() noexcept;
  82. bool connect(bool sendHost, bool sendOSC,
  83. uint groupA, uint portA, uint groupB, uint portB) noexcept;
  84. bool disconnect(bool sendHost, bool sendOSC,
  85. uint connectionId) noexcept;
  86. void setGroupPos(bool sendHost, bool sendOSC,
  87. uint groupId, int x1, int y1, int x2, int y2);
  88. void refresh(bool sendHost, bool sendOSC,
  89. const char* deviceName);
  90. const char* const* getConnections() const noexcept;
  91. bool getGroupFromName(const char* groupName, uint& groupId) const noexcept;
  92. bool getGroupAndPortIdFromFullName(const char* fullPortName, uint& groupId, uint& portId) const noexcept;
  93. CarlaEngine* const kEngine;
  94. CARLA_PREVENT_HEAP_ALLOCATION
  95. CARLA_DECLARE_NON_COPYABLE(ExternalGraph)
  96. };
  97. // -----------------------------------------------------------------------
  98. // RackGraph
  99. struct RackGraph {
  100. ExternalGraph extGraph;
  101. const uint32_t inputs;
  102. const uint32_t outputs;
  103. bool isOffline;
  104. struct Buffers {
  105. CarlaRecursiveMutex mutex;
  106. LinkedList<uint> connectedIn1;
  107. LinkedList<uint> connectedIn2;
  108. LinkedList<uint> connectedOut1;
  109. LinkedList<uint> connectedOut2;
  110. float* inBuf[2];
  111. float* inBufTmp[2];
  112. float* outBuf[2];
  113. float* unusedBuf;
  114. Buffers() noexcept;
  115. ~Buffers() noexcept;
  116. void setBufferSize(uint32_t bufferSize, bool createBuffers) noexcept;
  117. CARLA_PREVENT_HEAP_ALLOCATION
  118. CARLA_DECLARE_NON_COPYABLE(Buffers)
  119. } audioBuffers;
  120. RackGraph(CarlaEngine* engine, uint32_t inputs, uint32_t outputs) noexcept;
  121. ~RackGraph() noexcept;
  122. void setBufferSize(uint32_t bufferSize) noexcept;
  123. void setOffline(bool offline) noexcept;
  124. bool connect(uint groupA, uint portA, uint groupB, uint portB) noexcept;
  125. bool disconnect(uint connectionId) noexcept;
  126. void refresh(bool sendHost, bool sendOsc, bool ignored, const char* deviceName);
  127. const char* const* getConnections() const noexcept;
  128. bool getGroupAndPortIdFromFullName(const char* fullPortName, uint& groupId, uint& portId) const noexcept;
  129. // the base, where plugins run
  130. void process(CarlaEngine::ProtectedData* data, const float* inBuf[2], float* outBuf[2], uint32_t frames);
  131. // extended, will call process() in the middle
  132. void processHelper(CarlaEngine::ProtectedData* data, const float* const* inBuf, float* const* outBuf, uint32_t frames);
  133. CarlaEngine* const kEngine;
  134. CARLA_DECLARE_NON_COPYABLE(RackGraph)
  135. };
  136. // -----------------------------------------------------------------------
  137. // PatchbayGraph
  138. class PatchbayGraph : private CarlaRunner {
  139. public:
  140. PatchbayConnectionList connections;
  141. AudioProcessorGraph graph;
  142. AudioSampleBuffer audioBuffer;
  143. AudioSampleBuffer cvInBuffer;
  144. AudioSampleBuffer cvOutBuffer;
  145. MidiBuffer midiBuffer;
  146. const uint32_t numAudioIns;
  147. const uint32_t numAudioOuts;
  148. const uint32_t numCVIns;
  149. const uint32_t numCVOuts;
  150. mutable CharStringListPtr retCon;
  151. bool usingExternalHost;
  152. bool usingExternalOSC;
  153. ExternalGraph extGraph;
  154. PatchbayGraph(CarlaEngine* engine,
  155. uint32_t audioIns, uint32_t audioOuts,
  156. uint32_t cvIns, uint32_t cvOuts);
  157. ~PatchbayGraph();
  158. void setBufferSize(uint32_t bufferSize);
  159. void setSampleRate(double sampleRate);
  160. void setOffline(bool offline);
  161. void addPlugin(CarlaPluginPtr plugin);
  162. void replacePlugin(CarlaPluginPtr oldPlugin, CarlaPluginPtr newPlugin);
  163. void renamePlugin(CarlaPluginPtr plugin, const char* newName);
  164. void switchPlugins(CarlaPluginPtr pluginA, CarlaPluginPtr pluginB);
  165. void reconfigureForCV(CarlaPluginPtr plugin, const uint portIndex, bool added);
  166. void reconfigurePlugin(CarlaPluginPtr plugin, bool portsAdded);
  167. void removePlugin(CarlaPluginPtr plugin);
  168. void removeAllPlugins(bool aboutToClose);
  169. bool connect(bool external, uint groupA, uint portA, uint groupB, uint portB);
  170. bool disconnect(bool external, uint connectionId);
  171. void disconnectInternalGroup(uint groupId) noexcept;
  172. void setGroupPos(bool sendHost, bool sendOsc, bool external, uint groupId, int x1, int y1, int x2, int y2);
  173. void refresh(bool sendHost, bool sendOsc, bool external, const char* deviceName);
  174. const char* const* getConnections(bool external) const;
  175. const CarlaEngine::PatchbayPosition* getPositions(bool external, uint& count) const;
  176. bool getGroupFromName(bool external, const char* groupName, uint& groupId) const;
  177. bool getGroupAndPortIdFromFullName(bool external, const char* fullPortName, uint& groupId, uint& portId) const;
  178. void process(CarlaEngine::ProtectedData* data,
  179. const float* const* inBuf,
  180. float* const* outBuf,
  181. uint32_t frames);
  182. private:
  183. bool run() override;
  184. CarlaEngine* const kEngine;
  185. CARLA_DECLARE_NON_COPYABLE(PatchbayGraph)
  186. };
  187. // -----------------------------------------------------------------------
  188. CARLA_BACKEND_END_NAMESPACE
  189. #endif // CARLA_ENGINE_GRAPH_HPP_INCLUDED