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.

198 lines
6.9KB

  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 "AppConfig.h"
  24. #include "juce_audio_processors/juce_audio_processors.h"
  25. #if 1
  26. typedef juce::AudioProcessorGraph CarlaAudioProcessorGraph;
  27. #else
  28. typedef juce::AudioProcessorGraphMultiThreaded CarlaAudioProcessorGraph;
  29. #endif
  30. using juce::AudioSampleBuffer;
  31. using juce::MidiBuffer;
  32. CARLA_BACKEND_START_NAMESPACE
  33. // -----------------------------------------------------------------------
  34. // External Graph stuff
  35. enum ExternalGraphGroupIds {
  36. kExternalGraphGroupNull = 0,
  37. kExternalGraphGroupCarla = 1,
  38. kExternalGraphGroupAudioIn = 2,
  39. kExternalGraphGroupAudioOut = 3,
  40. kExternalGraphGroupMidiIn = 4,
  41. kExternalGraphGroupMidiOut = 5,
  42. kExternalGraphGroupMax = 6
  43. };
  44. enum ExternalGraphCarlaPortIds {
  45. kExternalGraphCarlaPortNull = 0,
  46. kExternalGraphCarlaPortAudioIn1 = 1,
  47. kExternalGraphCarlaPortAudioIn2 = 2,
  48. kExternalGraphCarlaPortAudioOut1 = 3,
  49. kExternalGraphCarlaPortAudioOut2 = 4,
  50. kExternalGraphCarlaPortMidiIn = 5,
  51. kExternalGraphCarlaPortMidiOut = 6,
  52. kExternalGraphCarlaPortMax = 7
  53. };
  54. enum ExternalGraphConnectionType {
  55. kExternalGraphConnectionNull = 0,
  56. kExternalGraphConnectionAudioIn1 = 1,
  57. kExternalGraphConnectionAudioIn2 = 2,
  58. kExternalGraphConnectionAudioOut1 = 3,
  59. kExternalGraphConnectionAudioOut2 = 4,
  60. kExternalGraphConnectionMidiInput = 5,
  61. kExternalGraphConnectionMidiOutput = 6
  62. };
  63. struct ExternalGraphPorts {
  64. LinkedList<PortNameToId> ins;
  65. LinkedList<PortNameToId> outs;
  66. const char* getName(const bool isInput, const uint portId) const noexcept;
  67. uint getPortId(const bool isInput, const char portName[], bool* const ok = nullptr) const noexcept;
  68. ExternalGraphPorts() noexcept;
  69. CARLA_PREVENT_HEAP_ALLOCATION
  70. CARLA_DECLARE_NON_COPY_CLASS(ExternalGraphPorts)
  71. };
  72. struct ExternalGraph {
  73. PatchbayConnectionList connections;
  74. ExternalGraphPorts audioPorts, midiPorts;
  75. mutable CharStringListPtr retCon;
  76. ExternalGraph(CarlaEngine* const engine) noexcept;
  77. void clear() noexcept;
  78. bool connect(const uint groupA, const uint portA, const uint groupB, const uint portB, const bool sendCallback) noexcept;
  79. bool disconnect(const uint connectionId) noexcept;
  80. void refresh(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. Buffers() noexcept;
  104. ~Buffers() noexcept;
  105. void setBufferSize(const uint32_t bufferSize, const bool createBuffers) noexcept;
  106. CARLA_PREVENT_HEAP_ALLOCATION
  107. CARLA_DECLARE_NON_COPY_CLASS(Buffers)
  108. } audioBuffers;
  109. RackGraph(CarlaEngine* const engine, const uint32_t inputs, const uint32_t outputs) noexcept;
  110. ~RackGraph() noexcept;
  111. void setBufferSize(const uint32_t bufferSize) noexcept;
  112. void setOffline(const bool offline) noexcept;
  113. bool connect(const uint groupA, const uint portA, const uint groupB, const uint portB) noexcept;
  114. bool disconnect(const uint connectionId) noexcept;
  115. void refresh(const char* const deviceName);
  116. const char* const* getConnections() const noexcept;
  117. bool getGroupAndPortIdFromFullName(const char* const fullPortName, uint& groupId, uint& portId) const noexcept;
  118. // the base, where plugins run
  119. void process(CarlaEngine::ProtectedData* const data, const float* inBufReal[2], float* outBuf[2], const uint32_t frames);
  120. // extended, will call process() in the middle
  121. void processHelper(CarlaEngine::ProtectedData* const data, const float* const* const inBuf, float* const* const outBuf, const uint32_t frames);
  122. CarlaEngine* const kEngine;
  123. CARLA_DECLARE_NON_COPY_CLASS(RackGraph)
  124. };
  125. // -----------------------------------------------------------------------
  126. // PatchbayGraph
  127. struct PatchbayGraph {
  128. PatchbayConnectionList connections;
  129. CarlaAudioProcessorGraph graph;
  130. AudioSampleBuffer audioBuffer;
  131. MidiBuffer midiBuffer;
  132. const uint32_t inputs;
  133. const uint32_t outputs;
  134. mutable CharStringListPtr retCon;
  135. bool usingExternal;
  136. ExternalGraph extGraph;
  137. PatchbayGraph(CarlaEngine* const engine, const uint32_t inputs, const uint32_t outputs);
  138. ~PatchbayGraph();
  139. void setBufferSize(const uint32_t bufferSize);
  140. void setSampleRate(const double sampleRate);
  141. void setOffline(const bool offline);
  142. void addPlugin(CarlaPlugin* const plugin);
  143. void replacePlugin(CarlaPlugin* const oldPlugin, CarlaPlugin* const newPlugin);
  144. void renamePlugin(CarlaPlugin* const plugin, const char* const newName);
  145. void removePlugin(CarlaPlugin* const plugin);
  146. void removeAllPlugins();
  147. bool connect(const bool external, const uint groupA, const uint portA, const uint groupB, const uint portB, const bool sendCallback);
  148. bool disconnect(const uint connectionId);
  149. void disconnectInternalGroup(const uint groupId) noexcept;
  150. void refresh(const char* const deviceName);
  151. const char* const* getConnections(const bool external) const;
  152. bool getGroupAndPortIdFromFullName(const bool external, const char* const fullPortName, uint& groupId, uint& portId) const;
  153. void process(CarlaEngine::ProtectedData* const data, const float* const* const inBuf, float* const* const outBuf, const int frames);
  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