SimpleGate190dgTests.inc 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. // --- Round 190dg: the quality gate of the Simple dock's one-knob effects (core/GoalKnobs.h), chain presets and Blend
  2. // (core/ChainPresets.h, RackRenderer): per knob position the level, the peaks and the cost on four test sounds; a knob
  3. // or Blend turned while the sound plays makes no click.
  4. #include <chrono>
  5. #include <cmath>
  6. #include <cstdlib>
  7. #include <functional>
  8. #include <memory>
  9. #include "core/ChainPresets.h"
  10. #include "core/Effects.h"
  11. #include "core/GoalKnobs.h"
  12. #include "core/RackRenderer.h"
  13. #include "core/SoundLibrary.h"
  14. namespace simple190dg
  15. {
  16. constexpr double rate = 48000.0;
  17. constexpr int block = 256;
  18. enum class Sig { pink, drums, chord, sine, quietDrums };
  19. // Five test sounds, the same every time, mono, 4 s: pink noise at −20 dBFS RMS; a drum loop (kick, snare, hats, 120
  20. // BPM) whose peaks reach −1 dBFS; a sustained low chord (rich in harmonics) at −3 dBFS peak; a 220 Hz sine at −6 dBFS;
  21. // the drum loop again at −13 dBFS (dynamics and saturation depend on the level they get).
  22. inline std::shared_ptr<const lynx::SampleData> signal (Sig which)
  23. {
  24. auto make = [] (Sig s) {
  25. auto d = std::make_shared<lynx::SampleData>();
  26. d->sampleRate = rate;
  27. auto& x = d->left;
  28. x.assign ((std::size_t) (rate * 4.0), 0.0f); // (sampler files longer than the renders)
  29. std::uint32_t seed = 0x190d;
  30. auto white = [&seed] {
  31. seed = seed * 1664525u + 1013904223u;
  32. return (float) ((seed >> 8) & 0xffff) / 32768.0f - 1.0f;
  33. };
  34. const auto pi2 = 6.283185307179586;
  35. if (s == Sig::pink)
  36. {
  37. float b0 = 0, b1 = 0, b2 = 0;
  38. for (auto& v : x)
  39. {
  40. const auto w = white();
  41. b0 = 0.99765f * b0 + w * 0.0990460f;
  42. b1 = 0.96300f * b1 + w * 0.2965164f;
  43. b2 = 0.57000f * b2 + w * 1.0526913f;
  44. v = b0 + b1 + b2 + w * 0.1848f;
  45. }
  46. }
  47. else if (s == Sig::drums || s == Sig::quietDrums)
  48. {
  49. const auto beat = (std::size_t) (rate * 0.5); // 120 BPM
  50. float hp = 0.0f, last = 0.0f;
  51. for (std::size_t i = 0; i < x.size(); ++i)
  52. {
  53. const auto inBeat = i % beat, b = (i / beat) % 4;
  54. const auto t = (double) inBeat / rate;
  55. double v = 0.0;
  56. if (b == 0 || b == 2) // kick: a falling sine
  57. {
  58. const auto f = 45.0 + 75.0 * std::exp (-t * 30.0);
  59. v += std::sin (pi2 * (45.0 * t + 75.0 / 30.0 * (1.0 - std::exp (-t * 30.0)))) * std::exp (-t * 7.0) * (f > 0 ? 1.0 : 0.0);
  60. }
  61. const auto w = white();
  62. if (b == 1 || b == 3) // snare: tone and noise
  63. v += 0.5 * std::sin (pi2 * 190.0 * t) * std::exp (-t * 25.0) + 0.6 * w * std::exp (-t * 18.0);
  64. // hats on every eighth: high-passed noise
  65. const auto th = (double) (i % (beat / 2)) / rate;
  66. hp = 0.6f * (hp + w - last);
  67. last = w;
  68. v += 0.25 * hp * std::exp (-th * 60.0);
  69. x[i] = (float) v;
  70. }
  71. }
  72. else if (s == Sig::chord)
  73. {
  74. const double f[] { 110.0, 164.81, 220.0, 277.18 };
  75. for (std::size_t i = 0; i < x.size(); ++i)
  76. {
  77. const auto t = (double) i / rate;
  78. double v = 0.0;
  79. for (const auto fr : f)
  80. for (int h = 1; h <= 8; ++h)
  81. v += std::sin (pi2 * fr * h * t + h) / h;
  82. x[i] = (float) v;
  83. }
  84. }
  85. else
  86. for (std::size_t i = 0; i < x.size(); ++i)
  87. x[i] = (float) std::sin (pi2 * 220.0 * (double) i / rate);
  88. // levels
  89. double sum = 0.0;
  90. float peak = 0.0f;
  91. for (auto v : x)
  92. {
  93. sum += (double) v * v;
  94. peak = std::max (peak, std::abs (v));
  95. }
  96. // (the sampler channel at its default volume and centre pan plays the file 5.2 dB down: made up here, so the
  97. // levels are the ones the insert gets)
  98. const auto path = std::pow (10.0, 5.2 / 20.0);
  99. const auto gain = path * (s == Sig::pink ? 0.1 / std::sqrt (sum / (double) x.size()) : s == Sig::drums ? 0.891 / peak : s == Sig::quietDrums ? 0.224 / peak : s == Sig::chord ? 0.708 / peak : 0.501 / peak);
  100. for (auto& v : x)
  101. v = (float) (v * gain);
  102. // a short fade in, so the start is not a click of its own
  103. for (std::size_t i = 0; i < 480; ++i)
  104. x[i] *= (float) i / 480.0f;
  105. return std::shared_ptr<const lynx::SampleData> (d);
  106. };
  107. static const std::shared_ptr<const lynx::SampleData> all[] { make (Sig::pink), make (Sig::drums), make (Sig::chord), make (Sig::sine), make (Sig::quietDrums) };
  108. return all[(int) which];
  109. }
  110. inline const char* signalName (Sig s)
  111. {
  112. return s == Sig::pink ? "pink" : s == Sig::drums ? "drums" : s == Sig::chord ? "chord" : s == Sig::sine ? "sine" : "drums-13";
  113. }
  114. struct Run
  115. {
  116. std::vector<float> out; // the left output
  117. double nsPerSample = 0.0;
  118. };
  119. // The sound played through insert 1 (a sampler at unity: the insert gets the file's own samples), whose chain `setup`
  120. // makes. `perBlock` (optional) changes the insert before each block, as the UI's edits do: a new state built from the
  121. // one before, so the running effects are kept (AudioEngine::publishSong).
  122. inline Run render (Sig which, const std::function<void (lynx::MixerTrack&)>& setup, int blocks = 0,
  123. const std::function<void (int, lynx::MixerTrack&)>& perBlock = {})
  124. {
  125. using namespace lynx;
  126. const auto data = signal (which);
  127. if (blocks <= 0)
  128. blocks = (int) (data->left.size() / block);
  129. Song s;
  130. s.bpm = 120.0;
  131. s.mixer.resize (2);
  132. ChannelDef c;
  133. c.instrument = InstrumentKind::sampler;
  134. c.samplePath = "signal";
  135. c.mixerTrack = 1;
  136. s.channels.push_back (c);
  137. s.patterns.emplace_back();
  138. setup (s.mixer[1]);
  139. auto provider = [data] (const std::string&) { return data; };
  140. auto state = RackState::build (s, nullptr, rate, provider);
  141. RackRenderer renderer;
  142. renderer.prepare (rate, block);
  143. LiveEventQueue live;
  144. NoteEvent on;
  145. on.channel = 0;
  146. on.key = 60;
  147. on.velocity = 1.0f;
  148. live.push (on);
  149. Run run;
  150. run.out.reserve ((std::size_t) (blocks * block));
  151. std::vector<float> l (block), r (block);
  152. std::int64_t ns = 0;
  153. for (int b = 0; b < blocks; ++b)
  154. {
  155. if (perBlock)
  156. {
  157. perBlock (b, s.mixer[1]);
  158. state = RackState::build (s, state.get(), rate, provider);
  159. }
  160. const auto t0 = std::chrono::steady_clock::now();
  161. renderer.process (state.get(), false, 0.0, block, l.data(), r.data(), &live, nullptr);
  162. ns += std::chrono::duration_cast<std::chrono::nanoseconds> (std::chrono::steady_clock::now() - t0).count();
  163. run.out.insert (run.out.end(), l.begin(), l.end());
  164. }
  165. run.nsPerSample = (double) ns / (double) (blocks * block);
  166. return run;
  167. }
  168. inline double rmsOf (const std::vector<float>& x, std::size_t from = 0, std::size_t to = 0)
  169. {
  170. to = to == 0 ? x.size() : std::min (to, x.size());
  171. double sum = 0.0;
  172. for (std::size_t i = from; i < to; ++i)
  173. sum += (double) x[i] * x[i];
  174. return std::sqrt (sum / (double) std::max<std::size_t> (1, to - from));
  175. }
  176. inline float peakOf (const std::vector<float>& x, std::size_t from = 0)
  177. {
  178. float p = 0.0f;
  179. for (std::size_t i = from; i < x.size(); ++i)
  180. p = std::max (p, std::abs (x[i]));
  181. return p;
  182. }
  183. inline int oversOf (const std::vector<float>& x)
  184. {
  185. int n = 0;
  186. for (auto v : x)
  187. n += std::abs (v) > 1.0f ? 1 : 0;
  188. return n;
  189. }
  190. inline bool finite (const std::vector<float>& x)
  191. {
  192. for (auto v : x)
  193. if (! std::isfinite (v))
  194. return false;
  195. return true;
  196. }
  197. inline double dbOf (double ratio) { return 20.0 * std::log10 (std::max (1.0e-12, ratio)); }
  198. // The largest jump of the signal's slope (its second difference) after `from`: a click is a jump far above what the
  199. // same sound has when nothing moves
  200. inline double kinkOf (const std::vector<float>& x, std::size_t from)
  201. {
  202. double k = 0.0;
  203. for (std::size_t i = std::max<std::size_t> (from, 2); i < x.size(); ++i)
  204. k = std::max (k, std::abs ((double) x[i] - 2.0 * x[i - 1] + x[i - 2]));
  205. return k;
  206. }
  207. constexpr std::size_t settle = (std::size_t) (rate * 0.75); // (past the effects' first moments)
  208. struct Point
  209. {
  210. double level = 0.0; // dB against the dry sound (RMS after `settle`)
  211. double peak = 0.0; // dBFS
  212. int overs = 0; // samples above full scale
  213. double ns = 0.0; // processing cost per sample (the whole render)
  214. bool finite = true;
  215. };
  216. inline Point measure (Sig which, const std::function<void (lynx::MixerTrack&)>& setup, const Run& dry)
  217. {
  218. const auto wet = render (which, setup);
  219. Point p;
  220. p.level = dbOf (rmsOf (wet.out, settle) / rmsOf (dry.out, settle));
  221. p.peak = dbOf (peakOf (wet.out));
  222. p.overs = oversOf (wet.out);
  223. p.ns = wet.nsPerSample;
  224. p.finite = finite (wet.out);
  225. return p;
  226. }
  227. // One knob turned from 0 to 100 % over `seconds` while `which` plays (a new value every block, the fastest the UI
  228. // sends), then back: how far above the steady renders' own worst slope jump the sweep's is (1 = no click at all)
  229. inline double sweepKink (int goal, Sig which, double seconds = 1.5)
  230. {
  231. using namespace lynx;
  232. const auto blocks = (int) (seconds * rate / block);
  233. const auto sweep = render (which, [goal] (MixerTrack& t) { t.effects.push_back (goals::make (goal, 0.0f)); }, 2 * blocks + 40,
  234. [goal, blocks] (int b, MixerTrack& t) {
  235. const auto up = b < 20 ? 0.0f : b < 20 + blocks ? (float) (b - 20) / (float) blocks : b < 20 + 2 * blocks ? 1.0f - (float) (b - 20 - blocks) / (float) blocks : 0.0f;
  236. goals::setAmount (t.effects[0], up);
  237. });
  238. double steady = 1.0e-9;
  239. for (int i = 0; i <= 10; ++i)
  240. {
  241. const auto still = render (which, [goal, i] (MixerTrack& t) { t.effects.push_back (goals::make (goal, (float) i / 10.0f)); }, 2 * blocks + 40);
  242. steady = std::max (steady, kinkOf (still.out, 20 * block));
  243. }
  244. return kinkOf (sweep.out, 20 * block) / steady;
  245. }
  246. } // namespace simple190dg
  247. namespace simple190dg
  248. {
  249. // The gate's bounds (round 190dg, HANDOFF.md "Quality gate"): the level against the dry sound at every knob position
  250. // (a saturator with auto gain lifts quiet sounds and squashes hot ones, a leveller lets a hit's start through: hot
  251. // drums may come out quieter, never more than 6 dB)
  252. inline bool levelInBounds (double level) { return level <= 3.0 && level >= -6.0; }
  253. // ... and the peaks: at most 3 dB over the input's own, or still below −6 dBFS; Punch's guard holds full scale
  254. inline bool peakInBounds (int goal, Sig which, double inPeakDb, double outPeakDb)
  255. {
  256. if (goal == lynx::goals::punch)
  257. return outPeakDb <= 0.01;
  258. // (a room on a steady pure tone beats against it: its modes, not a level the knob sets)
  259. if (goal == lynx::goals::room && which == Sig::sine)
  260. return outPeakDb <= 0.0;
  261. return outPeakDb <= inPeakDb + 3.0 || outPeakDb <= -6.0;
  262. }
  263. } // namespace simple190dg
  264. // Every one-knob effect at nine knob positions on five sounds: the level stays near the dry one, moves in small steps,
  265. // and no peak jumps (the gate of round 190dg; the full 21-position table with CPU is in the round's HANDOFF.md)
  266. TEST (simple190dg_one_knob_gate)
  267. {
  268. using namespace lynx;
  269. using namespace simple190dg;
  270. const bool print = std::getenv ("LYNX_GATE_PRINT") != nullptr;
  271. const Sig sigs[] { Sig::pink, Sig::drums, Sig::chord, Sig::sine, Sig::quietDrums };
  272. const int blocks = (int) (2.5 * rate / block);
  273. for (const auto which : sigs)
  274. {
  275. const auto dry = render (which, [] (MixerTrack&) {}, blocks);
  276. const auto inPeak = dbOf (peakOf (dry.out));
  277. CHECK (rmsOf (dry.out, settle) > 0.005);
  278. for (int id = 1; id <= goals::count; ++id)
  279. {
  280. double before = 0.0;
  281. for (int i = 0; i <= 8; ++i)
  282. {
  283. const auto amount = (float) i / 8.0f;
  284. const auto wet = render (which, [id, amount] (MixerTrack& t) { t.effects.push_back (goals::make (id, amount)); }, blocks);
  285. CHECK (finite (wet.out));
  286. const auto level = dbOf (rmsOf (wet.out, settle) / rmsOf (dry.out, settle));
  287. const auto peak = dbOf (peakOf (wet.out));
  288. if (print)
  289. std::printf ("GATE %-9s %-8s %3.0f%% level %+5.2f dB peak %+5.2f dBFS\n", goals::name (id), signalName (which), amount * 100.0f, level, peak);
  290. CHECK (levelInBounds (level));
  291. CHECK (peakInBounds (id, which, inPeak, peak));
  292. if (i == 0)
  293. CHECK (std::abs (level) < 0.3);
  294. else // (12.5 % apart: no step of more than 1.5 dB)
  295. CHECK (std::abs (level - before) <= 1.5 || (id == goals::room && which == Sig::sine));
  296. before = level;
  297. }
  298. }
  299. }
  300. }
  301. // A knob turned while a held tone plays (one new value every block, the fastest edits come), and one jumped from 0 to
  302. // 100 % and back: no click. "Kink" = the largest jump of the signal's slope, against the same sound's own worst with the
  303. // knob held still anywhere (1 = nothing added).
  304. TEST (simple190dg_knob_turns_without_clicks)
  305. {
  306. using namespace lynx;
  307. using namespace simple190dg;
  308. const bool print = std::getenv ("LYNX_GATE_PRINT") != nullptr;
  309. for (int id = 1; id <= goals::count; ++id)
  310. for (const auto which : { Sig::sine, Sig::chord })
  311. {
  312. const auto turned = sweepKink (id, which, 1.0);
  313. const int blocks = (int) (1.0 * rate / block);
  314. const auto jump = render (which, [id] (MixerTrack& t) { t.effects.push_back (goals::make (id, 0.0f)); }, 2 * blocks + 40,
  315. [id, blocks] (int b, MixerTrack& t) { goals::setAmount (t.effects[0], b >= 20 + blocks / 2 && b < 20 + blocks ? 1.0f : 0.0f); });
  316. double steady = 1.0e-9;
  317. for (int i = 0; i <= 10; ++i)
  318. steady = std::max (steady, kinkOf (render (which, [id, i] (MixerTrack& t) { t.effects.push_back (goals::make (id, (float) i / 10.0f)); }, 2 * blocks + 40).out, 20 * block));
  319. const auto jumped = kinkOf (jump.out, 20 * block) / steady;
  320. if (print)
  321. std::printf ("TURN %-9s %-6s sweep %.2f jump %.2f\n", goals::name (id), signalName (which), turned, jumped);
  322. CHECK (turned < 1.5);
  323. CHECK (jumped < 1.5);
  324. }
  325. }
  326. // Blend moved while the sound plays, or jumped 100 → 0 → 100 % (a preset, a double click): it ramps, also through a
  327. // chain with latency whose dry path starts empty, and the insert goes back to no stage at 100 %
  328. TEST (simple190dg_blend_ramps)
  329. {
  330. using namespace lynx;
  331. using namespace simple190dg;
  332. const int blocks = (int) (1.0 * rate / block);
  333. for (const char* name : { "Radio Booth", "Crunch Stack", "Growl", "Canyon", "Big Chorus" })
  334. {
  335. const auto* p = chains::find (name);
  336. CHECK (p != nullptr);
  337. if (p == nullptr)
  338. continue;
  339. for (const auto which : { Sig::sine, Sig::chord })
  340. {
  341. const auto setup = [p] (MixerTrack& t) {
  342. t.effects = chains::slots (*p);
  343. t.chainBlend = 1.0f;
  344. };
  345. const auto sweep = render (which, setup, 2 * blocks + 40, [blocks] (int b, MixerTrack& t) {
  346. const auto up = b < 20 ? 0.0f : b < 20 + blocks ? (float) (b - 20) / (float) blocks : b < 20 + 2 * blocks ? 1.0f - (float) (b - 20 - blocks) / (float) blocks : 0.0f;
  347. t.chainBlend = 1.0f - up;
  348. });
  349. const auto jump = render (which, setup, 2 * blocks + 40,
  350. [blocks] (int b, MixerTrack& t) { t.chainBlend = b >= 20 + blocks / 2 && b < 20 + blocks ? 0.0f : 1.0f; });
  351. double steady = 1.0e-9;
  352. for (int i = 0; i <= 10; ++i)
  353. steady = std::max (steady, kinkOf (render (which, [p, i] (MixerTrack& t) {
  354. t.effects = chains::slots (*p);
  355. t.chainBlend = (float) i / 10.0f;
  356. }, 2 * blocks + 40).out, 20 * block));
  357. CHECK (kinkOf (sweep.out, 20 * block) / steady < 1.5);
  358. CHECK (kinkOf (jump.out, 20 * block) / steady < 1.5);
  359. // the jump's end: 100 % again, the same samples as a chain that never moved (once the dry path is out)
  360. const auto still = render (which, setup, 2 * blocks + 40);
  361. double diff = 0.0;
  362. for (std::size_t i = (std::size_t) ((20 + blocks + 80) * block); i < still.out.size(); ++i) // (after the ramp back)
  363. diff = std::max (diff, (double) std::abs (still.out[i] - jump.out[i]));
  364. CHECK (diff < 1.0e-6 || dbOf (diff / std::max (1.0e-9, (double) peakOf (still.out))) < -60.0);
  365. }
  366. }
  367. // a chain at a steady Blend renders as before this round: a first build starts at its Blend (no ramp from 100 %)
  368. Song s;
  369. s.mixer.resize (2);
  370. s.mixer[1].effects = chains::slots (*chains::find ("Canyon"));
  371. s.mixer[1].chainBlend = 0.3f;
  372. const auto st = RackState::build (s, nullptr, rate);
  373. CHECK (st->chainBlends.size() == 2 && st->chainBlends[1] != nullptr);
  374. if (st->chainBlends.size() == 2 && st->chainBlends[1] != nullptr)
  375. {
  376. CHECK (std::abs (st->chainBlends[1]->lastWet.load() - 0.3f) < 1.0e-6f && st->chainBlends[1]->warmup == 0);
  377. // the next live build at 100 %: kept for one ramp back, then gone
  378. s.mixer[1].chainBlend = 1.0f;
  379. const auto next = RackState::build (s, st.get(), rate);
  380. CHECK (next->chainBlends[1] != nullptr);
  381. next->chainBlends[1]->lastWet.store (1.0f);
  382. const auto after = RackState::build (s, next.get(), rate);
  383. CHECK (after->chainBlends[1] == nullptr);
  384. }
  385. }
  386. // The 22 chain presets at Blend 0, 50, 100 % and their own on three sounds: near the dry level, no peak jump (a chain
  387. // stacks up to four effects: its peaks may rise 3.5 dB over the input's)
  388. TEST (simple190dg_presets_gate)
  389. {
  390. using namespace lynx;
  391. using namespace simple190dg;
  392. const int blocks = (int) (2.5 * rate / block);
  393. for (const auto which : { Sig::pink, Sig::drums, Sig::chord })
  394. {
  395. const auto dry = render (which, [] (MixerTrack&) {}, blocks);
  396. const auto inPeak = dbOf (peakOf (dry.out));
  397. for (const auto& p : chains::factory())
  398. for (const float blend : { 0.0f, 0.5f, 1.0f, p.blend })
  399. {
  400. const auto wet = render (which, [&p, blend] (MixerTrack& t) {
  401. t.effects = chains::slots (p);
  402. t.chainBlend = blend;
  403. }, blocks);
  404. const auto level = dbOf (rmsOf (wet.out, settle) / rmsOf (dry.out, settle));
  405. CHECK (finite (wet.out));
  406. CHECK (level < 3.0 && level > -4.5);
  407. CHECK (dbOf (peakOf (wet.out)) <= inPeak + 3.5);
  408. if (blend == 0.0f)
  409. CHECK (std::abs (level) < 0.05);
  410. }
  411. }
  412. }
  413. // The installed instrument plugins as sounds (round 190dg): their category, the channel a pick makes, finding them again
  414. TEST (simple190dg_sound_library_plugins)
  415. {
  416. using namespace lynx;
  417. using soundlib::Category;
  418. CHECK (soundlib::pluginCategory ("Instrument|Synth", "Vital") == Category::synths);
  419. CHECK (soundlib::pluginCategory ("Instrument|Drum", "Battery") == Category::drums);
  420. CHECK (soundlib::pluginCategory ("Instrument|Piano", "Grand") == Category::keys);
  421. CHECK (soundlib::pluginCategory ("Instrument|Synth", "Keyscape") == Category::keys);
  422. CHECK (soundlib::pluginCategory ("Synth", "808 Studio") == Category::drums);
  423. CHECK (soundlib::pluginCategory ("Instrument|Synth|Sampler", "Orchestral Strings") == Category::strings);
  424. CHECK (soundlib::pluginCategory ("", "Sub Bass Machine") == Category::bass);
  425. CHECK (soundlib::pluginCategory ("Instrument|Organ", "B-3") == Category::organ);
  426. CHECK (soundlib::pluginCategory ("", "") == Category::synths);
  427. CHECK (std::string (soundlib::categoryName (Category::synths)).size() > 3);
  428. const auto list = soundlib::fromPlugins ({ { "VST3-Vital-1", "Vital", "Vital Audio", "VST3", "Instrument|Synth" },
  429. { "VST3-Drums-2", "Kit Maker", "Someone", "VST3", "Instrument|Drum" },
  430. { "", "No id", "", "", "" } });
  431. CHECK (list.size() == 2);
  432. for (const auto& s : list)
  433. CHECK (s.source == soundlib::Source::plugin && s.kind == InstrumentKind::plugin && ! s.pluginId.empty());
  434. const auto synths = soundlib::filter (list, Category::synths);
  435. CHECK (synths.size() == 1 && list[(std::size_t) synths[0]].name == "Vital" && list[(std::size_t) synths[0]].origin == "Vital Audio \xc2\xb7 VST3");
  436. CHECK (soundlib::filter (list, Category::drums, "kit").size() == 1 && soundlib::filter (list, Category::drums, "vital").empty());
  437. ChannelDef mine;
  438. mine.instrument = InstrumentKind::synth;
  439. mine.name = "My track";
  440. mine.volume = 0.42f;
  441. mine.mixerTrack = 5;
  442. const auto& vital = list[(std::size_t) synths[0]];
  443. const auto def = soundlib::withSound (mine, vital);
  444. CHECK (def.has_value());
  445. if (! def)
  446. return;
  447. CHECK (def->instrument == InstrumentKind::plugin && def->plugin.id == "VST3-Vital-1" && def->plugin.name == "Vital");
  448. CHECK (def->name == "My track" && def->volume == 0.42f && def->mixerTrack == 5); // the channel's own settings stay
  449. // a running plugin saves a state of its own: the pick is still found by its plugin
  450. auto running = *def;
  451. running.plugin.state = "c3RhdGU=";
  452. CHECK (soundlib::find (list, running) == synths[0]);
  453. running.plugin.id = "VST3-Other";
  454. CHECK (soundlib::find (list, running) == -1);
  455. CHECK (soundlib::auditionKeys (list[(std::size_t) soundlib::filter (list, Category::drums)[0]]) == std::vector<int> { 60 });
  456. }