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.

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