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.

144 lines
5.0KB

  1. /*
  2. * Carla Plugin Host
  3. * Copyright (C) 2011-2017 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. CARLA_BACKEND_START_NAMESPACE
  24. // -----------------------------------------------------------------------
  25. // External Graph stuff
  26. enum ExternalGraphGroupIds {
  27. kExternalGraphGroupNull = 0,
  28. kExternalGraphGroupCarla = 1,
  29. kExternalGraphGroupAudioIn = 2,
  30. kExternalGraphGroupAudioOut = 3,
  31. kExternalGraphGroupMidiIn = 4,
  32. kExternalGraphGroupMidiOut = 5,
  33. kExternalGraphGroupMax = 6
  34. };
  35. enum ExternalGraphCarlaPortIds {
  36. kExternalGraphCarlaPortNull = 0,
  37. kExternalGraphCarlaPortAudioIn1 = 1,
  38. kExternalGraphCarlaPortAudioIn2 = 2,
  39. kExternalGraphCarlaPortAudioOut1 = 3,
  40. kExternalGraphCarlaPortAudioOut2 = 4,
  41. kExternalGraphCarlaPortMidiIn = 5,
  42. kExternalGraphCarlaPortMidiOut = 6,
  43. kExternalGraphCarlaPortMax = 7
  44. };
  45. enum ExternalGraphConnectionType {
  46. kExternalGraphConnectionNull = 0,
  47. kExternalGraphConnectionAudioIn1 = 1,
  48. kExternalGraphConnectionAudioIn2 = 2,
  49. kExternalGraphConnectionAudioOut1 = 3,
  50. kExternalGraphConnectionAudioOut2 = 4,
  51. kExternalGraphConnectionMidiInput = 5,
  52. kExternalGraphConnectionMidiOutput = 6
  53. };
  54. struct ExternalGraphPorts {
  55. LinkedList<PortNameToId> ins;
  56. LinkedList<PortNameToId> outs;
  57. const char* getName(const bool isInput, const uint portId) const noexcept;
  58. uint getPortId(const bool isInput, const char portName[], bool* const ok = nullptr) const noexcept;
  59. ExternalGraphPorts() noexcept;
  60. CARLA_PREVENT_HEAP_ALLOCATION
  61. CARLA_DECLARE_NON_COPY_CLASS(ExternalGraphPorts)
  62. };
  63. struct ExternalGraph {
  64. PatchbayConnectionList connections;
  65. ExternalGraphPorts audioPorts, midiPorts;
  66. mutable CharStringListPtr retCon;
  67. ExternalGraph(CarlaEngine* const engine) noexcept;
  68. void clear() noexcept;
  69. bool connect(const uint groupA, const uint portA, const uint groupB, const uint portB, const bool sendCallback) noexcept;
  70. bool disconnect(const uint connectionId) noexcept;
  71. void refresh(const char* const deviceName);
  72. const char* const* getConnections() const noexcept;
  73. bool getGroupAndPortIdFromFullName(const char* const fullPortName, uint& groupId, uint& portId) const noexcept;
  74. CarlaEngine* const kEngine;
  75. CARLA_PREVENT_HEAP_ALLOCATION
  76. CARLA_DECLARE_NON_COPY_CLASS(ExternalGraph)
  77. };
  78. // -----------------------------------------------------------------------
  79. // RackGraph
  80. struct RackGraph {
  81. ExternalGraph extGraph;
  82. const uint32_t inputs;
  83. const uint32_t outputs;
  84. bool isOffline;
  85. struct Buffers {
  86. CarlaRecursiveMutex mutex;
  87. LinkedList<uint> connectedIn1;
  88. LinkedList<uint> connectedIn2;
  89. LinkedList<uint> connectedOut1;
  90. LinkedList<uint> connectedOut2;
  91. float* inBuf[2];
  92. float* inBufTmp[2];
  93. float* outBuf[2];
  94. Buffers() noexcept;
  95. ~Buffers() noexcept;
  96. void setBufferSize(const uint32_t bufferSize, const bool createBuffers) noexcept;
  97. CARLA_PREVENT_HEAP_ALLOCATION
  98. CARLA_DECLARE_NON_COPY_CLASS(Buffers)
  99. } audioBuffers;
  100. RackGraph(CarlaEngine* const engine, const uint32_t inputs, const uint32_t outputs) noexcept;
  101. ~RackGraph() noexcept;
  102. void setBufferSize(const uint32_t bufferSize) noexcept;
  103. void setOffline(const bool offline) noexcept;
  104. bool connect(const uint groupA, const uint portA, const uint groupB, const uint portB) noexcept;
  105. bool disconnect(const uint connectionId) noexcept;
  106. void refresh(const char* const deviceName);
  107. const char* const* getConnections() const noexcept;
  108. bool getGroupAndPortIdFromFullName(const char* const fullPortName, uint& groupId, uint& portId) const noexcept;
  109. // the base, where plugins run
  110. void process(CarlaEngine::ProtectedData* const data, const float* inBufReal[2], float* outBuf[2], const uint32_t frames);
  111. // extended, will call process() in the middle
  112. void processHelper(CarlaEngine::ProtectedData* const data, const float* const* const inBuf, float* const* const outBuf, const uint32_t frames);
  113. CarlaEngine* const kEngine;
  114. CARLA_DECLARE_NON_COPY_CLASS(RackGraph)
  115. };
  116. // -----------------------------------------------------------------------
  117. CARLA_BACKEND_END_NAMESPACE
  118. #endif // CARLA_ENGINE_GRAPH_HPP_INCLUDED