Workflow190iuTests.inc 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. // Round 190iu (issues #186 and #191): wheel zones, temporary tools, MIDI drops, take clean-up.
  2. #include "core/LaneView.h"
  3. #include "core/MidiDrop.h"
  4. #include "core/TrackOnly.h"
  5. #include "core/TakeCleanup.h"
  6. #include "core/TempTool.h"
  7. #include "core/WheelZones.h"
  8. namespace workflow190iu
  9. {
  10. // a two-track MIDI file: "Bass" (C2, one bar long) and an unnamed track (E4 at beat 2, MIDI channel 10)
  11. inline lynx::midiimport::ParsedMidi twoTracks()
  12. {
  13. using namespace lynx;
  14. midiimport::ParsedMidi m;
  15. m.trackNames = { "Bass", "" };
  16. m.events = { { 0, 0, 0x90, 36, 100 }, { 0, 4 * ppq, 0x80, 36, 0 }, { 1, ppq, 0x99, 64, 90 }, { 1, 2 * ppq, 0x89, 64, 0 } };
  17. return m;
  18. }
  19. inline lynx::midiimport::ParsedMidi oneTrack()
  20. {
  21. using namespace lynx;
  22. midiimport::ParsedMidi m;
  23. m.trackNames = { "" };
  24. m.events = { { 0, 0, 0x90, 60, 100 }, { 0, ppq / 2, 0x80, 60, 0 }, { 0, ppq, 0x90, 62, 100 }, { 0, 3 * ppq / 2, 0x80, 62, 0 } };
  25. return m;
  26. }
  27. } // namespace workflow190iu
  28. TEST (workflow190iu_wheel_zones_scroll_over_headers_zoom_over_arrangement)
  29. {
  30. using namespace lynx::wheelzones;
  31. // off (the default, FL and Live): Ctrl zooms, the plain wheel scrolls, wherever the pointer is
  32. CHECK (! enabled());
  33. CHECK (! zooms (false, true, false) && ! zooms (false, false, false));
  34. CHECK (zooms (false, true, true) && zooms (false, false, true));
  35. CHECK (zooms (false, false, true, false)); // (a sideways wheel with Ctrl: as before)
  36. // on (#186): over the headers the plain wheel scrolls, over the arrangement it zooms; Ctrl swaps both
  37. CHECK (! zooms (true, true, false) && zooms (true, true, true));
  38. CHECK (zooms (true, false, false) && ! zooms (true, false, true));
  39. // a sideways wheel or swipe keeps scrolling sideways
  40. CHECK (! zooms (true, false, false, false) && ! zooms (true, true, true, false));
  41. // the global switch
  42. setEnabled (true);
  43. CHECK (zoomsHere (false, false) && ! zoomsHere (true, false));
  44. setEnabled (false);
  45. CHECK (! zoomsHere (false, false));
  46. }
  47. TEST (workflow190iu_temporary_tool_hold_tap_repeat_and_mouse)
  48. {
  49. using namespace lynx;
  50. using temptool::Editor;
  51. temptool::Hold h;
  52. EditTool back = EditTool::pencil;
  53. // a quick tap: the tool stays
  54. CHECK (h.press (Editor::playlist, 'C', EditTool::pencil, EditTool::knife, 1000));
  55. CHECK (! h.release (1000 + temptool::holdMs - 1, EditTool::knife, back) && ! h.active());
  56. // held: back to the tool before on release; the key's auto-repeats change nothing
  57. CHECK (h.press (Editor::playlist, 'C', EditTool::pencil, EditTool::knife, 2000));
  58. CHECK (! h.press (Editor::playlist, 'C', EditTool::knife, EditTool::knife, 2500)); // (repeat)
  59. CHECK (h.release (2000 + temptool::holdMs, EditTool::knife, back) && back == EditTool::pencil);
  60. // a short press while the mouse is used is a temporary use too
  61. CHECK (h.press (Editor::pianoRoll, 'D', EditTool::brush, EditTool::eraser, 3000));
  62. h.mouseUsed();
  63. CHECK (h.release (3050, EditTool::eraser, back) && back == EditTool::brush);
  64. // another tool key during a hold: letting it go returns to the tool from before the first one
  65. CHECK (h.press (Editor::playlist, 'C', EditTool::lasso, EditTool::knife, 4000));
  66. CHECK (h.press (Editor::playlist, 'D', EditTool::knife, EditTool::eraser, 4100));
  67. CHECK (h.release (5000, EditTool::eraser, back) && back == EditTool::lasso);
  68. // a tool picked meanwhile (a click on the tool strip) stays
  69. CHECK (h.press (Editor::playlist, 'C', EditTool::pencil, EditTool::knife, 6000));
  70. CHECK (! h.release (7000, EditTool::zoom, back));
  71. // the key of the tool already in use: nothing to go back to
  72. CHECK (! h.press (Editor::playlist, 'P', EditTool::pencil, EditTool::pencil, 8000));
  73. CHECK (! h.release (9000, EditTool::pencil, back));
  74. // the switch is off by default (a LYNX extra: FL's tool keys only select)
  75. CHECK (! temptool::enabled());
  76. }
  77. TEST (workflow190iu_midi_drop_on_the_playlist_pattern_layout)
  78. {
  79. using namespace lynx;
  80. // (on by default since 0.1.31.2, #287; off, only the Live-style arrangement takes them)
  81. CHECK (mididrop::playlistDrop() && mididrop::playlistTakes (true) && mididrop::playlistTakes (false));
  82. mididrop::setPlaylistDrop (false);
  83. CHECK (mididrop::playlistTakes (true) && ! mididrop::playlistTakes (false));
  84. mididrop::setPlaylistDrop (true);
  85. // an unassigned track: one pattern named after the file, a new channel per MIDI track, the clip at the drop
  86. {
  87. auto s = Song::makeDefault();
  88. s.playlist.clear();
  89. const auto channels = s.channels.size(), patterns = s.patterns.size(), clips = s.playlist.size();
  90. const auto r = mididrop::dropOnPlaylist (s, workflow190iu::twoTracks(), "groove", 2, 4 * ppq, false);
  91. CHECK (r.ok && r.patterns.size() == 1 && r.channels.size() == 2 && r.tracks == std::vector<int> { 2 });
  92. CHECK (s.channels.size() == channels + 2 && s.patterns.size() == patterns + 1 && s.playlist.size() == clips + 1);
  93. CHECK (s.channels[(std::size_t) r.channels[0]].name == "Bass" && s.channels[(std::size_t) r.channels[1]].name == "groove 2");
  94. CHECK (s.channels[(std::size_t) r.channels[0]].instrument == InstrumentKind::synth);
  95. const auto& p = s.patterns[(std::size_t) r.patterns[0]];
  96. CHECK (p.name == "groove" && p.notes.size() == 2);
  97. CHECK (p.notes[0].key == 36 && p.notes[0].start == 0 && p.notes[0].length == 4 * ppq && p.notes[0].channel == r.channels[0]);
  98. CHECK (p.notes[1].key == 64 && p.notes[1].start == ppq && p.notes[1].channel == r.channels[1]);
  99. const auto& clip = s.playlist.back();
  100. CHECK (clip.kind == ClipKind::pattern && clip.pattern == r.patterns[0] && clip.track == 2 && clip.start == 4 * ppq && clip.length >= 4 * ppq);
  101. CHECK (s.mode == PlayMode::song);
  102. // the track's mode stays (FL's Playlist: tracks and channels apart)
  103. CHECK (s.playlistTracks.size() <= 2 || s.playlistTracks[2].mode == PlaylistTrackMode::unassigned);
  104. }
  105. // an instrument track: every note to the track's channel, no new channel
  106. {
  107. auto s = Song::makeDefault();
  108. s.playlist.clear();
  109. const auto channel = trackmodes::addInstrumentTrack (s, mididrop::newChannel ("Keys"), 1);
  110. CHECK (channel >= 0);
  111. const auto channels = s.channels.size();
  112. const auto r = mididrop::dropOnPlaylist (s, workflow190iu::twoTracks(), "groove", 1, 0, false);
  113. CHECK (r.ok && s.channels.size() == channels && r.channels == std::vector<int> { channel });
  114. const auto& p = s.patterns[(std::size_t) r.patterns[0]];
  115. CHECK (p.notes.size() == 2 && p.notes[0].channel == channel && p.notes[1].channel == channel);
  116. }
  117. // a file without notes: refused, nothing changed
  118. {
  119. auto s = Song::makeDefault();
  120. s.playlist.clear();
  121. const auto before = s.patterns.size();
  122. midiimport::ParsedMidi empty;
  123. const auto r = mididrop::dropOnPlaylist (s, empty, "x", 0, 0, false);
  124. CHECK (! r.ok && r.error == "no notes" && s.patterns.size() == before);
  125. }
  126. }
  127. TEST (workflow190iu_midi_drop_live_style_arrangement_and_slots)
  128. {
  129. using namespace lynx;
  130. // the Clip-launch arrangement: an empty track becomes an instrument track of a new channel; each further MIDI track
  131. // of the file on its own track below (Live)
  132. {
  133. auto s = Song::makeDefault();
  134. s.playlist.clear();
  135. const auto r = mididrop::dropOnPlaylist (s, workflow190iu::twoTracks(), "groove", 0, 0, true);
  136. CHECK (r.ok && r.tracks.size() == 2 && r.tracks[0] == 0 && r.tracks[1] == 1 && r.patterns.size() == 2);
  137. CHECK (mididrop::channelUnder (s, 0, true) == r.channels[0] && mididrop::channelUnder (s, 1, true) == r.channels[1]);
  138. CHECK (s.playlistTracks[0].mode == PlaylistTrackMode::instrument && s.channels[(std::size_t) r.channels[0]].name == "Bass");
  139. // a second file on the same track: the track's instrument, no new channel
  140. const auto channels = s.channels.size();
  141. const auto again = mididrop::dropOnPlaylist (s, workflow190iu::oneTrack(), "lead", 0, 8 * ppq, true);
  142. CHECK (again.ok && s.channels.size() == channels && again.channels[0] == r.channels[0]);
  143. CHECK (s.patterns[(std::size_t) again.patterns[0]].name == "lead" && s.playlist.back().start == 8 * ppq);
  144. }
  145. // an audio track takes no MIDI
  146. {
  147. auto s = Song::makeDefault();
  148. s.playlist.clear();
  149. CHECK (trackmodes::makeAudioTrack (s, 0));
  150. const auto patterns = s.patterns.size();
  151. const auto r = mididrop::dropOnPlaylist (s, workflow190iu::oneTrack(), "x", 0, 0, true);
  152. CHECK (! r.ok && r.error == "audio track" && s.patterns.size() == patterns);
  153. CHECK (! mididrop::dropOnSlot (s, workflow190iu::oneTrack(), "x", 0, 0).ok);
  154. }
  155. // a slot: one clip with every MIDI track merged on the track's (new) instrument
  156. {
  157. auto s = Song::makeDefault();
  158. s.playlist.clear();
  159. const auto r = mididrop::dropOnSlot (s, workflow190iu::twoTracks(), "groove", 3, 2);
  160. CHECK (r.ok && r.channels.size() == 1 && r.tracks == std::vector<int> { 3 });
  161. CHECK (s.clipGrid.has_value());
  162. const auto* clip = s.clipGrid ? launcher::clipAt (*s.clipGrid, 3, 2) : nullptr;
  163. CHECK (clip != nullptr && clip != nullptr && clip->kind == ClipKind::pattern && clip->pattern == r.patterns[0]);
  164. const auto& p = s.patterns[(std::size_t) r.patterns[0]];
  165. CHECK (p.notes.size() == 2 && p.notes[0].channel == r.channels[0] && p.notes[1].channel == r.channels[0]);
  166. CHECK (s.playlistTracks[3].mode == PlaylistTrackMode::instrument && s.channels[(std::size_t) r.channels[0]].name == "groove");
  167. // the next file into the next slot of the same track: the same instrument
  168. const auto next = mididrop::dropOnSlot (s, workflow190iu::oneTrack(), "lead", 3, 3);
  169. CHECK (next.ok && next.channels[0] == r.channels[0]);
  170. }
  171. }
  172. TEST (workflow190iu_take_cleanup_deletes_takes_and_envelopes)
  173. {
  174. using namespace lynx;
  175. auto s = Song::makeDefault();
  176. s.playlist.clear();
  177. // two takes (audio clip channels), one placed; two recorded envelopes, one placed
  178. const auto take = [&s] (const char* name) {
  179. ChannelDef c;
  180. c.name = name;
  181. c.instrument = InstrumentKind::audioClip;
  182. s.channels.push_back (c);
  183. return (int) s.channels.size() - 1;
  184. };
  185. const auto t1 = take ("Take 1"), t2 = take ("Take 2");
  186. Clip a;
  187. a.kind = ClipKind::audio;
  188. a.channel = t1;
  189. a.track = 0;
  190. a.length = ppq;
  191. s.playlist.push_back (a);
  192. Automation e1, e2;
  193. e1.name = "Env 1";
  194. e2.name = "Env 2";
  195. s.automations.push_back (e1);
  196. s.automations.push_back (e2);
  197. Clip c;
  198. c.kind = ClipKind::automation;
  199. c.automation = 1;
  200. c.track = 1;
  201. c.length = ppq;
  202. s.playlist.push_back (c);
  203. CHECK (takecleanup::automationUses (s, 1) == 1 && takecleanup::automationUses (s, 0) == 0);
  204. CHECK (takecleanup::unusedAutomations (s) == std::vector<int> { 0 });
  205. // deleting a placed take removes its clips with it; anything else is refused
  206. auto deleted = s;
  207. CHECK (takecleanup::deleteAudioClip (deleted, t1));
  208. CHECK (deleted.channels.size() == s.channels.size() - 1);
  209. CHECK (std::none_of (deleted.playlist.begin(), deleted.playlist.end(), [] (const Clip& k) { return k.kind == ClipKind::audio; }));
  210. CHECK (! takecleanup::deleteAudioClip (deleted, -1) && ! takecleanup::deleteAudioClip (deleted, 999));
  211. {
  212. auto other = s;
  213. other.channels[(std::size_t) t1].instrument = InstrumentKind::synth; // (not a take)
  214. CHECK (! takecleanup::deleteAudioClip (other, t1));
  215. }
  216. // deleting a placed envelope removes its clip; the clips of the later ones are renumbered
  217. auto env = s;
  218. CHECK (takecleanup::deleteAutomation (env, 0));
  219. CHECK (env.automations.size() == 1 && env.automations[0].name == "Env 2");
  220. CHECK (std::any_of (env.playlist.begin(), env.playlist.end(), [] (const Clip& k) { return k.kind == ClipKind::automation && k.automation == 0; }));
  221. CHECK (takecleanup::deleteAutomation (env, 0) && env.automations.empty());
  222. CHECK (std::none_of (env.playlist.begin(), env.playlist.end(), [] (const Clip& k) { return k.kind == ClipKind::automation; }));
  223. // the unused ones at once: the placed envelope stays
  224. auto unused = s;
  225. CHECK (takecleanup::deleteUnusedAutomations (unused) == 1 && unused.automations.size() == 1 && unused.automations[0].name == "Env 2");
  226. CHECK (takecleanup::automationUses (unused, 0) == 1);
  227. (void) t2;
  228. }
  229. TEST (workflow190iu_track_only_mode_gives_each_new_instrument_a_track)
  230. {
  231. using namespace lynx;
  232. CHECK (! trackonly::enabled()); // off by default
  233. auto s = Song::makeDefault();
  234. s.playlist.clear();
  235. // a project made with the rack: two instruments, one with an instrument track already, one audio clip channel
  236. s.channels.clear();
  237. s.channels.push_back (mididrop::newChannel ("Lead"));
  238. s.channels.push_back (mididrop::newChannel ("Pad"));
  239. ChannelDef take;
  240. take.instrument = InstrumentKind::audioClip;
  241. s.channels.push_back (take);
  242. CHECK (trackmodes::makeInstrumentTrack (s, 0, 0));
  243. CHECK (trackonly::withoutTrack (s) == 1); // (Pad; the audio clip channel never gets one)
  244. // the edit that adds channels: only those from `channelsBefore` on get a track
  245. const auto before = s.channels.size();
  246. s.channels.push_back (mididrop::newChannel ("Bass"));
  247. CHECK (trackonly::follow (s, before) == 1);
  248. const auto bassTracks = trackmodes::instrumentTracksOf (s, (int) before);
  249. CHECK (bassTracks.size() == 1 && s.playlistTracks[(std::size_t) bassTracks[0]].mode == PlaylistTrackMode::instrument);
  250. CHECK (trackmodes::instrumentTracksOf (s, 1).empty()); // (Pad stays as it was)
  251. // "give every instrument its own track"
  252. CHECK (trackonly::assignAll (s) == 1 && trackonly::withoutTrack (s) == 0);
  253. CHECK (trackmodes::instrumentTracksOf (s, 2).empty());
  254. // active only in the Pattern layout with the switch on
  255. trackonly::setEnabled (true);
  256. CHECK (trackonly::active() == (layoutstyle::current() == layoutstyle::Style::pattern));
  257. trackonly::setEnabled (false);
  258. CHECK (! trackonly::active());
  259. }
  260. TEST (workflow190iu_automation_clips_move_into_their_tracks_lanes)
  261. {
  262. using namespace lynx;
  263. auto s = Song::makeDefault();
  264. s.playlist.clear();
  265. s.channels.clear();
  266. s.channels.push_back (mididrop::newChannel ("Lead"));
  267. CHECK (trackmodes::makeInstrumentTrack (s, 2, 0));
  268. const auto insert = s.channels[0].mixerTrack;
  269. CHECK (insert > 0);
  270. // an envelope of the Lead's volume (owned by track 2), one of the tempo (no owner)
  271. Automation vol;
  272. vol.name = "Lead volume";
  273. vol.target = { AutomationTargetKind::channelVolume, 0, 0, 0 };
  274. vol.points = { { 0, 0.2f, 0.0f }, { 4 * ppq, 0.9f, 0.0f } };
  275. Automation tempo;
  276. tempo.name = "Tempo";
  277. tempo.target = { AutomationTargetKind::tempo, 0, 0, 0 };
  278. tempo.points = { { 0, 0.5f, 0.0f } };
  279. s.automations = { vol, tempo };
  280. const auto clipOf = [] (int automation, int track) {
  281. Clip c;
  282. c.kind = ClipKind::automation;
  283. c.automation = automation;
  284. c.track = track;
  285. c.start = 8 * ppq;
  286. c.length = 4 * ppq;
  287. return c;
  288. };
  289. s.playlist.push_back (clipOf (0, 5));
  290. s.playlist.push_back (clipOf (1, 6));
  291. CHECK (laneview::ownerTrack (s, vol.target) == 2 && laneview::ownerTrack (s, tempo.target) == -1);
  292. // the Master and an unlinked insert have no owner track either
  293. CHECK (laneview::ownerTrack (s, { AutomationTargetKind::mixerVolume, 0, 0, 0 }) == -1);
  294. CHECK (laneview::ownerTrack (s, { AutomationTargetKind::mixerVolume, insert, 0, 0 }) == 2); // (the channel's own insert)
  295. CHECK (laneview::movableClips (s) == std::vector<int> { 0 });
  296. const auto valueMid = s.automations[0].valueAt (2.0 * ppq);
  297. CHECK (laneview::clipsToLanes (s) == 1);
  298. // the clip went into a lane under track 2; the tempo clip stayed; the leftover automation went with its clip
  299. CHECK (s.playlist.size() == 1 && s.playlist[0].automation >= 0 && s.automations[(std::size_t) s.playlist[0].automation].name == "Tempo");
  300. CHECK (s.playlistTracks.size() > 2 && s.playlistTracks[2].lanes.size() == 1);
  301. const auto lane = s.playlistTracks[2].lanes[0].automation;
  302. CHECK (lane >= 0 && lane < (int) s.automations.size() && s.automations[(std::size_t) lane].target == vol.target);
  303. CHECK (s.automations.size() == 2); // (tempo + the lane; the old Lead volume automation is gone)
  304. // the lane plays the clip's curve where the clip was
  305. CHECK (std::abs (s.automations[(std::size_t) lane].valueAt (10.0 * ppq) - valueMid) < 0.02f);
  306. CHECK (laneview::movableClips (s).empty());
  307. }