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.

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