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.

377 lines
10KB

  1. /*
  2. * Carla Plugin
  3. * Copyright (C) 2011-2014 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 doc/GPL.txt file.
  16. */
  17. #ifndef CARLA_PLUGIN_INTERNAL_HPP_INCLUDED
  18. #define CARLA_PLUGIN_INTERNAL_HPP_INCLUDED
  19. #include "CarlaPlugin.hpp"
  20. #include "CarlaPluginThread.hpp"
  21. #include "CarlaOscUtils.hpp"
  22. #include "CarlaStateUtils.hpp"
  23. #include "CarlaMutex.hpp"
  24. #include "RtLinkedList.hpp"
  25. #include "CarlaMIDI.h"
  26. // -----------------------------------------------------------------------
  27. #define CARLA_PROCESS_CONTINUE_CHECK if (! pData->enabled) { pData->engine->callback(ENGINE_CALLBACK_DEBUG, pData->id, 0, 0, 0.0f, "Processing while plugin is disabled!!"); return; }
  28. // -----------------------------------------------------------------------
  29. CARLA_BACKEND_START_NAMESPACE
  30. #if 0
  31. } // Fix editor indentation
  32. #endif
  33. // -----------------------------------------------------------------------
  34. // Forward declarations of CarlaEngine classes
  35. class CarlaEngineAudioPort;
  36. class CarlaEngineCVPort;
  37. class CarlaEngineEventPort;
  38. // -----------------------------------------------------------------------
  39. // Maximum pre-allocated events for some plugin types
  40. const ushort kPluginMaxMidiEvents = 512;
  41. // -----------------------------------------------------------------------
  42. // Extra plugin hints, hidden from backend
  43. const uint PLUGIN_EXTRA_HINT_HAS_MIDI_IN = 0x01;
  44. const uint PLUGIN_EXTRA_HINT_HAS_MIDI_OUT = 0x02;
  45. const uint PLUGIN_EXTRA_HINT_CAN_RUN_RACK = 0x04;
  46. const uint PLUGIN_EXTRA_HINT_USES_MULTI_PROGS = 0x08;
  47. // -----------------------------------------------------------------------
  48. /*!
  49. * Post-RT event type.\n
  50. * These are events postponned from within the process function,
  51. *
  52. * During process, we cannot lock, allocate memory or do UI stuff,\n
  53. * so events have to be postponned to be executed later, on a separate thread.
  54. */
  55. enum PluginPostRtEventType {
  56. kPluginPostRtEventNull = 0,
  57. kPluginPostRtEventDebug,
  58. kPluginPostRtEventParameterChange, // param, SP (*), value (SP: if 1 only report change to UI, don't report to Callback and OSC)
  59. kPluginPostRtEventProgramChange, // index
  60. kPluginPostRtEventMidiProgramChange, // index
  61. kPluginPostRtEventNoteOn, // channel, note, velo
  62. kPluginPostRtEventNoteOff // channel, note
  63. };
  64. /*!
  65. * A Post-RT event.
  66. * \see PluginPostRtEventType
  67. */
  68. struct PluginPostRtEvent {
  69. PluginPostRtEventType type;
  70. int32_t value1;
  71. int32_t value2;
  72. float value3;
  73. };
  74. // -----------------------------------------------------------------------
  75. struct ExternalMidiNote {
  76. int8_t channel; // invalid if -1
  77. uint8_t note; // 0 to 127
  78. uint8_t velo; // note-off if 0
  79. };
  80. // -----------------------------------------------------------------------
  81. struct PluginAudioPort {
  82. uint32_t rindex;
  83. CarlaEngineAudioPort* port;
  84. };
  85. struct PluginAudioData {
  86. uint32_t count;
  87. PluginAudioPort* ports;
  88. PluginAudioData() noexcept;
  89. ~PluginAudioData() noexcept;
  90. void createNew(const uint32_t newCount);
  91. void clear() noexcept;
  92. void initBuffers() const noexcept;
  93. CARLA_DECLARE_NON_COPY_STRUCT(PluginAudioData)
  94. };
  95. // -----------------------------------------------------------------------
  96. struct PluginCVPort {
  97. uint32_t rindex;
  98. uint32_t param;
  99. CarlaEngineCVPort* port;
  100. };
  101. struct PluginCVData {
  102. uint32_t count;
  103. PluginCVPort* ports;
  104. PluginCVData() noexcept;
  105. ~PluginCVData() noexcept;
  106. void createNew(const uint32_t newCount);
  107. void clear() noexcept;
  108. void initBuffers() const noexcept;
  109. CARLA_DECLARE_NON_COPY_STRUCT(PluginCVData)
  110. };
  111. // -----------------------------------------------------------------------
  112. struct PluginEventData {
  113. CarlaEngineEventPort* portIn;
  114. CarlaEngineEventPort* portOut;
  115. PluginEventData() noexcept;
  116. ~PluginEventData() noexcept;
  117. void clear() noexcept;
  118. void initBuffers() const noexcept;
  119. CARLA_DECLARE_NON_COPY_STRUCT(PluginEventData)
  120. };
  121. // -----------------------------------------------------------------------
  122. enum SpecialParameterType {
  123. PARAMETER_SPECIAL_NULL = 0,
  124. PARAMETER_SPECIAL_LATENCY = 1,
  125. PARAMETER_SPECIAL_SAMPLE_RATE = 2,
  126. PARAMETER_SPECIAL_LV2_FREEWHEEL = 3,
  127. PARAMETER_SPECIAL_LV2_TIME = 4
  128. };
  129. struct PluginParameterData {
  130. uint32_t count;
  131. ParameterData* data;
  132. ParameterRanges* ranges;
  133. SpecialParameterType* special;
  134. PluginParameterData() noexcept;
  135. ~PluginParameterData() noexcept;
  136. void createNew(const uint32_t newCount, const bool withSpecial);
  137. void clear() noexcept;
  138. float getFixedValue(const uint32_t parameterId, const float& value) const noexcept;
  139. CARLA_DECLARE_NON_COPY_STRUCT(PluginParameterData)
  140. };
  141. // -----------------------------------------------------------------------
  142. typedef const char* ProgramName;
  143. struct PluginProgramData {
  144. uint32_t count;
  145. int32_t current;
  146. ProgramName* names;
  147. PluginProgramData() noexcept;
  148. ~PluginProgramData() noexcept;
  149. void createNew(const uint32_t newCount);
  150. void clear() noexcept;
  151. CARLA_DECLARE_NON_COPY_STRUCT(PluginProgramData)
  152. };
  153. // -----------------------------------------------------------------------
  154. struct PluginMidiProgramData {
  155. uint32_t count;
  156. int32_t current;
  157. MidiProgramData* data;
  158. PluginMidiProgramData() noexcept;
  159. ~PluginMidiProgramData() noexcept;
  160. void createNew(const uint32_t newCount);
  161. void clear() noexcept;
  162. const MidiProgramData& getCurrent() const noexcept;
  163. CARLA_DECLARE_NON_COPY_STRUCT(PluginMidiProgramData)
  164. };
  165. // -----------------------------------------------------------------------
  166. struct CarlaPlugin::ProtectedData {
  167. CarlaEngine* const engine;
  168. CarlaEngineClient* client;
  169. uint id;
  170. uint hints;
  171. uint options;
  172. bool active;
  173. bool enabled;
  174. bool needsReset;
  175. void* lib;
  176. void* uiLib;
  177. // misc
  178. int8_t ctrlChannel;
  179. uint extraHints;
  180. uint transientTryCounter;
  181. // latency
  182. uint32_t latency;
  183. #ifndef BUILD_BRIDGE
  184. float** latencyBuffers;
  185. #endif
  186. // data 1
  187. const char* name;
  188. const char* filename;
  189. const char* iconName;
  190. #ifndef BUILD_BRIDGE
  191. const char* identifier; // used for save/restore settings per plugin
  192. #endif
  193. // data 2
  194. PluginAudioData audioIn;
  195. PluginAudioData audioOut;
  196. PluginEventData event;
  197. PluginParameterData param;
  198. PluginProgramData prog;
  199. PluginMidiProgramData midiprog;
  200. LinkedList<CustomData> custom;
  201. SaveState saveState;
  202. CarlaMutex masterMutex; // global master lock
  203. CarlaMutex singleMutex; // small lock used only in processSingle()
  204. struct ExternalNotes {
  205. CarlaMutex mutex;
  206. RtLinkedList<ExternalMidiNote>::Pool dataPool;
  207. RtLinkedList<ExternalMidiNote> data;
  208. ExternalNotes() noexcept;
  209. ~ExternalNotes() noexcept;
  210. void appendNonRT(const ExternalMidiNote& note) noexcept;
  211. CARLA_DECLARE_NON_COPY_STRUCT(ExternalNotes)
  212. } extNotes;
  213. struct PostRtEvents {
  214. CarlaMutex mutex;
  215. RtLinkedList<PluginPostRtEvent>::Pool dataPool;
  216. RtLinkedList<PluginPostRtEvent> data;
  217. RtLinkedList<PluginPostRtEvent> dataPendingRT;
  218. PostRtEvents() noexcept;
  219. ~PostRtEvents() noexcept;
  220. void appendRT(const PluginPostRtEvent& event) noexcept;
  221. void trySplice() noexcept;
  222. void clear() noexcept;
  223. CARLA_DECLARE_NON_COPY_STRUCT(PostRtEvents)
  224. } postRtEvents;
  225. #ifndef BUILD_BRIDGE
  226. struct PostProc {
  227. float dryWet;
  228. float volume;
  229. float balanceLeft;
  230. float balanceRight;
  231. float panning;
  232. PostProc() noexcept;
  233. CARLA_DECLARE_NON_COPY_STRUCT(PostProc)
  234. } postProc;
  235. #endif
  236. struct OSC {
  237. CarlaOscData data;
  238. CarlaPluginThread thread;
  239. OSC(CarlaEngine* const engine, CarlaPlugin* const plugin) noexcept;
  240. #ifdef CARLA_PROPER_CPP11_SUPPORT
  241. OSC() = delete;
  242. CARLA_DECLARE_NON_COPY_STRUCT(OSC)
  243. #endif
  244. } osc;
  245. ProtectedData(CarlaEngine* const engine, const uint idx, CarlaPlugin* const plugin) noexcept;
  246. ~ProtectedData() noexcept;
  247. // -------------------------------------------------------------------
  248. // Buffer functions
  249. void clearBuffers() noexcept;
  250. #ifndef BUILD_BRIDGE
  251. void recreateLatencyBuffers();
  252. #endif
  253. // -------------------------------------------------------------------
  254. // Post-poned events
  255. void postponeRtEvent(const PluginPostRtEvent& rtEvent) noexcept;
  256. void postponeRtEvent(const PluginPostRtEventType type, const int32_t value1, const int32_t value2, const float value3) noexcept;
  257. // -------------------------------------------------------------------
  258. // Library functions
  259. static const char* libError(const char* const filename) noexcept;
  260. bool libOpen(const char* const filename) noexcept;
  261. bool libClose() noexcept;
  262. void* libSymbol(const char* const symbol) const noexcept;
  263. bool uiLibOpen(const char* const filename, const bool canDelete) noexcept;
  264. bool uiLibClose() noexcept;
  265. void* uiLibSymbol(const char* const symbol) const noexcept;
  266. #ifndef BUILD_BRIDGE
  267. // -------------------------------------------------------------------
  268. // Settings functions
  269. void saveSetting(const uint option, const bool yesNo) const;
  270. uint loadSettings(const uint options, const uint availOptions) const;
  271. // -------------------------------------------------------------------
  272. // Misc
  273. void tryTransient() noexcept;
  274. #endif
  275. void updateParameterValues(CarlaPlugin* const plugin, const bool sendOsc, const bool sendCallback, const bool useDefault) noexcept;
  276. // -------------------------------------------------------------------
  277. #ifdef CARLA_PROPER_CPP11_SUPPORT
  278. ProtectedData() = delete;
  279. CARLA_DECLARE_NON_COPY_STRUCT(ProtectedData)
  280. #endif
  281. };
  282. CARLA_BACKEND_END_NAMESPACE
  283. #endif // CARLA_PLUGIN_INTERNAL_HPP_INCLUDED