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.

142 lines
5.0KB

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