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.

433 lines
14KB

  1. /*
  2. * DISTRHO Cardinal Plugin
  3. * Copyright (C) 2021-2022 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 3 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 LICENSE file.
  16. */
  17. #include "rack.hpp"
  18. #include "plugin.hpp"
  19. #include "DistrhoUtils.hpp"
  20. // Cardinal (built-in)
  21. #include "Cardinal/src/plugin.hpp"
  22. // Fundamental
  23. #include "Fundamental/src/plugin.hpp"
  24. // AudibleInstruments
  25. #include "AudibleInstruments/src/plugin.hpp"
  26. // BogaudioModules - integrate theme/skin support
  27. #include <mutex>
  28. #include <string>
  29. #include <unordered_map>
  30. #include <unordered_set>
  31. #include <vector>
  32. #define private public
  33. #include "BogaudioModules/src/skins.hpp"
  34. #undef private
  35. // BogaudioModules
  36. extern Model* modelBogaudioLFO;
  37. extern Model* modelBogaudioNoise;
  38. extern Model* modelBogaudioVCA;
  39. extern Model* modelBogaudioVCF;
  40. extern Model* modelBogaudioVCO;
  41. // known terminal modules
  42. std::vector<Model*> hostTerminalModels;
  43. // plugin instances
  44. Plugin* pluginInstance__Cardinal;
  45. Plugin* pluginInstance__Fundamental;
  46. Plugin* pluginInstance__AudibleInstruments;
  47. Plugin* pluginInstance__BogaudioModules;
  48. namespace rack {
  49. namespace asset {
  50. std::string pluginManifest(const std::string& dirname);
  51. std::string pluginPath(const std::string& dirname);
  52. }
  53. namespace plugin {
  54. struct StaticPluginLoader {
  55. Plugin* const plugin;
  56. FILE* file;
  57. json_t* rootJ;
  58. StaticPluginLoader(Plugin* const p, const char* const name)
  59. : plugin(p),
  60. file(nullptr),
  61. rootJ(nullptr)
  62. {
  63. #ifdef DEBUG
  64. DEBUG("Loading plugin module %s", name);
  65. #endif
  66. p->path = asset::pluginPath(name);
  67. const std::string manifestFilename = asset::pluginManifest(name);
  68. if ((file = std::fopen(manifestFilename.c_str(), "r")) == nullptr)
  69. {
  70. d_stderr2("Manifest file %s does not exist", manifestFilename.c_str());
  71. return;
  72. }
  73. json_error_t error;
  74. if ((rootJ = json_loadf(file, 0, &error)) == nullptr)
  75. {
  76. d_stderr2("JSON parsing error at %s %d:%d %s", manifestFilename.c_str(), error.line, error.column, error.text);
  77. return;
  78. }
  79. // force ABI, we use static plugins so this doesnt matter as long as it builds
  80. json_t* const version = json_string((APP_VERSION_MAJOR + ".0").c_str());
  81. json_object_set(rootJ, "version", version);
  82. json_decref(version);
  83. // Load manifest
  84. p->fromJson(rootJ);
  85. // Reject plugin if slug already exists
  86. if (Plugin* const existingPlugin = getPlugin(p->slug))
  87. throw Exception("Plugin %s is already loaded, not attempting to load it again", p->slug.c_str());
  88. }
  89. ~StaticPluginLoader()
  90. {
  91. if (rootJ != nullptr)
  92. {
  93. // Load modules manifest
  94. json_t* const modulesJ = json_object_get(rootJ, "modules");
  95. plugin->modulesFromJson(modulesJ);
  96. json_decref(rootJ);
  97. plugins.push_back(plugin);
  98. }
  99. if (file != nullptr)
  100. std::fclose(file);
  101. }
  102. bool ok() const noexcept
  103. {
  104. return rootJ != nullptr;
  105. }
  106. void removeModule(const char* const slugToRemove) const noexcept
  107. {
  108. json_t* const modules = json_object_get(rootJ, "modules");
  109. DISTRHO_SAFE_ASSERT_RETURN(modules != nullptr,);
  110. size_t i;
  111. json_t* v;
  112. json_array_foreach(modules, i, v)
  113. {
  114. if (json_t* const slug = json_object_get(v, "slug"))
  115. {
  116. if (const char* const value = json_string_value(slug))
  117. {
  118. if (std::strcmp(value, slugToRemove) == 0)
  119. {
  120. json_array_remove(modules, i);
  121. break;
  122. }
  123. }
  124. }
  125. }
  126. }
  127. };
  128. static void initStatic__Cardinal()
  129. {
  130. Plugin* const p = new Plugin;
  131. pluginInstance__Cardinal = p;
  132. const StaticPluginLoader spl(p, "Cardinal");
  133. if (spl.ok())
  134. {
  135. p->addModel(modelHostAudio2);
  136. p->addModel(modelHostCV);
  137. p->addModel(modelHostMIDI);
  138. p->addModel(modelHostMIDICC);
  139. p->addModel(modelHostMIDIGate);
  140. p->addModel(modelHostMIDIMap);
  141. p->addModel(modelHostParameters);
  142. p->addModel(modelHostParametersMap);
  143. p->addModel(modelHostTime);
  144. p->addModel(modelTextEditor);
  145. #ifdef HAVE_FFTW3F
  146. p->addModel(modelAudioToCVPitch);
  147. #else
  148. spl.removeModule("AudioToCVPitch");
  149. #endif
  150. spl.removeModule("AudioFile");
  151. spl.removeModule("Blank");
  152. spl.removeModule("Carla");
  153. spl.removeModule("ExpanderInputMIDI");
  154. spl.removeModule("ExpanderOutputMIDI");
  155. spl.removeModule("HostAudio8");
  156. spl.removeModule("Ildaeil");
  157. spl.removeModule("MPV");
  158. spl.removeModule("SassyScope");
  159. spl.removeModule("glBars");
  160. hostTerminalModels = {
  161. modelHostAudio2,
  162. modelHostCV,
  163. modelHostMIDI,
  164. modelHostMIDICC,
  165. modelHostMIDIGate,
  166. modelHostMIDIMap,
  167. modelHostParameters,
  168. modelHostParametersMap,
  169. modelHostTime,
  170. };
  171. }
  172. }
  173. static void initStatic__Fundamental()
  174. {
  175. Plugin* const p = new Plugin;
  176. pluginInstance__Fundamental = p;
  177. const StaticPluginLoader spl(p, "Fundamental");
  178. if (spl.ok())
  179. {
  180. p->addModel(modelLFO);
  181. p->addModel(modelNoise);
  182. p->addModel(modelRandom);
  183. p->addModel(modelVCF);
  184. p->addModel(modelVCMixer);
  185. spl.removeModule("8vert");
  186. spl.removeModule("ADSR");
  187. spl.removeModule("Delay");
  188. spl.removeModule("LFO2");
  189. spl.removeModule("Merge");
  190. spl.removeModule("MidSide");
  191. spl.removeModule("Mixer");
  192. spl.removeModule("Mutes");
  193. spl.removeModule("Octave");
  194. spl.removeModule("Pulses");
  195. spl.removeModule("Quantizer");
  196. spl.removeModule("SEQ3");
  197. spl.removeModule("Scope");
  198. spl.removeModule("SequentialSwitch1");
  199. spl.removeModule("SequentialSwitch2");
  200. spl.removeModule("Split");
  201. spl.removeModule("Sum");
  202. spl.removeModule("VCA");
  203. spl.removeModule("VCA-1");
  204. spl.removeModule("VCO");
  205. spl.removeModule("VCO2");
  206. }
  207. }
  208. static void initStatic__AudibleInstruments()
  209. {
  210. Plugin* const p = new Plugin;
  211. pluginInstance__AudibleInstruments = p;
  212. const StaticPluginLoader spl(p, "AudibleInstruments");
  213. if (spl.ok())
  214. {
  215. p->addModel(modelPlaits);
  216. spl.removeModule("Blinds");
  217. spl.removeModule("Braids");
  218. spl.removeModule("Branches");
  219. spl.removeModule("Clouds");
  220. spl.removeModule("Elements");
  221. spl.removeModule("Frames");
  222. spl.removeModule("Kinks");
  223. spl.removeModule("Links");
  224. spl.removeModule("Marbles");
  225. spl.removeModule("Rings");
  226. spl.removeModule("Ripples");
  227. spl.removeModule("Shades");
  228. spl.removeModule("Shelves");
  229. spl.removeModule("Stages");
  230. spl.removeModule("Streams");
  231. spl.removeModule("Tides");
  232. spl.removeModule("Tides2");
  233. spl.removeModule("Veils");
  234. spl.removeModule("Warps");
  235. }
  236. }
  237. static void initStatic__BogaudioModules()
  238. {
  239. Plugin* const p = new Plugin;
  240. pluginInstance__BogaudioModules = p;
  241. const StaticPluginLoader spl(p, "BogaudioModules");
  242. if (spl.ok())
  243. {
  244. // Make sure to use match Cardinal theme
  245. Skins& skins(Skins::skins());
  246. skins._default = settings::darkMode ? "dark" : "light";
  247. p->addModel(modelBogaudioLFO);
  248. p->addModel(modelBogaudioNoise);
  249. p->addModel(modelBogaudioVCA);
  250. p->addModel(modelBogaudioVCF);
  251. p->addModel(modelBogaudioVCO);
  252. // cat plugins/BogaudioModules/plugin.json | jq -r .modules[].slug - | sort
  253. spl.removeModule("Bogaudio-AD");
  254. spl.removeModule("Bogaudio-Additator");
  255. spl.removeModule("Bogaudio-AddrSeq");
  256. spl.removeModule("Bogaudio-AddrSeqX");
  257. spl.removeModule("Bogaudio-ADSR");
  258. spl.removeModule("Bogaudio-AMRM");
  259. spl.removeModule("Bogaudio-Analyzer");
  260. spl.removeModule("Bogaudio-AnalyzerXL");
  261. spl.removeModule("Bogaudio-Arp");
  262. spl.removeModule("Bogaudio-ASR");
  263. spl.removeModule("Bogaudio-Assign");
  264. spl.removeModule("Bogaudio-Blank3");
  265. spl.removeModule("Bogaudio-Blank6");
  266. spl.removeModule("Bogaudio-Bool");
  267. spl.removeModule("Bogaudio-Chirp");
  268. spl.removeModule("Bogaudio-Clpr");
  269. spl.removeModule("Bogaudio-Cmp");
  270. spl.removeModule("Bogaudio-CmpDist");
  271. spl.removeModule("Bogaudio-CVD");
  272. spl.removeModule("Bogaudio-DADSRH");
  273. spl.removeModule("Bogaudio-DADSRHPlus");
  274. spl.removeModule("Bogaudio-Detune");
  275. spl.removeModule("Bogaudio-DGate");
  276. spl.removeModule("Bogaudio-Edge");
  277. spl.removeModule("Bogaudio-EightFO");
  278. spl.removeModule("Bogaudio-EightOne");
  279. spl.removeModule("Bogaudio-EQ");
  280. spl.removeModule("Bogaudio-EQS");
  281. spl.removeModule("Bogaudio-FFB");
  282. spl.removeModule("Bogaudio-FlipFlop");
  283. spl.removeModule("Bogaudio-FMOp");
  284. spl.removeModule("Bogaudio-Follow");
  285. spl.removeModule("Bogaudio-FourFO");
  286. spl.removeModule("Bogaudio-FourMan");
  287. spl.removeModule("Bogaudio-Inv");
  288. spl.removeModule("Bogaudio-Lgsw");
  289. spl.removeModule("Bogaudio-LLFO");
  290. spl.removeModule("Bogaudio-LLPG");
  291. spl.removeModule("Bogaudio-Lmtr");
  292. spl.removeModule("Bogaudio-LPG");
  293. spl.removeModule("Bogaudio-LVCF");
  294. spl.removeModule("Bogaudio-LVCO");
  295. spl.removeModule("Bogaudio-Manual");
  296. spl.removeModule("Bogaudio-Matrix18");
  297. spl.removeModule("Bogaudio-Matrix44");
  298. spl.removeModule("Bogaudio-Matrix44Cvm");
  299. spl.removeModule("Bogaudio-Matrix81");
  300. spl.removeModule("Bogaudio-Matrix88");
  301. spl.removeModule("Bogaudio-Matrix88Cv");
  302. spl.removeModule("Bogaudio-Matrix88M");
  303. spl.removeModule("Bogaudio-MegaGate");
  304. spl.removeModule("Bogaudio-Mix1");
  305. spl.removeModule("Bogaudio-Mix2");
  306. spl.removeModule("Bogaudio-Mix4");
  307. spl.removeModule("Bogaudio-Mix4x");
  308. spl.removeModule("Bogaudio-Mix8");
  309. spl.removeModule("Bogaudio-Mix8x");
  310. spl.removeModule("Bogaudio-Mono");
  311. spl.removeModule("Bogaudio-Mult");
  312. spl.removeModule("Bogaudio-Mumix");
  313. spl.removeModule("Bogaudio-Mute8");
  314. spl.removeModule("Bogaudio-Nsgt");
  315. spl.removeModule("Bogaudio-Offset");
  316. spl.removeModule("Bogaudio-OneEight");
  317. spl.removeModule("Bogaudio-Pan");
  318. spl.removeModule("Bogaudio-PEQ");
  319. spl.removeModule("Bogaudio-PEQ14");
  320. spl.removeModule("Bogaudio-PEQ14XF");
  321. spl.removeModule("Bogaudio-PEQ6");
  322. spl.removeModule("Bogaudio-PEQ6XF");
  323. spl.removeModule("Bogaudio-Pgmr");
  324. spl.removeModule("Bogaudio-PgmrX");
  325. spl.removeModule("Bogaudio-PolyCon");
  326. spl.removeModule("Bogaudio-PolyCon8");
  327. spl.removeModule("Bogaudio-PolyMult");
  328. spl.removeModule("Bogaudio-PolyOff16");
  329. spl.removeModule("Bogaudio-PolyOff8");
  330. spl.removeModule("Bogaudio-Pressor");
  331. spl.removeModule("Bogaudio-Pulse");
  332. spl.removeModule("Bogaudio-Ranalyzer");
  333. spl.removeModule("Bogaudio-Reftone");
  334. spl.removeModule("Bogaudio-RGate");
  335. spl.removeModule("Bogaudio-SampleHold");
  336. spl.removeModule("Bogaudio-Shaper");
  337. spl.removeModule("Bogaudio-ShaperPlus");
  338. spl.removeModule("Bogaudio-Sine");
  339. spl.removeModule("Bogaudio-Slew");
  340. spl.removeModule("Bogaudio-Stack");
  341. spl.removeModule("Bogaudio-Sums");
  342. spl.removeModule("Bogaudio-Switch");
  343. spl.removeModule("Bogaudio-Switch1616");
  344. spl.removeModule("Bogaudio-Switch18");
  345. spl.removeModule("Bogaudio-Switch44");
  346. spl.removeModule("Bogaudio-Switch81");
  347. spl.removeModule("Bogaudio-Switch88");
  348. spl.removeModule("Bogaudio-UMix");
  349. spl.removeModule("Bogaudio-Unison");
  350. spl.removeModule("Bogaudio-VCAmp");
  351. spl.removeModule("Bogaudio-VCM");
  352. spl.removeModule("Bogaudio-Velo");
  353. spl.removeModule("Bogaudio-Vish");
  354. spl.removeModule("Bogaudio-VU");
  355. spl.removeModule("Bogaudio-Walk");
  356. spl.removeModule("Bogaudio-Walk2");
  357. spl.removeModule("Bogaudio-XCO");
  358. spl.removeModule("Bogaudio-XFade");
  359. }
  360. }
  361. void initStaticPlugins()
  362. {
  363. initStatic__Cardinal();
  364. initStatic__Fundamental();
  365. initStatic__AudibleInstruments();
  366. initStatic__BogaudioModules();
  367. }
  368. void destroyStaticPlugins()
  369. {
  370. for (Plugin* p : plugins)
  371. delete p;
  372. plugins.clear();
  373. }
  374. void updateStaticPluginsDarkMode()
  375. {
  376. const bool darkMode = settings::darkMode;
  377. // bogaudio
  378. {
  379. Skins& skins(Skins::skins());
  380. skins._default = darkMode ? "dark" : "light";
  381. std::lock_guard<std::mutex> lock(skins._defaultSkinListenersLock);
  382. for (auto listener : skins._defaultSkinListeners) {
  383. listener->defaultSkinChanged(skins._default);
  384. }
  385. }
  386. }
  387. }
  388. }