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.

213 lines
7.0KB

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