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.

207 lines
5.4KB

  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. enum EnginePostAction {
  87. EnginePostActionNull,
  88. EnginePostActionRemovePlugin
  89. };
  90. struct EnginePluginData {
  91. CarlaPlugin* plugin;
  92. float insPeak[CarlaEngine::MAX_PEAKS];
  93. float outsPeak[CarlaEngine::MAX_PEAKS];
  94. EnginePluginData()
  95. : plugin(nullptr),
  96. insPeak{0.0f},
  97. outsPeak{0.0f} {}
  98. };
  99. // -------------------------------------------------------------------------------------------------------------------
  100. struct CarlaEngineProtectedData {
  101. CarlaEngineOsc osc;
  102. CarlaEngineThread thread;
  103. const CarlaOscData* oscData;
  104. CallbackFunc callback;
  105. void* callbackPtr;
  106. CarlaString lastError;
  107. #ifndef BUILD_BRIDGE
  108. QProcessEnvironment procEnv;
  109. #endif
  110. bool aboutToClose; // don't re-activate thread if true
  111. unsigned int curPluginCount; // number of plugins loaded (0...max)
  112. unsigned int maxPluginNumber; // number of plugins allowed (0, 16, 99 or 999)
  113. struct NextAction {
  114. EnginePostAction opcode;
  115. unsigned int pluginId;
  116. CarlaMutex mutex;
  117. NextAction()
  118. : opcode(EnginePostActionNull),
  119. pluginId(0) {}
  120. void ready()
  121. {
  122. mutex.lock();
  123. mutex.unlock();
  124. }
  125. } nextAction;
  126. struct Rack {
  127. EngineEvent* in;
  128. EngineEvent* out;
  129. Rack()
  130. : in(nullptr),
  131. out(nullptr) {}
  132. } rack;
  133. struct Time {
  134. bool playing;
  135. uint32_t frame;
  136. Time()
  137. : playing(false),
  138. frame(0) {}
  139. } time;
  140. //RtList<EnginePluginData>::Pool pluginsPool;
  141. //RtList<EnginePluginData> plugins;
  142. EnginePluginData* plugins;
  143. CarlaEngineProtectedData(CarlaEngine* const engine)
  144. : osc(engine),
  145. thread(engine),
  146. oscData(nullptr),
  147. callback(nullptr),
  148. callbackPtr(nullptr),
  149. aboutToClose(false),
  150. curPluginCount(0),
  151. //pluginsPool(1, 999),
  152. //plugins(&pluginsPool)
  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 RtList<EnginePluginData>::Itenerator pluginsBegin(CarlaEngine* const engine)
  163. //{
  164. // return engine->kData->plugins.begin();
  165. //}
  166. };
  167. CARLA_BACKEND_END_NAMESPACE
  168. #endif // __CARLA_ENGINE_INTERNAL_HPP__