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.

184 lines
4.9KB

  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 modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * 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 COPYING 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. #include "rt_list.hpp"
  24. #ifndef BUILD_BRIDGE
  25. # include <QtCore/QProcessEnvironment>
  26. #endif
  27. CARLA_BACKEND_START_NAMESPACE
  28. // -------------------------------------------------------------------------------------------------------------------
  29. static inline
  30. const char* CarlaEngineType2Str(const CarlaEngineType type)
  31. {
  32. switch (type)
  33. {
  34. case CarlaEngineTypeNull:
  35. return "CarlaEngineTypeNull";
  36. case CarlaEngineTypeJack:
  37. return "CarlaEngineTypeJack";
  38. case CarlaEngineTypeRtAudio:
  39. return "CarlaEngineTypeRtAudio";
  40. case CarlaEngineTypePlugin:
  41. return "CarlaEngineTypePlugin";
  42. }
  43. qWarning("CarlaBackend::CarlaEngineType2Str(%i) - invalid type", type);
  44. return nullptr;
  45. }
  46. static inline
  47. const char* CarlaEnginePortType2Str(const CarlaEnginePortType type)
  48. {
  49. switch (type)
  50. {
  51. case CarlaEnginePortTypeNull:
  52. return "CarlaEnginePortTypeNull";
  53. case CarlaEnginePortTypeAudio:
  54. return "CarlaEnginePortTypeAudio";
  55. case CarlaEnginePortTypeControl:
  56. return "CarlaEnginePortTypeControl";
  57. case CarlaEnginePortTypeMIDI:
  58. return "CarlaEnginePortTypeMIDI";
  59. }
  60. qWarning("CarlaBackend::CarlaEnginePortType2Str(%i) - invalid type", type);
  61. return nullptr;
  62. }
  63. static inline
  64. const char* CarlaEngineControlEventType2Str(const CarlaEngineControlEventType type)
  65. {
  66. switch (type)
  67. {
  68. case CarlaEngineControlEventTypeNull:
  69. return "CarlaEngineNullEvent";
  70. case CarlaEngineControlEventTypeParameterChange:
  71. return "CarlaEngineControlEventTypeParameterChange";
  72. case CarlaEngineControlEventTypeMidiBankChange:
  73. return "CarlaEngineControlEventTypeMidiBankChange";
  74. case CarlaEngineControlEventTypeMidiProgramChange:
  75. return "CarlaEngineControlEventTypeMidiProgramChange";
  76. case CarlaEngineControlEventTypeAllSoundOff:
  77. return "CarlaEngineControlEventTypeAllSoundOff";
  78. case CarlaEngineControlEventTypeAllNotesOff:
  79. return "CarlaEngineControlEventTypeAllNotesOff";
  80. }
  81. qWarning("CarlaBackend::CarlaEngineControlEventType2Str(%i) - invalid type", type);
  82. return nullptr;
  83. }
  84. // -------------------------------------------------------------------------------------------------------------------
  85. /*!
  86. * Maximum number of peaks per plugin.\n
  87. * \note There are both input and output peaks.
  88. */
  89. /*static*/ const unsigned short MAX_PEAKS = 2;
  90. const uint32_t PATCHBAY_BUFFER_SIZE = 128;
  91. const unsigned short PATCHBAY_EVENT_COUNT = 256;
  92. enum EnginePostEventType {
  93. EnginePostEventNull,
  94. EnginePostEventDebug,
  95. PluginPostEventAddPlugin, // id, ptr
  96. PluginPostEventRemovePlugin // id
  97. };
  98. struct EnginePostEvent {
  99. EnginePostEventType type;
  100. int32_t value1;
  101. void* valuePtr;
  102. EnginePostEvent()
  103. : type(EnginePostEventNull),
  104. value1(-1),
  105. valuePtr(nullptr) {}
  106. };
  107. struct EnginePluginData {
  108. CarlaPlugin* const plugin;
  109. double insPeak[MAX_PEAKS];
  110. double outsPeak[MAX_PEAKS];
  111. EnginePluginData(CarlaPlugin* const plugin_)
  112. : plugin(plugin_),
  113. insPeak{0},
  114. outsPeak{0} {}
  115. EnginePluginData() = delete;
  116. };
  117. struct CarlaEnginePrivateData {
  118. CarlaEngineOsc osc;
  119. CarlaEngineThread thread;
  120. ScopedPointer<const CarlaOscData> oscData;
  121. CallbackFunc callback;
  122. void* callbackPtr;
  123. CarlaString lastError;
  124. #ifndef BUILD_BRIDGE
  125. QProcessEnvironment procEnv;
  126. #endif
  127. // for postEvents
  128. CarlaMutex eventLock;
  129. // for external midi input (GUI and OSC)
  130. CarlaMutex midiLock;
  131. RtList<EnginePostEvent> postEvents;
  132. RtList<EnginePluginData> plugins;
  133. bool aboutToClose;
  134. unsigned int maxPluginNumber;
  135. unsigned int nextPluginId;
  136. CarlaEnginePrivateData(CarlaEngine* const engine)
  137. : osc(engine),
  138. thread(engine),
  139. oscData(nullptr),
  140. callback(nullptr),
  141. callbackPtr(nullptr),
  142. postEvents(1, 1),
  143. plugins(1, 1),
  144. aboutToClose(false),
  145. maxPluginNumber(0),
  146. nextPluginId(0) {}
  147. };
  148. CARLA_BACKEND_END_NAMESPACE
  149. #endif // __CARLA_ENGINE_INTERNAL_HPP__