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.

219 lines
5.8KB

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