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.

208 lines
5.3KB

  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. #include "dgl/App.hpp"
  25. #ifndef BUILD_BRIDGE
  26. # include <QtCore/QProcessEnvironment>
  27. #endif
  28. CARLA_BACKEND_START_NAMESPACE
  29. // -------------------------------------------------------------------------------------------------------------------
  30. static inline
  31. const char* EngineType2Str(const EngineType type)
  32. {
  33. switch (type)
  34. {
  35. case kEngineTypeNull:
  36. return "kEngineTypeNull";
  37. case kEngineTypeJack:
  38. return "kEngineTypeJack";
  39. case kEngineTypeRtAudio:
  40. return "kEngineTypeRtAudio";
  41. case kEngineTypePlugin:
  42. return "kEngineTypePlugin";
  43. }
  44. carla_stderr("CarlaBackend::EngineType2Str(%i) - invalid type", type);
  45. return nullptr;
  46. }
  47. static inline
  48. const char* EnginePortType2Str(const EnginePortType type)
  49. {
  50. switch (type)
  51. {
  52. case kEnginePortTypeNull:
  53. return "kEnginePortTypeNull";
  54. case kEnginePortTypeAudio:
  55. return "kEnginePortTypeAudio";
  56. case kEnginePortTypeEvent:
  57. return "kEnginePortTypeEvent";
  58. }
  59. carla_stderr("CarlaBackend::EnginePortType2Str(%i) - invalid type", type);
  60. return nullptr;
  61. }
  62. static inline
  63. const char* EngineControlEventType2Str(const EngineControlEventType type)
  64. {
  65. switch (type)
  66. {
  67. case kEngineControlEventTypeNull:
  68. return "kEngineNullEvent";
  69. case kEngineControlEventTypeParameter:
  70. return "kEngineControlEventTypeParameter";
  71. case kEngineControlEventTypeMidiBank:
  72. return "kEngineControlEventTypeMidiBank";
  73. case kEngineControlEventTypeMidiProgram:
  74. return "kEngineControlEventTypeMidiProgram";
  75. case kEngineControlEventTypeAllSoundOff:
  76. return "kEngineControlEventTypeAllSoundOff";
  77. case kEngineControlEventTypeAllNotesOff:
  78. return "kEngineControlEventTypeAllNotesOff";
  79. }
  80. carla_stderr("CarlaBackend::EngineControlEventType2Str(%i) - invalid type", type);
  81. return nullptr;
  82. }
  83. // -------------------------------------------------------------------------------------------------------------------
  84. const uint32_t PATCHBAY_BUFFER_SIZE = 128;
  85. const unsigned short PATCHBAY_EVENT_COUNT = 512;
  86. const unsigned short RACK_EVENT_COUNT = 512;
  87. enum EnginePostAction {
  88. EnginePostActionNull,
  89. EnginePostActionRemovePlugin
  90. };
  91. struct EnginePluginData {
  92. CarlaPlugin* plugin;
  93. float insPeak[CarlaEngine::MAX_PEAKS];
  94. float outsPeak[CarlaEngine::MAX_PEAKS];
  95. #ifndef QTCREATOR_TEST
  96. EnginePluginData()
  97. : plugin(nullptr),
  98. insPeak{0.0f},
  99. outsPeak{0.0f} {}
  100. #endif
  101. };
  102. // -------------------------------------------------------------------------------------------------------------------
  103. struct CarlaEngineProtectedData {
  104. DGL::App app;
  105. CarlaEngineOsc osc;
  106. CarlaEngineThread thread;
  107. const CarlaOscData* oscData;
  108. CallbackFunc callback;
  109. void* callbackPtr;
  110. CarlaString lastError;
  111. #ifndef BUILD_BRIDGE
  112. QProcessEnvironment procEnv;
  113. #endif
  114. bool aboutToClose; // don't re-activate thread if true
  115. unsigned int curPluginCount; // number of plugins loaded (0...max)
  116. unsigned int maxPluginNumber; // number of plugins allowed (0, 16, 99 or 999)
  117. struct NextAction {
  118. EnginePostAction opcode;
  119. unsigned int pluginId;
  120. CarlaMutex mutex;
  121. NextAction()
  122. : opcode(EnginePostActionNull),
  123. pluginId(0) {}
  124. void ready()
  125. {
  126. mutex.lock();
  127. mutex.unlock();
  128. }
  129. } nextAction;
  130. struct Rack {
  131. EngineEvent* in;
  132. EngineEvent* out;
  133. Rack()
  134. : in(nullptr),
  135. out(nullptr) {}
  136. } rack;
  137. struct Time {
  138. bool playing;
  139. uint32_t frame;
  140. Time()
  141. : playing(false),
  142. frame(0) {}
  143. } time;
  144. EnginePluginData* plugins;
  145. CarlaEngineProtectedData(CarlaEngine* const engine)
  146. : osc(engine),
  147. thread(engine),
  148. oscData(nullptr),
  149. callback(nullptr),
  150. callbackPtr(nullptr),
  151. aboutToClose(false),
  152. curPluginCount(0),
  153. maxPluginNumber(0),
  154. plugins(nullptr) {}
  155. ~CarlaEngineProtectedData()
  156. {
  157. //plugins.clear();
  158. }
  159. CarlaEngineProtectedData() = delete;
  160. CarlaEngineProtectedData(CarlaEngineProtectedData&) = delete;
  161. CarlaEngineProtectedData(const CarlaEngineProtectedData&) = delete;
  162. static DGL::App* getApp(CarlaEngine* const engine)
  163. {
  164. return &engine->kData->app;
  165. }
  166. };
  167. CARLA_BACKEND_END_NAMESPACE
  168. #endif // __CARLA_ENGINE_INTERNAL_HPP__