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 5.4KB

10 years ago
10 years ago
10 years ago
10 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. // c++ compat stuff
  66. Audio() noexcept;
  67. CARLA_PREVENT_HEAP_ALLOCATION
  68. CARLA_DECLARE_NON_COPY_CLASS(Audio)
  69. } audio;
  70. struct MIDI {
  71. LinkedList<PortNameToId> ins;
  72. LinkedList<PortNameToId> outs;
  73. const char* getName(const bool isInput, const uint portId) const noexcept;
  74. uint getPortId(const bool isInput, const char portName[], bool* const ok = nullptr) const noexcept;
  75. // c++ compat stuff
  76. MIDI() noexcept;
  77. CARLA_PREVENT_HEAP_ALLOCATION
  78. CARLA_DECLARE_NON_COPY_CLASS(MIDI)
  79. } midi;
  80. RackGraph(const uint32_t bufferSize, const uint32_t inputs, const uint32_t outputs) noexcept;
  81. ~RackGraph() noexcept;
  82. void setBufferSize(const uint32_t bufferSize) noexcept;
  83. void setOffline(const bool offline) noexcept;
  84. bool connect(CarlaEngine* const engine, const uint groupA, const uint portA, const uint groupB, const uint portB) noexcept;
  85. bool disconnect(CarlaEngine* const engine, const uint connectionId) noexcept;
  86. void clearConnections() noexcept;
  87. const char* const* getConnections() const noexcept;
  88. bool getGroupAndPortIdFromFullName(const char* const fullPortName, uint& groupId, uint& portId) const noexcept;
  89. // the base, where plugins run
  90. void process(CarlaEngine::ProtectedData* const data, const float* inBufReal[2], float* outBuf[2], const uint32_t frames);
  91. // extended, will call process() in the middle
  92. void processHelper(CarlaEngine::ProtectedData* const data, const float* const* const inBuf, float* const* const outBuf, const uint32_t frames);
  93. };
  94. // -----------------------------------------------------------------------
  95. // PatchbayGraph
  96. struct PatchbayGraph {
  97. PatchbayConnectionList connections;
  98. AudioProcessorGraph graph;
  99. AudioSampleBuffer audioBuffer;
  100. MidiBuffer midiBuffer;
  101. const uint32_t inputs;
  102. const uint32_t outputs;
  103. bool ignorePathbay;
  104. mutable CharStringListPtr retCon;
  105. PatchbayGraph(const int bufferSize, const double sampleRate, const uint32_t inputs, const uint32_t outputs);
  106. ~PatchbayGraph();
  107. void setBufferSize(const int bufferSize);
  108. void setSampleRate(const double sampleRate);
  109. void setOffline(const bool offline);
  110. void addPlugin(CarlaPlugin* const plugin);
  111. void replacePlugin(CarlaPlugin* const oldPlugin, CarlaPlugin* const newPlugin);
  112. void removePlugin(CarlaPlugin* const plugin);
  113. void removeAllPlugins(CarlaEngine* const engine);
  114. bool connect(CarlaEngine* const engine, const uint groupA, const uint portA, const uint groupB, const uint portB) noexcept;
  115. bool disconnect(CarlaEngine* const engine, const uint connectionId) noexcept;
  116. void clearConnections();
  117. void refreshConnections(CarlaEngine* const engine);
  118. const char* const* getConnections() const;
  119. bool getGroupAndPortIdFromFullName(const char* const fullPortName, uint& groupId, uint& portId) const;
  120. void process(CarlaEngine::ProtectedData* const data, const float* const* const inBuf, float* const* const outBuf, const int frames);
  121. };
  122. // -----------------------------------------------------------------------
  123. CARLA_BACKEND_END_NAMESPACE
  124. #endif // CARLA_ENGINE_GRAPH_HPP_INCLUDED