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.

162 lines
5.5KB

  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. // Rack Graph stuff
  30. enum RackGraphGroupIds {
  31. RACK_GRAPH_GROUP_NULL = 0,
  32. RACK_GRAPH_GROUP_CARLA = 1,
  33. RACK_GRAPH_GROUP_AUDIO_IN = 2,
  34. RACK_GRAPH_GROUP_AUDIO_OUT = 3,
  35. RACK_GRAPH_GROUP_MIDI_IN = 4,
  36. RACK_GRAPH_GROUP_MIDI_OUT = 5,
  37. RACK_GRAPH_GROUP_MAX = 6
  38. };
  39. enum RackGraphCarlaPortIds {
  40. RACK_GRAPH_CARLA_PORT_NULL = 0,
  41. RACK_GRAPH_CARLA_PORT_AUDIO_IN1 = 1,
  42. RACK_GRAPH_CARLA_PORT_AUDIO_IN2 = 2,
  43. RACK_GRAPH_CARLA_PORT_AUDIO_OUT1 = 3,
  44. RACK_GRAPH_CARLA_PORT_AUDIO_OUT2 = 4,
  45. RACK_GRAPH_CARLA_PORT_MIDI_IN = 5,
  46. RACK_GRAPH_CARLA_PORT_MIDI_OUT = 6,
  47. RACK_GRAPH_CARLA_PORT_MAX = 7
  48. };
  49. // -----------------------------------------------------------------------
  50. // RackGraph
  51. struct RackGraph {
  52. PatchbayConnectionList connections;
  53. const uint32_t inputs;
  54. const uint32_t outputs;
  55. bool isOffline;
  56. mutable CharStringListPtr retCon;
  57. struct Audio {
  58. CarlaRecursiveMutex mutex;
  59. LinkedList<uint> connectedIn1;
  60. LinkedList<uint> connectedIn2;
  61. LinkedList<uint> connectedOut1;
  62. LinkedList<uint> connectedOut2;
  63. float* inBuf[2];
  64. float* inBufTmp[2];
  65. float* outBuf[2];
  66. // c++ compat stuff
  67. Audio() noexcept;
  68. CARLA_PREVENT_HEAP_ALLOCATION
  69. CARLA_DECLARE_NON_COPY_CLASS(Audio)
  70. } audio;
  71. struct MIDI {
  72. LinkedList<PortNameToId> ins;
  73. LinkedList<PortNameToId> outs;
  74. const char* getName(const bool isInput, const uint portId) const noexcept;
  75. uint getPortId(const bool isInput, const char portName[], bool* const ok = nullptr) const noexcept;
  76. // c++ compat stuff
  77. MIDI() noexcept;
  78. CARLA_PREVENT_HEAP_ALLOCATION
  79. CARLA_DECLARE_NON_COPY_CLASS(MIDI)
  80. } midi;
  81. RackGraph(CarlaEngine* const engine, const uint32_t inputs, const uint32_t outputs) noexcept;
  82. ~RackGraph() noexcept;
  83. void setBufferSize(const uint32_t bufferSize) noexcept;
  84. void setOffline(const bool offline) noexcept;
  85. bool connect(const uint groupA, const uint portA, const uint groupB, const uint portB) noexcept;
  86. bool disconnect(const uint connectionId) noexcept;
  87. void clearConnections() noexcept;
  88. void refreshConnections(const char* const deviceName);
  89. const char* const* getConnections() const noexcept;
  90. bool getGroupAndPortIdFromFullName(const char* const fullPortName, uint& groupId, uint& portId) const noexcept;
  91. // the base, where plugins run
  92. void process(CarlaEngine::ProtectedData* const data, const float* inBufReal[2], float* outBuf[2], const uint32_t frames);
  93. // extended, will call process() in the middle
  94. void processHelper(CarlaEngine::ProtectedData* const data, const float* const* const inBuf, float* const* const outBuf, const uint32_t frames);
  95. CarlaEngine* const kEngine;
  96. CARLA_DECLARE_NON_COPY_CLASS(RackGraph)
  97. };
  98. // -----------------------------------------------------------------------
  99. // PatchbayGraph
  100. struct PatchbayGraph {
  101. PatchbayConnectionList connections;
  102. AudioProcessorGraph graph;
  103. AudioSampleBuffer audioBuffer;
  104. MidiBuffer midiBuffer;
  105. const uint32_t inputs;
  106. const uint32_t outputs;
  107. bool ignorePathbay;
  108. mutable CharStringListPtr retCon;
  109. PatchbayGraph(CarlaEngine* const engine, const uint32_t inputs, const uint32_t outputs);
  110. ~PatchbayGraph();
  111. void setBufferSize(const int bufferSize);
  112. void setSampleRate(const double sampleRate);
  113. void setOffline(const bool offline);
  114. void addPlugin(CarlaPlugin* const plugin);
  115. void replacePlugin(CarlaPlugin* const oldPlugin, CarlaPlugin* const newPlugin);
  116. void removePlugin(CarlaPlugin* const plugin);
  117. void removeAllPlugins();
  118. bool connect(const uint groupA, const uint portA, const uint groupB, const uint portB) noexcept;
  119. bool disconnect(const uint connectionId) noexcept;
  120. void disconnectGroup(const uint groupId) noexcept;
  121. void clearConnections();
  122. void refreshConnections(const char* const deviceName);
  123. const char* const* getConnections() const;
  124. bool getGroupAndPortIdFromFullName(const char* const fullPortName, uint& groupId, uint& portId) const;
  125. void process(CarlaEngine::ProtectedData* const data, const float* const* const inBuf, float* const* const outBuf, const int frames);
  126. CarlaEngine* const kEngine;
  127. CARLA_DECLARE_NON_COPY_CLASS(PatchbayGraph)
  128. };
  129. // -----------------------------------------------------------------------
  130. CARLA_BACKEND_END_NAMESPACE
  131. #endif // CARLA_ENGINE_GRAPH_HPP_INCLUDED