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
9.9KB

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