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.

236 lines
6.2KB

  1. /*
  2. * Carla Engine
  3. * Copyright (C) 2012-2013 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 GPL.txt file
  16. */
  17. #ifndef __CARLA_ENGINE_INTERNAL_HPP__
  18. #define __CARLA_ENGINE_INTERNAL_HPP__
  19. #include "CarlaEngineOsc.hpp"
  20. #include "CarlaEngineThread.hpp"
  21. #include "CarlaEngine.hpp"
  22. #include "CarlaPlugin.hpp"
  23. #include "RtList.hpp"
  24. class QMainWindow;
  25. CARLA_BACKEND_START_NAMESPACE
  26. // -------------------------------------------------------------------------------------------------------------------
  27. static inline
  28. const char* EngineType2Str(const EngineType type)
  29. {
  30. switch (type)
  31. {
  32. case kEngineTypeNull:
  33. return "kEngineTypeNull";
  34. case kEngineTypeJack:
  35. return "kEngineTypeJack";
  36. case kEngineTypeRtAudio:
  37. return "kEngineTypeRtAudio";
  38. case kEngineTypePlugin:
  39. return "kEngineTypePlugin";
  40. case kEngineTypeBridge:
  41. return "kEngineTypeBridge";
  42. }
  43. carla_stderr("CarlaBackend::EngineType2Str(%i) - invalid type", type);
  44. return nullptr;
  45. }
  46. static inline
  47. const char* EnginePortType2Str(const EnginePortType type)
  48. {
  49. switch (type)
  50. {
  51. case kEnginePortTypeNull:
  52. return "kEnginePortTypeNull";
  53. case kEnginePortTypeAudio:
  54. return "kEnginePortTypeAudio";
  55. case kEnginePortTypeEvent:
  56. return "kEnginePortTypeEvent";
  57. }
  58. carla_stderr("CarlaBackend::EnginePortType2Str(%i) - invalid type", type);
  59. return nullptr;
  60. }
  61. static inline
  62. const char* EngineEventType2Str(const EngineEventType type)
  63. {
  64. switch (type)
  65. {
  66. case kEngineEventTypeNull:
  67. return "kEngineEventTypeNull";
  68. case kEngineEventTypeControl:
  69. return "kEngineEventTypeControl";
  70. case kEngineEventTypeMidi:
  71. return "kEngineEventTypeMidi";
  72. }
  73. carla_stderr("CarlaBackend::EngineEventType2Str(%i) - invalid type", type);
  74. return nullptr;
  75. }
  76. static inline
  77. const char* EngineControlEventType2Str(const EngineControlEventType type)
  78. {
  79. switch (type)
  80. {
  81. case kEngineControlEventTypeNull:
  82. return "kEngineNullEvent";
  83. case kEngineControlEventTypeParameter:
  84. return "kEngineControlEventTypeParameter";
  85. case kEngineControlEventTypeMidiBank:
  86. return "kEngineControlEventTypeMidiBank";
  87. case kEngineControlEventTypeMidiProgram:
  88. return "kEngineControlEventTypeMidiProgram";
  89. case kEngineControlEventTypeAllSoundOff:
  90. return "kEngineControlEventTypeAllSoundOff";
  91. case kEngineControlEventTypeAllNotesOff:
  92. return "kEngineControlEventTypeAllNotesOff";
  93. }
  94. carla_stderr("CarlaBackend::EngineControlEventType2Str(%i) - invalid type", type);
  95. return nullptr;
  96. }
  97. // -------------------------------------------------------------------------------------------------------------------
  98. const unsigned short INTERNAL_EVENT_COUNT = 512;
  99. const uint32_t PATCHBAY_BUFFER_SIZE = 128;
  100. enum EnginePostAction {
  101. kEnginePostActionNull,
  102. kEnginePostActionIdle,
  103. kEnginePostActionRemovePlugin,
  104. kEnginePostActionSwitchPlugins
  105. };
  106. struct EnginePluginData {
  107. CarlaPlugin* plugin;
  108. float insPeak[CarlaEngine::MAX_PEAKS];
  109. float outsPeak[CarlaEngine::MAX_PEAKS];
  110. #ifdef CARLA_PROPER_CPP11_SUPPORT
  111. EnginePluginData()
  112. : plugin(nullptr),
  113. insPeak{0.0f},
  114. outsPeak{0.0f} {}
  115. #else
  116. EnginePluginData()
  117. : plugin(nullptr)
  118. {
  119. insPeak[0] = insPeak[1] = nullptr;
  120. outsPeak[0] = outsPeak[1] = nullptr;
  121. }
  122. #endif
  123. };
  124. // -------------------------------------------------------------------------------------------------------------------
  125. struct CarlaEngineProtectedData {
  126. CarlaEngineOsc osc;
  127. CarlaEngineThread thread;
  128. const CarlaOscData* oscData;
  129. CallbackFunc callback;
  130. void* callbackPtr;
  131. CarlaString lastError;
  132. QMainWindow* hostWindow;
  133. bool aboutToClose; // don't re-activate thread if true
  134. unsigned int curPluginCount; // number of plugins loaded (0...max)
  135. unsigned int maxPluginNumber; // number of plugins allowed (0, 16, 99 or 255)
  136. struct InternalEventBuffer {
  137. EngineEvent* in;
  138. EngineEvent* out;
  139. InternalEventBuffer()
  140. : in(nullptr),
  141. out(nullptr) {}
  142. } bufEvent;
  143. struct NextAction {
  144. EnginePostAction opcode;
  145. unsigned int pluginId;
  146. unsigned int value;
  147. CarlaMutex mutex;
  148. NextAction()
  149. : opcode(kEnginePostActionNull),
  150. pluginId(0),
  151. value(0) {}
  152. ~NextAction()
  153. {
  154. CARLA_ASSERT(opcode == kEnginePostActionNull);
  155. }
  156. void ready()
  157. {
  158. mutex.lock();
  159. mutex.unlock();
  160. }
  161. } nextAction;
  162. struct Time {
  163. bool playing;
  164. uint32_t frame;
  165. Time()
  166. : playing(false),
  167. frame(0) {}
  168. } time;
  169. EnginePluginData* plugins;
  170. CarlaEngineProtectedData(CarlaEngine* const engine)
  171. : osc(engine),
  172. thread(engine),
  173. oscData(nullptr),
  174. callback(nullptr),
  175. callbackPtr(nullptr),
  176. hostWindow(nullptr),
  177. aboutToClose(false),
  178. curPluginCount(0),
  179. maxPluginNumber(0),
  180. plugins(nullptr) {}
  181. #ifdef CARLA_PROPER_CPP11_SUPPORT
  182. CarlaEngineProtectedData() = delete;
  183. CarlaEngineProtectedData(CarlaEngineProtectedData&) = delete;
  184. CarlaEngineProtectedData(const CarlaEngineProtectedData&) = delete;
  185. #endif
  186. #ifndef BUILD_BRIDGE
  187. static void registerEnginePlugin(CarlaEngine* const engine, const unsigned int id, CarlaPlugin* const plugin)
  188. {
  189. CARLA_ASSERT(id == engine->kData->curPluginCount);
  190. if (id == engine->kData->curPluginCount)
  191. engine->kData->plugins[id].plugin = plugin;
  192. }
  193. #endif
  194. };
  195. CARLA_BACKEND_END_NAMESPACE
  196. #endif // __CARLA_ENGINE_INTERNAL_HPP__