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.

227 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 uint32_t PATCHBAY_BUFFER_SIZE = 128;
  99. const unsigned short PATCHBAY_EVENT_COUNT = 512;
  100. const unsigned short RACK_EVENT_COUNT = 512;
  101. enum EnginePostAction {
  102. EnginePostActionNull,
  103. EnginePostActionRemovePlugin,
  104. EnginePostActionSwitchPlugins
  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 NextAction {
  128. EnginePostAction opcode;
  129. unsigned int pluginId;
  130. unsigned int value;
  131. CarlaMutex mutex;
  132. NextAction()
  133. : opcode(EnginePostActionNull),
  134. pluginId(0),
  135. value(0) {}
  136. ~NextAction()
  137. {
  138. CARLA_ASSERT(opcode == EnginePostActionNull);
  139. }
  140. void ready()
  141. {
  142. mutex.lock();
  143. mutex.unlock();
  144. }
  145. } nextAction;
  146. #ifndef BUILD_BRIDGE
  147. struct Rack {
  148. EngineEvent* in;
  149. EngineEvent* out;
  150. Rack()
  151. : in(nullptr),
  152. out(nullptr) {}
  153. } rack;
  154. #endif
  155. struct Time {
  156. bool playing;
  157. uint32_t frame;
  158. Time()
  159. : playing(false),
  160. frame(0) {}
  161. } time;
  162. EnginePluginData* plugins;
  163. CarlaEngineProtectedData(CarlaEngine* const engine)
  164. : osc(engine),
  165. thread(engine),
  166. oscData(nullptr),
  167. callback(nullptr),
  168. callbackPtr(nullptr),
  169. hostWindow(nullptr),
  170. aboutToClose(false),
  171. curPluginCount(0),
  172. maxPluginNumber(0),
  173. plugins(nullptr) {}
  174. CarlaEngineProtectedData() = delete;
  175. CarlaEngineProtectedData(CarlaEngineProtectedData&) = delete;
  176. CarlaEngineProtectedData(const CarlaEngineProtectedData&) = delete;
  177. #ifndef BUILD_BRIDGE
  178. static void registerEnginePlugin(CarlaEngine* const engine, const unsigned int id, CarlaPlugin* const plugin)
  179. {
  180. CARLA_ASSERT(id == engine->kData->curPluginCount);
  181. if (id == engine->kData->curPluginCount)
  182. engine->kData->plugins[id].plugin = plugin;
  183. }
  184. #endif
  185. };
  186. CARLA_BACKEND_END_NAMESPACE
  187. #endif // __CARLA_ENGINE_INTERNAL_HPP__