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 7.2KB

10 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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(const bool isInput, const uint portId) const noexcept;
  64. uint getPortId(const bool isInput, const char portName[], bool* const 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* const engine) noexcept;
  74. void clear() noexcept;
  75. bool connect(const bool sendHost, const bool sendOSC,
  76. const uint groupA, const uint portA, const uint groupB, const uint portB) noexcept;
  77. bool disconnect(const bool sendHost, const bool sendOSC,
  78. const uint connectionId) noexcept;
  79. void refresh(const bool sendHost, const bool sendOSC,
  80. const char* const deviceName);
  81. const char* const* getConnections() const noexcept;
  82. bool getGroupAndPortIdFromFullName(const char* const 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(const uint32_t bufferSize, const bool createBuffers) noexcept;
  107. CARLA_PREVENT_HEAP_ALLOCATION
  108. CARLA_DECLARE_NON_COPY_CLASS(Buffers)
  109. } audioBuffers;
  110. RackGraph(CarlaEngine* const engine, const uint32_t inputs, const uint32_t outputs) noexcept;
  111. ~RackGraph() noexcept;
  112. void setBufferSize(const uint32_t bufferSize) noexcept;
  113. void setOffline(const bool offline) noexcept;
  114. bool connect(const uint groupA, const uint portA, const uint groupB, const uint portB) noexcept;
  115. bool disconnect(const uint connectionId) noexcept;
  116. void refresh(const bool sendHost, const bool sendOsc, const bool ignored, const char* const deviceName);
  117. const char* const* getConnections() const noexcept;
  118. bool getGroupAndPortIdFromFullName(const char* const fullPortName, uint& groupId, uint& portId) const noexcept;
  119. // the base, where plugins run
  120. void process(CarlaEngine::ProtectedData* const data, const float* inBuf[2], float* outBuf[2], const uint32_t frames);
  121. // extended, will call process() in the middle
  122. void processHelper(CarlaEngine::ProtectedData* const data, const float* const* const inBuf, float* const* const outBuf, const 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. MidiBuffer midiBuffer;
  134. const uint32_t inputs;
  135. const uint32_t outputs;
  136. mutable CharStringListPtr retCon;
  137. bool usingExternalHost;
  138. bool usingExternalOSC;
  139. ExternalGraph extGraph;
  140. PatchbayGraph(CarlaEngine* const engine, const uint32_t inputs, const uint32_t outputs);
  141. ~PatchbayGraph();
  142. void setBufferSize(const uint32_t bufferSize);
  143. void setSampleRate(const double sampleRate);
  144. void setOffline(const bool offline);
  145. void addPlugin(CarlaPlugin* const plugin);
  146. void replacePlugin(CarlaPlugin* const oldPlugin, CarlaPlugin* const newPlugin);
  147. void renamePlugin(CarlaPlugin* const plugin, const char* const newName);
  148. void removePlugin(CarlaPlugin* const plugin);
  149. void removeAllPlugins();
  150. bool connect(const bool external, const uint groupA, const uint portA, const uint groupB, const uint portB);
  151. bool disconnect(const bool external, const uint connectionId);
  152. void disconnectInternalGroup(const uint groupId) noexcept;
  153. void refresh(const bool sendHost, const bool sendOsc, const bool external, const char* const deviceName);
  154. const char* const* getConnections(const bool external) const;
  155. bool getGroupAndPortIdFromFullName(const bool external, const char* const fullPortName, uint& groupId, uint& portId) const;
  156. void process(CarlaEngine::ProtectedData* const data, const float* const* const inBuf, float* const* const outBuf, const uint32_t frames);
  157. private:
  158. void run() override;
  159. CarlaEngine* const kEngine;
  160. CARLA_DECLARE_NON_COPY_CLASS(PatchbayGraph)
  161. };
  162. // -----------------------------------------------------------------------
  163. CARLA_BACKEND_END_NAMESPACE
  164. #endif // CARLA_ENGINE_GRAPH_HPP_INCLUDED