Fix190eaTests.inc 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495
  1. // Round 190ea, two bugs found by round 190dv.
  2. // (1) A Song with no pattern at all crashed the docked Piano roll (PianoRollComponent::changeListenerCallback read the
  3. // current pattern of an empty list). FL always has a pattern: deleting the last one leaves an empty "Pattern 1".
  4. // Song::keepOnePattern is that invariant, AudioEngine::publishSong applies it to every song state the UI can see,
  5. // and Song::activePattern is the safe accessor the editors use. Here: every way a song can end up without a pattern
  6. // (delete, imports, templates, MIDI, the export copy) and the source guards; the app route --patterns190ea drives
  7. // the engine and the three layouts.
  8. // (2) The Master looks ended in Fruity Limiter, which holds sample peaks only: bright mixes left +0.8 … +3.3 dBTP.
  9. // Every look now ends in Apex Limiter with True peak on at −1 dBTP (core/MasterLooks.h). Measured here on the
  10. // 16× reference meter of round 190co (apexfix190co::reference16x). LYNX_190EA_REPORT=1 prints the numbers.
  11. #include <chrono>
  12. #include <cstdlib>
  13. #include "core/AlsImport.h"
  14. #include "core/ApexLimiter.h"
  15. #include "core/FlmImport.h"
  16. #include "core/FlpExport.h"
  17. #include "core/FlpImport.h"
  18. #include "core/Loudness.h"
  19. #include "core/MasterLooks.h"
  20. #include "core/MidiImport.h"
  21. #include "core/MixerOps.h"
  22. #include "core/RackOps.h"
  23. #include "core/ShowcaseSong.h"
  24. #include "core/Templates.h"
  25. namespace fix190ea
  26. {
  27. using namespace lynx;
  28. inline bool onePattern (const Song& s)
  29. {
  30. return ! s.patterns.empty() && s.currentPattern >= 0 && s.currentPattern < (int) s.patterns.size();
  31. }
  32. constexpr double rate = 48000.0;
  33. // a hot, bright drum loop: kick, clap and open hats on a 16th grid at 128 BPM, rim clicks, a sub on the kick; sample
  34. // peak −0.1 dBFS (as a loop out of a sample pack, already limited), stereo with the hats panned
  35. inline void hotDrums (std::vector<float>& l, std::vector<float>& r, double seconds)
  36. {
  37. const auto n = (std::size_t) (seconds * rate);
  38. std::vector<double> a (n, 0.0), b (n, 0.0);
  39. apexfix190co::Noise rnd { 190 };
  40. const double step = 60.0 / 128.0 / 4.0;
  41. for (int k = 0; k * step < seconds; ++k)
  42. {
  43. const auto at = (std::size_t) (k * step * rate);
  44. const auto put = [&] (std::size_t i, double left, double right) {
  45. if (at + i < n)
  46. a[at + i] += left, b[at + i] += right;
  47. };
  48. if (k % 4 == 0) // kick: a falling sine with a click
  49. for (std::size_t i = 0; i < (std::size_t) (0.25 * rate); ++i)
  50. {
  51. const double t = (double) i / rate;
  52. const double v = std::sin (2.0 * apexfix190co::pi * (45.0 * t + 160.0 / 35.0 * (1.0 - std::exp (-t * 35.0)))) * std::exp (-t * 9.0)
  53. + (i < 24 ? 0.6 * rnd.next() : 0.0);
  54. put (i, v, v);
  55. }
  56. if (k % 8 == 4) // clap: three noise bursts
  57. for (int burst = 0; burst < 3; ++burst)
  58. for (std::size_t i = 0; i < (std::size_t) (0.04 * rate); ++i)
  59. {
  60. const double v = 0.8 * rnd.next() * std::exp (-(double) i / (0.008 * rate));
  61. put (i + (std::size_t) (burst * 0.011 * rate), v, 0.9 * v);
  62. }
  63. // hats every 16th, the off-beats open: white noise through a one-zero high-pass (bright)
  64. {
  65. const auto len = (std::size_t) ((k % 2 == 1 ? 0.09 : 0.03) * rate);
  66. double prev = 0.0;
  67. for (std::size_t i = 0; i < len; ++i)
  68. {
  69. const double w = rnd.next();
  70. const double v = 0.45 * (w - prev) * std::exp (-(double) i / (len / 4.0));
  71. prev = w;
  72. put (i, 0.6 * v, v);
  73. }
  74. }
  75. if (k % 16 == 14) // a rim click: two full-scale samples of opposite sign
  76. put (0, 1.0, 1.0), put (1, -1.0, -1.0);
  77. }
  78. double peak = 0.0;
  79. for (std::size_t i = 0; i < n; ++i)
  80. peak = std::max ({ peak, std::abs (a[i]), std::abs (b[i]) });
  81. const double g = std::pow (10.0, -0.1 / 20.0) / peak;
  82. l.resize (n), r.resize (n);
  83. for (std::size_t i = 0; i < n; ++i)
  84. l[i] = (float) (a[i] * g), r[i] = (float) (b[i] * g);
  85. }
  86. // round 190cn's dense mix (low tones, thumps, noise bursts, clicks) at 0 dBFS sample peak, the right channel reversed
  87. inline void brightMix (std::vector<float>& l, std::vector<float>& r, double seconds)
  88. {
  89. l = apexfix190co::mix ((int) (seconds * rate), rate, 11);
  90. for (auto& v : l)
  91. v = std::clamp (v / 0.7079f, -1.0f, 1.0f);
  92. r.assign (l.rbegin(), l.rend());
  93. }
  94. // the slots one after the other, in blocks of 256 (as the mixer runs them); the effects' processing time in ms
  95. inline double runChain (const std::vector<EffectSlot>& chain, std::vector<float>& l, std::vector<float>& r)
  96. {
  97. std::vector<std::unique_ptr<Effect>> fx;
  98. for (const auto& s : chain)
  99. {
  100. fx.push_back (makeEffect (s));
  101. fx.back()->prepare (rate);
  102. }
  103. const auto start = std::chrono::steady_clock::now();
  104. for (std::size_t i = 0; i < l.size(); i += 256)
  105. {
  106. const int n = (int) std::min<std::size_t> (256, l.size() - i);
  107. for (std::size_t k = 0; k < fx.size(); ++k)
  108. fx[k]->process (l.data() + i, r.data() + i, n, chain[k].params, 128.0);
  109. }
  110. return std::chrono::duration<double, std::milli> (std::chrono::steady_clock::now() - start).count();
  111. }
  112. struct Measured
  113. {
  114. double truePeak = -200.0, lufs = -200.0, samplePeak = -200.0;
  115. };
  116. // true peak on the 16× reference (`reference`) or on LYNX's own meter (fixed in round 190co; faster)
  117. inline Measured measure (const std::vector<float>& l, const std::vector<float>& r, bool reference)
  118. {
  119. Measured m;
  120. if (reference)
  121. m.truePeak = std::max (apexfix190co::reference16x (l, 0, l.size()), apexfix190co::reference16x (r, 0, r.size()));
  122. loudness::Meter meter;
  123. meter.prepare (rate);
  124. auto a = l, b = r;
  125. for (std::size_t i = 0; i < a.size(); i += 512)
  126. meter.process (a.data() + i, b.data() + i, (int) std::min<std::size_t> (512, a.size() - i));
  127. meter.flushTruePeak();
  128. m.lufs = meter.integratedLoudness();
  129. if (! reference)
  130. m.truePeak = meter.truePeakDb();
  131. float peak = 0.0f;
  132. for (std::size_t i = 0; i < l.size(); ++i)
  133. peak = std::max ({ peak, std::abs (l[i]), std::abs (r[i]) });
  134. m.samplePeak = 20.0 * std::log10 (std::max (1e-12, (double) peak));
  135. return m;
  136. }
  137. // a Master with an EQ and an older project's four-slot look (no true-peak stage) at rows 1…4
  138. inline Song legacyLookSong (const MasterLookSettings& s)
  139. {
  140. Song song;
  141. song.mixer = Song::defaultMixer (2);
  142. auto eq = makeEffectSlot (EffectKind::eq);
  143. eq.row = 0;
  144. song.mixer[0].effects.push_back (eq);
  145. auto chain = looks::chain (s);
  146. chain.resize ((std::size_t) looks::legacySlots);
  147. int row = 1;
  148. for (auto& slot : chain)
  149. {
  150. slot.row = row++;
  151. song.mixer[0].effects.push_back (slot);
  152. }
  153. song.masterLook = s;
  154. return song;
  155. }
  156. } // namespace fix190ea
  157. // --- (1) at least one pattern --------------------------------------------------------------------------------------
  158. TEST (fix190ea_song_keeps_one_pattern)
  159. {
  160. using namespace lynx;
  161. using namespace fix190ea;
  162. Song bare; // what only code builds by hand (Song{}): no pattern
  163. CHECK (bare.patterns.empty());
  164. const auto& constBare = bare;
  165. CHECK (constBare.activePattern().notes.empty() && constBare.activePattern().events.empty()); // (no crash, no change)
  166. CHECK (bare.patterns.empty());
  167. CHECK (bare.keepOnePattern());
  168. CHECK (bare.patterns.size() == 1 && bare.patterns[0].name == "Pattern 1" && bare.currentPattern == 0);
  169. CHECK (! bare.keepOnePattern()); // (nothing more to do)
  170. // an index out of range is put back in range, both ways
  171. Song s;
  172. s.patterns.resize (3);
  173. s.currentPattern = 7;
  174. CHECK (std::addressof (std::as_const (s).activePattern()) == std::addressof (s.patterns[2])); // (const: read, clamped)
  175. CHECK (s.currentPattern == 7);
  176. CHECK (s.keepOnePattern() && s.currentPattern == 2);
  177. s.currentPattern = -4;
  178. CHECK (std::addressof (s.activePattern()) == std::addressof (s.patterns[0]) && s.currentPattern == 0);
  179. // the non-const accessor makes the pattern an edit writes into
  180. Song edit;
  181. edit.activePattern().notes.push_back ({});
  182. CHECK (edit.patterns.size() == 1 && edit.patterns[0].notes.size() == 1);
  183. }
  184. TEST (fix190ea_deleting_the_last_pattern_leaves_pattern_1)
  185. {
  186. using namespace lynx;
  187. using namespace fix190ea;
  188. auto s = Song::makeDefault();
  189. s.patterns.resize (3);
  190. s.patterns[1].notes.push_back ({});
  191. Clip clip;
  192. clip.pattern = 1;
  193. clip.length = ppq * 4;
  194. s.playlist.push_back (clip);
  195. s.currentPattern = 2;
  196. // Patterns › Delete one by one (MainComponent: s.removePattern (s.currentPattern))
  197. for (int k = 0; k < 5; ++k)
  198. {
  199. s.removePattern (s.currentPattern);
  200. CHECK (onePattern (s));
  201. }
  202. CHECK (s.patterns.size() == 1 && s.patterns[0].name == "Pattern 1" && s.patterns[0].notes.empty() && s.playlist.empty());
  203. // the picker's Delete unused / Merge identical (deletePatterns keeps one)
  204. auto t = Song::makeDefault();
  205. t.patterns.resize (4);
  206. CHECK (deletePatterns (t, { 0, 1, 2, 3 }) == 3 && onePattern (t));
  207. t.patterns.resize (4);
  208. deletePatterns (t, unusedPatterns (t));
  209. CHECK (onePattern (t));
  210. t.patterns.resize (4);
  211. mergeIdenticalPatterns (t);
  212. CHECK (onePattern (t));
  213. }
  214. TEST (fix190ea_new_projects_and_imports_have_a_pattern)
  215. {
  216. using namespace lynx;
  217. using namespace fix190ea;
  218. // File › New: every built-in template (Empty, Basic beat, Trap with 808, House) and the default song
  219. const auto names = templateNames();
  220. CHECK (names.size() >= 4 && builtInTemplateIndex ("Empty") >= 0);
  221. for (int i = 0; i < (int) names.size(); ++i)
  222. {
  223. CHECK (onePattern (makeTemplate (i)));
  224. CHECK (onePattern (makeNewProject (i)));
  225. }
  226. CHECK (onePattern (makeNewProject()) && onePattern (Song::makeDefault()));
  227. // an FL project with no pattern (FL itself always saves one; a hand-made or damaged file may not)
  228. CHECK (onePattern (importFlp (flp::Project {})));
  229. // an FL Studio Mobile project with none
  230. if (const auto flm = importFlmProject (flm::Project {}); flm)
  231. CHECK (onePattern (*flm));
  232. // a Live set with no track and no clip
  233. std::string error;
  234. const std::string set = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<Ableton MajorVersion=\"5\" MinorVersion=\"12.0_12117\" Creator=\"test\">"
  235. "<LiveSet><Tracks /><MainTrack><DeviceChain><DeviceChain><Devices /></DeviceChain></DeviceChain></MainTrack></LiveSet></Ableton>";
  236. const auto als = importAls (std::vector<std::uint8_t> (set.begin(), set.end()), {}, &error);
  237. CHECK (als.has_value());
  238. if (als)
  239. CHECK (onePattern (*als));
  240. // MIDI › Start new project: a file with no note is refused (nothing reaches the engine); one note gives one pattern
  241. midiimport::ParsedMidi midi;
  242. midiimport::Options o;
  243. o.newProject = true;
  244. Song fromMidi;
  245. CHECK (! midiimport::importInto (fromMidi, midi, o, "MIDI", error));
  246. midi.trackNames = { "Track 1" };
  247. midi.events.push_back ({ 0, 0, 0x90, 60, 100 });
  248. midi.events.push_back ({ 0, ppq, 0x80, 60, 0 });
  249. const bool imported = midiimport::importInto (fromMidi, midi, o, "MIDI", error);
  250. CHECK (imported);
  251. if (imported)
  252. CHECK (onePattern (fromMidi));
  253. // the export's copy of a song without a pattern
  254. std::int64_t ticks = 0;
  255. CHECK (onePattern (makeExportSong (Song {}, false, 0, ticks)));
  256. }
  257. TEST (fix190ea_engine_and_editors_keep_and_guard_the_pattern)
  258. {
  259. using namespace i18ntest;
  260. // the engine keeps the invariant on every publish (new / opened / imported song, edit, undo, redo, a remote song)
  261. // and right after an edit (before the edit's follow-ups read the current pattern)
  262. const auto engine = readFile ("src/engine/AudioEngine.cpp");
  263. const auto publish = engine.find ("void AudioEngine::publishSong()");
  264. CHECK (publish != std::string::npos);
  265. const auto keep = engine.find ("song.keepOnePattern();", publish);
  266. const auto normalize = engine.find ("uids::normalize (song);", publish);
  267. CHECK (keep != std::string::npos && normalize != std::string::npos && keep < normalize);
  268. const auto editSong = engine.find ("void AudioEngine::editSong (");
  269. const auto afterEdit = engine.find ("edit (song);\n song.keepOnePattern();", editSong);
  270. CHECK (editSong != std::string::npos && afterEdit != std::string::npos && afterEdit < engine.find ("void AudioEngine::editSongPatternOrder"));
  271. // the editors' current-pattern helpers go through the safe accessor
  272. const auto roll = readFile ("src/ui/PianoRollComponent.cpp");
  273. CHECK (roll.find ("const Pattern& currentPattern (const Song& s)\n{\n return s.activePattern();") != std::string::npos);
  274. CHECK (roll.find ("Pattern& currentPattern (Song& s)\n{\n return s.activePattern();") != std::string::npos);
  275. CHECK (readFile ("src/ui/EventEditor.cpp").find ("return engine.getSong().activePattern();") != std::string::npos);
  276. // no unchecked "song.patterns[(std::size_t) song.currentPattern]" is left in the UI
  277. for (const char* file : { "src/ui/PianoRollComponent.cpp", "src/ui/ChannelRackComponent.cpp", "src/ui/MainComponent.cpp", "src/ui/EditorTools.cpp",
  278. "src/ui/PlaylistComponent.cpp", "src/ui/ControllerBridge.cpp", "src/ui/EventEditor.cpp" })
  279. {
  280. const auto code = readFile (file);
  281. CHECK (! code.empty());
  282. for (const char* var : { "song", "s", "followSong" })
  283. {
  284. const auto unchecked = std::string (var) + ".patterns[(std::size_t) " + var + ".currentPattern]";
  285. if (code.find (unchecked) != std::string::npos)
  286. std::printf (" unchecked current pattern in %s: %s\n", file, unchecked.c_str());
  287. CHECK (code.find (unchecked) == std::string::npos);
  288. }
  289. CHECK (code.find ("engine.getSong().patterns[(std::size_t) engine.getSong().currentPattern]") == std::string::npos);
  290. }
  291. }
  292. // --- (2) the Master looks end true-peak safe ------------------------------------------------------------------------
  293. TEST (fix190ea_looks_end_in_a_true_peak_stage)
  294. {
  295. using namespace lynx;
  296. for (int id = 1; id <= looks::count; ++id)
  297. {
  298. const auto c = looks::chain (MasterLookSettings { id, 0.5f, { 0, 0, 0 }, 0 });
  299. CHECK (c.size() == (std::size_t) looks::chainSlots && looks::chainSlots == 5);
  300. if (c.size() != 5)
  301. continue;
  302. const auto& tp = c.back();
  303. CHECK (tp.kind == EffectKind::apexLimiter && tp.look == id);
  304. CHECK (apex::gainDb (tp.params[(std::size_t) apex::pGain]) == 0.0);
  305. CHECK (std::abs (apex::ceilingDb (tp.params[(std::size_t) apex::pCeiling]) - (double) (looks::trueCeilingDb - looks::truePeakMarginDb)) < 1e-4);
  306. CHECK (tp.params[(std::size_t) apex::pTruePeak] >= 0.5f);
  307. CHECK (apex::oversamplingFactor (tp.params[(std::size_t) apex::pOversampling]) == 1 && apex::ditherBits (tp.params[(std::size_t) apex::pDither]) == 0);
  308. }
  309. CHECK (looks::trueCeilingDb == -1.0f);
  310. // the showcase song (Demo.lynx, the website's demo.mp3) ends with the same stage, after its own Limiter
  311. const auto showcase = makeShowcaseSong();
  312. const auto& master = showcase.mixer[0].effects;
  313. CHECK (master.size() >= 2 && master.back().kind == EffectKind::apexLimiter && master.back().look == 0
  314. && master[master.size() - 2].kind == EffectKind::limiter && master.back().params == looks::truePeakStage().params);
  315. }
  316. // Below its ceiling the stage changes nothing but the time (its constant latency): the looks keep their sound
  317. TEST (fix190ea_true_peak_stage_is_transparent_below_the_ceiling)
  318. {
  319. using namespace lynx;
  320. using namespace fix190ea;
  321. const auto slot = looks::chain (MasterLookSettings { looks::balanced, 0.5f, { 0, 0, 0 }, 0 }).back();
  322. auto l = apexfix190co::mix ((int) rate, rate, 5), r = l;
  323. for (auto& v : l)
  324. v *= 0.25f; // peak −15 dBFS, true peak well under −1 dBTP
  325. std::reverse (r.begin(), r.end());
  326. for (auto& v : r)
  327. v *= 0.25f;
  328. const auto inL = l, inR = r;
  329. auto fx = makeEffect (slot);
  330. fx->prepare (rate);
  331. const auto latency = fx->latencySamples();
  332. CHECK (latency > 0 && latency < (int) (0.01 * rate)); // (a few ms: 5 ms look-ahead reach + the guard)
  333. for (std::size_t i = 0; i < l.size(); i += 256)
  334. fx->process (l.data() + i, r.data() + i, (int) std::min<std::size_t> (256, l.size() - i), slot.params, 120.0);
  335. double worst = 0.0;
  336. for (std::size_t i = (std::size_t) latency; i < l.size(); ++i)
  337. worst = std::max ({ worst, std::abs ((double) l[i] - inL[i - (std::size_t) latency]), std::abs ((double) r[i] - inR[i - (std::size_t) latency]) });
  338. if (worst > 1e-6)
  339. std::printf (" true-peak stage below its ceiling: largest difference %.3g\n", worst);
  340. CHECK (worst <= 1e-6); // (−120 dB)
  341. }
  342. TEST (fix190ea_every_look_holds_minus_1_dbtp)
  343. {
  344. using namespace lynx;
  345. using namespace fix190ea;
  346. const bool report = std::getenv ("LYNX_190EA_REPORT") != nullptr;
  347. std::vector<float> drumsL, drumsR, mixL, mixR;
  348. hotDrums (drumsL, drumsR, 2.0);
  349. brightMix (mixL, mixR, 1.5);
  350. double worstBefore = -200.0, worstAfter = -200.0, worstLoudness = 0.0, msBefore = 0.0, msAfter = 0.0;
  351. if (report)
  352. std::printf (" look intensity signal | before: dBTP LUFS | after: dBTP LUFS\n");
  353. for (int id = 1; id <= looks::count; ++id)
  354. for (const float intensity : { 0.25f, 0.5f, 0.85f, 1.0f })
  355. for (int signal = 0; signal < 2; ++signal)
  356. {
  357. if (intensity == 1.0f && id != looks::loud)
  358. continue; // (Heavy's trend beyond 0.85: the loudest look only, to keep the test short)
  359. const auto& inL = signal == 0 ? drumsL : mixL;
  360. const auto& inR = signal == 0 ? drumsR : mixR;
  361. auto chain = looks::chain (MasterLookSettings { id, intensity, { 0, 0, 0 }, 0 });
  362. auto legacy = chain;
  363. legacy.resize ((std::size_t) looks::legacySlots); // the 0.1.26 look (Fruity Limiter last)
  364. auto bl = inL, br = inR, al = inL, ar = inR;
  365. msBefore += runChain (legacy, bl, br);
  366. msAfter += runChain (chain, al, ar);
  367. const auto b = measure (bl, br, report), a = measure (al, ar, true);
  368. worstBefore = std::max (worstBefore, b.truePeak);
  369. worstAfter = std::max (worstAfter, a.truePeak);
  370. worstLoudness = std::max (worstLoudness, std::abs (a.lufs - b.lufs));
  371. if (report)
  372. std::printf (" %-12s %.2f %-7s | %+6.2f %6.2f | %+6.2f %6.2f\n", looks::name (id), intensity, signal == 0 ? "drums" : "mix",
  373. b.truePeak, b.lufs, a.truePeak, a.lufs);
  374. CHECK (a.truePeak <= (double) looks::trueCeilingDb + 0.005); // (the stated ceiling, on the 16× reference)
  375. CHECK (a.samplePeak <= (double) looks::trueCeilingDb);
  376. CHECK (std::abs (a.lufs - b.lufs) < 0.5); // only the overs are touched
  377. }
  378. if (report)
  379. std::printf (" worst true peak: before %+.2f dBTP, after %+.2f dBTP; loudness change at most %.2f LU; chain time %.0f -> %.0f ms\n",
  380. worstBefore, worstAfter, worstLoudness, msBefore, msAfter);
  381. CHECK (worstBefore > -0.5); // (the signals do show the bug on the four-slot look)
  382. CHECK (worstAfter <= (double) looks::trueCeilingDb + 0.005);
  383. }
  384. // Old projects: a look saved before this round keeps its four slots (nothing re-creates a look on load: the slots are
  385. // the project's own effects). Applying a look again gives the five-slot chain, in place where the next row is free.
  386. TEST (fix190ea_older_four_slot_looks)
  387. {
  388. using namespace lynx;
  389. using namespace fix190ea;
  390. const MasterLookSettings normal { looks::warmTape, 0.5f, { 1, 0, -1 }, -2 };
  391. auto song = legacyLookSong (normal);
  392. const auto saved = song.mixer[0].effects;
  393. CHECK (looks::present (song) && ! looks::custom (song) && ! looks::bypassed (song)); // (not "edited by hand")
  394. looks::setBypassed (song, true);
  395. CHECK (looks::bypassed (song));
  396. looks::setBypassed (song, false);
  397. CHECK (song.mixer[0].effects.size() == saved.size());
  398. // a user effect two rows after the look: the true-peak slot takes row 5, the user effect stays at row 7
  399. auto withAfter = song;
  400. auto delay = makeEffectSlot (EffectKind::delay);
  401. delay.row = 7;
  402. withAfter.mixer[0].effects.push_back (delay);
  403. looks::setBypassed (withAfter, true); // ("Hear without" is kept)
  404. const MasterLookSettings heavy { looks::warmTape, 0.85f, { 1, 0, -1 }, -2 };
  405. CHECK (looks::apply (withAfter, heavy));
  406. const auto& fx = withAfter.mixer[0].effects;
  407. CHECK (fx.size() == 7 && fx[5].kind == EffectKind::apexLimiter && fx[5].look == looks::warmTape && fx[5].row == 5);
  408. CHECK (fx[6].kind == EffectKind::delay && fx[6].row == 7 && fx[1].row == 1 && fx[4].row == 4);
  409. CHECK (looks::bypassed (withAfter) && ! looks::custom (withAfter) && withAfter.masterLook == heavy);
  410. const auto rows = mixerops::effectRows (fx);
  411. CHECK (std::is_sorted (rows.begin(), rows.end()) && std::adjacent_find (rows.begin(), rows.end()) == rows.end());
  412. // the row after the look is taken: that effect moves down one row (the order stays), still bypassed
  413. auto packed = legacyLookSong (normal);
  414. auto right = makeEffectSlot (EffectKind::delay);
  415. right.row = 5;
  416. packed.mixer[0].effects.push_back (right);
  417. right.row = 7;
  418. packed.mixer[0].effects.push_back (right);
  419. looks::setBypassed (packed, true);
  420. CHECK (looks::apply (packed, heavy));
  421. const auto& p = packed.mixer[0].effects;
  422. CHECK (p.size() == 8 && p[5].kind == EffectKind::apexLimiter && p[5].row == 5 && p[6].kind == EffectKind::delay && p[6].row == 6
  423. && p[7].row == 7);
  424. CHECK (looks::bypassed (packed) && ! looks::custom (packed));
  425. // no room at all (ten slots in use): nothing changes, the Finish dock says so
  426. auto full = legacyLookSong (normal);
  427. for (int row = 5; row < maxEffectSlots; ++row)
  428. {
  429. right.row = row;
  430. full.mixer[0].effects.push_back (right);
  431. }
  432. const auto before = full.mixer[0].effects.size();
  433. CHECK (before == (std::size_t) maxEffectSlots && ! looks::apply (full, heavy) && full.mixer[0].effects.size() == before && full.masterLook == normal);
  434. // a fresh chain when the old one is not in one piece: after the Master's last effect
  435. auto split = legacyLookSong (normal);
  436. split.mixer[0].effects.erase (split.mixer[0].effects.begin()); // (no EQ before it)
  437. auto mid = makeEffectSlot (EffectKind::delay);
  438. mid.row = 3;
  439. split.mixer[0].effects.insert (split.mixer[0].effects.begin() + 2, mid); // look, look, delay, look, look
  440. split.mixer[0].effects[3].row = 4, split.mixer[0].effects[4].row = 5;
  441. CHECK (looks::apply (split, heavy));
  442. CHECK (split.mixer[0].effects.size() == 6 && split.mixer[0].effects[0].look == 0 && split.mixer[0].effects.back().kind == EffectKind::apexLimiter);
  443. // a hand edit of an old look is still "Custom"
  444. auto edited = legacyLookSong (normal);
  445. edited.mixer[0].effects[2].params[6] = 0.1f;
  446. CHECK (looks::custom (edited));
  447. }
  448. TEST (fix190ea_fl_export_of_a_look)
  449. {
  450. using namespace lynx;
  451. auto song = Song::makeDefault();
  452. CHECK (looks::apply (song, MasterLookSettings { looks::balanced, 0.5f, { 0, 0, 0 }, 0 }));
  453. flpexport::Report report;
  454. const auto bytes = flpexport::exportFlp (song, {}, report);
  455. CHECK (! bytes.empty());
  456. // FL's four plugins are written exactly; the true-peak stage has no FL equivalent and is listed as left out
  457. int fl = 0;
  458. for (const auto& e : report.exact)
  459. for (const char* name : { "Fruity Parametric EQ 2", "Fruity Multiband Compressor", "Fruity Soft Clipper", "Fruity Limiter" })
  460. fl += e.find (name) != std::string::npos ? 1 : 0;
  461. CHECK (fl >= 4);
  462. CHECK (std::any_of (report.dropped.begin(), report.dropped.end(), [] (const std::string& d) { return d.find ("Apex Limiter") != std::string::npos; }));
  463. }