SubstituteTests.inc 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. #include "core/LynxVerbs.h" // (round 190mb: Epoch's rate law index in the VintageVerb substitute test)
  2. // --- LYNX substitutes for missing third-party plugins (core/PluginSubstitutes.h) - round 98 -------------------------
  3. namespace substtest
  4. {
  5. std::vector<std::uint8_t> bytesOf (const std::string& s)
  6. {
  7. return { s.begin(), s.end() };
  8. }
  9. void putRecord (std::vector<std::uint8_t>& out, std::uint32_t id, const std::vector<std::uint8_t>& data)
  10. {
  11. for (int i = 0; i < 4; ++i)
  12. out.push_back ((std::uint8_t) (id >> (8 * i)));
  13. const auto size = (std::uint64_t) data.size();
  14. for (int i = 0; i < 8; ++i)
  15. out.push_back ((std::uint8_t) (size >> (8 * i)));
  16. out.insert (out.end(), data.begin(), data.end());
  17. }
  18. // FL's VST3 state (record 0x35): u32 0 + records (3 = component, 4 = parameter slots)
  19. std::vector<std::uint8_t> flVst3State (const std::vector<std::uint8_t>& component)
  20. {
  21. std::vector<std::uint8_t> state { 0, 0, 0, 0 };
  22. putRecord (state, 4, { 1, 0, 0, 0, 0x12, 0, 0, 0 });
  23. putRecord (state, 3, component);
  24. return state;
  25. }
  26. std::array<std::uint8_t, 16> classIdOf (const char* hex)
  27. {
  28. std::array<std::uint8_t, 16> id {};
  29. for (int i = 0; i < 16; ++i)
  30. id[(std::size_t) i] = (std::uint8_t) std::stoul (std::string (hex + 2 * i, 2), nullptr, 16);
  31. return id;
  32. }
  33. // a JUCE-style state as a VST2-in-VST3 wrapper would hold it: some binary header, then "VC2!" + size + XML
  34. std::vector<std::uint8_t> juceXmlComponent (const std::string& element)
  35. {
  36. auto c = bytesOf (std::string ("VstW\0\0\0\x08", 8));
  37. c.insert (c.end(), 40, 0x00);
  38. const auto xml = std::string ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n") + element;
  39. auto vc2 = bytesOf ("VC2!");
  40. const auto size = (std::uint32_t) xml.size() + 1;
  41. for (int i = 0; i < 4; ++i)
  42. vc2.push_back ((std::uint8_t) (size >> (8 * i)));
  43. c.insert (c.end(), vc2.begin(), vc2.end());
  44. c.insert (c.end(), xml.begin(), xml.end());
  45. c.push_back (0);
  46. c.insert (c.end(), { 0x00, 0x01, 0x02, 0xFF });
  47. return c;
  48. }
  49. std::vector<std::uint8_t> wavesComponent (const std::string& pluginName, const std::string& parametersA, const std::string& active = "SETUP_A")
  50. {
  51. auto c = bytesOf (std::string ("\0\0\x03\xe2\0\0\0\x03\0\0\0\x01URCSsetA\0\0\x03\xc6XPst", 28));
  52. c.push_back (0);
  53. const auto xml = "<PresetChunkXMLTree version=\"3\">\n <Preset Name=\"\" GenericType=\"ARCS\">\n <PresetHeader>\n <PluginName>"
  54. + pluginName + "</PluginName>\n <ActiveSetup>" + active
  55. + "</ActiveSetup>\n </PresetHeader>\n <PresetData Setup=\"SETUP_A\">\n <Parameters Type=\"RealWorld\">\n"
  56. + parametersA + "\n</Parameters>\n </PresetData>\n <PresetData Setup=\"SETUP_B\">\n <Parameters Type=\"RealWorld\">\n7 8 9\n</Parameters>\n </PresetData>\n </Preset>\n</PresetChunkXMLTree>\n";
  57. c.insert (c.end(), xml.begin(), xml.end());
  58. return c;
  59. }
  60. } // namespace substtest
  61. TEST (substitute_builtin_table_parses)
  62. {
  63. int errors = -1;
  64. // the built-in table (through the registry) has no bad line; re-parsing a copy of an entry counts errors
  65. const auto& entries = lynx::pluginSubstitutes();
  66. CHECK (entries.size() >= 20);
  67. for (const auto& e : entries)
  68. {
  69. CHECK (! e.key.empty() && ! e.product.empty());
  70. CHECK (e.effect != lynx::EffectKind::plugin && e.effect != lynx::EffectKind::parallel);
  71. CHECK (! e.instrument);
  72. CHECK (! e.vst2Ids.empty() || ! e.vst3ClassIds.empty() || ! e.names.empty() || ! e.wavesNames.empty());
  73. }
  74. const auto parsed = lynx::parseSubstituteTable ("[a]\nlynx = Reeverb 2\npreset = Dry=0; Nope=1; Wet=x\nmap = xml:Mix -> mix\nmap = vst2:x -> Wet\n"
  75. "bogus line\nfoo = bar\n[b]\nlynx = No such effect\n[c]\nlynx = Compressor\nvst2 = StEB; 0x10; 12345678901\n"
  76. "vst3 = 00112233445566778899aabbccddeeff; 0011\nnames = FabFilter Pro-C 2 (Stereo)\n",
  77. &errors);
  78. CHECK (parsed.size() == 2 && parsed[0].key == "a" && parsed[1].key == "c");
  79. CHECK (errors == 8); // Nope, Wet=x, vst2:x, bogus line, foo, entry b, 12345678901, 0011
  80. if (parsed.size() == 2)
  81. {
  82. CHECK (parsed[0].effect == lynx::EffectKind::reeverb2 && parsed[0].preset.size() == 1 && parsed[0].preset[0].first == 10);
  83. CHECK (parsed[0].params.size() == 1 && parsed[0].params[0].toSlotMix);
  84. CHECK (parsed[1].vst2Ids == std::vector<std::uint32_t> ({ 0x53744542u, 0x10u }));
  85. CHECK (parsed[1].vst3ClassIds.size() == 1 && parsed[1].vst3ClassIds[0][15] == 0xff);
  86. CHECK (parsed[1].names == std::vector<std::string> ({ "fabfilterproc2" })); // "(Stereo)" dropped
  87. }
  88. }
  89. TEST (substitute_valhalla_vst3_translates_mix_and_keeps_original)
  90. {
  91. using namespace substtest;
  92. lynx::ForeignPlugin vv;
  93. vv.format = lynx::ForeignPlugin::Format::vst3;
  94. vv.classId = classIdOf ("7654535665657633616c68616c6c6176");
  95. vv.hasClassId = true;
  96. vv.name = "ValhallaVintageVerb";
  97. vv.path = "C:\\Program Files\\Common Files\\VST3\\ValhallaDSP\\ValhallaVintageVerb.vst3";
  98. vv.state = flVst3State (juceXmlComponent ("<ValhallaVintageVerb pluginVersion=\"4.0.5\" presetName=\"Big &amp; Wide\" Mix=\"0.42\" Decay=\"0.3\"/>"));
  99. vv.midiInPort = 3;
  100. const auto id = lynx::pluginIdentity (vv);
  101. const auto* entry = lynx::findPluginSubstitute (id, false);
  102. CHECK (entry != nullptr && entry->key == "valhalla-vintageverb");
  103. CHECK (lynx::findPluginSubstitute (id, true) == nullptr); // not an instrument
  104. const auto attrs = lynx::juceXmlStateAttributes (id.state);
  105. CHECK (attrs.size() == 4 && attrs[1].first == "presetName" && attrs[1].second == "Big & Wide" && attrs[2].second == "0.42");
  106. lynx::EffectSlot slot;
  107. slot.kind = lynx::EffectKind::plugin;
  108. slot.plugin.name = vv.name;
  109. slot.plugin.foreign = vv;
  110. slot.mix = 0.5f;
  111. slot.enabled = false;
  112. slot.sidechain = 4;
  113. const auto before = slot.plugin;
  114. CHECK (lynx::substituteEffectSlot (slot, id));
  115. CHECK (slot.kind == lynx::EffectKind::epochVerb && slot.isSubstitute()); // LYNX's own vintage-digital reverb (round 100)
  116. CHECK (std::abs (slot.mix - 0.5f) < 1e-6f); // FL's slot dry/wet; the plugin's Mix is the effect's own
  117. CHECK (! slot.enabled && slot.sidechain == 4);
  118. CHECK (std::abs (slot.params[0] - 0.42f) < 1e-6f && std::abs (slot.params[2] - 0.3f) < 1e-6f); // Mix, Decay: same laws
  119. CHECK (slot.substituteFor == before);
  120. CHECK (slot.substituteFor.foreign.state == vv.state); // byte for byte
  121. CHECK (lynx::substituteOriginalName (slot) == "ValhallaVintageVerb");
  122. // a second substitution doesn't apply (no longer a plugin slot); restoring gives the original back unchanged
  123. CHECK (! lynx::substituteEffectSlot (slot, id));
  124. CHECK (lynx::restoreOriginalPlugin (slot));
  125. CHECK (slot.kind == lynx::EffectKind::plugin && slot.plugin == before && ! slot.isSubstitute() && ! slot.enabled && slot.sidechain == 4);
  126. CHECK (! lynx::restoreOriginalPlugin (slot));
  127. // unreadable state: the default preset
  128. vv.state = flVst3State ({ 1, 2, 3 });
  129. int translated = -1;
  130. const auto plain = lynx::makeSubstituteSlot (*entry, nullptr, &translated);
  131. const auto id2 = lynx::pluginIdentity (vv);
  132. const auto fromJunk = lynx::makeSubstituteSlot (*entry, &id2, &translated);
  133. // (round 190mb: a state that came from an original device also gets the entry's `replaced` items — Epoch's rate law)
  134. auto junkBase = fromJunk;
  135. CHECK (junkBase.params[(std::size_t) lynx::verbs::epoch::rateLaw] == 1.0f && plain.params[(std::size_t) lynx::verbs::epoch::rateLaw] == 0.0f);
  136. junkBase.params[(std::size_t) lynx::verbs::epoch::rateLaw] = 0.0f;
  137. CHECK (translated == 0 && fromJunk.mix == plain.mix && plain.mix == 1.0f && junkBase.params == plain.params);
  138. }
  139. TEST (substitute_waves_shell_by_plugin_name)
  140. {
  141. using namespace substtest;
  142. lynx::ForeignPlugin shell;
  143. shell.format = lynx::ForeignPlugin::Format::vst3;
  144. shell.name = "WaveShell1-VST3 15.5_x64";
  145. shell.path = "C:\\Program Files\\Common Files\\VST3\\WaveShell1-VST3 15.5_x64.vst3";
  146. shell.state = flVst3State (wavesComponent ("RComp", "160.31 -15 0 * * 0.5"));
  147. const auto id = lynx::pluginIdentity (shell);
  148. CHECK (lynx::wavesPluginName (id.state) == "RComp");
  149. const auto values = lynx::wavesRealWorldParams (id.state);
  150. CHECK (values.size() == 6 && std::abs (values[0] - 160.31) < 1e-9 && values[1] == -15.0 && std::isnan (values[3]) && values[5] == 0.5);
  151. const auto* entry = lynx::findPluginSubstitute (id, false);
  152. CHECK (entry != nullptr && entry->key == "waves-rcomp" && entry->effect == lynx::EffectKind::compressor);
  153. // the active setup is the one read
  154. const auto b = lynx::pluginIdentity ([&] { auto s = shell; s.state = flVst3State (wavesComponent ("RComp", "1 2", "SETUP_B")); return s; }());
  155. CHECK (lynx::wavesRealWorldParams (b.state) == std::vector<double> ({ 7, 8, 9 }));
  156. // CLA-2A by class ID alone (no state), H-Delay by name in the state
  157. lynx::PluginIdentity cla;
  158. cla.format = lynx::ForeignPlugin::Format::vst3;
  159. cla.name = shell.name;
  160. cla.classId = classIdOf ("4c545356324163536c612d3261207374");
  161. cla.hasClassId = true;
  162. CHECK (lynx::findPluginSubstitute (cla, false) != nullptr && lynx::findPluginSubstitute (cla, false)->key == "waves-cla-2a");
  163. shell.state = flVst3State (wavesComponent ("H-Delay", "1"));
  164. CHECK (lynx::findPluginSubstitute (lynx::pluginIdentity (shell), false) != nullptr
  165. && lynx::findPluginSubstitute (lynx::pluginIdentity (shell), false)->effect == lynx::EffectKind::echoform); // round 119
  166. // round 119: NS1 and Doubler have LYNX roles now
  167. shell.state = flVst3State (wavesComponent ("NS1", "1"));
  168. CHECK (lynx::findPluginSubstitute (lynx::pluginIdentity (shell), false) != nullptr
  169. && lynx::findPluginSubstitute (lynx::pluginIdentity (shell), false)->effect == lynx::EffectKind::quellDenoiser);
  170. shell.state = flVst3State (wavesComponent ("Doubler", "1"));
  171. CHECK (lynx::findPluginSubstitute (lynx::pluginIdentity (shell), false) != nullptr
  172. && lynx::findPluginSubstitute (lynx::pluginIdentity (shell), false)->effect == lynx::EffectKind::geminiDoubler);
  173. // a shell sub-plugin LYNX has no substitute for: nothing (the shell's file name must not match anything; round 124:
  174. // S1 Imager has one now, Vocal Rider serves as the example)
  175. shell.state = flVst3State (wavesComponent ("Vocal Rider", "1"));
  176. CHECK (lynx::findPluginSubstitute (lynx::pluginIdentity (shell), false) == nullptr);
  177. // a .lynx reference of an installed-elsewhere Waves plugin: its display name
  178. lynx::PluginIdentity named;
  179. named.format = lynx::ForeignPlugin::Format::vst3;
  180. named.name = "SSLChannel Stereo";
  181. named.state = wavesComponent ("SSLChannel", "0");
  182. CHECK (lynx::findPluginSubstitute (named, false) != nullptr && lynx::findPluginSubstitute (named, false)->effect == lynx::EffectKind::ridgeStrip);
  183. }
  184. TEST (substitute_vst2_ids_names_and_float_params)
  185. {
  186. // EchoBoy (chunk state: nothing to translate) by its VST2 ID
  187. lynx::PluginIdentity echo;
  188. echo.format = lynx::ForeignPlugin::Format::vst2;
  189. echo.vst2Id = 0x53744542u;
  190. echo.name = "Some renamed plugin";
  191. const auto* e = lynx::findPluginSubstitute (echo, false);
  192. CHECK (e != nullptr && e->key == "soundtoys-echoboy");
  193. // by name / file name, case and punctuation aside, any format
  194. lynx::PluginIdentity proq;
  195. proq.format = lynx::ForeignPlugin::Format::vst3;
  196. proq.name = "Pro-Q 3";
  197. CHECK (lynx::findPluginSubstitute (proq, false) != nullptr && lynx::findPluginSubstitute (proq, false)->effect == lynx::EffectKind::facetEq);
  198. lynx::PluginIdentity prol;
  199. prol.format = lynx::ForeignPlugin::Format::vst2;
  200. prol.path = "C:\\VstPlugins\\FabFilter\\FabFilter Pro-L 2 x64.dll";
  201. CHECK (lynx::findPluginSubstitute (prol, false) != nullptr && lynx::findPluginSubstitute (prol, false)->effect == lynx::EffectKind::apexLimiter);
  202. lynx::PluginIdentity unknown;
  203. unknown.name = "Serum";
  204. CHECK (lynx::findPluginSubstitute (unknown, false) == nullptr);
  205. // a registered entry with a VST2 float-parameter map (the hook later modules use); later registrations win
  206. CHECK (lynx::registerPluginSubstitutes ("[test-vst2-floats]\nproduct = Test Verb\nlynx = Reeverb 2\nvst2 = TsT1\n"
  207. "vst2params = 3\nmap = vst2:2 -> Wet | 0 1 0 0.5\nmap = vst2:0 -> mix\nmap = vst2:9 -> Decay\n")
  208. == 1);
  209. lynx::FlVst2State s;
  210. s.version = -9;
  211. s.flags = 1; // all programs: 2 programs × 3 parameters, the second is current
  212. s.currentProgram = 1;
  213. s.params = { 0.1f, 0.2f, 0.3f, 0.6f, 0.7f, 0.8f };
  214. s.programNames = { "A", "B" };
  215. lynx::PluginIdentity t;
  216. t.format = lynx::ForeignPlugin::Format::vst2;
  217. t.vst2Id = 0x54735431u; // "TsT1"
  218. t.state = lynx::writeFlVst2State (s);
  219. const auto* te = lynx::findPluginSubstitute (t, false);
  220. CHECK (te != nullptr && te->key == "test-vst2-floats");
  221. if (te != nullptr)
  222. {
  223. int translated = 0;
  224. const auto slot = lynx::makeSubstituteSlot (*te, &t, &translated);
  225. CHECK (translated == 2); // parameter 9 doesn't exist
  226. CHECK (std::abs (slot.params[12] - 0.4f) < 1e-6f && std::abs (slot.mix - 0.6f) < 1e-6f);
  227. }
  228. CHECK (lynx::registerPluginSubstitutes ("[test-vst2-floats]\nlynx = Compressor\nvst2 = TsT1\n") == 1);
  229. CHECK (lynx::findPluginSubstitute (t, false) != nullptr && lynx::findPluginSubstitute (t, false)->effect == lynx::EffectKind::compressor);
  230. }
  231. TEST (substitute_foreign_text_round_trip_is_byte_identical)
  232. {
  233. lynx::ForeignPlugin p;
  234. p.format = lynx::ForeignPlugin::Format::vst3;
  235. p.vst2Id = 0xDEADBEEF;
  236. for (int i = 0; i < 16; ++i)
  237. p.classId[(std::size_t) i] = (std::uint8_t) (i * 17);
  238. p.hasClassId = true;
  239. p.clapId = "com.example.x";
  240. p.name = "N\xc3\xa3o \"quoted\"";
  241. p.path = "C:\\x\\y.vst3";
  242. p.midiInPort = -1;
  243. p.midiOutPort = 7;
  244. for (std::size_t n : { 0u, 1u, 2u, 3u, 4u, 1000u, 65537u })
  245. {
  246. p.state.resize (n);
  247. for (std::size_t i = 0; i < n; ++i)
  248. p.state[i] = (std::uint8_t) (i * 31 + 7);
  249. lynx::ForeignPlugin back;
  250. CHECK (lynx::foreignFromText (lynx::foreignToText (p), back) && back == p);
  251. }
  252. lynx::ForeignPlugin out;
  253. CHECK (! lynx::foreignFromText ("", out) && ! lynx::foreignFromText ("not base64!", out) && ! lynx::foreignFromText ("AAAA", out));
  254. auto text = lynx::foreignToText (p);
  255. text.resize (text.size() / 2); // truncated
  256. CHECK (! lynx::foreignFromText (text, out));
  257. std::vector<std::uint8_t> bytes;
  258. CHECK (lynx::base64Decode ("aGVsbG8=", bytes) && std::string (bytes.begin(), bytes.end()) == "hello");
  259. CHECK (lynx::base64Encode ((const std::uint8_t*) "hello", 5) == "aGVsbG8=");
  260. }
  261. TEST (substitute_table_reaches_the_newest_effects)
  262. {
  263. // effectKindNamed walks the enum up to its last value: a kind appended later must still be nameable in the table
  264. for (const auto kind : { lynx::EffectKind::facetEq, lynx::EffectKind::apexLimiter })
  265. {
  266. int errors = -1;
  267. const auto t = lynx::parseSubstituteTable (std::string ("[k]\nnames = X\nlynx = ") + lynx::effectInfo (kind).name + "\n", &errors);
  268. CHECK (errors == 0 && t.size() == 1 && t[0].effect == kind);
  269. }
  270. }