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.

205 lines
5.2KB

  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. #ifndef BUILD_BRIDGE
  24. # include <QtCore/QProcessEnvironment>
  25. #endif
  26. CARLA_BACKEND_START_NAMESPACE
  27. // -------------------------------------------------------------------------------------------------------------------
  28. static inline
  29. const char* EngineType2Str(const EngineType type)
  30. {
  31. switch (type)
  32. {
  33. case kEngineTypeNull:
  34. return "kEngineTypeNull";
  35. case kEngineTypeJack:
  36. return "kEngineTypeJack";
  37. case kEngineTypeRtAudio:
  38. return "kEngineTypeRtAudio";
  39. case kEngineTypePlugin:
  40. return "kEngineTypePlugin";
  41. }
  42. carla_stderr("CarlaBackend::EngineType2Str(%i) - invalid type", type);
  43. return nullptr;
  44. }
  45. static inline
  46. const char* EnginePortType2Str(const EnginePortType type)
  47. {
  48. switch (type)
  49. {
  50. case kEnginePortTypeNull:
  51. return "kEnginePortTypeNull";
  52. case kEnginePortTypeAudio:
  53. return "kEnginePortTypeAudio";
  54. case kEnginePortTypeEvent:
  55. return "kEnginePortTypeEvent";
  56. }
  57. carla_stderr("CarlaBackend::EnginePortType2Str(%i) - invalid type", type);
  58. return nullptr;
  59. }
  60. static inline
  61. const char* EngineControlEventType2Str(const EngineControlEventType type)
  62. {
  63. switch (type)
  64. {
  65. case kEngineControlEventTypeNull:
  66. return "kEngineNullEvent";
  67. case kEngineControlEventTypeParameter:
  68. return "kEngineControlEventTypeParameter";
  69. case kEngineControlEventTypeMidiBank:
  70. return "kEngineControlEventTypeMidiBank";
  71. case kEngineControlEventTypeMidiProgram:
  72. return "kEngineControlEventTypeMidiProgram";
  73. case kEngineControlEventTypeAllSoundOff:
  74. return "kEngineControlEventTypeAllSoundOff";
  75. case kEngineControlEventTypeAllNotesOff:
  76. return "kEngineControlEventTypeAllNotesOff";
  77. }
  78. carla_stderr("CarlaBackend::EngineControlEventType2Str(%i) - invalid type", type);
  79. return nullptr;
  80. }
  81. // -------------------------------------------------------------------------------------------------------------------
  82. /*!
  83. * Maximum number of peaks per plugin.\n
  84. * \note There are both input and output peaks.
  85. */
  86. const uint32_t PATCHBAY_BUFFER_SIZE = 128;
  87. const unsigned short PATCHBAY_EVENT_COUNT = 512;
  88. const unsigned short RACK_EVENT_COUNT = 512;
  89. #if 0
  90. struct EnginePostEvent {
  91. EnginePostEventType type;
  92. int32_t value1;
  93. void* valuePtr;
  94. EnginePostEvent()
  95. : type(EnginePostEventNull),
  96. value1(-1),
  97. valuePtr(nullptr) {}
  98. };
  99. #endif
  100. enum EnginePostAction {
  101. EnginePostActionNull,
  102. EnginePostActionIdle,
  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. #ifndef BUILD_BRIDGE
  123. QProcessEnvironment procEnv;
  124. #endif
  125. bool aboutToClose; // don't re-activate thread if true
  126. unsigned int curPluginCount; // number of plugins loaded (0...max)
  127. unsigned int maxPluginNumber; // number of plugins allowed (0, 16, 99 or 999)
  128. struct NextAction {
  129. EnginePostAction opcode;
  130. unsigned int pluginId;
  131. CarlaMutex mutex;
  132. NextAction()
  133. : opcode(EnginePostActionNull),
  134. pluginId(0) {}
  135. void ready()
  136. {
  137. mutex.lock();
  138. mutex.unlock();
  139. }
  140. } nextAction;
  141. struct Rack {
  142. EngineEvent* in;
  143. EngineEvent* out;
  144. Rack()
  145. : in(nullptr),
  146. out(nullptr) {}
  147. } rack;
  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. aboutToClose(false),
  163. curPluginCount(0),
  164. maxPluginNumber(0),
  165. plugins(nullptr) {}
  166. };
  167. CARLA_BACKEND_END_NAMESPACE
  168. #endif // __CARLA_ENGINE_INTERNAL_HPP__