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

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