Issues190htTests.inc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. // Round 190ht: issue #127 phase 2 (the other Playlist tools on FL 10's Pattern Blocks: Mute, Select + group move,
  2. // Slice) and issue #154 (the linked headers' insert effects list, core/TrackInserts.h). docs/analise/REA_rodada190ht.md
  3. #include "core/DetailChain.h"
  4. #include "core/History.h"
  5. #include "core/PatternBlocks.h"
  6. #include "core/TrackInserts.h"
  7. namespace iss190ht
  8. {
  9. constexpr std::int64_t bar = 4 * lynx::ppq;
  10. // P1: 1 bar (a note per beat), P2: 2 bars (a note on beat 1 and a long note from beat 7 to the end), P3: 1 bar
  11. inline lynx::Song song()
  12. {
  13. lynx::Song s;
  14. s.channels.resize (1);
  15. s.patterns.resize (3);
  16. for (int i = 0; i < 3; ++i)
  17. s.patterns[(std::size_t) i].name = "P" + std::to_string (i + 1);
  18. for (int step : { 0, 4, 8, 12 })
  19. s.patterns[0].toggleStep (0, step);
  20. s.patterns[1].toggleStep (0, 0);
  21. lynx::Note longNote;
  22. longNote.start = 6 * lynx::ppq;
  23. longNote.length = 2 * lynx::ppq;
  24. s.patterns[1].notes.push_back (longNote);
  25. s.patterns[1].sortNotes();
  26. s.patterns[2].toggleStep (0, 0);
  27. s.patternBlocksOn = true;
  28. s.mode = lynx::PlayMode::song;
  29. return s;
  30. }
  31. } // namespace iss190ht
  32. TEST (iss190ht_mute_tool_mutes_blocks_and_their_clips)
  33. {
  34. using namespace lynx;
  35. using iss190ht::bar;
  36. auto s = iss190ht::song();
  37. CHECK (patternblocks::place (s, 0, 0) && patternblocks::place (s, 0, bar) && patternblocks::place (s, 2, 0));
  38. // a sweep over bars 1-2 of every row finds the three blocks; row 0 alone, two
  39. CHECK (patternblocks::blocksInRange (s, -1, 0, bar + 5).size() == 3);
  40. CHECK (patternblocks::blocksInRange (s, 0, bar + 5, 0).size() == 2); // (either order)
  41. const auto i = (std::size_t) patternblocks::indexOf (s, { 0, bar });
  42. CHECK (patternblocks::setMuted (s, i, true));
  43. CHECK (! patternblocks::setMuted (s, i, true)); // (already so: no change)
  44. CHECK (! patternblocks::setMuted (s, 99, true));
  45. // the block stays where it is; its clip is muted, the others play
  46. CHECK (s.blocks.size() == 3 && s.blocks[i].muted);
  47. const auto clips = patternblocks::asClips (s);
  48. int muted = 0;
  49. for (const auto& c : clips)
  50. muted += c.muted ? 1 : 0;
  51. CHECK (clips.size() == 3 && muted == 1);
  52. // moving keeps the mute; a block in place of a muted one is the same block (normalize ignores the mute)
  53. CHECK (patternblocks::move (s, 0, bar, 3 * bar) == 3 * bar);
  54. CHECK (s.blocks[(std::size_t) patternblocks::indexOf (s, { 0, 3 * bar })].muted);
  55. auto twice = s.blocks;
  56. twice.push_back ({ 0, 3 * bar, false });
  57. patternblocks::normalize (twice, 3);
  58. CHECK (twice.size() == 3);
  59. // turned into clips, the block is a muted clip (FL's clip mute)
  60. auto copy = s;
  61. CHECK (patternblocks::toClips (copy) == 3);
  62. muted = 0;
  63. for (const auto& c : copy.playlist)
  64. muted += c.muted ? 1 : 0;
  65. CHECK (muted == 1);
  66. // the undo step is named
  67. auto before = s;
  68. patternblocks::setMuted (s, (std::size_t) patternblocks::indexOf (s, { 2, 0 }), true);
  69. CHECK (std::string (describeChange (before, s).text) == "Mute pattern blocks");
  70. }
  71. TEST (iss190ht_muted_block_plays_nothing)
  72. {
  73. using namespace lynx;
  74. auto s = iss190ht::song();
  75. CHECK (patternblocks::place (s, 0, 0));
  76. auto played = s;
  77. patternblocks::expandSong (played);
  78. CHECK (played.playlist.size() == 1 && ! played.playlist[0].muted);
  79. patternblocks::setMuted (s, 0, true);
  80. auto silent = s;
  81. patternblocks::expandSong (silent);
  82. CHECK (silent.playlist.size() == 1 && silent.playlist[0].muted);
  83. }
  84. TEST (iss190ht_select_tool_area_and_group_move)
  85. {
  86. using namespace lynx;
  87. using iss190ht::bar;
  88. auto s = iss190ht::song();
  89. CHECK (patternblocks::place (s, 0, 0) && patternblocks::place (s, 1, 0) && patternblocks::place (s, 2, 2 * bar) && patternblocks::place (s, 0, 4 * bar));
  90. // a box over rows 0-1, bars 1-2 meets P1@1 and P2@1 (2 bars long); rows given either way round
  91. auto area = patternblocks::inArea (s, 1, 0, bar / 2, bar + 10);
  92. CHECK (area.size() == 2);
  93. CHECK (patternblocks::contains (area, { 0, 0 }) && patternblocks::contains (area, { 1, 0 }));
  94. CHECK (! patternblocks::contains (area, { 2, 2 * bar }));
  95. // the box over every row
  96. CHECK (patternblocks::inArea (s, 0, 2, 0, 5 * bar).size() == 4);
  97. // the group moves by a bar, each block in its own row; the mute goes with a block
  98. patternblocks::setMuted (s, (std::size_t) patternblocks::indexOf (s, { 1, 0 }), true);
  99. area = patternblocks::inArea (s, 0, 1, 0, bar - 1);
  100. const auto moved = patternblocks::moveGroup (s, area, bar);
  101. CHECK (moved.has_value() && moved->size() == 2);
  102. CHECK (patternblocks::indexOf (s, { 0, bar }) >= 0 && patternblocks::indexOf (s, { 1, bar }) >= 0);
  103. CHECK (patternblocks::indexOf (s, { 0, 0 }) < 0 && patternblocks::indexOf (s, { 1, 0 }) < 0);
  104. CHECK (s.blocks[(std::size_t) patternblocks::indexOf (s, { 1, bar })].muted);
  105. CHECK (s.blocks.size() == 4);
  106. // a block of the group would meet one that stays (P1@5 when P1 goes to bar 5): nothing moves
  107. const auto before = s.blocks;
  108. CHECK (! patternblocks::moveGroup (s, *moved, 3 * bar).has_value());
  109. CHECK (s.blocks == before);
  110. // nothing goes before bar 1: the group keeps its shape
  111. CHECK (! patternblocks::moveGroup (s, *moved, -2 * bar).has_value());
  112. CHECK (s.blocks == before);
  113. // a group of blocks one bar apart in the same row can move over its own places
  114. auto row = iss190ht::song();
  115. CHECK (patternblocks::place (row, 0, 0) && patternblocks::place (row, 0, bar));
  116. const auto both = patternblocks::inArea (row, 0, 0, 0, 2 * bar - 1);
  117. CHECK (both.size() == 2 && patternblocks::moveGroup (row, both, bar).has_value());
  118. CHECK (patternblocks::indexOf (row, { 0, bar }) >= 0 && patternblocks::indexOf (row, { 0, 2 * bar }) >= 0 && row.blocks.size() == 2);
  119. // a block that is gone (undo) makes no move
  120. CHECK (! patternblocks::moveGroup (row, { { 2, 0 } }, bar).has_value());
  121. }
  122. TEST (iss190ht_slice_tool_cuts_the_pattern_into_two)
  123. {
  124. using namespace lynx;
  125. using iss190ht::bar;
  126. auto s = iss190ht::song();
  127. s.currentPattern = 2;
  128. s.patterns[1].events.push_back ({});
  129. s.patterns[1].events[0].events = { { 0, 0.2f }, { 2 * bar, 0.9f } };
  130. CHECK (patternblocks::place (s, 1, 0) && patternblocks::place (s, 1, 4 * bar) && patternblocks::place (s, 2, 0));
  131. patternblocks::setMuted (s, (std::size_t) patternblocks::indexOf (s, { 1, 4 * bar }), true);
  132. Clip clip; // a clip of P3 keeps playing P3 after the patterns move down
  133. clip.kind = ClipKind::pattern;
  134. clip.pattern = 2;
  135. clip.length = bar;
  136. s.playlist.push_back (clip);
  137. const auto before = s;
  138. // cut P2 (2 bars) at bar 2 beat 4 (7 beats in): the cut is inside the pattern
  139. CHECK (patternblocks::slice (s, 1, 0) < 0 && patternblocks::slice (s, 1, 2 * bar) < 0 && patternblocks::slice (s, 7, ppq) < 0);
  140. CHECK (s.patterns.size() == 3);
  141. const auto cut = bar + 3 * ppq;
  142. CHECK (patternblocks::slice (s, 1, cut) == 2);
  143. CHECK (s.patterns.size() == 4);
  144. const auto& head = s.patterns[1];
  145. const auto& tail = s.patterns[2];
  146. // the pattern keeps the first note and the long note shortened at the cut (FL 10 trims it, no second half)
  147. CHECK (head.notes.size() == 2 && head.notes[0].start == 0);
  148. CHECK (head.notes[1].start == 6 * ppq && head.notes[1].length == cut - 6 * ppq && cut - 6 * ppq == ppq);
  149. // the new pattern has what started at or after the cut (nothing here: the long note started before)
  150. CHECK (tail.notes.empty() && tail.name == "P2 #2");
  151. // events: the first stays, the later one moves to the new pattern's start
  152. CHECK (head.events.size() == 1 && head.events[0].events.size() == 1);
  153. CHECK (tail.events.size() == 1 && tail.events[0].events.size() == 1 && tail.events[0].events[0].tick == 2 * bar - cut);
  154. // automatic lengths stay automatic: the head plays 2 bars still (7 beats round up), the tail 1 bar
  155. CHECK (head.lengthTicks == 0 && patternblocks::lengthOf (s, 1) == 2 * bar && patternblocks::lengthOf (s, 2) == bar);
  156. // every block of P2 gets a block of the new pattern where it ends, muted like it; P3's block and clip follow P3
  157. CHECK (patternblocks::indexOf (s, { 2, 2 * bar }) >= 0 && patternblocks::indexOf (s, { 2, 6 * bar }) >= 0);
  158. CHECK (s.blocks[(std::size_t) patternblocks::indexOf (s, { 2, 6 * bar })].muted);
  159. CHECK (! s.blocks[(std::size_t) patternblocks::indexOf (s, { 2, 2 * bar })].muted);
  160. CHECK (patternblocks::indexOf (s, { 3, 0 }) >= 0 && s.playlist[0].pattern == 3);
  161. CHECK (s.currentPattern == 3);
  162. CHECK (std::string (describeChange (before, s).text) == "Slice pattern");
  163. }
  164. TEST (iss190ht_slice_shares_a_set_length_and_moves_notes)
  165. {
  166. using namespace lynx;
  167. using iss190ht::bar;
  168. auto s = iss190ht::song();
  169. // P1 with a set length of 1 bar and notes on every beat: cut at beat 3
  170. s.patterns[0].lengthTicks = bar;
  171. CHECK (patternblocks::place (s, 0, 0) && patternblocks::place (s, 0, 3 * bar));
  172. CHECK (patternblocks::slice (s, 0, 2 * ppq) == 1);
  173. CHECK (s.patterns[0].lengthTicks == 2 * ppq && s.patterns[1].lengthTicks == 2 * ppq);
  174. CHECK (s.patterns[0].notes.size() == 2 && s.patterns[1].notes.size() == 2);
  175. CHECK (s.patterns[1].notes[0].start == 0 && s.patterns[1].notes[1].start == ppq);
  176. // the new blocks start exactly where the shortened ones end (half a bar in)
  177. CHECK (patternblocks::indexOf (s, { 1, 2 * ppq }) >= 0 && patternblocks::indexOf (s, { 1, 3 * bar + 2 * ppq }) >= 0);
  178. // other arrangements follow too
  179. auto a = iss190ht::song();
  180. a.arrangements.resize (2);
  181. a.currentArrangement = 0;
  182. a.arrangements[1].blocks = { { 1, 8 * bar } };
  183. CHECK (patternblocks::slice (a, 1, bar) == 2);
  184. CHECK (a.arrangements[1].blocks.size() == 2 && a.arrangements[1].blocks[1].pattern == 2 && a.arrangements[1].blocks[1].start == 9 * bar);
  185. }
  186. TEST (iss190ht_track_inserts_list_layout)
  187. {
  188. using namespace lynx;
  189. namespace ti = trackinserts;
  190. // rows: one per effect, then "add" while a slot is free
  191. CHECK (ti::itemCount (0) == 1 && ti::itemCount (3) == 4 && ti::itemCount (maxEffectSlots) == maxEffectSlots);
  192. CHECK (ti::rowsThatFit (12) == 0 && ti::rowsThatFit (13) == 1 && ti::rowsThatFit (43) == 3);
  193. // 3 effects in 3 rows: the list scrolls by one (the "add" row is the 4th); never a blank tail
  194. CHECK (ti::clampFirst (5, 3, 3) == 1 && ti::clampFirst (-2, 3, 3) == 0 && ti::clampFirst (1, 1, 3) == 0);
  195. CHECK (ti::itemAt (3, 0, 3, 0) == 0 && ti::itemAt (3, 0, 3, 14) == 1 && ti::itemAt (3, 0, 3, 38) == 2);
  196. CHECK (ti::itemAt (3, 1, 3, 38) == ti::addRow && ti::itemAt (3, 0, 3, 39) == -1 && ti::itemAt (3, 0, 3, -1) == -1);
  197. CHECK (ti::itemAt (maxEffectSlots, 9, 1, 0) == 9 && ti::itemAt (0, 0, 2, 13) == -1);
  198. // a drop goes before the row whose upper half it is on
  199. CHECK (ti::dropPosition (3, 0, 4, 2) == 0 && ti::dropPosition (3, 0, 4, 8) == 1 && ti::dropPosition (3, 0, 4, 200) == 3);
  200. CHECK (ti::dropPosition (3, 1, 3, 2) == 1);
  201. // a new effect: after the last one, else the first free slot
  202. std::vector<EffectSlot> fx (2);
  203. fx[0].row = 0;
  204. fx[1].row = 4;
  205. CHECK (ti::nextFreeRow (fx) == 5);
  206. fx[1].row = maxEffectSlots - 1;
  207. CHECK (ti::nextFreeRow (fx) == 1);
  208. }
  209. TEST (iss190ht_track_inserts_edits_are_the_mixers)
  210. {
  211. using namespace lynx;
  212. // the list's gestures use the Device View's edits on the linked insert (round 183a / 190dr)
  213. Song s;
  214. s.mixer.resize (4);
  215. for (auto k : { EffectKind::parametricEq, EffectKind::compressor, EffectKind::reverb })
  216. s.mixer[1].effects.push_back (makeEffectSlot (k));
  217. // drag the reverb above the EQ: the list's drop position 0
  218. CHECK (detailchain::moveEffectBefore (s, 1, 2, 0) == 0);
  219. CHECK (s.mixer[1].effects[0].kind == EffectKind::reverb && s.mixer[1].effects[1].kind == EffectKind::parametricEq);
  220. // Ctrl + drag copies it below the compressor
  221. CHECK (detailchain::duplicateEffect (s, 1, 0, 3) == 3 && s.mixer[1].effects.size() == 4 && s.mixer[1].effects[3].kind == EffectKind::reverb);
  222. // onto another linked track: it moves to the end of that insert's chain
  223. CHECK (detailchain::moveEffectToInsert (s, 1, 1, 2, false) == 0);
  224. CHECK (s.mixer[1].effects.size() == 3 && s.mixer[2].effects.size() == 1 && s.mixer[2].effects[0].kind == EffectKind::parametricEq);
  225. // a Browser effect dropped between the first two rows
  226. CHECK (detailchain::insertEffectAt (s, 1, makeEffectSlot (EffectKind::delay), 1) == 1 && s.mixer[1].effects[1].kind == EffectKind::delay);
  227. }