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.

222 lines
5.7KB

  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. #ifndef BUILD_BRIDGE
  25. # include <QtCore/QProcessEnvironment>
  26. #endif
  27. CARLA_BACKEND_START_NAMESPACE
  28. // -------------------------------------------------------------------------------------------------------------------
  29. static inline
  30. const char* EngineType2Str(const EngineType type)
  31. {
  32. switch (type)
  33. {
  34. case kEngineTypeNull:
  35. return "kEngineTypeNull";
  36. case kEngineTypeJack:
  37. return "kEngineTypeJack";
  38. case kEngineTypeRtAudio:
  39. return "kEngineTypeRtAudio";
  40. case kEngineTypePlugin:
  41. return "kEngineTypePlugin";
  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* EngineControlEventType2Str(const EngineControlEventType type)
  63. {
  64. switch (type)
  65. {
  66. case kEngineControlEventTypeNull:
  67. return "kEngineNullEvent";
  68. case kEngineControlEventTypeParameter:
  69. return "kEngineControlEventTypeParameter";
  70. case kEngineControlEventTypeMidiBank:
  71. return "kEngineControlEventTypeMidiBank";
  72. case kEngineControlEventTypeMidiProgram:
  73. return "kEngineControlEventTypeMidiProgram";
  74. case kEngineControlEventTypeAllSoundOff:
  75. return "kEngineControlEventTypeAllSoundOff";
  76. case kEngineControlEventTypeAllNotesOff:
  77. return "kEngineControlEventTypeAllNotesOff";
  78. }
  79. carla_stderr("CarlaBackend::EngineControlEventType2Str(%i) - invalid type", type);
  80. return nullptr;
  81. }
  82. // -------------------------------------------------------------------------------------------------------------------
  83. const uint32_t PATCHBAY_BUFFER_SIZE = 128;
  84. const unsigned short PATCHBAY_EVENT_COUNT = 512;
  85. const unsigned short RACK_EVENT_COUNT = 512;
  86. #if 0
  87. struct EnginePostEvent {
  88. EnginePostEventType type;
  89. int32_t value1;
  90. void* valuePtr;
  91. EnginePostEvent()
  92. : type(EnginePostEventNull),
  93. value1(-1),
  94. valuePtr(nullptr) {}
  95. };
  96. #endif
  97. enum EnginePostAction {
  98. EnginePostActionNull,
  99. EnginePostActionIdle,
  100. EnginePostActionInsertPlugin,
  101. EnginePostActionRemovePlugin
  102. };
  103. struct EnginePluginData {
  104. CarlaPlugin* plugin;
  105. float insPeak[CarlaEngine::MAX_PEAKS];
  106. float outsPeak[CarlaEngine::MAX_PEAKS];
  107. EnginePluginData()
  108. : plugin(nullptr),
  109. insPeak{0.0f},
  110. outsPeak{0.0f} {}
  111. };
  112. // -------------------------------------------------------------------------------------------------------------------
  113. struct CarlaEngineProtectedData {
  114. CarlaEngineOsc osc;
  115. CarlaEngineThread thread;
  116. const CarlaOscData* oscData;
  117. CallbackFunc callback;
  118. void* callbackPtr;
  119. CarlaString lastError;
  120. #ifndef BUILD_BRIDGE
  121. QProcessEnvironment procEnv;
  122. #endif
  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 999)
  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. struct Rack {
  140. EngineEvent* in;
  141. EngineEvent* out;
  142. Rack()
  143. : in(nullptr),
  144. out(nullptr) {}
  145. } rack;
  146. struct Time {
  147. bool playing;
  148. uint32_t frame;
  149. Time()
  150. : playing(false),
  151. frame(0) {}
  152. } time;
  153. //RtList<EnginePluginData>::Pool pluginsPool;
  154. //RtList<EnginePluginData> plugins;
  155. EnginePluginData* plugins;
  156. CarlaEngineProtectedData(CarlaEngine* const engine)
  157. : osc(engine),
  158. thread(engine),
  159. oscData(nullptr),
  160. callback(nullptr),
  161. callbackPtr(nullptr),
  162. aboutToClose(false),
  163. curPluginCount(0),
  164. //pluginsPool(1, 999),
  165. //plugins(&pluginsPool)
  166. maxPluginNumber(0),
  167. plugins(nullptr) {}
  168. ~CarlaEngineProtectedData()
  169. {
  170. //plugins.clear();
  171. }
  172. CarlaEngineProtectedData() = delete;
  173. CarlaEngineProtectedData(CarlaEngineProtectedData&) = delete;
  174. CarlaEngineProtectedData(const CarlaEngineProtectedData&) = delete;
  175. //static RtList<EnginePluginData>::Itenerator pluginsBegin(CarlaEngine* const engine)
  176. //{
  177. // return engine->kData->plugins.begin();
  178. //}
  179. };
  180. CARLA_BACKEND_END_NAMESPACE
  181. #endif // __CARLA_ENGINE_INTERNAL_HPP__