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
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
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
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
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
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
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
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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  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. class CarlaEngineClient;
  39. // -----------------------------------------------------------------------
  40. // Maximum pre-allocated events for some plugin types
  41. const unsigned short kPluginMaxMidiEvents = 512;
  42. // -----------------------------------------------------------------------
  43. // Extra plugin hints, hidden from backend
  44. const unsigned int PLUGIN_EXTRA_HINT_HAS_MIDI_IN = 0x01;
  45. const unsigned int PLUGIN_EXTRA_HINT_HAS_MIDI_OUT = 0x02;
  46. const unsigned int PLUGIN_EXTRA_HINT_CAN_RUN_RACK = 0x04;
  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,
  57. kPluginPostRtEventDebug,
  58. kPluginPostRtEventParameterChange, // param, SP (*), value (SP: if 1, don't report change 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. PluginAudioPort() noexcept;
  85. ~PluginAudioPort();
  86. CARLA_DECLARE_NON_COPY_STRUCT(PluginAudioPort)
  87. };
  88. struct PluginAudioData {
  89. uint32_t count;
  90. PluginAudioPort* ports;
  91. PluginAudioData() noexcept;
  92. ~PluginAudioData();
  93. void createNew(const uint32_t newCount);
  94. void clear();
  95. void initBuffers();
  96. CARLA_DECLARE_NON_COPY_STRUCT(PluginAudioData)
  97. };
  98. // -----------------------------------------------------------------------
  99. struct PluginCVPort {
  100. uint32_t rindex;
  101. uint32_t param;
  102. CarlaEngineCVPort* port;
  103. PluginCVPort() noexcept;
  104. ~PluginCVPort();
  105. CARLA_DECLARE_NON_COPY_STRUCT(PluginCVPort)
  106. };
  107. struct PluginCVData {
  108. uint32_t count;
  109. PluginCVPort* ports;
  110. PluginCVData() noexcept;
  111. ~PluginCVData();
  112. void createNew(const uint32_t newCount);
  113. void clear();
  114. void initBuffers();
  115. CARLA_DECLARE_NON_COPY_STRUCT(PluginCVData)
  116. };
  117. // -----------------------------------------------------------------------
  118. struct PluginEventData {
  119. CarlaEngineEventPort* portIn;
  120. CarlaEngineEventPort* portOut;
  121. PluginEventData() noexcept;
  122. ~PluginEventData();
  123. void clear();
  124. void initBuffers();
  125. CARLA_DECLARE_NON_COPY_STRUCT(PluginEventData)
  126. };
  127. // -----------------------------------------------------------------------
  128. enum SpecialParameterType {
  129. PARAMETER_SPECIAL_NULL = 0,
  130. PARAMETER_SPECIAL_LATENCY = 1,
  131. PARAMETER_SPECIAL_SAMPLE_RATE = 2,
  132. PARAMETER_SPECIAL_LV2_FREEWHEEL = 3,
  133. PARAMETER_SPECIAL_LV2_TIME = 4
  134. };
  135. struct PluginParameterData {
  136. uint32_t count;
  137. ParameterData* data;
  138. ParameterRanges* ranges;
  139. SpecialParameterType* special;
  140. PluginParameterData() noexcept;
  141. ~PluginParameterData();
  142. void createNew(const uint32_t newCount, const bool withSpecial);
  143. void clear();
  144. float getFixedValue(const uint32_t parameterId, const float& value) const;
  145. CARLA_DECLARE_NON_COPY_STRUCT(PluginParameterData)
  146. };
  147. // -----------------------------------------------------------------------
  148. typedef const char* ProgramName;
  149. struct PluginProgramData {
  150. uint32_t count;
  151. int32_t current;
  152. ProgramName* names;
  153. PluginProgramData() noexcept;
  154. ~PluginProgramData();
  155. void createNew(const uint32_t newCount);
  156. void clear();
  157. CARLA_DECLARE_NON_COPY_STRUCT(PluginProgramData)
  158. };
  159. // -----------------------------------------------------------------------
  160. struct PluginMidiProgramData {
  161. uint32_t count;
  162. int32_t current;
  163. MidiProgramData* data;
  164. PluginMidiProgramData() noexcept;
  165. ~PluginMidiProgramData();
  166. void createNew(const uint32_t newCount);
  167. void clear();
  168. const MidiProgramData& getCurrent() const noexcept;
  169. CARLA_DECLARE_NON_COPY_STRUCT(PluginMidiProgramData)
  170. };
  171. // -----------------------------------------------------------------------
  172. struct CarlaPluginProtectedData {
  173. CarlaEngine* const engine;
  174. CarlaEngineClient* client;
  175. unsigned int id;
  176. unsigned int hints;
  177. unsigned int options;
  178. bool active;
  179. bool enabled;
  180. bool needsReset;
  181. void* lib;
  182. void* uiLib;
  183. // misc
  184. int8_t ctrlChannel;
  185. uint extraHints;
  186. uint transientTryCounter;
  187. // latency
  188. uint32_t latency;
  189. float** latencyBuffers;
  190. // data 1
  191. const char* name;
  192. const char* filename;
  193. const char* iconName;
  194. const char* identifier; // used for save/restore settings per plugin
  195. // data 2
  196. PluginAudioData audioIn;
  197. PluginAudioData audioOut;
  198. PluginEventData event;
  199. PluginParameterData param;
  200. PluginProgramData prog;
  201. PluginMidiProgramData midiprog;
  202. LinkedList<CustomData> custom;
  203. SaveState saveState;
  204. CarlaMutex masterMutex; // global master lock
  205. CarlaMutex singleMutex; // small lock used only in processSingle()
  206. struct ExternalNotes {
  207. CarlaMutex mutex;
  208. RtLinkedList<ExternalMidiNote>::Pool dataPool;
  209. RtLinkedList<ExternalMidiNote> data;
  210. ExternalNotes();
  211. ~ExternalNotes();
  212. void append(const ExternalMidiNote& note);
  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();
  221. ~PostRtEvents();
  222. void appendRT(const PluginPostRtEvent& event);
  223. void trySplice();
  224. void clear();
  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);
  242. #ifdef CARLA_PROPER_CPP11_SUPPORT
  243. OSC() = delete;
  244. CARLA_DECLARE_NON_COPY_STRUCT(OSC)
  245. #endif
  246. } osc;
  247. CarlaPluginProtectedData(CarlaEngine* const eng, const unsigned int idx, CarlaPlugin* const self);
  248. ~CarlaPluginProtectedData();
  249. // -------------------------------------------------------------------
  250. // Buffer functions
  251. void clearBuffers();
  252. void recreateLatencyBuffers();
  253. // -------------------------------------------------------------------
  254. // Post-poned events
  255. void postponeRtEvent(const PluginPostRtEventType type, const int32_t value1, const int32_t value2, const float value3);
  256. // -------------------------------------------------------------------
  257. // Library functions
  258. const char* libError(const char* const filename);
  259. bool libOpen(const char* const filename);
  260. bool libClose();
  261. void* libSymbol(const char* const symbol);
  262. bool uiLibOpen(const char* const filename);
  263. bool uiLibClose();
  264. void* uiLibSymbol(const char* const symbol);
  265. // -------------------------------------------------------------------
  266. // Settings functions
  267. void saveSetting(const uint option, const bool yesNo);
  268. uint loadSettings(const uint options, const uint availOptions);
  269. // -------------------------------------------------------------------
  270. // Misc
  271. void tryTransient();
  272. // -------------------------------------------------------------------
  273. #ifdef CARLA_PROPER_CPP11_SUPPORT
  274. CarlaPluginProtectedData() = delete;
  275. CARLA_DECLARE_NON_COPY_STRUCT(CarlaPluginProtectedData)
  276. #endif
  277. };
  278. CARLA_BACKEND_END_NAMESPACE
  279. #endif // CARLA_PLUGIN_INTERNAL_HPP_INCLUDED