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.

234 lines
6.6KB

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