WorkflowP2Tests.inc 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. // Workflow P2 tests (docs/WORKFLOW_FL.md section 3.2, P2). Included at the end of tests.cpp.
  2. #include "core/History.h"
  3. #include "core/MixerOps.h"
  4. #include "core/NoteTools.h"
  5. #include "core/SearchQuery.h"
  6. namespace p2test
  7. {
  8. lynx::Note note (std::int64_t start, int key, std::int64_t length = lynx::ticksPerStep, int channel = 0, float velocity = 0.78f)
  9. {
  10. lynx::Note n;
  11. n.start = start;
  12. n.key = key;
  13. n.length = length;
  14. n.channel = channel;
  15. n.velocity = velocity;
  16. return n;
  17. }
  18. std::vector<int> all (const lynx::Pattern& p)
  19. {
  20. std::vector<int> out;
  21. for (int i = 0; i < (int) p.notes.size(); ++i)
  22. out.push_back (i);
  23. return out;
  24. }
  25. std::vector<int> stepsOf (const lynx::Pattern& p, int channel)
  26. {
  27. std::vector<int> out;
  28. for (const auto& n : p.notes)
  29. if (n.channel == channel)
  30. out.push_back ((int) (n.start / lynx::ticksPerStep));
  31. std::sort (out.begin(), out.end());
  32. return out;
  33. }
  34. } // namespace p2test
  35. TEST (p2_note_levels_roundtrip)
  36. {
  37. using namespace lynx::notetools;
  38. lynx::Note n;
  39. for (int l = 0; l < levelCount; ++l)
  40. {
  41. const auto level = (Level) l;
  42. CHECK (std::abs (levelValue (n, level) - levelDefault (level)) < 1e-6f);
  43. setLevelValue (n, level, 0.25f);
  44. CHECK (std::abs (levelValue (n, level) - 0.25f) < 1e-5f);
  45. }
  46. CHECK (std::abs (n.pan + 0.5f) < 1e-5f && std::abs (n.finePitch + 60.0f) < 1e-3f);
  47. setLevelValue (n, Level::velocity, 3.0f); // clamped
  48. CHECK (n.velocity == 1.0f);
  49. CHECK (levelIsBipolar (Level::pan) && ! levelIsBipolar (Level::velocity));
  50. }
  51. TEST (p2_scale_snap)
  52. {
  53. using namespace lynx::notetools;
  54. // C major (scale 1, root 0)
  55. CHECK (inScale (60, 0, 1) && ! inScale (61, 0, 1) && inScale (61, 0, 0));
  56. CHECK (snapToScale (61, 0, 1) == 60); // C# -> C (tie goes down)
  57. CHECK (snapToScale (66, 0, 1) == 65); // F# -> F
  58. CHECK (snapToScale (63, 0, 1) == 62); // D# -> D
  59. CHECK (snapToScale (61, 0, 0) == 61); // no scale
  60. // A minor pentatonic (scale 5, root 9): A C D E G
  61. CHECK (snapToScale (70, 9, 5) == 69); // A# -> A
  62. CHECK (snapToScale (71, 9, 5) == 72); // B -> C (one up beats two down)
  63. lynx::Pattern p;
  64. p.notes = { p2test::note (0, 61), p2test::note (0, 66) };
  65. snapNotesToScale (p, { 0, 1 }, 0, 1);
  66. CHECK (p.notes[0].key == 60 && p.notes[1].key == 65);
  67. }
  68. TEST (p2_strum)
  69. {
  70. using namespace lynx::notetools;
  71. lynx::Pattern p;
  72. p.notes = { p2test::note (0, 64, 960), p2test::note (0, 60, 960), p2test::note (0, 67, 960), p2test::note (960, 72, 480, 0) };
  73. StrumOptions o;
  74. o.spread = 30;
  75. o.velocityStep = 0.05f;
  76. strum (p, p2test::all (p), o);
  77. // low to high: 60 at 0, 64 at 30, 67 at 60; the ends stay at 960
  78. CHECK (p.notes[1].start == 0 && p.notes[0].start == 30 && p.notes[2].start == 60);
  79. CHECK (p.notes[0].start + p.notes[0].length == 960 && p.notes[2].length == 900);
  80. CHECK (std::abs (p.notes[2].velocity - 0.88f) < 1e-5f);
  81. CHECK (p.notes[3].start == 960); // a single note is not a chord
  82. lynx::Pattern q;
  83. q.notes = { p2test::note (0, 60), p2test::note (0, 64), p2test::note (480, 60), p2test::note (480, 64) };
  84. o.alternate = true;
  85. o.velocityStep = 0.0f;
  86. o.keepEnds = false;
  87. strum (q, p2test::all (q), o);
  88. CHECK (q.notes[0].start == 0 && q.notes[1].start == 30); // first chord: up
  89. CHECK (q.notes[3].start == 480 && q.notes[2].start == 510); // second chord: down
  90. CHECK (q.notes[2].length == lynx::ticksPerStep); // lengths kept
  91. }
  92. TEST (p2_arpeggiate)
  93. {
  94. using namespace lynx::notetools;
  95. lynx::Pattern p;
  96. p.notes = { p2test::note (0, 60, 960), p2test::note (0, 64, 960), p2test::note (0, 67, 960) };
  97. ArpeggiateOptions o;
  98. o.step = 240;
  99. o.gate = 0.5f;
  100. auto added = arpeggiate (p, p2test::all (p), o);
  101. CHECK (added.size() == 4 && p.notes.size() == 4);
  102. CHECK (p.notes[0].key == 60 && p.notes[1].key == 64 && p.notes[2].key == 67 && p.notes[3].key == 60);
  103. CHECK (p.notes[3].start == 720 && p.notes[0].length == 120);
  104. lynx::Pattern q;
  105. q.notes = { p2test::note (0, 60, 960), p2test::note (0, 64, 960) };
  106. o.direction = ArpeggiateOptions::upDown;
  107. o.octaves = 2;
  108. o.step = 120;
  109. arpeggiate (q, p2test::all (q), o);
  110. // run 60 64 72 76, then back down 72 64
  111. std::vector<int> keys;
  112. for (const auto& n : q.notes)
  113. keys.push_back (n.key);
  114. CHECK ((keys == std::vector<int> { 60, 64, 72, 76, 72, 64, 60, 64 }));
  115. lynx::Pattern single;
  116. single.notes = { p2test::note (0, 60, 960) };
  117. o.octaves = 1;
  118. CHECK (arpeggiate (single, { 0 }, o).empty() && single.notes.size() == 1); // nothing to arpeggiate
  119. }
  120. TEST (p2_flip)
  121. {
  122. using namespace lynx::notetools;
  123. lynx::Pattern p;
  124. p.notes = { p2test::note (0, 60, 240), p2test::note (480, 67, 480) }; // span 0..960, keys 60..67
  125. flip (p, { 0, 1 }, true, false);
  126. CHECK (p.notes[0].start == 720 && p.notes[1].start == 0);
  127. flip (p, { 0, 1 }, false, true);
  128. CHECK (p.notes[0].key == 67 && p.notes[1].key == 60);
  129. }
  130. TEST (p2_randomise_is_deterministic_and_bounded)
  131. {
  132. using namespace lynx::notetools;
  133. lynx::Pattern a;
  134. for (int i = 0; i < 32; ++i)
  135. a.notes.push_back (p2test::note (i * 240, 60, 240, 0, 0.5f));
  136. auto b = a;
  137. RandomiseOptions o;
  138. o.velocity = 0.2f;
  139. o.timing = 20;
  140. o.seed = 7;
  141. randomise (a, p2test::all (a), o);
  142. randomise (b, p2test::all (b), o);
  143. bool same = true, changed = false, bounded = true;
  144. for (std::size_t i = 0; i < a.notes.size(); ++i)
  145. {
  146. same = same && a.notes[i].velocity == b.notes[i].velocity && a.notes[i].start == b.notes[i].start;
  147. changed = changed || a.notes[i].velocity != 0.5f;
  148. bounded = bounded && std::abs (a.notes[i].velocity - 0.5f) <= 0.2f + 1e-6f && std::abs (a.notes[i].start - (std::int64_t) i * 240) <= 20
  149. && a.notes[i].start >= 0;
  150. }
  151. CHECK (same && changed && bounded);
  152. o.seed = 8;
  153. randomise (b, p2test::all (b), o);
  154. CHECK (b.notes[3].velocity != a.notes[3].velocity || b.notes[5].velocity != a.notes[5].velocity);
  155. // one-sided (FL's Bipolar off, live check 190cq): velocities only go up
  156. lynx::Pattern c;
  157. c.notes = { p2test::note (0, 60, 240, 0, 0.5f), p2test::note (240, 60, 240, 0, 0.5f), p2test::note (480, 60, 240, 0, 0.5f) };
  158. o.bipolar = false;
  159. o.timing = 0;
  160. randomise (c, p2test::all (c), o);
  161. CHECK (c.notes[0].velocity >= 0.5f && c.notes[1].velocity >= 0.5f && c.notes[2].velocity >= 0.5f);
  162. }
  163. TEST (p2_scale_levels_and_limit)
  164. {
  165. using namespace lynx::notetools;
  166. lynx::Pattern p;
  167. p.notes = { p2test::note (0, 60, 240, 0, 0.8f), p2test::note (480, 60, 240, 0, 0.8f), p2test::note (960, 60, 240, 0, 0.8f) };
  168. scaleLevels (p, p2test::all (p), Level::velocity, 1.0f, 0.0f, 0.0f); // fade out
  169. CHECK (std::abs (p.notes[0].velocity - 0.8f) < 1e-5f && std::abs (p.notes[1].velocity - 0.4f) < 1e-5f && p.notes[2].velocity == 0.0f);
  170. p.notes[0].pan = 0.5f;
  171. scaleLevels (p, { 0 }, Level::pan, 0.5f, 0.5f, 0.0f); // pan scales around the centre
  172. CHECK (std::abs (p.notes[0].pan - 0.25f) < 1e-5f);
  173. lynx::Pattern q;
  174. q.notes = { p2test::note (0, 30, 240, 0, 0.1f), p2test::note (0, 100, 240, 0, 0.95f), p2test::note (0, 60, 240, 0, 0.5f) };
  175. LimitOptions o;
  176. o.lowKey = 48;
  177. o.highKey = 72;
  178. o.minVelocity = 0.2f;
  179. o.maxVelocity = 0.9f;
  180. limit (q, p2test::all (q), o);
  181. CHECK (q.notes[0].key == 54 && q.notes[1].key == 64 && q.notes[2].key == 60); // moved by octaves (pitch class kept)
  182. CHECK (q.notes[0].velocity == 0.2f && q.notes[1].velocity == 0.9f && q.notes[2].velocity == 0.5f);
  183. o.lowKey = 60;
  184. o.highKey = 64; // narrower than an octave: moved by octaves as far as needed, then clamped (FL's law, round 190bw:
  185. // 54 goes one octave up to 66 and is clamped to the top)
  186. limit (q, p2test::all (q), o);
  187. CHECK (q.notes[0].key == 64 && q.notes[1].key == 64);
  188. }
  189. TEST (p2_euclidean_and_fill)
  190. {
  191. using lynx::euclideanRhythm;
  192. auto text = [] (const std::vector<bool>& r) {
  193. std::string s;
  194. for (auto b : r)
  195. s += b ? 'x' : '.';
  196. return s;
  197. };
  198. CHECK (text (euclideanRhythm (3, 8)) == "x..x..x.");
  199. CHECK (text (euclideanRhythm (4, 16)) == "x...x...x...x...");
  200. CHECK (text (euclideanRhythm (5, 8)) == "x.x.xx.x");
  201. CHECK (text (euclideanRhythm (3, 8, 1)) == ".x..x..x");
  202. CHECK (text (euclideanRhythm (3, 8, -1)) == "..x..x.x");
  203. CHECK (text (euclideanRhythm (0, 4)) == "...." && text (euclideanRhythm (9, 4)) == "xxxx" && euclideanRhythm (2, 0).empty());
  204. lynx::Pattern p;
  205. lynx::fillEverySteps (p, 1, 4, 16);
  206. CHECK ((p2test::stepsOf (p, 1) == std::vector<int> { 0, 4, 8, 12 }));
  207. lynx::fillEverySteps (p, 1, 2, 16, 2); // adds 2, 6, 10, 14; keeps the others
  208. CHECK (p2test::stepsOf (p, 1).size() == 8);
  209. // a rhythm replaces the step notes but keeps notes off the grid and other channels
  210. p.notes.push_back (p2test::note (100, 60, 60, 1));
  211. p.notes.push_back (p2test::note (0, 60, 240, 2));
  212. p.sortNotes();
  213. lynx::setStepRhythm (p, 1, euclideanRhythm (3, 8), 16);
  214. CHECK ((p2test::stepsOf (p, 1) == std::vector<int> { 0, 0, 3, 6, 8, 11, 14 })); // step 0 holds the off-grid note too
  215. CHECK (p2test::stepsOf (p, 2).size() == 1);
  216. lynx::Pattern r;
  217. r.notes = { p2test::note (0, 60, 240, 0), p2test::note (15 * lynx::ticksPerStep, 62, 240, 0), p2test::note (0, 60, 240, 1) };
  218. lynx::rotateSteps (r, 0, 1, 16);
  219. CHECK ((p2test::stepsOf (r, 0) == std::vector<int> { 0, 1 }) && p2test::stepsOf (r, 1) == std::vector<int> { 0 });
  220. lynx::rotateSteps (r, 0, -2, 16);
  221. CHECK ((p2test::stepsOf (r, 0) == std::vector<int> { 14, 15 }));
  222. CHECK (lynx::notesInStep (r, 0, 14).size() == 1 && lynx::notesInStep (r, 0, 3).empty());
  223. }
  224. TEST (p2_pattern_clone_and_move)
  225. {
  226. auto song = lynx::Song::makeDefault();
  227. song.patterns.push_back ({});
  228. song.patterns[1].name = "B";
  229. lynx::Clip c0, c1;
  230. c0.pattern = 0;
  231. c1.pattern = 1;
  232. song.playlist = { c0, c1 };
  233. const auto clone = lynx::clonePattern (song, 0);
  234. CHECK (clone == 1 && song.patterns.size() == 3 && song.currentPattern == 1);
  235. CHECK (song.patterns[1].notes.size() == song.patterns[0].notes.size() && song.patterns[1].name == song.patterns[0].name + " #2");
  236. CHECK (song.playlist[0].pattern == 0 && song.playlist[1].pattern == 2); // "B" moved down one
  237. CHECK (lynx::clonePattern (song, 0) == 1 && song.patterns[1].name == song.patterns[0].name + " #3");
  238. CHECK (lynx::movePattern (song, 3, -1)); // "B" up
  239. CHECK (song.patterns[2].name == "B" && song.playlist[1].pattern == 2);
  240. CHECK (! lynx::movePattern (song, 0, -1) && ! lynx::movePattern (song, 3, 1));
  241. song.currentPattern = 0;
  242. CHECK (lynx::movePattern (song, 0, 1) && song.currentPattern == 1 && song.playlist[0].pattern == 1);
  243. }
  244. TEST (p2_channel_sort_and_unused)
  245. {
  246. auto song = lynx::Song::makeDefault();
  247. song.channels.resize (4);
  248. song.channels[0].name = "kick";
  249. song.channels[1].name = "Bass";
  250. song.channels[2].name = "clap";
  251. song.channels[3].name = "Arp";
  252. song.channels[0].mixerTrack = 3;
  253. song.channels[1].mixerTrack = 1;
  254. song.channels[2].mixerTrack = 0;
  255. song.channels[3].mixerTrack = 2;
  256. CHECK ((lynx::channelSortOrder (song, lynx::ChannelSort::name) == std::vector<int> { 3, 1, 2, 0 }));
  257. CHECK ((lynx::channelSortOrder (song, lynx::ChannelSort::insert) == std::vector<int> { 1, 3, 0, 2 })); // Master last
  258. song.channels[0].colour = 0xff3d8fd1u; // blue
  259. song.channels[1].colour = 0xffd94a4fu; // red
  260. song.channels[2].colour = 0;
  261. song.channels[3].colour = 0xff3fae6au; // green
  262. CHECK ((lynx::channelSortOrder (song, lynx::ChannelSort::colour) == std::vector<int> { 1, 3, 0, 2 }));
  263. for (auto& p : song.patterns)
  264. p.notes.clear();
  265. song.patterns[0].notes = { p2test::note (0, 60, 240, 1) };
  266. lynx::Clip audio;
  267. audio.kind = lynx::ClipKind::audio;
  268. audio.channel = 3;
  269. song.playlist = { audio };
  270. CHECK ((lynx::unusedChannels (song) == std::vector<int> { 0, 2 }));
  271. }
  272. TEST (p2_mixer_swap_and_move)
  273. {
  274. auto song = lynx::Song::makeDefault();
  275. song.mixer = lynx::Song::defaultMixer (4);
  276. song.mixer[1].name = "one";
  277. song.mixer[2].name = "two";
  278. song.channels.resize (2);
  279. song.channels[0].mixerTrack = 1;
  280. song.channels[1].mixerTrack = 2;
  281. song.setRoute (1, 3, true, 0.5f);
  282. lynx::EffectSlot comp;
  283. comp.kind = lynx::EffectKind::compressor;
  284. comp.sidechain = 1;
  285. song.mixer[4].effects = { comp };
  286. lynx::Automation a;
  287. a.target = { lynx::AutomationTargetKind::mixerVolume, 2 };
  288. song.automations = { a };
  289. lynx::mixerops::swapTracks (song, 1, 2);
  290. CHECK (song.mixer[1].name == "two" && song.mixer[2].name == "one");
  291. CHECK (song.channels[0].mixerTrack == 2 && song.channels[1].mixerTrack == 1);
  292. CHECK (song.routes (2, 3) && ! song.routes (1, 3) && song.mixer[4].effects[0].sidechain == 2);
  293. CHECK (song.automations[0].target.index == 1);
  294. std::vector<int> selection { 2, 3 };
  295. CHECK (lynx::mixerops::moveTracks (song, selection, -1) && (selection == std::vector<int> { 1, 2 }));
  296. CHECK (song.mixer[1].name == "one" && song.mixer[3].name == "two");
  297. CHECK (! lynx::mixerops::moveTracks (song, selection, -1)); // the Master never moves
  298. selection = { 0 };
  299. CHECK (! lynx::mixerops::moveTracks (song, selection, 1));
  300. }
  301. TEST (p2_mixer_link_route_sidechain)
  302. {
  303. auto song = lynx::Song::makeDefault();
  304. song.mixer = lynx::Song::defaultMixer (3);
  305. song.channels.resize (3);
  306. auto inserts = lynx::mixerops::linkChannels (song, { 0, 1, 2 }, 2, true);
  307. CHECK ((inserts == std::vector<int> { 2, 3, 4 }) && song.mixer.size() == 5); // one insert added
  308. inserts = lynx::mixerops::linkChannels (song, { 0, 2 }, 1, false);
  309. CHECK ((inserts == std::vector<int> { 1, 1 }) && (lynx::mixerops::channelsOn (song, 1) == std::vector<int> { 0, 2 }));
  310. CHECK (lynx::mixerops::routeTo (song, { 2, 3 }, 4, false) == 2 && song.routes (2, 4) && song.routes (2, 0));
  311. CHECK (lynx::mixerops::routeTo (song, { 2 }, 1, true) == 1 && song.routes (2, 1) && ! song.routes (2, 4) && ! song.routes (2, 0));
  312. CHECK (lynx::mixerops::routeTo (song, { 4 }, 3, false) == 0); // 3 -> 4 already: a cycle
  313. lynx::EffectSlot comp;
  314. comp.kind = lynx::EffectKind::compressor;
  315. song.mixer[1].effects = { comp };
  316. CHECK (lynx::mixerops::sidechainTo (song, 3, 1) == 1 && song.mixer[1].effects[0].sidechain == 3);
  317. CHECK (song.routes (3, 1) && song.mixer[3].sends.back().level == 0.0f);
  318. const auto order = song.mixerOrder();
  319. CHECK (std::find (order.begin(), order.end(), 3) < std::find (order.begin(), order.end(), 1));
  320. }
  321. TEST (p2_effect_slot_move_and_switch)
  322. {
  323. auto song = lynx::Song::makeDefault();
  324. song.mixer = lynx::Song::defaultMixer (2);
  325. for (auto kind : { lynx::EffectKind::eq, lynx::EffectKind::delay, lynx::EffectKind::reverb })
  326. {
  327. lynx::EffectSlot s;
  328. s.kind = kind;
  329. song.mixer[1].effects.push_back (s);
  330. }
  331. lynx::Automation a;
  332. a.target = { lynx::AutomationTargetKind::effectParam, 1, 0, 3 };
  333. song.automations = { a };
  334. CHECK (lynx::mixerops::moveEffectSlot (song, 1, 0, 2));
  335. CHECK (song.mixer[1].effects[0].kind == lynx::EffectKind::delay && song.mixer[1].effects[2].kind == lynx::EffectKind::eq);
  336. CHECK (song.automations[0].target.slot == 2);
  337. CHECK (! lynx::mixerops::moveEffectSlot (song, 1, 0, 5));
  338. lynx::mixerops::setAllEffectsEnabled (song, 1, false);
  339. CHECK (! lynx::mixerops::anyEffectEnabled (song, 1));
  340. lynx::mixerops::setAllEffectsEnabled (song, 1, true);
  341. CHECK (lynx::mixerops::anyEffectEnabled (song, 1));
  342. }
  343. TEST (p2_history_labels)
  344. {
  345. const auto before = lynx::Song::makeDefault();
  346. auto after = before;
  347. after.patterns[0].notes.push_back (p2test::note (0, 60));
  348. CHECK (lynx::describeChangeText (before, after) == "Add notes: " + before.patterns[0].name);
  349. after = before;
  350. after.patterns[0].notes[0].velocity = 0.1f;
  351. CHECK (lynx::describeChangeText (before, after) == "Edit notes: " + before.patterns[0].name);
  352. after = before;
  353. after.channels[1].muted = true;
  354. CHECK (lynx::describeChangeText (before, after) == "Mute: " + before.channels[1].name);
  355. after = before;
  356. after.channels[1].volume = 0.2f;
  357. CHECK (lynx::describeChangeText (before, after) == "Channel level: " + before.channels[1].name);
  358. after = before;
  359. after.channels.pop_back();
  360. CHECK (std::string (lynx::describeChange (before, after).text) == "Delete channel");
  361. after = before;
  362. after.bpm = 99.0;
  363. CHECK (lynx::describeChangeText (before, after) == "Tempo");
  364. after = before;
  365. after.mixer[1].volume = 0.3f;
  366. CHECK (lynx::describeChangeText (before, after) == "Mixer level: " + before.mixer[1].name);
  367. after = before;
  368. after.playlist.push_back ({});
  369. CHECK (lynx::describeChangeText (before, after) == "Add clips");
  370. CHECK (lynx::describeChangeText (before, before) == "Edit");
  371. }
  372. TEST (p2_browser_search)
  373. {
  374. using lynx::search::matches;
  375. CHECK (matches ("", "anything.wav"));
  376. CHECK (matches ("kick", "Big KICK 01.wav") && ! matches ("kick", "snare.wav"));
  377. CHECK (matches ("kick 808", "808 Kick.wav") && ! matches ("kick 808", "909 Kick.wav"));
  378. CHECK (matches ("kick AND 808", "kick_808.wav"));
  379. CHECK (matches ("kick OR snare", "snare.wav") && matches ("kick OR snare", "kick.wav") && ! matches ("kick OR snare", "hat.wav"));
  380. CHECK (! matches ("kick -loop", "kick loop.wav") && matches ("kick -loop", "kick one.wav"));
  381. CHECK (! matches ("kick NOT loop", "kick loop.wav"));
  382. CHECK (matches ("\"808 kick\"", "my 808 kick.wav") && ! matches ("\"808 kick\"", "kick 808.wav"));
  383. CHECK (matches ("k*k.wav", "kick.wav") && ! matches ("k*k.wav", "kick.flac") && matches ("h?t*", "hat 01.wav"));
  384. CHECK (lynx::search::wildcardMatch ("*", "") && ! lynx::search::wildcardMatch ("?", ""));
  385. }
  386. TEST (p2_record_commit_take)
  387. {
  388. lynx::Pattern p;
  389. p.notes = { p2test::note (0, 60, 240, 0), p2test::note (0, 60, 240, 1) };
  390. std::vector<int> cleared;
  391. // overdub with record quantise to steps
  392. lynx::commitTake (p, { p2test::note (250, 62, 100, 0), p2test::note (130, 64, 100, 0) }, lynx::RecordMode::overdub, lynx::ticksPerStep, cleared);
  393. CHECK (p.notes.size() == 4 && p.notes[2].start == 240 && p.notes[3].start == 240);
  394. CHECK (p.notes[0].start == 0 && cleared.empty());
  395. // replace: the channel's old notes go once, notes from later in the same take stay
  396. lynx::commitTake (p, { p2test::note (480, 65, 100, 0) }, lynx::RecordMode::replace, 1, cleared);
  397. CHECK (p.notes.size() == 2 && (cleared == std::vector<int> { 0 }));
  398. lynx::commitTake (p, { p2test::note (720, 67, 100, 0) }, lynx::RecordMode::replace, 1, cleared);
  399. CHECK (p.notes.size() == 3 && p2test::stepsOf (p, 1).size() == 1);
  400. }
  401. TEST (p2_record_song_mode_clip_and_count_in)
  402. {
  403. auto song = lynx::Song::makeDefault();
  404. song.playlist.clear();
  405. const auto bar = (std::int64_t) lynx::ppq * song.beatsPerBar;
  406. CHECK (lynx::placePatternClipAt (song, 0, bar + 100));
  407. CHECK (song.playlist.size() == 1 && song.playlist[0].start == bar && song.playlist[0].track == 0);
  408. CHECK (! lynx::placePatternClipAt (song, 0, bar + 200)); // already covered
  409. song.patterns.emplace_back().name = "Other";
  410. lynx::Clip other;
  411. other.pattern = 1;
  412. other.start = 3 * bar;
  413. other.length = bar;
  414. song.playlist.push_back (other);
  415. CHECK (lynx::placePatternClipAt (song, 0, 3 * bar));
  416. CHECK (song.playlist.back().track == 1); // track 0 is busy there
  417. CHECK (lynx::countInLength (song, 2) == 2 * bar && lynx::countInLength (song, 0) == 0);
  418. }
  419. TEST (p2_ripple_and_time_range)
  420. {
  421. std::vector<lynx::Clip> clips (4);
  422. clips[0] = { 0, 0, 0, 100 };
  423. clips[1] = { 0, 0, 100, 50 };
  424. clips[2] = { 0, 0, 200, 50 };
  425. clips[3] = { 0, 1, 120, 50 }; // another track
  426. lynx::noteedit::rippleDelete (clips, { 1 });
  427. CHECK (clips.size() == 3 && clips[1].start == 150 && clips[2].start == 120);
  428. lynx::noteedit::rippleResize (clips, 0, 140);
  429. CHECK (clips[0].length == 140 && clips[1].start == 190 && clips[2].start == 120);
  430. std::vector<lynx::Clip> t (2);
  431. t[0] = { 0, 0, 0, 400 };
  432. t[1] = { 0, 1, 150, 50 };
  433. const auto moved = lynx::noteedit::moveTimeRange (t, 100, 300, 500, false);
  434. // clip 0 was cut at 100 and 300; its middle part and clip 1 moved by 500
  435. CHECK (t.size() == 4 && moved.size() == 2);
  436. CHECK (t[0].start == 0 && t[0].length == 100);
  437. bool middle = false, tail = false;
  438. for (const auto& c : t)
  439. {
  440. middle = middle || (c.track == 0 && c.start == 600 && c.length == 200 && c.offset == 100);
  441. tail = tail || (c.track == 0 && c.start == 300 && c.length == 100 && c.offset == 300);
  442. }
  443. CHECK (middle && tail && t[1].start == 650);
  444. std::vector<lynx::Clip> u (1);
  445. u[0] = { 0, 0, 100, 100 };
  446. const auto copies = lynx::noteedit::moveTimeRange (u, 0, 400, -1000, true);
  447. CHECK (copies.size() == 1 && u.size() == 2 && u[1].start == 100 && u[0].start == 100); // clamped: the selection starts at 0
  448. }
  449. TEST (p2_key_map_bindings)
  450. {
  451. using namespace lynx::keys;
  452. KeyMap map;
  453. CHECK (map.conflicts().empty());
  454. CHECK (map.find ({ f8, none }, Context::global, false) == "view.pluginPicker"); // F8 = FL's Plugin picker since round 169k
  455. CHECK (map.find ({ numpad3, none }, Context::playlist, true) == "pattern.select3");
  456. CHECK (map.find ({ 'C', alt }, Context::playlist, false) == "pattern.clone");
  457. CHECK (map.find ({ 'C', alt }, Context::pianoRoll, false) == "pianoRoll.colourSelected"); // FL's piano roll: Alt+C = colour (round 153)
  458. CHECK (map.find ({ 'C', alt }, Context::channelRack, false) == "rack.clone"); // the rack wins while focused
  459. CHECK (map.find ({ 'A', alt }, Context::pianoRoll, false) == "pianoRoll.arpeggiate");
  460. CHECK (map.find ({ '4', shift }, Context::playlist, true) == "playlist.zoomAll");
  461. CHECK (map.find ({ left, alt }, Context::mixer, false) == "mixer.moveLeft");
  462. CHECK (map.find ({ 'L', ctrl | shift }, Context::mixer, false) == "mixer.linkChannelsFrom");
  463. CHECK (map.find ({ 'I', ctrl }, Context::global, false) == "record.waitForInput");
  464. CHECK (toString ({ numpad7, none }) == "Numpad 7" && (parseChord ("Numpad 7") == Chord { numpad7, none }));
  465. }
  466. TEST (p2_playlist_tracks_and_chop)
  467. {
  468. auto song = lynx::Song::makeDefault();
  469. song.playlist.clear();
  470. lynx::Clip a, b, c;
  471. a.track = 0; a.length = 100;
  472. b.track = 1; b.length = 100;
  473. c.track = 2; c.length = 100;
  474. song.playlist = { a, b, c };
  475. song.playlistTracks.resize (2);
  476. song.playlistTracks[1].name = "B";
  477. lynx::noteedit::insertTrack (song, 1);
  478. CHECK (song.playlist[0].track == 0 && song.playlist[1].track == 2 && song.playlist[2].track == 3);
  479. CHECK (song.playlistTracks[2].name == "B" && song.playlistTracks[1].name.empty());
  480. lynx::noteedit::swapTracks (song, 2, 3);
  481. CHECK (song.playlist[1].track == 3 && song.playlist[2].track == 2 && song.playlistTracks[3].name == "B");
  482. lynx::noteedit::removeTrack (song, 2);
  483. CHECK (song.playlist.size() == 2 && song.playlist[1].track == 2 && song.playlistTracks[2].name == "B");
  484. lynx::noteedit::soloTrack (song, 1, 4);
  485. CHECK (! song.playlistTracks[1].muted && song.playlistTracks[0].muted && song.playlistTracks[3].muted);
  486. lynx::noteedit::soloTrack (song, 1, 4); // again: everything plays
  487. CHECK (! song.playlistTracks[0].muted && ! song.playlistTracks[3].muted);
  488. std::vector<lynx::Clip> clips (1);
  489. clips[0].start = 100;
  490. clips[0].length = 1000;
  491. const auto pieces = lynx::noteedit::chopClip (clips, 0, 480);
  492. CHECK (pieces.size() == 3 && clips[0].length == 380 && clips[1].start == 480 && clips[1].length == 480 && clips[2].start == 960
  493. && clips[2].length == 140 && clips[2].offset == 860);
  494. lynx::Pattern steps, roll;
  495. steps.notes = { p2test::note (0, 60), p2test::note (480, 60) };
  496. roll.notes = { p2test::note (0, 64) };
  497. CHECK (! lynx::hasPianoRollNotes (steps) && lynx::hasPianoRollNotes (roll));
  498. }