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.1KB

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
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
10 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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 InternalGraph;
  42. struct EngineInternalGraph {
  43. bool isRack;
  44. bool isReady;
  45. InternalGraph* graph;
  46. EngineInternalGraph() noexcept;
  47. ~EngineInternalGraph() noexcept;
  48. void create(const double sampleRate, const uint32_t bufferSize);
  49. void clear() noexcept;
  50. void setBufferSize(const uint32_t bufferSize);
  51. void setSampleRate(const double sampleRate);
  52. CARLA_DECLARE_NON_COPY_STRUCT(EngineInternalGraph)
  53. };
  54. #endif
  55. // -----------------------------------------------------------------------
  56. // InternalTime
  57. struct EngineInternalTime {
  58. bool playing;
  59. uint64_t frame;
  60. EngineInternalTime() noexcept;
  61. CARLA_DECLARE_NON_COPY_STRUCT(EngineInternalTime)
  62. };
  63. // -----------------------------------------------------------------------
  64. // EngineNextAction
  65. enum EnginePostAction {
  66. kEnginePostActionNull = 0,
  67. kEnginePostActionZeroCount, // set curPluginCount to 0
  68. #ifndef BUILD_BRIDGE
  69. kEnginePostActionRemovePlugin, // remove a plugin
  70. kEnginePostActionSwitchPlugins // switch between 2 plugins
  71. #endif
  72. };
  73. struct EngineNextAction {
  74. EnginePostAction opcode;
  75. uint pluginId;
  76. uint value;
  77. CarlaMutex mutex;
  78. EngineNextAction() noexcept;
  79. ~EngineNextAction() noexcept;
  80. void ready() const noexcept;
  81. CARLA_DECLARE_NON_COPY_STRUCT(EngineNextAction)
  82. };
  83. // -----------------------------------------------------------------------
  84. // EnginePluginData
  85. struct EnginePluginData {
  86. CarlaPlugin* plugin;
  87. float insPeak[2];
  88. float outsPeak[2];
  89. };
  90. // -----------------------------------------------------------------------
  91. // CarlaEngineProtectedData
  92. struct CarlaEngine::ProtectedData {
  93. CarlaEngineOsc osc;
  94. CarlaEngineThread thread;
  95. const CarlaOscData* oscData;
  96. EngineCallbackFunc callback;
  97. void* callbackPtr;
  98. FileCallbackFunc fileCallback;
  99. void* fileCallbackPtr;
  100. uint hints;
  101. uint32_t bufferSize;
  102. double sampleRate;
  103. bool aboutToClose; // don't re-activate thread if true
  104. uint curPluginCount; // number of plugins loaded (0...max)
  105. uint maxPluginNumber; // number of plugins allowed (0, 16, 99 or 255)
  106. uint nextPluginId; // invalid if == maxPluginNumber
  107. CarlaString lastError;
  108. CarlaString name;
  109. EngineOptions options;
  110. EngineTimeInfo timeInfo;
  111. #ifdef BUILD_BRIDGE
  112. EnginePluginData plugins[1];
  113. #else
  114. EnginePluginData* plugins;
  115. #endif
  116. EngineInternalEvents events;
  117. #ifndef BUILD_BRIDGE
  118. EngineInternalGraph graph;
  119. #endif
  120. EngineInternalTime time;
  121. EngineNextAction nextAction;
  122. // -------------------------------------------------------------------
  123. ProtectedData(CarlaEngine* const engine) noexcept;
  124. ~ProtectedData() noexcept;
  125. // -------------------------------------------------------------------
  126. bool init(const char* const clientName);
  127. void close();
  128. // -------------------------------------------------------------------
  129. void doPluginRemove() noexcept;
  130. void doPluginsSwitch() noexcept;
  131. void doNextPluginAction(const bool unlock) noexcept;
  132. #ifndef BUILD_BRIDGE
  133. // -------------------------------------------------------------------
  134. // the base, where plugins run
  135. void processRack(const float* inBufReal[2], float* outBuf[2], const uint32_t nframes, const bool isOffline);
  136. // extended, will call processRack() in the middle
  137. void processRackFull(const float* const* const inBuf, const uint32_t inCount, float* const* const outBuf, const uint32_t outCount, const uint32_t nframes, const bool isOffline);
  138. #endif
  139. // -------------------------------------------------------------------
  140. //friend class ScopedActionLock;
  141. #ifdef CARLA_PROPER_CPP11_SUPPORT
  142. ProtectedData() = delete;
  143. CARLA_DECLARE_NON_COPY_STRUCT(ProtectedData)
  144. #endif
  145. };
  146. // -----------------------------------------------------------------------
  147. class ScopedActionLock
  148. {
  149. public:
  150. ScopedActionLock(CarlaEngine::ProtectedData* const data, const EnginePostAction action, const uint pluginId, const uint value, const bool lockWait) noexcept;
  151. ~ScopedActionLock() noexcept;
  152. private:
  153. CarlaEngine::ProtectedData* const fData;
  154. CARLA_PREVENT_HEAP_ALLOCATION
  155. CARLA_DECLARE_NON_COPY_CLASS(ScopedActionLock)
  156. };
  157. // -----------------------------------------------------------------------
  158. CARLA_BACKEND_END_NAMESPACE
  159. #endif // CARLA_ENGINE_INTERNAL_HPP_INCLUDED