PluginExport180bTests.inc 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. // --- Round 180b: LYNX's own plugins as VST3 / CLAP ---------------------------------------------------------------------
  2. // The plugin runs the app's renderer on a one-slot song: its input enters the insert through the metronome input, and
  3. // the host's parameters reach the slot without a rebuild. That path must sound like the effect run alone.
  4. #include <regex>
  5. #include "core/NativeEngines.h"
  6. #include "core/UpdateCheck.h"
  7. #include "core/LynxBanks.h"
  8. #include "core/ModelParams.h"
  9. #include "plugin/ExportCatalog.h"
  10. namespace
  11. {
  12. lynx::Song pluginExportSong (lynx::EffectKind kind)
  13. {
  14. auto song = lynx::Song::makeDefault();
  15. song.channels.clear();
  16. song.mixer.resize (2);
  17. song.mixer[0].effects.clear();
  18. auto slot = lynx::makeEffectSlot (kind);
  19. slot.smartDisable = false;
  20. slot.sidechain = 2; // round 188b: as the plugin's song (plugin/ExportProcessor.cpp): the host's side-chain bus track
  21. song.mixer[1].effects = { slot };
  22. song.mixer.resize (3);
  23. song.mixer[2].effects.clear();
  24. song.mixer[2].toMaster = false;
  25. return song;
  26. }
  27. void pluginExportInput (std::vector<float>& l, std::vector<float>& r, int block)
  28. {
  29. for (std::size_t i = 0; i < l.size(); ++i)
  30. {
  31. l[i] = 0.3f * std::sin (0.031f * (float) (block * (int) l.size() + (int) i));
  32. r[i] = 0.5f * l[i];
  33. }
  34. }
  35. } // namespace
  36. TEST (pluginexport180b_rack_path_equals_the_effect_alone)
  37. {
  38. constexpr double rate = 48000.0;
  39. constexpr int size = 256;
  40. // round 188b: every exported effect (the catalog), plus the generic utility
  41. std::vector<lynx::EffectKind> kinds { lynx::EffectKind::utility };
  42. for (const auto& e : lynx::plugexport::catalog)
  43. if (! e.instrument)
  44. kinds.push_back (e.effect);
  45. for (const auto kind : kinds)
  46. {
  47. const auto song = pluginExportSong (kind);
  48. auto state = lynx::RackState::build (song, nullptr, rate);
  49. auto renderer = std::make_unique<lynx::RackRenderer>();
  50. renderer->prepare (rate, size);
  51. auto direct = lynx::makeEffect (kind);
  52. direct->prepare (rate);
  53. const auto params = song.mixer[1].effects[0].params;
  54. std::vector<float> inL (size), inR (size), outL (size), outR (size), l (size), r (size);
  55. auto worst = 0.0f;
  56. for (int b = 0; b < 100; ++b)
  57. {
  58. pluginExportInput (inL, inR, b);
  59. l = inL;
  60. r = inR;
  61. direct->setSongPosition (0.0);
  62. direct->setPlaying (false);
  63. direct->process (l.data(), r.data(), size, params, 120.0);
  64. renderer->setMetronomeInput (inL.data(), inR.data(), 1);
  65. renderer->setSlotParamsOverride (&params, 1, 0);
  66. renderer->process (state.get(), false, 0.0, size, outL.data(), outR.data());
  67. for (int i = 0; i < size; ++i)
  68. worst = std::max ({ worst, std::abs (outL[(std::size_t) i] - l[(std::size_t) i]), std::abs (outR[(std::size_t) i] - r[(std::size_t) i]) });
  69. }
  70. CHECK (worst < 1.0e-5f);
  71. }
  72. }
  73. TEST (pluginexport180b_host_parameters_reach_the_slot_without_a_rebuild)
  74. {
  75. constexpr double rate = 48000.0;
  76. constexpr int size = 256;
  77. const auto song = pluginExportSong (lynx::EffectKind::utility);
  78. auto state = lynx::RackState::build (song, nullptr, rate);
  79. auto renderer = std::make_unique<lynx::RackRenderer>();
  80. renderer->prepare (rate, size);
  81. auto params = song.mixer[1].effects[0].params;
  82. const auto& info = lynx::effectInfo (lynx::EffectKind::utility);
  83. CHECK (! info.params.empty());
  84. std::vector<float> inL (size), inR (size), outL (size), outR (size);
  85. const auto energy = [&] {
  86. auto sum = 0.0f;
  87. for (int b = 0; b < 8; ++b)
  88. {
  89. pluginExportInput (inL, inR, b);
  90. renderer->setMetronomeInput (inL.data(), inR.data(), 1);
  91. renderer->setSlotParamsOverride (&params, 1, 0);
  92. renderer->process (state.get(), false, 0.0, size, outL.data(), outR.data());
  93. }
  94. for (auto v : outL)
  95. sum += v * v;
  96. return sum;
  97. };
  98. const auto before = energy();
  99. params[0] = params[0] < 0.5f ? 1.0f : 0.0f;
  100. CHECK (energy() != before);
  101. }
  102. TEST (pluginexport180b_catalog_needs_no_fl_data)
  103. {
  104. // every exported engine starts from LYNX's own state, on a PC without FL Studio
  105. for (const auto& e : lynx::plugexport::catalog)
  106. {
  107. if (e.instrument)
  108. {
  109. const auto* engine = lynx::natives::instrumentEngine (e.synth);
  110. CHECK (engine != nullptr && engine->needs == lynx::natives::Needs::nothing);
  111. // (a bank's first preset; Tetra and Braid have no bank and start from their engine's defaults: rollup 0.1.31 step 6)
  112. const auto channel = lynx::plugexport::instrumentChannel (e);
  113. CHECK (channel.instrument == e.synth && lynx::banks::defaultChannel (e.synth, e.name).has_value() == lynx::banks::hasBank (e.synth));
  114. CHECK (lynx::modelparams::tableOf (e.synth) != nullptr);
  115. }
  116. else
  117. {
  118. const auto* engine = lynx::natives::effectEngine (e.effect);
  119. CHECK (engine == nullptr || engine->needs == lynx::natives::Needs::nothing);
  120. }
  121. }
  122. }
  123. TEST (pluginexport180b_static_image_caches_are_registered)
  124. {
  125. // A static juce::Image (or a cache of them) must register in ui/ImageCaches.h, so a plugin empties it before the host
  126. // unloads the DLL: freed at unload, its Direct2D device deadlocked FL Studio's exit (round 180b, dump of 09:35).
  127. // A lint over src/ (the tests run from the repository root): the declaration, then registerImageCache within 2 lines.
  128. namespace fs = std::filesystem;
  129. CHECK (fs::is_directory ("src/ui"));
  130. if (! fs::is_directory ("src/ui"))
  131. return;
  132. const std::regex declaration (R"(^\s*(?:inline\s+|thread_local\s+)*static\s+(?:inline\s+|thread_local\s+)*(?:const\s+)?[^;=(]*(?:juce::Image\b|juce::Drawable\b|SpriteCache\b)[^;=(]*(?:;|=|\{))");
  133. int found = 0;
  134. for (const auto& entry : fs::recursive_directory_iterator ("src"))
  135. {
  136. const auto ext = entry.path().extension().string();
  137. if (! entry.is_regular_file() || (ext != ".cpp" && ext != ".h" && ext != ".inc" && ext != ".mm"))
  138. continue;
  139. std::ifstream in (entry.path());
  140. std::vector<std::string> lines;
  141. for (std::string line; std::getline (in, line);)
  142. lines.push_back (line);
  143. for (std::size_t i = 0; i < lines.size(); ++i)
  144. if (std::regex_search (lines[i], declaration))
  145. {
  146. ++found;
  147. bool registered = false;
  148. for (std::size_t k = i; k < std::min (lines.size(), i + 3); ++k)
  149. registered = registered || lines[k].find ("registerImageCache") != std::string::npos;
  150. if (! registered)
  151. std::printf (" unregistered static image: %s:%zu\n", entry.path().string().c_str(), i + 1);
  152. CHECK (registered);
  153. }
  154. }
  155. CHECK (found >= 8); // (the lint still sees the caches it was written for)
  156. }
  157. // --- Round 188b: every LYNX effect in the CLAP, a short list as VST3, a separate optional download -----------------------
  158. TEST (pluginexport188b_catalog_identities_are_unique_and_lynx_named)
  159. {
  160. std::set<std::string> names, ids;
  161. std::set<lynx::EffectKind> effects;
  162. auto instruments = 0;
  163. for (const auto& e : lynx::plugexport::catalog)
  164. {
  165. const std::string name = e.name, id = e.clapId;
  166. CHECK (names.insert (name).second);
  167. CHECK (ids.insert (id).second);
  168. CHECK (name.rfind ("LYNX ", 0) == 0);
  169. CHECK (id.rfind ("com.ka1-s.lynx.", 0) == 0);
  170. // LYNX names only (the user, 2026-11-08): never an FL Studio name
  171. for (const char* banned : { "Fruity", "FL ", "Image-Line", "Gross Beat", "Maximus", "Sytrus", "Harmor" })
  172. CHECK (name.find (banned) == std::string::npos);
  173. if (e.instrument)
  174. ++instruments;
  175. else
  176. CHECK (effects.insert (e.effect).second);
  177. }
  178. // every LYNX-named effect is in the CLAP (option C)
  179. for (const auto kind : { lynx::EffectKind::facetEq, lynx::EffectKind::apexLimiter, lynx::EffectKind::ridgeStrip, lynx::EffectKind::glowLeveler,
  180. lynx::EffectKind::hushDeEsser, lynx::EffectKind::aether, lynx::EffectKind::ember, lynx::EffectKind::lynxTune,
  181. lynx::EffectKind::epochVerb, lynx::EffectKind::atrium, lynx::EffectKind::foilPlate, lynx::EffectKind::nebula,
  182. lynx::EffectKind::halo, lynx::EffectKind::horizon, lynx::EffectKind::echoform, lynx::EffectKind::spiralEcho,
  183. lynx::EffectKind::orbit, lynx::EffectKind::latticeMod, lynx::EffectKind::crestCompressor,
  184. lynx::EffectKind::prismMultiband, lynx::EffectKind::sentryGate, lynx::EffectKind::quellDenoiser,
  185. lynx::EffectKind::geminiDoubler, lynx::EffectKind::voiceShift, lynx::EffectKind::kilnChannel,
  186. lynx::EffectKind::fretChannel, lynx::EffectKind::shellChannel })
  187. CHECK (effects.count (kind) == 1);
  188. CHECK (instruments >= 1);
  189. }
  190. TEST (pluginexport188b_table_codes_are_unique)
  191. {
  192. // the VST3 codes (hosts store them in their projects) and the built column, read from the table as the build reads it
  193. std::ifstream in ("src/plugin/plugins.def");
  194. CHECK (in.good());
  195. const std::regex line (R"re(^LYNX_PLUGIN \("([^"]+)", ([01]), [^,]+, [^,]+, "[^"]+", (0x[0-9a-f]+), "([^"]+)", ([012])\)$)re");
  196. std::set<std::string> codes;
  197. auto rows = 0, vst3 = 0, built = 0;
  198. for (std::string text; std::getline (in, text);)
  199. {
  200. if (text.rfind ("LYNX_PLUGIN ", 0) != 0)
  201. continue;
  202. std::smatch m;
  203. CHECK (std::regex_match (text, m, line));
  204. if (m.empty())
  205. continue;
  206. ++rows;
  207. CHECK (codes.insert (m[3].str()).second);
  208. built += m[5].str() != "0" ? 1 : 0;
  209. vst3 += m[5].str() == "2" ? 1 : 0;
  210. }
  211. CHECK (rows > 0);
  212. CHECK (built == (int) lynx::plugexport::catalog.size());
  213. // a short list: each VST3 carries the whole runtime (docs/PLUGIN_EXPORT.md). Round 190pq: 11, the three synths
  214. // (Fourfold, Wavecoil, Duoloom) joined the eight, as the round's brief asked
  215. CHECK (vst3 >= 1 && vst3 <= 11);
  216. }
  217. TEST (pluginexport188b_plugin_downloads_are_never_taken_for_the_app)
  218. {
  219. // The plugin bundles sit in the same GitHub release as the app (scripts/package-plugins.sh): the updater must never
  220. // pick one for an app update, and their checksum file is not the app's SHA256SUMS.txt
  221. using namespace lynx::update;
  222. std::vector<Asset> assets;
  223. for (const char* name : { "LYNX-Plugins-0.1.26-win-x64.zip", "LYNX-Plugins-0.1.26-win-x64.7z", "LYNX-Plugins-0.1.26-linux-x86_64.tar.xz",
  224. "LYNX-Plugins-0.1.26-macos-universal.tar.xz", "LYNX-Plugins-0.1.26-SHA256SUMS.txt" })
  225. assets.push_back ({ name, std::string ("https://example.invalid/") + name, 1 });
  226. for (const auto f : { Flavour::windowsInstaller, Flavour::windowsPortable, Flavour::macos, Flavour::linuxAppImage, Flavour::linuxTarball })
  227. CHECK (assetFor (f, assets) == -1);
  228. CHECK (checksumsAsset (assets) == -1);
  229. }
  230. TEST (pluginexport188b_side_chain_bus_reaches_the_detector)
  231. {
  232. // The host's side-chain bus enters the side track (RackRenderer::setSideInput), the slot's side-chain source: with
  233. // Crest Compressor's external side chain on, a loud side signal compresses the main input; a silent one doesn't,
  234. // and the side track itself is never heard
  235. constexpr double rate = 48000.0;
  236. constexpr int size = 256;
  237. auto song = pluginExportSong (lynx::EffectKind::crestCompressor);
  238. const auto& info = lynx::effectInfo (lynx::EffectKind::crestCompressor);
  239. for (std::size_t i = 0; i < info.params.size(); ++i)
  240. if (std::string (info.params[i].name) == "External SC")
  241. song.mixer[1].effects[0].params[i] = 1.0f;
  242. auto state = lynx::RackState::build (song, nullptr, rate);
  243. const auto params = song.mixer[1].effects[0].params;
  244. const auto run = [&] (float sideLevel, float mainLevel) {
  245. auto renderer = std::make_unique<lynx::RackRenderer>();
  246. renderer->prepare (rate, size);
  247. std::vector<float> inL (size), inR (size), sideL (size), sideR (size), outL (size), outR (size);
  248. auto energy = 0.0;
  249. for (int b = 0; b < 200; ++b)
  250. {
  251. pluginExportInput (inL, inR, b);
  252. for (std::size_t i = 0; i < inL.size(); ++i)
  253. {
  254. sideL[i] = sideR[i] = sideLevel * (i % 64 < 32 ? 1.0f : -1.0f);
  255. inL[i] *= mainLevel;
  256. inR[i] *= mainLevel;
  257. }
  258. renderer->setMetronomeInput (inL.data(), inR.data(), 1);
  259. renderer->setSideInput (sideL.data(), sideR.data(), 2);
  260. renderer->setSlotParamsOverride (&params, 1, 0);
  261. renderer->process (state.get(), false, 0.0, size, outL.data(), outR.data());
  262. if (b >= 100)
  263. for (int i = 0; i < size; ++i)
  264. energy += (double) outL[(std::size_t) i] * outL[(std::size_t) i];
  265. }
  266. return energy;
  267. };
  268. const auto quietSide = run (0.0f, 1.0f), loudSide = run (0.9f, 1.0f), sideOnly = run (0.9f, 0.0f);
  269. CHECK (quietSide > 0.0);
  270. CHECK (loudSide < quietSide * 0.7); // compressed by the side signal
  271. CHECK (sideOnly < 1.0e-9); // the side track goes nowhere
  272. }