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

10 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. * Carla Plugin Host
  3. * Copyright (C) 2011-2017 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 uint groupA, const uint portA, const uint groupB, const uint portB, const bool sendCallback) noexcept;
  76. bool disconnect(const uint connectionId) noexcept;
  77. void refresh(const char* const deviceName);
  78. const char* const* getConnections() const noexcept;
  79. bool getGroupAndPortIdFromFullName(const char* const fullPortName, uint& groupId, uint& portId) const noexcept;
  80. CarlaEngine* const kEngine;
  81. CARLA_PREVENT_HEAP_ALLOCATION
  82. CARLA_DECLARE_NON_COPY_CLASS(ExternalGraph)
  83. };
  84. // -----------------------------------------------------------------------
  85. // RackGraph
  86. struct RackGraph {
  87. ExternalGraph extGraph;
  88. const uint32_t inputs;
  89. const uint32_t outputs;
  90. bool isOffline;
  91. struct Buffers {
  92. CarlaRecursiveMutex mutex;
  93. LinkedList<uint> connectedIn1;
  94. LinkedList<uint> connectedIn2;
  95. LinkedList<uint> connectedOut1;
  96. LinkedList<uint> connectedOut2;
  97. float* inBuf[2];
  98. float* inBufTmp[2];
  99. float* outBuf[2];
  100. Buffers() noexcept;
  101. ~Buffers() noexcept;
  102. void setBufferSize(const uint32_t bufferSize, const bool createBuffers) noexcept;
  103. CARLA_PREVENT_HEAP_ALLOCATION
  104. CARLA_DECLARE_NON_COPY_CLASS(Buffers)
  105. } audioBuffers;
  106. RackGraph(CarlaEngine* const engine, const uint32_t inputs, const uint32_t outputs) noexcept;
  107. ~RackGraph() noexcept;
  108. void setBufferSize(const uint32_t bufferSize) noexcept;
  109. void setOffline(const bool offline) noexcept;
  110. bool connect(const uint groupA, const uint portA, const uint groupB, const uint portB) noexcept;
  111. bool disconnect(const uint connectionId) noexcept;
  112. void refresh(const char* const deviceName);
  113. const char* const* getConnections() const noexcept;
  114. bool getGroupAndPortIdFromFullName(const char* const fullPortName, uint& groupId, uint& portId) const noexcept;
  115. // the base, where plugins run
  116. void process(CarlaEngine::ProtectedData* const data, const float* inBufReal[2], float* outBuf[2], const uint32_t frames);
  117. // extended, will call process() in the middle
  118. void processHelper(CarlaEngine::ProtectedData* const data, const float* const* const inBuf, float* const* const outBuf, const uint32_t frames);
  119. CarlaEngine* const kEngine;
  120. CARLA_DECLARE_NON_COPY_CLASS(RackGraph)
  121. };
  122. // -----------------------------------------------------------------------
  123. // PatchbayGraph
  124. class PatchbayGraph : private CarlaThread {
  125. public:
  126. PatchbayConnectionList connections;
  127. AudioProcessorGraph graph;
  128. AudioSampleBuffer audioBuffer;
  129. MidiBuffer midiBuffer;
  130. const uint32_t inputs;
  131. const uint32_t outputs;
  132. mutable CharStringListPtr retCon;
  133. bool usingExternal;
  134. ExternalGraph extGraph;
  135. PatchbayGraph(CarlaEngine* const engine, const uint32_t inputs, const uint32_t outputs);
  136. ~PatchbayGraph();
  137. void setBufferSize(const uint32_t bufferSize);
  138. void setSampleRate(const double sampleRate);
  139. void setOffline(const bool offline);
  140. void addPlugin(CarlaPlugin* const plugin);
  141. void replacePlugin(CarlaPlugin* const oldPlugin, CarlaPlugin* const newPlugin);
  142. void renamePlugin(CarlaPlugin* const plugin, const char* const newName);
  143. void removePlugin(CarlaPlugin* const plugin);
  144. void removeAllPlugins();
  145. bool connect(const bool external, const uint groupA, const uint portA, const uint groupB, const uint portB, const bool sendCallback);
  146. bool disconnect(const uint connectionId);
  147. void disconnectInternalGroup(const uint groupId) noexcept;
  148. void refresh(const char* const deviceName);
  149. const char* const* getConnections(const bool external) const;
  150. bool getGroupAndPortIdFromFullName(const bool external, const char* const fullPortName, uint& groupId, uint& portId) const;
  151. void process(CarlaEngine::ProtectedData* const data, const float* const* const inBuf, float* const* const outBuf, const int frames);
  152. private:
  153. void run() override;
  154. CarlaEngine* const kEngine;
  155. CARLA_DECLARE_NON_COPY_CLASS(PatchbayGraph)
  156. };
  157. // -----------------------------------------------------------------------
  158. CARLA_BACKEND_END_NAMESPACE
  159. #endif // CARLA_ENGINE_GRAPH_HPP_INCLUDED