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.

195 lines
5.0KB

  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 "carla_engine.hpp"
  20. #include "carla_engine_osc.hpp"
  21. #include "carla_engine_thread.hpp"
  22. #include "carla_plugin.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. qWarning("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. qWarning("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. qWarning("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. /*static*/
  87. const unsigned short MAX_PEAKS = 2;
  88. const uint32_t PATCHBAY_BUFFER_SIZE = 128;
  89. const unsigned short PATCHBAY_EVENT_COUNT = 512;
  90. const unsigned short RACK_EVENT_COUNT = 1024;
  91. #if 0
  92. struct EnginePostEvent {
  93. EnginePostEventType type;
  94. int32_t value1;
  95. void* valuePtr;
  96. EnginePostEvent()
  97. : type(EnginePostEventNull),
  98. value1(-1),
  99. valuePtr(nullptr) {}
  100. };
  101. #endif
  102. enum EnginePostAction {
  103. EnginePostActionNull,
  104. EnginePostActionIdle,
  105. EnginePostActionRemovePlugin
  106. };
  107. struct EnginePluginData {
  108. CarlaPlugin* plugin;
  109. float insPeak[MAX_PEAKS];
  110. float outsPeak[MAX_PEAKS];
  111. EnginePluginData()
  112. : plugin(nullptr),
  113. insPeak{0.0f},
  114. outsPeak{0.0f} {}
  115. };
  116. // -------------------------------------------------------------------------------------------------------------------
  117. struct CarlaEngineProtectedData {
  118. CarlaEngineOsc osc;
  119. CarlaEngineThread thread;
  120. const CarlaOscData* oscData;
  121. CallbackFunc callback;
  122. void* callbackPtr;
  123. CarlaString lastError;
  124. #ifndef BUILD_BRIDGE
  125. QProcessEnvironment procEnv;
  126. #endif
  127. bool aboutToClose; // don't re-activate thread if true
  128. unsigned int curPluginCount; // number of plugins loaded (0...max)
  129. unsigned int maxPluginNumber; // number of plugins allowed (0, 16, 99 or 999)
  130. struct NextAction {
  131. EnginePostAction opcode;
  132. unsigned int pluginId;
  133. CarlaMutex mutex;
  134. NextAction()
  135. : opcode(EnginePostActionNull),
  136. pluginId(0) {}
  137. void ready()
  138. {
  139. mutex.lock();
  140. mutex.unlock();
  141. }
  142. } nextAction;
  143. EnginePluginData* plugins;
  144. CarlaEngineProtectedData(CarlaEngine* const engine)
  145. : osc(engine),
  146. thread(engine),
  147. oscData(nullptr),
  148. callback(nullptr),
  149. callbackPtr(nullptr),
  150. aboutToClose(false),
  151. curPluginCount(0),
  152. maxPluginNumber(0),
  153. plugins(nullptr) {}
  154. CarlaEngineProtectedData() = delete;
  155. CARLA_LEAK_DETECTOR(CarlaEngineProtectedData)
  156. };
  157. CARLA_BACKEND_END_NAMESPACE
  158. #endif // __CARLA_ENGINE_INTERNAL_HPP__