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.

CarlaEngineInternal.hpp 7.3KB

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