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.

225 lines
6.0KB

  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. EnginePluginData()
  111. : plugin(nullptr),
  112. insPeak{0.0f},
  113. outsPeak{0.0f} {}
  114. };
  115. // -------------------------------------------------------------------------------------------------------------------
  116. struct CarlaEngineProtectedData {
  117. CarlaEngineOsc osc;
  118. CarlaEngineThread thread;
  119. const CarlaOscData* oscData;
  120. CallbackFunc callback;
  121. void* callbackPtr;
  122. CarlaString lastError;
  123. QMainWindow* hostWindow;
  124. bool aboutToClose; // don't re-activate thread if true
  125. unsigned int curPluginCount; // number of plugins loaded (0...max)
  126. unsigned int maxPluginNumber; // number of plugins allowed (0, 16, 99 or 255)
  127. struct InternalEventBuffer {
  128. EngineEvent* in;
  129. EngineEvent* out;
  130. InternalEventBuffer()
  131. : in(nullptr),
  132. out(nullptr) {}
  133. } bufEvent;
  134. struct NextAction {
  135. EnginePostAction opcode;
  136. unsigned int pluginId;
  137. unsigned int value;
  138. CarlaMutex mutex;
  139. NextAction()
  140. : opcode(kEnginePostActionNull),
  141. pluginId(0),
  142. value(0) {}
  143. ~NextAction()
  144. {
  145. CARLA_ASSERT(opcode == kEnginePostActionNull);
  146. }
  147. void ready()
  148. {
  149. mutex.lock();
  150. mutex.unlock();
  151. }
  152. } nextAction;
  153. struct Time {
  154. bool playing;
  155. uint32_t frame;
  156. Time()
  157. : playing(false),
  158. frame(0) {}
  159. } time;
  160. EnginePluginData* plugins;
  161. CarlaEngineProtectedData(CarlaEngine* const engine)
  162. : osc(engine),
  163. thread(engine),
  164. oscData(nullptr),
  165. callback(nullptr),
  166. callbackPtr(nullptr),
  167. hostWindow(nullptr),
  168. aboutToClose(false),
  169. curPluginCount(0),
  170. maxPluginNumber(0),
  171. plugins(nullptr) {}
  172. CarlaEngineProtectedData() = delete;
  173. CarlaEngineProtectedData(CarlaEngineProtectedData&) = delete;
  174. CarlaEngineProtectedData(const CarlaEngineProtectedData&) = delete;
  175. #ifndef BUILD_BRIDGE
  176. static void registerEnginePlugin(CarlaEngine* const engine, const unsigned int id, CarlaPlugin* const plugin)
  177. {
  178. CARLA_ASSERT(id == engine->kData->curPluginCount);
  179. if (id == engine->kData->curPluginCount)
  180. engine->kData->plugins[id].plugin = plugin;
  181. }
  182. #endif
  183. };
  184. CARLA_BACKEND_END_NAMESPACE
  185. #endif // __CARLA_ENGINE_INTERNAL_HPP__