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.

CarlaPluginInternal.hpp 9.8KB

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