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.

155 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(const uint32_t bufferSize, 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(CarlaEngine* const engine, const uint groupA, const uint portA, const uint groupB, const uint portB) noexcept;
  86. bool disconnect(CarlaEngine* const engine, const uint connectionId) noexcept;
  87. void clearConnections() noexcept;
  88. const char* const* getConnections() const noexcept;
  89. bool getGroupAndPortIdFromFullName(const char* const fullPortName, uint& groupId, uint& portId) const noexcept;
  90. // the base, where plugins run
  91. void process(CarlaEngine::ProtectedData* const data, const float* inBufReal[2], float* outBuf[2], const uint32_t frames);
  92. // extended, will call process() in the middle
  93. void processHelper(CarlaEngine::ProtectedData* const data, const float* const* const inBuf, float* const* const outBuf, const uint32_t frames);
  94. };
  95. // -----------------------------------------------------------------------
  96. // PatchbayGraph
  97. struct PatchbayGraph {
  98. PatchbayConnectionList connections;
  99. AudioProcessorGraph graph;
  100. AudioSampleBuffer audioBuffer;
  101. MidiBuffer midiBuffer;
  102. const uint32_t inputs;
  103. const uint32_t outputs;
  104. bool ignorePathbay;
  105. mutable CharStringListPtr retCon;
  106. PatchbayGraph(const int bufferSize, const double sampleRate, const uint32_t inputs, const uint32_t outputs);
  107. ~PatchbayGraph();
  108. void setBufferSize(const int bufferSize);
  109. void setSampleRate(const double sampleRate);
  110. void setOffline(const bool offline);
  111. void addPlugin(CarlaPlugin* const plugin);
  112. void replacePlugin(CarlaPlugin* const oldPlugin, CarlaPlugin* const newPlugin);
  113. void removePlugin(CarlaPlugin* const plugin);
  114. void removeAllPlugins(CarlaEngine* const engine);
  115. bool connect(CarlaEngine* const engine, const uint groupA, const uint portA, const uint groupB, const uint portB) noexcept;
  116. bool disconnect(CarlaEngine* const engine, const uint connectionId) noexcept;
  117. void disconnectGroup(CarlaEngine* const engine, const uint groupId) noexcept;
  118. void clearConnections();
  119. void refreshConnections(CarlaEngine* const engine);
  120. const char* const* getConnections() const;
  121. bool getGroupAndPortIdFromFullName(const char* const fullPortName, uint& groupId, uint& portId) const;
  122. void process(CarlaEngine::ProtectedData* const data, const float* const* const inBuf, float* const* const outBuf, const int frames);
  123. };
  124. // -----------------------------------------------------------------------
  125. CARLA_BACKEND_END_NAMESPACE
  126. #endif // CARLA_ENGINE_GRAPH_HPP_INCLUDED