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.

214 lines
6.0KB

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