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.8KB

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