Comp177Tests.inc 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697
  1. // Round 177c: comping on take lanes — swipe, equal-power crossfades, used ranges, audition, flatten, more takes over a
  2. // comp (docs/analise/REA_rodada177c.md). Included at the end of tests.cpp (after Round166eTests.inc: its render helper).
  3. #include "core/Comping.h"
  4. #include "core/TakeRecording.h"
  5. namespace comp177
  6. {
  7. // three passes of a loop recording over [1000, 2000) on insert 2 ("Vox"), after "Comp these takes": comp track 0, lanes
  8. // 1..3 (take 1..3)
  9. inline lynx::Song loopTakes()
  10. {
  11. using namespace lynx;
  12. auto song = Song::makeDefault();
  13. song.mode = PlayMode::song;
  14. song.bpm = 120.0; // 5 ms = 10 ticks
  15. song.playlist.clear();
  16. while (song.mixer.size() < 4)
  17. song.mixer.emplace_back();
  18. song.mixer[2].name = "Vox";
  19. song.loopStart = 1000;
  20. song.loopEnd = 2000;
  21. const auto parts = takes::loopPasses (takes::place (1000.0, 2900.0, 0.04, 0), 1000, 2000);
  22. takes::placeTakeClips (song, { { "/rec/Vox_Take1.wav", "Vox_Take1", 2 } }, parts);
  23. comp::compTakes (song, 0);
  24. return song;
  25. }
  26. inline std::vector<lynx::Clip> onTrack (const lynx::Song& song, int track)
  27. {
  28. std::vector<lynx::Clip> out;
  29. for (const auto& c : song.playlist)
  30. if (c.track == track)
  31. out.push_back (c);
  32. std::sort (out.begin(), out.end(), [] (const lynx::Clip& a, const lynx::Clip& b) { return a.start < b.start; });
  33. return out;
  34. }
  35. // the audio-to-song alignment of a clip (which take it plays)
  36. inline std::int64_t alignment (const lynx::Clip& c) { return c.offset - c.start; }
  37. } // namespace comp177
  38. TEST (comp177_groups_and_loop_takes)
  39. {
  40. using namespace lynx;
  41. auto song = comp177::loopTakes();
  42. const auto g = comp::groupOf (song, 2);
  43. CHECK (g.valid() && g.comp == 0 && g.first == 1 && g.last == 3 && g.lanes() == 3);
  44. CHECK (comp::groupOf (song, 0).comp == 0 && comp::groupOf (song, 0).isLane (3) && ! comp::groupOf (song, 0).isLane (0));
  45. CHECK (! comp::groupOf (song, 4).valid() && ! comp::groupOf (song, -1).valid());
  46. CHECK (comp::crossfadeTicks (song) == 10);
  47. song.compCrossfadeMs = 0.0f;
  48. CHECK (comp::crossfadeTicks (song) == 0);
  49. song.compCrossfadeMs = Song::defaultCompCrossfadeMs;
  50. // every pass on a lane (oldest first), the last one also on the comp; the comp plays the last pass
  51. const auto c = comp177::onTrack (song, 0);
  52. CHECK (c.size() == 1 && ! c[0].muted && c[0].offset == 2000);
  53. CHECK (comp177::onTrack (song, 3).size() == 1 && comp177::onTrack (song, 3)[0].offset == 2000 && comp177::onTrack (song, 3)[0].muted);
  54. CHECK (comp177::onTrack (song, 1).size() == 1 && comp177::onTrack (song, 1)[0].offset == 0);
  55. const auto used = comp::usedRanges (song, g);
  56. CHECK (used.size() == 1 && used[0].lane == 3 && used[0].from == 1000 && used[0].to == 1900);
  57. }
  58. TEST (comp177_swipe_crossfades_and_back)
  59. {
  60. using namespace lynx;
  61. auto song = comp177::loopTakes();
  62. const auto original = comp177::onTrack (song, 0);
  63. // take 1 (lane 1) for [1200, 1500): three comp pieces, equal-power crossfades of 10 ticks centred on 1200 and 1500
  64. CHECK (comp::swipe (song, 1, 1200, 1500));
  65. auto c = comp177::onTrack (song, 0);
  66. CHECK (c.size() == 3);
  67. if (c.size() == 3)
  68. {
  69. CHECK (c[0].start == 1000 && c[0].end() == 1205 && c[0].fadeOut == 10 && c[0].fadeCurve == 2 && comp177::alignment (c[0]) == 1000);
  70. CHECK (c[1].start == 1195 && c[1].end() == 1505 && c[1].fadeIn == 10 && c[1].fadeOut == 10 && c[1].fadeCurve == 3
  71. && comp177::alignment (c[1]) == -1000 && ! c[1].muted);
  72. CHECK (c[2].start == 1495 && c[2].end() == 1900 && c[2].fadeIn == 10 && c[2].fadeCurve == 1 && comp177::alignment (c[2]) == 1000);
  73. }
  74. const auto g = comp::groupOf (song, 0);
  75. auto used = comp::usedRanges (song, g);
  76. std::sort (used.begin(), used.end(), [] (const comp::Used& a, const comp::Used& b) { return a.from < b.from; });
  77. CHECK (used.size() == 3);
  78. if (used.size() == 3)
  79. CHECK (used[0].lane == 3 && used[0].to == 1200 && used[1].lane == 1 && used[1].from == 1200 && used[1].to == 1500
  80. && used[2].lane == 3 && used[2].from == 1500 && used[2].to == 1900);
  81. // the same swipe again changes nothing; a swipe across a switch moves it
  82. CHECK (! comp::swipe (song, 1, 1200, 1500));
  83. CHECK (comp::swipe (song, 2, 1400, 1600)); // take 2 over the second switch
  84. c = comp177::onTrack (song, 0);
  85. CHECK (c.size() == 4 && c[1].end() == 1405 && c[2].start == 1395 && c[2].end() == 1605 && comp177::alignment (c[2]) == 0
  86. && c[3].start == 1595 && comp177::alignment (c[3]) == 1000);
  87. // another crossfade length re-applies to every switch; 0 = hard cuts
  88. comp::applyCrossfades (song, 0, 0);
  89. c = comp177::onTrack (song, 0);
  90. CHECK (c.size() == 4 && c[0].end() == 1200 && c[1].start == 1200 && c[1].fadeIn == 0 && c[0].fadeCurve == 0 && c[3].start == 1600);
  91. comp::applyCrossfades (song, 0, 40);
  92. c = comp177::onTrack (song, 0);
  93. CHECK (c.size() == 4 && c[0].end() == 1220 && c[1].start == 1180 && c[1].fadeIn == 40 && c[1].fadeCurve == 3);
  94. // the last take over the whole range: back to the original comp
  95. CHECK (comp::swipe (song, 3, 1000, 1900));
  96. CHECK (comp177::onTrack (song, 0).size() == 1 && comp177::onTrack (song, 0)[0].start == original[0].start
  97. && comp177::onTrack (song, 0)[0].length == original[0].length && comp177::onTrack (song, 0)[0].offset == original[0].offset
  98. && comp177::onTrack (song, 0)[0].fadeCurve == 0);
  99. // invalid: the comp track itself, an empty range, a track outside any group
  100. CHECK (! comp::swipe (song, 0, 1000, 1200) && ! comp::swipe (song, 3, 1500, 1500) && ! comp::swipe (song, 7, 1000, 1200));
  101. }
  102. TEST (comp177_crossfade_limits_and_gaps)
  103. {
  104. using namespace lynx;
  105. auto song = comp177::loopTakes();
  106. // a 4-tick piece gets at most a 2-tick crossfade on each side
  107. CHECK (comp::swipe (song, 1, 1300, 1304));
  108. auto c = comp177::onTrack (song, 0);
  109. CHECK (c.size() == 3 && c[1].fadeIn == 4 && c[1].fadeOut == 4 && c[1].start == 1298 && c[1].end() == 1306);
  110. // a lane with a gap: the comp is cleared where the lane has no take
  111. song = comp177::loopTakes();
  112. for (auto& clip : song.playlist)
  113. if (clip.track == 1)
  114. clip.length = 300; // take 1 = [1000, 1300)
  115. CHECK (comp::swipe (song, 1, 1200, 1500));
  116. c = comp177::onTrack (song, 0);
  117. CHECK (c.size() == 3 && c[1].start == 1195 && c[1].end() == 1300 && c[1].fadeOut == 0 && c[2].start == 1500 && c[2].fadeIn == 0);
  118. // a comp crossfade keeps its curve while FL's automatic crossfades are on
  119. song = comp177::loopTakes();
  120. song.autoCrossfades = true;
  121. CHECK (comp::swipe (song, 1, 1200, 1500));
  122. clipops::updateCrossfades (song);
  123. for (const auto& clip : comp177::onTrack (song, 0))
  124. CHECK (clip.crossfadeIn == 0 && clip.crossfadeOut == 0);
  125. }
  126. TEST (comp177_equal_power_render)
  127. {
  128. using namespace lynx;
  129. for (int k = 0; k <= 10; ++k)
  130. {
  131. const auto x = (float) k / 10.0f;
  132. CHECK (std::abs (clipops::equalPowerCurve (x) * clipops::equalPowerCurve (x) + clipops::equalPowerCurve (1.0f - x) * clipops::equalPowerCurve (1.0f - x) - 1.0f) < 1e-5f);
  133. }
  134. // one take channel (constant 1.0), two lanes of it, the second swiped in from beat 2: a 100 ms crossfade
  135. auto make = [] (bool muteA, bool muteB) {
  136. auto s = round166e::overlapSong (false);
  137. s.playlist.clear();
  138. s.playlistTracks.resize (3);
  139. s.playlistTracks[1].grouped = s.playlistTracks[2].grouped = true;
  140. s.playlist.push_back (round166e::audioClip (1, 0, 4 * ppq));
  141. s.playlist.push_back (round166e::audioClip (2, 0, 4 * ppq));
  142. s.playlist[0].muted = s.playlist[1].muted = true;
  143. s.compCrossfadeMs = 100.0f; // 192 ticks = 4800 samples
  144. comp::swipe (s, 1, 0, 4 * ppq);
  145. comp::swipe (s, 2, 2 * ppq, 4 * ppq);
  146. for (auto& c : s.playlist)
  147. if (c.track == 0)
  148. c.muted = (c.start == 0 && muteA) || (c.start != 0 && muteB);
  149. return s;
  150. };
  151. const auto a = make (false, true), b = make (true, false);
  152. const auto full = round166e::levelAt (a, 1.0);
  153. CHECK (full > 0.1f);
  154. // levelAt(2.0) reads sample 187·256 + 255 = 48127; the crossfade runs over samples [45600, 50400)
  155. const auto t = (48127.0f - 45600.0f) / 4800.0f;
  156. const auto la = round166e::levelAt (a, 2.0) / full, lb = round166e::levelAt (b, 2.0) / full;
  157. CHECK (std::abs (la - clipops::equalPowerCurve (1.0f - t)) < 0.01f);
  158. CHECK (std::abs (lb - clipops::equalPowerCurve (t)) < 0.01f);
  159. CHECK (std::abs (la * la + lb * lb - 1.0f) < 0.02f); // constant power
  160. }
  161. TEST (comp177_audition_flatten_and_more_takes)
  162. {
  163. using namespace lynx;
  164. auto song = comp177::loopTakes();
  165. const auto tps = ticksPerSample (120.0, 48000.0);
  166. auto playing = [&] (const Song& s) {
  167. EventBuffer ev;
  168. scheduleSong (s, 1100.0, 1000, tps, ev, true);
  169. std::vector<int> tracks;
  170. for (const auto& e : ev)
  171. if (e.type == NoteEvent::Type::on && e.key >= audioClipKeyBase)
  172. tracks.push_back (s.playlist[(std::size_t) (e.key - audioClipKeyBase)].track);
  173. return tracks;
  174. };
  175. CHECK (playing (song) == std::vector<int> { 0 });
  176. comp::setAudition (song, 3);
  177. CHECK (song.auditionLane == 3 && song.auditionComp == 0);
  178. CHECK (playing (song) == std::vector<int> { 3 }); // the lane (its take is muted) instead of the comp
  179. comp::setAudition (song, 0); // the comp track is no lane: off
  180. CHECK (song.auditionLane == -1 && playing (song) == std::vector<int> { 0 });
  181. // flatten: the comp stays, the lanes go, the tracks below move up
  182. Clip below;
  183. below.pattern = 0;
  184. below.track = 9;
  185. below.length = 100;
  186. song.playlist.push_back (below);
  187. CHECK (comp::isComp (song, 0));
  188. CHECK (comp::flatten (song, 0));
  189. CHECK (! comp::isComp (song, 0) && ! song.playlistTracks[0].compTrack);
  190. CHECK (! comp::groupOf (song, 0).valid() && comp177::onTrack (song, 0).size() == 1 && comp177::onTrack (song, 6).size() == 1
  191. && comp177::onTrack (song, 6)[0].kind == ClipKind::pattern && song.playlist.size() == 2);
  192. CHECK (! comp::flatten (song, 0));
  193. }
  194. TEST (comp177_fl_loop_take_layout)
  195. {
  196. using namespace lynx;
  197. // what FL 26 leaves after a loop recording (REA round 177c §2.1)
  198. auto song = Song::makeDefault();
  199. song.mode = PlayMode::song;
  200. song.bpm = 120.0;
  201. song.playlist.clear();
  202. while (song.mixer.size() < 4)
  203. song.mixer.emplace_back();
  204. song.mixer[2].name = "Vox";
  205. const auto clean = song;
  206. const auto parts = takes::loopPasses (takes::place (1000.0, 2900.0, 0.04, 0), 1000, 2000);
  207. CHECK (parts.size() == 3);
  208. // Blend off: one track per pass, the first on top as an open group's header; every pass muted, the last too
  209. takes::placeTakeClips (song, { { "/rec/a.wav", "a", 2 } }, parts);
  210. CHECK (song.playlist.size() == 3);
  211. for (const auto& c : song.playlist)
  212. CHECK (c.muted);
  213. for (int t = 0; t < 3; ++t)
  214. CHECK (comp177::onTrack (song, t).size() == 1 && comp177::onTrack (song, t)[0].offset == t * 1000);
  215. CHECK (! song.playlistTracks[0].grouped && ! song.playlistTracks[0].collapsed && song.playlistTracks[1].grouped && song.playlistTracks[2].grouped);
  216. CHECK (song.playlistTracks[0].mode == PlaylistTrackMode::unassigned && song.playlistTracks[0].mixerTrack == -1);
  217. CHECK (song.channels.back().mixerTrack == 2);
  218. CHECK (! song.playlistTracks[0].compTrack);
  219. // no comp yet: nothing can write over the first pass
  220. CHECK (takes::compTrackOf (song, 2) == -1);
  221. int lastPass = -1;
  222. for (int i = 0; i < (int) song.playlist.size(); ++i)
  223. if (song.playlist[(std::size_t) i].track == 2)
  224. lastPass = i;
  225. CHECK (! takes::promoteTake (song, lastPass, 0, 1000, 1100));
  226. // recording again over it: a new group on the next tracks free in that range; nothing replaced, no track moved
  227. Clip other;
  228. other.pattern = 0;
  229. other.track = 5;
  230. other.length = 100;
  231. song.playlist.push_back (other);
  232. const auto before = song.playlist;
  233. const auto tracksBefore = song.playlistTracks.size();
  234. takes::placeTakeClips (song, { { "/rec/b.wav", "b", 2 } }, parts);
  235. CHECK (song.playlist.size() == before.size() + 3);
  236. for (std::size_t i = 0; i < before.size(); ++i)
  237. CHECK (song.playlist[i].track == before[i].track && song.playlist[i].start == before[i].start);
  238. CHECK (comp177::onTrack (song, 3).size() == 1 && comp177::onTrack (song, 4).size() == 1 && comp177::onTrack (song, 3)[0].offset == 0);
  239. CHECK (comp177::onTrack (song, 5).size() == 2); // the pattern clip (ticks 0-100) is outside this range
  240. CHECK (! song.playlistTracks[3].grouped && song.playlistTracks[4].grouped && song.playlistTracks[5].grouped);
  241. CHECK (comp::groupOf (song, 0).last == 2 && tracksBefore <= song.playlistTracks.size());
  242. // rows stay "Track N": the insert's name is not used (R10)
  243. CHECK (song.playlistTracks[0].name.empty() && song.playlistTracks[1].name.empty() && song.playlistTracks[2].name.empty());
  244. // the first track free in the range, not the first after everything (R11, R12): nothing plays at tick 5000 yet
  245. {
  246. auto later = song;
  247. takes::Part far;
  248. far.start = 5000;
  249. far.length = 100;
  250. takes::TakeOptions loop;
  251. loop.loopRecord = true;
  252. const auto count = later.playlist.size();
  253. takes::placeTakeClips (later, { { "/rec/c.wav", "c", 2 } }, { far }, loop);
  254. CHECK (later.playlist.size() == count + 1 && later.playlist.back().track == 0);
  255. }
  256. // a named first track: the other passes take its name (R13)
  257. {
  258. auto named = clean;
  259. named.playlistTracks.resize (1);
  260. named.playlistTracks[0].name = "REC";
  261. takes::placeTakeClips (named, { { "/rec/a.wav", "a", 2 } }, parts);
  262. CHECK (named.playlistTracks[0].name == "REC" && named.playlistTracks[1].name == "REC" && named.playlistTracks[2].name == "REC");
  263. }
  264. // started in the middle of the loop (R11): the first pass goes to the first track free in its part of the loop and stays
  265. // what that track was, the next passes follow below it and join its group
  266. {
  267. auto mid = clean;
  268. Clip early;
  269. early.kind = ClipKind::audio;
  270. early.channel = 0;
  271. early.track = 2;
  272. early.start = 1000;
  273. early.length = 200;
  274. Clip a = early, b = early;
  275. a.track = 0, a.length = 1000;
  276. b.track = 1, b.length = 1000;
  277. mid.playlist = { a, b, early };
  278. mid.playlistTracks.resize (3);
  279. mid.playlistTracks[1].grouped = mid.playlistTracks[2].grouped = true;
  280. std::vector<takes::Part> passes (2);
  281. passes[0].start = 1500, passes[0].length = 500, passes[0].offset = 0;
  282. passes[1].start = 1000, passes[1].length = 1000, passes[1].offset = 500;
  283. takes::placeTakeClips (mid, { { "/rec/m.wav", "m", 2 } }, passes);
  284. const auto row2 = comp177::onTrack (mid, 2), row3 = comp177::onTrack (mid, 3);
  285. CHECK (row2.size() == 2 && row2[1].start == 1500 && row3.size() == 1 && row3[0].start == 1000);
  286. CHECK (mid.playlistTracks[2].grouped && mid.playlistTracks[3].grouped && comp::groupOf (mid, 0).last == 3);
  287. }
  288. // passes that don't overlap (R12): still one track per pass, in a new group
  289. {
  290. auto apart = clean;
  291. std::vector<takes::Part> passes (2);
  292. passes[0].start = 1500, passes[0].length = 500;
  293. passes[1].start = 1000, passes[1].length = 100, passes[1].offset = 500;
  294. takes::TakeOptions loop;
  295. loop.loopRecord = true;
  296. takes::placeTakeClips (apart, { { "/rec/n.wav", "n", 2 } }, passes, loop);
  297. CHECK (comp177::onTrack (apart, 0).size() == 1 && comp177::onTrack (apart, 1).size() == 1 && ! apart.playlistTracks[0].grouped && apart.playlistTracks[1].grouped);
  298. for (const auto& c : apart.playlist)
  299. CHECK (c.muted);
  300. }
  301. // never onto a comp group: it must keep what it plays
  302. {
  303. auto comped = clean;
  304. takes::placeTakeClips (comped, { { "/rec/a.wav", "a", 2 } }, parts);
  305. comp::compTakes (comped, 0);
  306. takes::Part far;
  307. far.start = 5000;
  308. far.length = 100;
  309. takes::TakeOptions loop;
  310. loop.loopRecord = true;
  311. takes::placeTakeClips (comped, { { "/rec/c.wav", "c", 2 } }, { far }, loop);
  312. CHECK (comped.playlist.back().track == 4);
  313. }
  314. // stopped just past a pass boundary: FL keeps even a 1-tick pass, on its own track, muted
  315. song = clean;
  316. takes::placeTakeClips (song, { { "/rec/a.wav", "a", 2 } }, takes::loopPasses (takes::place (1000.0, 2010.0, 0.04, 0), 1000, 2000));
  317. CHECK (song.playlist.size() == 3 && comp177::onTrack (song, 2).size() == 1 && comp177::onTrack (song, 2)[0].length == 10 && comp177::onTrack (song, 2)[0].muted);
  318. // Blend on: every pass plays
  319. song = clean;
  320. takes::TakeOptions blend;
  321. blend.blend = blend.loopRecord = true;
  322. takes::placeTakeClips (song, { { "/rec/a.wav", "a", 2 } }, parts, blend);
  323. CHECK (song.playlist.size() == 3);
  324. for (const auto& c : song.playlist)
  325. CHECK (! c.muted);
  326. // a lone pass: muted when loop recording with Blend off (R1), playing without Loop record (R4); no group either way
  327. takes::Part part;
  328. part.start = 1000;
  329. part.length = 226;
  330. song = clean;
  331. takes::TakeOptions loop;
  332. loop.loopRecord = true;
  333. takes::placeTakeClips (song, { { "/rec/a.wav", "a", 2 } }, { part }, loop);
  334. CHECK (song.playlist.size() == 1 && song.playlist[0].muted && ! comp::groupOf (song, 0).valid());
  335. song = clean;
  336. takes::placeTakeClips (song, { { "/rec/a.wav", "a", 2 } }, { part });
  337. CHECK (song.playlist.size() == 1 && ! song.playlist[0].muted);
  338. }
  339. TEST (comp177_comp_these_takes)
  340. {
  341. using namespace lynx;
  342. auto song = Song::makeDefault();
  343. song.mode = PlayMode::song;
  344. song.bpm = 120.0;
  345. song.playlist.clear();
  346. while (song.mixer.size() < 4)
  347. song.mixer.emplace_back();
  348. song.mixer[2].name = "Vox";
  349. Clip above, below;
  350. above.pattern = below.pattern = 0;
  351. above.track = 0;
  352. above.start = 1000;
  353. above.length = 1000;
  354. below.track = 5;
  355. below.length = 100;
  356. song.playlist = { above, below };
  357. song.playlistTracks.resize (1);
  358. song.playlistTracks[0].name = "Drums";
  359. const auto parts = takes::loopPasses (takes::place (1000.0, 2900.0, 0.04, 0), 1000, 2000);
  360. takes::placeTakeClips (song, { { "/rec/a.wav", "a", 2 } }, parts);
  361. CHECK (comp177::onTrack (song, 1).size() == 1 && comp177::onTrack (song, 3).size() == 1);
  362. CHECK (! comp::canComp (song, 0) && comp::canComp (song, 2));
  363. CHECK (comp::compTakes (song, 0) == -1); // no group there
  364. const auto beforeComp = song;
  365. CHECK (comp::compTakes (song, 3) == 1);
  366. // the undo step is named for what it does
  367. CHECK (std::string (describeChange (beforeComp, song).text) == "Comp takes");
  368. // one comp track above the group: what is above it stays, the group moves down by one
  369. CHECK (song.playlistTracks[1].compTrack && song.playlistTracks[1].name == "Track 2 comp" && ! song.playlistTracks[1].grouped
  370. && ! song.playlistTracks[1].collapsed);
  371. CHECK (comp177::onTrack (song, 0).size() == 1 && comp177::onTrack (song, 6).size() == 1);
  372. CHECK (song.playlistTracks[0].name == "Drums");
  373. for (int k = 0; k < 3; ++k)
  374. {
  375. const auto lane = comp177::onTrack (song, 2 + k);
  376. CHECK (lane.size() == 1 && lane[0].muted && lane[0].offset == k * 1000);
  377. CHECK (song.playlistTracks[(std::size_t) (2 + k)].grouped && song.playlistTracks[(std::size_t) (2 + k)].name == "Track 2 (take " + std::to_string (k + 1) + ")");
  378. }
  379. const auto c = comp177::onTrack (song, 1);
  380. CHECK (c.size() == 1 && ! c[0].muted && c[0].offset == 2000 && c[0].length == 900);
  381. CHECK (comp::isComp (song, 1) && ! comp::canComp (song, 3) && takes::compTrackOf (song, 3) == 1);
  382. CHECK (comp::compTakes (song, 3) == -1);
  383. // a take recorded over it does not join it
  384. const auto lanes = comp::groupOf (song, 1).lanes();
  385. takes::placeTakeClips (song, { { "/rec/b.wav", "b", 2 } }, parts);
  386. CHECK (comp::groupOf (song, 1).lanes() == lanes && comp177::onTrack (song, 1).size() == 1 && comp177::onTrack (song, 1)[0].offset == 2000);
  387. // every pass was playing (Blend on), and FL's own takes have one channel per pass: all muted, the newest channel plays
  388. song = Song::makeDefault();
  389. song.playlist.clear();
  390. while (song.mixer.size() < 4)
  391. song.mixer.emplace_back();
  392. for (int k = 0; k < 2; ++k)
  393. {
  394. ChannelDef take;
  395. take.instrument = InstrumentKind::audioClip;
  396. take.samplePath = "/rec/fl" + std::to_string (k) + ".wav";
  397. song.channels.push_back (take);
  398. Clip clip;
  399. clip.kind = ClipKind::audio;
  400. clip.channel = (int) song.channels.size() - 1;
  401. clip.track = k;
  402. clip.start = 1000;
  403. clip.length = 500;
  404. song.playlist.push_back (clip);
  405. }
  406. song.playlistTracks.resize (2);
  407. song.playlistTracks[1].grouped = true;
  408. const auto newest = (int) song.channels.size() - 1;
  409. CHECK (comp::compTakes (song, 0) == 0);
  410. CHECK (comp177::onTrack (song, 0).size() == 1 && comp177::onTrack (song, 0)[0].channel == newest);
  411. CHECK (comp177::onTrack (song, 1)[0].muted && comp177::onTrack (song, 2)[0].muted);
  412. CHECK (song.playlistTracks[0].name == "Track 1 comp" && song.playlistTracks[1].name == "Track 1 (take 1)" && song.playlistTracks[2].name == "Track 1 (take 2)");
  413. }
  414. TEST (comp177_existing_projects_do_not_change)
  415. {
  416. using namespace lynx;
  417. // a project saved before round 177c: loop takes in round 163's layout, with no comp mark
  418. auto song = Song::makeDefault();
  419. song.mode = PlayMode::song;
  420. song.bpm = 120.0;
  421. song.playlist.clear();
  422. while (song.mixer.size() < 4)
  423. song.mixer.emplace_back();
  424. song.mixer[2].name = "Gtr";
  425. takes::TakeOptions old;
  426. old.lastPassPlays = true;
  427. takes::placeTakeClips (song, { { "/rec/g.wav", "g", 2 } }, takes::loopPasses (takes::place (1000.0, 2900.0, 0.04, 0), 1000, 2000), old);
  428. CHECK (song.playlistTracks[0].collapsed && song.playlistTracks[1].grouped && ! song.playlistTracks[0].compTrack);
  429. // (saving and loading it without a comp mark: --selftest, comp_crossfades)
  430. // its promote still works, without a comp mark
  431. CHECK (takes::compTrackOf (song, 1) == 0 && ! comp::isComp (song, 0));
  432. // "Comp these takes" on it keeps every pass: the last pass was only on the header, it becomes a lane too
  433. auto comped = song;
  434. CHECK (comp::compTakes (comped, 1) == 0);
  435. CHECK (comped.playlist.size() == 4 && comp::groupOf (comped, 0).lanes() == 3);
  436. CHECK (comp177::onTrack (comped, 0).size() == 1 && comp177::onTrack (comped, 0)[0].offset == 2000 && ! comp177::onTrack (comped, 0)[0].muted);
  437. CHECK (comp177::onTrack (comped, 1)[0].offset == 2000 && comp177::onTrack (comped, 1)[0].muted);
  438. CHECK (comped.playlistTracks[1].mode == PlaylistTrackMode::unassigned);
  439. // (round 163 named the group's header after its insert, "Gtr": a header name is kept, as a user's is)
  440. CHECK (comped.playlistTracks[1].name == "Gtr (take 3)" && comped.playlistTracks[3].name == "Gtr (take 1)");
  441. // a header the user named gives its name: "<name> comp", "<name> (take N)"
  442. auto named = song;
  443. named.playlistTracks[0].name = "Lead";
  444. CHECK (comp::compTakes (named, 1) == 0);
  445. CHECK (named.playlistTracks[0].name == "Lead comp" && named.playlistTracks[1].name == "Lead (take 3)");
  446. }
  447. TEST (comp177_a_take_never_replaces_clips_of_an_ordinary_group)
  448. {
  449. using namespace lynx;
  450. // a track group the user made: the header's clip is on no lane, so a take recorded over it must not touch it
  451. auto song = Song::makeDefault();
  452. song.mode = PlayMode::song;
  453. song.playlist.clear();
  454. while (song.mixer.size() < 4)
  455. song.mixer.emplace_back();
  456. song.playlistTracks.resize (2);
  457. song.playlistTracks[0].mode = PlaylistTrackMode::audio;
  458. song.playlistTracks[0].mixerTrack = 2;
  459. song.playlistTracks[1].grouped = true;
  460. ChannelDef own;
  461. own.instrument = InstrumentKind::audioClip;
  462. own.samplePath = "/rec/own.wav";
  463. song.channels.push_back (own);
  464. Clip mine;
  465. mine.kind = ClipKind::audio;
  466. mine.channel = (int) song.channels.size() - 1;
  467. mine.track = 0;
  468. mine.start = 1000;
  469. mine.length = 900;
  470. song.playlist.push_back (mine);
  471. takes::Part part;
  472. part.start = 1200;
  473. part.length = 300;
  474. takes::placeTakeClips (song, { { "/rec/t.wav", "t", 2 } }, { part });
  475. const auto header = comp177::onTrack (song, 0);
  476. CHECK (header.size() == 1 && header[0].start == 1000 && header[0].length == 900 && header[0].channel == mine.channel);
  477. CHECK (comp::groupOf (song, 0).lanes() == 1); // no lane was added
  478. // round 190ir: FL's rule (FLEngine FUN_012aa4d0): the linked audio track is busy there, so the take goes to the first
  479. // free track grouped right under it (its sub-track), Track 2; the group's own clips stay as they are
  480. CHECK (song.playlist.size() == 2 && song.playlist.back().track == 1);
  481. }
  482. TEST (comp177_fl_clip_mute_survives_import_and_export)
  483. {
  484. using namespace lynx;
  485. // FL's item flag 0x2000 = muted clip (FL's Mute tool toggled it, and FL leaves loop-recorded takes muted when "Blend
  486. // recorded notes" is off): such a clip must stay silent in LYNX and come back muted in FL
  487. auto song = comp177::loopTakes();
  488. int muted = 0, playing = 0;
  489. for (const auto& c : song.playlist)
  490. ++(c.muted ? muted : playing);
  491. CHECK (muted == 3 && playing == 1);
  492. flpexport::Options options;
  493. flpexport::Report report;
  494. const auto project = flp::parseProject (flpexport::exportFlp (song, options, report));
  495. CHECK (project.arrangements.size() == 1);
  496. if (project.arrangements.size() == 1)
  497. {
  498. CHECK (project.arrangements[0].items.size() == 4);
  499. int flagged = 0;
  500. for (const auto& item : project.arrangements[0].items)
  501. flagged += item.muted() ? 1 : 0;
  502. CHECK (flagged == 3);
  503. }
  504. const auto back = importFlp (project, {});
  505. int mutedBack = 0;
  506. for (const auto& c : back.playlist)
  507. mutedBack += c.muted ? 1 : 0;
  508. CHECK (back.playlist.size() == 4 && mutedBack == 3);
  509. }
  510. TEST (comp177_blend_starts_off_only_for_new_installs)
  511. {
  512. using lynx::RecordMode;
  513. // a new install: FL's factory default
  514. CHECK (lynx::startingRecordMode (false, false, false) == RecordMode::replace);
  515. // (the engine's own default, AudioEngine::RecordOptions, is not in the test binary: the guarded GUI session checked it)
  516. // settings from before 0.1.25 have no answer, and those sessions always started on: nothing changes for them
  517. CHECK (lynx::startingRecordMode (true, false, false) == RecordMode::overdub);
  518. // from then on, the saved answer is what counts
  519. CHECK (lynx::startingRecordMode (true, true, true) == RecordMode::overdub);
  520. CHECK (lynx::startingRecordMode (true, true, false) == RecordMode::replace);
  521. }
  522. TEST (comp177_audition_ends_when_rows_move_and_before_a_render)
  523. {
  524. using namespace lynx;
  525. Song song;
  526. song.playlistTracks.resize (4);
  527. song.playlistTracks[0].compTrack = true;
  528. song.playlistTracks[1].grouped = song.playlistTracks[2].grouped = song.playlistTracks[3].grouped = true;
  529. song.playlistTracks[1].name = "take 1";
  530. song.playlistTracks[2].name = "take 2";
  531. song.playlistTracks[3].name = "take 3";
  532. comp::setAudition (song, 2);
  533. CHECK (song.auditionLane == 2 && song.auditionComp == 0);
  534. {
  535. // an edit that leaves the rows alone keeps it, one that changes it is not undone
  536. auto s = song;
  537. auto before = comp::auditionedTrack (s);
  538. s.bpm = 90.0;
  539. comp::checkAudition (s, before);
  540. CHECK (s.auditionLane == 2);
  541. before = comp::auditionedTrack (s);
  542. comp::setAudition (s, 3);
  543. comp::checkAudition (s, before);
  544. CHECK (s.auditionLane == 3);
  545. }
  546. {
  547. // a row removed above it: that row now holds another take
  548. auto s = song;
  549. const auto before = comp::auditionedTrack (s);
  550. s.playlistTracks.erase (s.playlistTracks.begin() + 1);
  551. comp::checkAudition (s, before);
  552. CHECK (s.auditionLane == -1 && s.auditionComp == -1);
  553. }
  554. {
  555. // a row inserted above the comp: the lane's row is another row now
  556. auto s = song;
  557. const auto before = comp::auditionedTrack (s);
  558. s.playlistTracks.insert (s.playlistTracks.begin(), PlaylistTrack {});
  559. comp::checkAudition (s, before);
  560. CHECK (s.auditionLane == -1);
  561. }
  562. {
  563. // nothing auditioned: nothing to compare
  564. Song s;
  565. CHECK (comp::auditionedTrack (s).lane == -1);
  566. comp::checkAudition (s, comp::auditionedTrack (s));
  567. CHECK (s.auditionLane == -1);
  568. }
  569. // a render plays the song, not the audition
  570. std::int64_t music = 0, loop = 0;
  571. song.playlist.push_back ([] { Clip c; c.kind = ClipKind::audio; c.track = 0; c.length = 960; return c; }());
  572. const auto rendered = exportopts::makeRenderSong (song, exportopts::Options {}, 0, music, loop);
  573. CHECK (rendered.auditionLane == -1 && rendered.auditionComp == -1);
  574. }
  575. TEST (comp177_undo_labels_for_the_comp_steps)
  576. {
  577. using namespace lynx;
  578. Song before;
  579. before.playlistTracks.resize (3);
  580. before.playlistTracks[0].compTrack = true;
  581. before.playlistTracks[1].grouped = before.playlistTracks[2].grouped = true;
  582. for (int t = 0; t < 3; ++t)
  583. {
  584. Clip c;
  585. c.kind = ClipKind::audio;
  586. c.track = t;
  587. c.length = 960;
  588. before.playlist.push_back (c);
  589. }
  590. auto after = before;
  591. CHECK (comp::flatten (after, 0));
  592. CHECK (std::string (describeChange (before, after).text) == "Flatten comp");
  593. // a swipe: only the comp track's clips change
  594. auto swiped = before;
  595. swiped.playlist[0].length = 480;
  596. CHECK (std::string (describeChange (before, swiped).text) == "Swipe to comp");
  597. // an edit of a lane clip is an ordinary clip edit
  598. auto edited = before;
  599. edited.playlist[1].length = 480;
  600. CHECK (std::string (describeChange (before, edited).text) == "Edit clips");
  601. }
  602. TEST (comp177_three_ways_to_swipe)
  603. {
  604. using namespace lynx;
  605. // the user's choice (2026-11-07): every way works
  606. CHECK (comp::swipeStyle == comp::SwipeStyle::both);
  607. // 1. a plain drag (the pencil) and 2. a Draw-mode drag (the brush) both swipe
  608. CHECK (comp::dragSwipes (comp::swipeStyle, false) && comp::dragSwipes (comp::swipeStyle, true));
  609. // (Live's own way would leave the pencil alone)
  610. CHECK (! comp::dragSwipes (comp::SwipeStyle::liveSelectEnter, false) && comp::dragSwipes (comp::SwipeStyle::liveSelectEnter, true));
  611. // 3. a time selection sent to the comp, the same edit as a swipe of that range
  612. CHECK (comp::selectionSwipes (comp::swipeStyle) && ! comp::selectionSwipes (comp::SwipeStyle::quickSwipe));
  613. auto song = comp177::loopTakes(); // comp track 0, lanes 1..3
  614. const auto c = 0;
  615. CHECK (comp::isComp (song, c));
  616. const auto g = comp::groupOf (song, c);
  617. auto bySelection = song, bySwipe = song;
  618. bySelection.loopStart = 1200;
  619. bySelection.loopEnd = 1500;
  620. bySwipe.loopStart = 1200;
  621. bySwipe.loopEnd = 1500;
  622. CHECK (comp::swipeSelection (bySelection, g.first));
  623. CHECK (comp::swipe (bySwipe, g.first, 1200, 1500));
  624. CHECK (bySelection.playlist.size() == bySwipe.playlist.size());
  625. for (std::size_t i = 0; i < bySwipe.playlist.size() && i < bySelection.playlist.size(); ++i)
  626. CHECK (bySelection.playlist[i].track == bySwipe.playlist[i].track && bySelection.playlist[i].start == bySwipe.playlist[i].start
  627. && bySelection.playlist[i].length == bySwipe.playlist[i].length && bySelection.playlist[i].offset == bySwipe.playlist[i].offset);
  628. // no time selection, the comp track itself, an ordinary group: nothing happens
  629. auto none = song;
  630. none.loopStart = none.loopEnd = 0;
  631. CHECK (! comp::swipeSelection (none, g.first));
  632. auto onComp = song;
  633. onComp.loopStart = 1200;
  634. onComp.loopEnd = 1500;
  635. CHECK (! comp::swipeSelection (onComp, c));
  636. auto plain = song; // the same rows as an ordinary group: no comp mark
  637. plain.playlistTracks[0].compTrack = false;
  638. plain.loopStart = 1200;
  639. plain.loopEnd = 1500;
  640. const auto before = plain.playlist.size();
  641. CHECK (! comp::swipeSelection (plain, 1) && plain.playlist.size() == before);
  642. // the command: in the shortcut editor, no default key; Enter stays FL's "Maximize or restore the Playlist"
  643. const auto* action = keys::findAction ("playlist.swipeSelectionToComp");
  644. CHECK (action != nullptr && action->defaults.empty());
  645. keys::KeyMap map;
  646. CHECK (map.find ({ keys::enter, keys::none }, keys::Context::global, false) == "panel.maximisePlaylist");
  647. }