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 "CarlaMIDI.h"
  24. #include "CarlaMutex.hpp"
  25. #include "RtLinkedList.hpp"
  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 port 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; // FIXME is this needed?
  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_FREEWHEEL = 1,
  126. PARAMETER_SPECIAL_LATENCY = 2,
  127. PARAMETER_SPECIAL_SAMPLE_RATE = 3,
  128. PARAMETER_SPECIAL_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. CarlaMutex masterMutex; // global master lock
  203. CarlaMutex singleMutex; // small lock used only in processSingle()
  204. StateSave stateSave;
  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. void clear() noexcept;
  213. CARLA_DECLARE_NON_COPY_STRUCT(ExternalNotes)
  214. } extNotes;
  215. struct PostRtEvents {
  216. CarlaMutex mutex;
  217. RtLinkedList<PluginPostRtEvent>::Pool dataPool;
  218. RtLinkedList<PluginPostRtEvent> data;
  219. RtLinkedList<PluginPostRtEvent> dataPendingRT;
  220. PostRtEvents() noexcept;
  221. ~PostRtEvents() noexcept;
  222. void appendRT(const PluginPostRtEvent& event) noexcept;
  223. void trySplice() noexcept;
  224. void clear() noexcept;
  225. CARLA_DECLARE_NON_COPY_STRUCT(PostRtEvents)
  226. } postRtEvents;
  227. #ifndef BUILD_BRIDGE
  228. struct PostProc {
  229. float dryWet;
  230. float volume;
  231. float balanceLeft;
  232. float balanceRight;
  233. float panning;
  234. PostProc() noexcept;
  235. CARLA_DECLARE_NON_COPY_STRUCT(PostProc)
  236. } postProc;
  237. #endif
  238. struct OSC {
  239. CarlaOscData data;
  240. CarlaPluginThread thread;
  241. OSC(CarlaEngine* const engine, CarlaPlugin* const plugin) noexcept;
  242. #ifdef CARLA_PROPER_CPP11_SUPPORT
  243. OSC() = delete;
  244. CARLA_DECLARE_NON_COPY_STRUCT(OSC)
  245. #endif
  246. } osc;
  247. ProtectedData(CarlaEngine* const engine, const uint idx, CarlaPlugin* const plugin) noexcept;
  248. ~ProtectedData() noexcept;
  249. // -------------------------------------------------------------------
  250. // Buffer functions
  251. void clearBuffers() noexcept;
  252. #ifndef BUILD_BRIDGE
  253. void recreateLatencyBuffers();
  254. #endif
  255. // -------------------------------------------------------------------
  256. // Post-poned events
  257. void postponeRtEvent(const PluginPostRtEvent& rtEvent) noexcept;
  258. void postponeRtEvent(const PluginPostRtEventType type, const int32_t value1, const int32_t value2, const float value3) noexcept;
  259. // -------------------------------------------------------------------
  260. // Library functions
  261. static const char* libError(const char* const filename) noexcept;
  262. bool libOpen(const char* const filename) noexcept;
  263. bool libClose() noexcept;
  264. void* libSymbol(const char* const symbol) const noexcept;
  265. bool uiLibOpen(const char* const filename, const bool canDelete) noexcept;
  266. bool uiLibClose() noexcept;
  267. void* uiLibSymbol(const char* const symbol) const noexcept;
  268. #ifndef BUILD_BRIDGE
  269. // -------------------------------------------------------------------
  270. // Settings functions
  271. void saveSetting(const uint option, const bool yesNo) const;
  272. uint loadSettings(const uint options, const uint availOptions) const;
  273. // -------------------------------------------------------------------
  274. // Misc
  275. void tryTransient() noexcept;
  276. #endif
  277. void updateParameterValues(CarlaPlugin* const plugin, const bool sendOsc, const bool sendCallback, const bool useDefault) noexcept;
  278. // -------------------------------------------------------------------
  279. #ifdef CARLA_PROPER_CPP11_SUPPORT
  280. ProtectedData() = delete;
  281. CARLA_DECLARE_NON_COPY_STRUCT(ProtectedData)
  282. #endif
  283. };
  284. CARLA_BACKEND_END_NAMESPACE
  285. #endif // CARLA_PLUGIN_INTERNAL_HPP_INCLUDED