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

11 years ago
11 years ago
11 years ago
10 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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 "CarlaMutex.hpp"
  23. #include "LinkedList.hpp"
  24. // -----------------------------------------------------------------------
  25. // Engine helper macro, sets lastError and returns false/NULL
  26. #define CARLA_SAFE_ASSERT_RETURN_ERR(cond, err) if (cond) pass(); else { carla_safe_assert(#cond, __FILE__, __LINE__); setLastError(err); return false; }
  27. #define CARLA_SAFE_ASSERT_RETURN_ERRN(cond, err) if (cond) pass(); else { carla_safe_assert(#cond, __FILE__, __LINE__); setLastError(err); return nullptr; }
  28. // -----------------------------------------------------------------------
  29. CARLA_BACKEND_START_NAMESPACE
  30. #if 0
  31. } // Fix editor indentation
  32. #endif
  33. // -----------------------------------------------------------------------
  34. // Maximum pre-allocated events for rack and bridge modes
  35. const unsigned short kMaxEngineEventInternalCount = 512;
  36. // -----------------------------------------------------------------------
  37. // Rack Patchbay stuff
  38. enum RackPatchbayGroupIds {
  39. RACK_PATCHBAY_GROUP_CARLA = 0,
  40. RACK_PATCHBAY_GROUP_AUDIO_IN = 1,
  41. RACK_PATCHBAY_GROUP_AUDIO_OUT = 2,
  42. RACK_PATCHBAY_GROUP_MIDI_IN = 3,
  43. RACK_PATCHBAY_GROUP_MIDI_OUT = 4,
  44. RACK_PATCHBAY_GROUP_MAX = 5
  45. };
  46. enum RackPatchbayPortIds {
  47. RACK_PATCHBAY_PORT_AUDIO_IN1 = -1,
  48. RACK_PATCHBAY_PORT_AUDIO_IN2 = -2,
  49. RACK_PATCHBAY_PORT_AUDIO_OUT1 = -3,
  50. RACK_PATCHBAY_PORT_AUDIO_OUT2 = -4,
  51. RACK_PATCHBAY_PORT_MIDI_IN = -5,
  52. RACK_PATCHBAY_PORT_MIDI_OUT = -6,
  53. RACK_PATCHBAY_PORT_MAX = -7
  54. };
  55. struct PortNameToId {
  56. int portId;
  57. char name[STR_MAX+1];
  58. };
  59. struct ConnectionToId {
  60. uint id;
  61. int portOut;
  62. int portIn;
  63. };
  64. // -----------------------------------------------------------------------
  65. // EngineRackBuffers
  66. struct EngineRackBuffers {
  67. float* in[2];
  68. float* out[2];
  69. // connections stuff
  70. LinkedList<int> connectedIns[2];
  71. LinkedList<int> connectedOuts[2];
  72. CarlaMutex connectLock;
  73. uint lastConnectionId;
  74. LinkedList<ConnectionToId> usedConnections;
  75. EngineRackBuffers(const uint32_t bufferSize);
  76. ~EngineRackBuffers();
  77. void clear();
  78. void resize(const uint32_t bufferSize);
  79. const char* const* getConnections() const;
  80. CARLA_DECLARE_NON_COPY_STRUCT(EngineRackBuffers)
  81. };
  82. // -----------------------------------------------------------------------
  83. // EnginePatchbayBuffers
  84. struct EnginePatchbayBuffers {
  85. // TODO
  86. EnginePatchbayBuffers(const uint32_t bufferSize);
  87. ~EnginePatchbayBuffers();
  88. void clear();
  89. void resize(const uint32_t bufferSize);
  90. const char* const* getConnections() const;
  91. CARLA_DECLARE_NON_COPY_STRUCT(EnginePatchbayBuffers)
  92. };
  93. // -----------------------------------------------------------------------
  94. // InternalAudio
  95. struct EngineInternalAudio {
  96. bool isReady;
  97. bool usePatchbay;
  98. uint inCount;
  99. uint outCount;
  100. union {
  101. EngineRackBuffers* rack;
  102. EnginePatchbayBuffers* patchbay;
  103. };
  104. EngineInternalAudio() noexcept;
  105. ~EngineInternalAudio() noexcept;
  106. void initPatchbay() noexcept;
  107. void clear();
  108. void create(const uint32_t bufferSize);
  109. void resize(const uint32_t bufferSize);
  110. CARLA_DECLARE_NON_COPY_STRUCT(EngineInternalAudio)
  111. };
  112. // -----------------------------------------------------------------------
  113. // InternalEvents
  114. struct EngineInternalEvents {
  115. EngineEvent* in;
  116. EngineEvent* out;
  117. EngineInternalEvents() noexcept;
  118. ~EngineInternalEvents() noexcept;
  119. CARLA_DECLARE_NON_COPY_STRUCT(EngineInternalEvents)
  120. };
  121. // -----------------------------------------------------------------------
  122. // InternalTime
  123. struct EngineInternalTime {
  124. bool playing;
  125. uint64_t frame;
  126. EngineInternalTime() noexcept;
  127. CARLA_DECLARE_NON_COPY_STRUCT(EngineInternalTime)
  128. };
  129. // -----------------------------------------------------------------------
  130. // NextAction
  131. enum EnginePostAction {
  132. kEnginePostActionNull,
  133. kEnginePostActionZeroCount,
  134. kEnginePostActionRemovePlugin,
  135. kEnginePostActionSwitchPlugins
  136. };
  137. struct EngineNextAction {
  138. EnginePostAction opcode;
  139. unsigned int pluginId;
  140. unsigned int value;
  141. CarlaMutex mutex;
  142. EngineNextAction() noexcept;
  143. ~EngineNextAction() noexcept;
  144. void ready() noexcept;
  145. CARLA_DECLARE_NON_COPY_STRUCT(EngineNextAction)
  146. };
  147. // -----------------------------------------------------------------------
  148. // EnginePluginData
  149. struct EnginePluginData {
  150. CarlaPlugin* plugin;
  151. float insPeak[2];
  152. float outsPeak[2];
  153. void clear() noexcept;
  154. };
  155. // -----------------------------------------------------------------------
  156. // CarlaEngineProtectedData
  157. struct CarlaEngineProtectedData {
  158. CarlaEngineOsc osc;
  159. CarlaEngineThread thread;
  160. const CarlaOscData* oscData;
  161. EngineCallbackFunc callback;
  162. void* callbackPtr;
  163. unsigned int hints;
  164. uint32_t bufferSize;
  165. double sampleRate;
  166. bool aboutToClose; // don't re-activate thread if true
  167. unsigned int curPluginCount; // number of plugins loaded (0...max)
  168. unsigned int maxPluginNumber; // number of plugins allowed (0, 16, 99 or 255)
  169. unsigned int nextPluginId; // invalid if == maxPluginNumber
  170. CarlaString lastError;
  171. CarlaString name;
  172. EngineOptions options;
  173. EngineTimeInfo timeInfo;
  174. EnginePluginData* plugins;
  175. #ifndef BUILD_BRIDGE
  176. EngineInternalAudio bufAudio;
  177. #endif
  178. EngineInternalEvents bufEvents;
  179. EngineInternalTime time;
  180. EngineNextAction nextAction;
  181. // -------------------------------------------------------------------
  182. CarlaEngineProtectedData(CarlaEngine* const engine);
  183. ~CarlaEngineProtectedData() noexcept;
  184. // -------------------------------------------------------------------
  185. void doPluginRemove() noexcept;
  186. void doPluginsSwitch() noexcept;
  187. void doNextPluginAction(const bool unlock) noexcept;
  188. // -------------------------------------------------------------------
  189. #ifndef BUILD_BRIDGE
  190. // the base, where plugins run
  191. void processRack(float* inBufReal[2], float* outBuf[2], const uint32_t nframes, const bool isOffline);
  192. // extended, will call processRack() in the middle
  193. void processRackFull(float** const inBuf, const uint32_t inCount, float** const outBuf, const uint32_t outCount, const uint32_t nframes, const bool isOffline);
  194. #endif
  195. // -------------------------------------------------------------------
  196. class ScopedActionLock
  197. {
  198. public:
  199. ScopedActionLock(CarlaEngineProtectedData* const data, const EnginePostAction action, const unsigned int pluginId, const unsigned int value, const bool lockWait) noexcept;
  200. ~ScopedActionLock() noexcept;
  201. private:
  202. CarlaEngineProtectedData* const fData;
  203. CARLA_PREVENT_HEAP_ALLOCATION
  204. CARLA_DECLARE_NON_COPY_CLASS(ScopedActionLock)
  205. };
  206. // -------------------------------------------------------------------
  207. #ifdef CARLA_PROPER_CPP11_SUPPORT
  208. CarlaEngineProtectedData() = delete;
  209. CARLA_DECLARE_NON_COPY_STRUCT(CarlaEngineProtectedData)
  210. #endif
  211. };
  212. // -----------------------------------------------------------------------
  213. CARLA_BACKEND_END_NAMESPACE
  214. #endif // CARLA_ENGINE_INTERNAL_HPP_INCLUDED