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.

225 lines
6.3KB

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