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.

226 lines
6.4KB

  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_INTERNAL_HPP_INCLUDED
  18. #define CARLA_ENGINE_INTERNAL_HPP_INCLUDED
  19. #include "CarlaEngine.hpp"
  20. #include "CarlaEngineOsc.hpp"
  21. #include "CarlaEngineThread.hpp"
  22. #include "CarlaEngineUtils.hpp"
  23. CARLA_BACKEND_START_NAMESPACE
  24. // -----------------------------------------------------------------------
  25. // Engine helper macro, sets lastError and returns false/NULL
  26. #define CARLA_SAFE_ASSERT_RETURN_ERR(cond, err) if (! (cond)) { carla_safe_assert(#cond, __FILE__, __LINE__); setLastError(err); return false; }
  27. #define CARLA_SAFE_ASSERT_RETURN_ERRN(cond, err) if (! (cond)) { carla_safe_assert(#cond, __FILE__, __LINE__); setLastError(err); return nullptr; }
  28. // -----------------------------------------------------------------------
  29. // InternalEvents
  30. struct EngineInternalEvents {
  31. EngineEvent* in;
  32. EngineEvent* out;
  33. EngineInternalEvents() noexcept;
  34. ~EngineInternalEvents() noexcept;
  35. void clear() noexcept;
  36. CARLA_DECLARE_NON_COPY_STRUCT(EngineInternalEvents)
  37. };
  38. #ifndef BUILD_BRIDGE
  39. // -----------------------------------------------------------------------
  40. // InternalGraph
  41. struct RackGraph;
  42. struct PatchbayGraph;
  43. class EngineInternalGraph
  44. {
  45. public:
  46. EngineInternalGraph() noexcept;
  47. ~EngineInternalGraph() noexcept;
  48. void create(const bool isRack, const double sampleRate, const uint32_t bufferSize, const uint32_t inputs, const uint32_t outputs);
  49. void destroy() noexcept;
  50. void setBufferSize(const uint32_t bufferSize);
  51. void setSampleRate(const double sampleRate);
  52. void setOffline(const bool offline);
  53. bool isReady() const noexcept;
  54. RackGraph* getRackGraph() const noexcept;
  55. PatchbayGraph* getPatchbayGraph() const noexcept;
  56. void process(CarlaEngine::ProtectedData* const data, const float* const* const inBuf, float* const* const outBuf, const uint32_t frames);
  57. // special direct process with connections already handled, used in JACK and Plugin
  58. void processRack(CarlaEngine::ProtectedData* const data, const float* inBuf[2], float* outBuf[2], const uint32_t frames);
  59. private:
  60. bool fIsRack;
  61. bool fIsReady;
  62. union {
  63. RackGraph* fRack;
  64. PatchbayGraph* fPatchbay;
  65. };
  66. CARLA_DECLARE_NON_COPY_STRUCT(EngineInternalGraph)
  67. };
  68. #endif
  69. // -----------------------------------------------------------------------
  70. // InternalTime
  71. struct EngineInternalTime {
  72. bool playing;
  73. uint64_t frame;
  74. EngineInternalTime() noexcept;
  75. CARLA_DECLARE_NON_COPY_STRUCT(EngineInternalTime)
  76. };
  77. // -----------------------------------------------------------------------
  78. // EngineNextAction
  79. enum EnginePostAction {
  80. kEnginePostActionNull = 0,
  81. kEnginePostActionZeroCount, // set curPluginCount to 0
  82. #ifndef BUILD_BRIDGE
  83. kEnginePostActionRemovePlugin, // remove a plugin
  84. kEnginePostActionSwitchPlugins // switch between 2 plugins
  85. #endif
  86. };
  87. struct EngineNextAction {
  88. EnginePostAction opcode;
  89. uint pluginId;
  90. uint value;
  91. CarlaMutex mutex;
  92. EngineNextAction() noexcept;
  93. ~EngineNextAction() noexcept;
  94. void ready() const noexcept;
  95. CARLA_DECLARE_NON_COPY_STRUCT(EngineNextAction)
  96. };
  97. // -----------------------------------------------------------------------
  98. // EnginePluginData
  99. struct EnginePluginData {
  100. CarlaPlugin* plugin;
  101. float insPeak[2];
  102. float outsPeak[2];
  103. };
  104. // -----------------------------------------------------------------------
  105. // CarlaEngineProtectedData
  106. struct CarlaEngine::ProtectedData {
  107. CarlaEngineOsc osc;
  108. CarlaEngineThread thread;
  109. const CarlaOscData* oscData;
  110. EngineCallbackFunc callback;
  111. void* callbackPtr;
  112. FileCallbackFunc fileCallback;
  113. void* fileCallbackPtr;
  114. uint hints;
  115. uint32_t bufferSize;
  116. double sampleRate;
  117. bool aboutToClose; // don't re-activate thread if true
  118. bool isIdling; // don't allow any operations while idling
  119. uint curPluginCount; // number of plugins loaded (0...max)
  120. uint maxPluginNumber; // number of plugins allowed (0, 16, 99 or 255)
  121. uint nextPluginId; // invalid if == maxPluginNumber
  122. CarlaString lastError;
  123. CarlaString name;
  124. EngineOptions options;
  125. EngineTimeInfo timeInfo;
  126. #ifdef BUILD_BRIDGE
  127. EnginePluginData plugins[1];
  128. #else
  129. EnginePluginData* plugins;
  130. #endif
  131. EngineInternalEvents events;
  132. #ifndef BUILD_BRIDGE
  133. EngineInternalGraph graph;
  134. #endif
  135. EngineInternalTime time;
  136. EngineNextAction nextAction;
  137. // -------------------------------------------------------------------
  138. ProtectedData(CarlaEngine* const engine) noexcept;
  139. ~ProtectedData() noexcept;
  140. // -------------------------------------------------------------------
  141. bool init(const char* const clientName);
  142. void close();
  143. // -------------------------------------------------------------------
  144. void doPluginRemove() noexcept;
  145. void doPluginsSwitch() noexcept;
  146. void doNextPluginAction(const bool unlock) noexcept;
  147. // -------------------------------------------------------------------
  148. //friend class ScopedActionLock;
  149. #ifdef CARLA_PROPER_CPP11_SUPPORT
  150. ProtectedData() = delete;
  151. CARLA_DECLARE_NON_COPY_STRUCT(ProtectedData)
  152. #endif
  153. };
  154. // -----------------------------------------------------------------------
  155. class ScopedActionLock
  156. {
  157. public:
  158. ScopedActionLock(CarlaEngine::ProtectedData* const data, const EnginePostAction action, const uint pluginId, const uint value, const bool lockWait) noexcept;
  159. ~ScopedActionLock() noexcept;
  160. private:
  161. CarlaEngine::ProtectedData* const fData;
  162. CARLA_PREVENT_HEAP_ALLOCATION
  163. CARLA_DECLARE_NON_COPY_CLASS(ScopedActionLock)
  164. };
  165. // -----------------------------------------------------------------------
  166. CARLA_BACKEND_END_NAMESPACE
  167. #endif // CARLA_ENGINE_INTERNAL_HPP_INCLUDED