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.

185 lines
6.4KB

  1. /*
  2. * Carla Plugin Host
  3. * Copyright (C) 2011-2014 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 "juce_audio_processors.h"
  24. using juce::AudioProcessorGraph;
  25. using juce::AudioSampleBuffer;
  26. using juce::MidiBuffer;
  27. CARLA_BACKEND_START_NAMESPACE
  28. // -----------------------------------------------------------------------
  29. // External Graph stuff
  30. enum ExternalGraphGroupIds {
  31. kExternalGraphGroupNull = 0,
  32. kExternalGraphGroupCarla = 1,
  33. kExternalGraphGroupAudioIn = 2,
  34. kExternalGraphGroupAudioOut = 3,
  35. kExternalGraphGroupMidiIn = 4,
  36. kExternalGraphGroupMidiOut = 5,
  37. kExternalGraphGroupMax = 6
  38. };
  39. enum ExternalGraphCarlaPortIds {
  40. kExternalGraphCarlaPortNull = 0,
  41. kExternalGraphCarlaPortAudioIn1 = 1,
  42. kExternalGraphCarlaPortAudioIn2 = 2,
  43. kExternalGraphCarlaPortAudioOut1 = 3,
  44. kExternalGraphCarlaPortAudioOut2 = 4,
  45. kExternalGraphCarlaPortMidiIn = 5,
  46. kExternalGraphCarlaPortMidiOut = 6,
  47. kExternalGraphCarlaPortMax = 7
  48. };
  49. struct ExternalGraphBuffers {
  50. CarlaRecursiveMutex mutex;
  51. LinkedList<uint> connectedIn1;
  52. LinkedList<uint> connectedIn2;
  53. LinkedList<uint> connectedOut1;
  54. LinkedList<uint> connectedOut2;
  55. float* inBuf[2];
  56. float* inBufTmp[2];
  57. float* outBuf[2];
  58. ExternalGraphBuffers() noexcept;
  59. void setBufferSize(const uint32_t bufferSize, const bool createBuffers) noexcept;
  60. CARLA_PREVENT_HEAP_ALLOCATION
  61. CARLA_DECLARE_NON_COPY_CLASS(ExternalGraphBuffers)
  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. ExternalGraphBuffers audioBuffers;
  75. ExternalGraphPorts audioPorts, midiPorts;
  76. mutable CharStringListPtr retCon;
  77. ExternalGraph(CarlaEngine* const engine) noexcept;
  78. void clearConnections() noexcept;
  79. void clearPorts() noexcept;
  80. bool connect(const uint groupA, const uint portA, const uint groupB, const uint portB) noexcept;
  81. bool disconnect(const uint connectionId) noexcept;
  82. void refresh(const char* const deviceName);
  83. const char* const* getConnections() const noexcept;
  84. bool getGroupAndPortIdFromFullName(const char* const fullPortName, uint& groupId, uint& portId) const noexcept;
  85. CarlaEngine* const kEngine;
  86. CARLA_PREVENT_HEAP_ALLOCATION
  87. CARLA_DECLARE_NON_COPY_CLASS(ExternalGraph)
  88. };
  89. // -----------------------------------------------------------------------
  90. // RackGraph
  91. struct RackGraph {
  92. ExternalGraph extGraph;
  93. const uint32_t inputs;
  94. const uint32_t outputs;
  95. bool isOffline;
  96. RackGraph(CarlaEngine* const engine, const uint32_t inputs, const uint32_t outputs) noexcept;
  97. ~RackGraph() noexcept;
  98. void setBufferSize(const uint32_t bufferSize) noexcept;
  99. void setOffline(const bool offline) noexcept;
  100. bool connect(const uint groupA, const uint portA, const uint groupB, const uint portB) noexcept;
  101. bool disconnect(const uint connectionId) noexcept;
  102. void clearPorts() noexcept;
  103. void clearConnections() noexcept;
  104. void refresh(const char* const deviceName);
  105. const char* const* getConnections() const noexcept;
  106. bool getGroupAndPortIdFromFullName(const char* const fullPortName, uint& groupId, uint& portId) const noexcept;
  107. // the base, where plugins run
  108. void process(CarlaEngine::ProtectedData* const data, const float* inBufReal[2], float* outBuf[2], const uint32_t frames);
  109. // extended, will call process() in the middle
  110. void processHelper(CarlaEngine::ProtectedData* const data, const float* const* const inBuf, float* const* const outBuf, const uint32_t frames);
  111. CarlaEngine* const kEngine;
  112. CARLA_DECLARE_NON_COPY_CLASS(RackGraph)
  113. };
  114. // -----------------------------------------------------------------------
  115. // PatchbayGraph
  116. struct PatchbayGraph {
  117. PatchbayConnectionList connections;
  118. AudioProcessorGraph graph;
  119. AudioSampleBuffer audioBuffer;
  120. MidiBuffer midiBuffer;
  121. const uint32_t inputs;
  122. const uint32_t outputs;
  123. mutable CharStringListPtr retCon;
  124. bool usingExternal;
  125. ExternalGraph extGraph;
  126. PatchbayGraph(CarlaEngine* const engine, const uint32_t inputs, const uint32_t outputs);
  127. ~PatchbayGraph();
  128. void setBufferSize(const uint32_t bufferSize);
  129. void setSampleRate(const double sampleRate);
  130. void setOffline(const bool offline);
  131. void addPlugin(CarlaPlugin* const plugin);
  132. void replacePlugin(CarlaPlugin* const oldPlugin, CarlaPlugin* const newPlugin);
  133. void removePlugin(CarlaPlugin* const plugin);
  134. void removeAllPlugins();
  135. bool connect(const uint groupA, const uint portA, const uint groupB, const uint portB) noexcept;
  136. bool disconnect(const uint connectionId) noexcept;
  137. void disconnectGroup(const uint groupId) noexcept;
  138. void clearInternalConnections();
  139. void refresh(const char* const deviceName);
  140. const char* const* getConnections(const bool external) const;
  141. bool getGroupAndPortIdFromFullName(const bool external, const char* const fullPortName, uint& groupId, uint& portId) const;
  142. void process(CarlaEngine::ProtectedData* const data, const float* const* const inBuf, float* const* const outBuf, const int frames);
  143. CarlaEngine* const kEngine;
  144. CARLA_DECLARE_NON_COPY_CLASS(PatchbayGraph)
  145. };
  146. // -----------------------------------------------------------------------
  147. CARLA_BACKEND_END_NAMESPACE
  148. #endif // CARLA_ENGINE_GRAPH_HPP_INCLUDED