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.

196 lines
6.8KB

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