Issues190llTests.inc 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. // --- Round 190ll: GitHub issues #199 (a hosted synth's piano-roll playback), #200 (a folder dropped on the Browser),
  2. // #201 (colour several selected tracks), #203 (the Piano roll's key and scale chosen apart) ----------------------------
  3. #include "core/SelectionRename.h"
  4. #include "core/KeyMap.h"
  5. #include "core/UserFolders.h"
  6. #include "core/FixedBlock.h"
  7. // #201: FL's Mixer rule (manual: "Set the selected Mixer Track name, color & icon [...] For a selection of tracks - The
  8. // name/icon will only apply to unnamed tracks"): the colour goes to every selected track, the name to the unnamed ones
  9. TEST (issues190ll_201_mixer_selection_takes_the_colour)
  10. {
  11. using namespace lynx;
  12. Song s;
  13. s.mixer.resize (6);
  14. s.mixer[2].name = "Kick";
  15. s.mixer[3].colour = 0xff112233u;
  16. const auto targets = selrename::targets (2, { 4, 2, 3 });
  17. CHECK ((targets == std::vector<int> { 2, 3, 4 }));
  18. CHECK ((selrename::targets (1, { 2, 3 }) == std::vector<int> { 1 })); // (a track outside the selection: itself alone)
  19. selrename::applyToMixer (s, 2, targets, { "Kick", "Drums", 0u, 0xffaa0000u });
  20. CHECK (s.mixer[2].name == "Drums" && s.mixer[2].colour == 0xffaa0000u);
  21. CHECK (s.mixer[3].name == "Drums" && s.mixer[3].colour == 0xffaa0000u); // (unnamed: takes the name)
  22. CHECK (s.mixer[4].name == "Drums" && s.mixer[4].colour == 0xffaa0000u);
  23. CHECK (s.mixer[1].name.empty() && s.mixer[1].colour == 0u && s.mixer[5].colour == 0u); // (not selected)
  24. // a named track keeps its name; a rename alone keeps the others' colours
  25. s.mixer[3].name = "Snare";
  26. s.mixer[4].colour = 0xff00ff00u;
  27. selrename::applyToMixer (s, 2, targets, { "Drums", "Perc", 0xffaa0000u, 0xffaa0000u });
  28. CHECK (s.mixer[2].name == "Perc" && s.mixer[3].name == "Snare" && s.mixer[4].name == "Drums");
  29. CHECK (s.mixer[3].colour == 0xffaa0000u && s.mixer[4].colour == 0xff00ff00u);
  30. selrename::colourMixer (s, targets, 0xff0000ffu); // "Change color..." / "Random color"
  31. for (const auto t : targets)
  32. CHECK (s.mixer[(std::size_t) t].colour == 0xff0000ffu);
  33. CHECK (s.mixer[1].colour == 0u);
  34. }
  35. TEST (issues190ll_201_playlist_tracks_and_channels_take_the_colour)
  36. {
  37. using namespace lynx;
  38. Song s;
  39. s.playlistTracks.resize (2);
  40. s.playlistTracks[1].name = "Bass";
  41. // the dialog opened on track 1 with tracks 1, 3 and 5 selected (5 is past the stored list: it is made)
  42. selrename::applyToPlaylistTracks (s, 1, { 1, 3, 5 }, { "Bass", "Low end", 0u, 0xff445566u });
  43. CHECK (s.playlistTracks.size() >= 6);
  44. CHECK (s.playlistTracks[1].name == "Low end" && s.playlistTracks[1].colour == 0xff445566u);
  45. CHECK (s.playlistTracks[3].colour == 0xff445566u && s.playlistTracks[3].name.empty()); // (the name stays the track's own)
  46. CHECK (s.playlistTracks[5].colour == 0xff445566u && s.playlistTracks[0].colour == 0u);
  47. selrename::applyToPlaylistTracks (s, 1, { 1, 3, 5 }, { "Low end", "Sub", 0xff445566u, 0xff445566u }); // (a rename alone)
  48. CHECK (s.playlistTracks[1].name == "Sub" && s.playlistTracks[3].name.empty());
  49. s.channels.resize (4);
  50. s.channels[0].name = "Kick";
  51. s.channels[2].name = "Hat";
  52. s.channels[3].colour = 0xff999999u;
  53. selrename::applyToChannels (s, 0, selrename::targets (0, { 0, 2 }), { "Kick", "Kick 2", 0u, 0xff123456u });
  54. CHECK (s.channels[0].name == "Kick 2" && s.channels[0].colour == 0xff123456u);
  55. CHECK (s.channels[2].name == "Hat" && s.channels[2].colour == 0xff123456u);
  56. CHECK (s.channels[1].colour == 0u && s.channels[3].colour == 0xff999999u);
  57. selrename::colourChannels (s, { 1, 3 }, 0xff000001u);
  58. CHECK (s.channels[1].colour == 0xff000001u && s.channels[3].colour == 0xff000001u && s.channels[0].colour == 0xff123456u);
  59. }
  60. TEST (issues190ll_201_f2_renames_the_selected_channel_in_the_rack)
  61. {
  62. // the channel menu shows "Rename and color... F2": with the Channel Rack focused F2 opens it (elsewhere F2 stays the
  63. // pattern's rename, in the Mixer the track's)
  64. using namespace lynx::keys;
  65. KeyMap map;
  66. CHECK (map.conflicts().empty());
  67. CHECK (map.find ({ f2, none }, Context::channelRack, false) == "rack.rename");
  68. CHECK (map.find ({ f2, none }, Context::global, false) == "pattern.rename");
  69. CHECK (map.find ({ f2, none }, Context::mixer, false) == "mixer.rename");
  70. }
  71. // #200: a folder dropped on the Browser joins the list Add folder... writes (FL: "drop any folder from an external File
  72. // Browser onto the FL Studio Browser and it will be added to the list"); listed already: nothing changes
  73. TEST (issues190ll_200_dropped_folders_join_the_list)
  74. {
  75. using namespace lynx;
  76. std::vector<std::string> list { "/home/u/Samples", "", " ", "/home/u/Loops/" };
  77. auto added = userfolders::add (list, { "/home/u/Drums", "/home/u/Samples/", "/home/u/Loops", "/home/u/Drums" }, false);
  78. CHECK ((added == std::vector<std::string> { "/home/u/Drums" }));
  79. CHECK ((list == std::vector<std::string> { "/home/u/Samples", "/home/u/Loops/", "/home/u/Drums" }));
  80. // Windows: the case and the separator do not make another folder; a drive root keeps its backslash
  81. std::vector<std::string> win { "C:\\Samples" };
  82. CHECK (userfolders::add (win, { "c:\\samples\\" }, true).empty());
  83. CHECK (userfolders::add (win, { "D:\\" }, true).front() == "D:\\");
  84. CHECK (userfolders::key ("D:\\", true) == "d:\\" && userfolders::key ("/", false) == "/");
  85. CHECK (userfolders::add (win, { "D:\\" }, true).empty());
  86. }
  87. // #199: with "Use fixed size buffers" a hosted plugin's play head said the same position for every fixed block that
  88. // completed inside one stretch of the chunk (and the stretch's start for a block begun in the stretch before): the song
  89. // stood still, then jumped. A synth that keeps its LFOs / chorus / flanger / phaser in step with the host position
  90. // (Vital resets them to it before every 128 samples) clicks there. The blocks now say where they began.
  91. TEST (issues190ll_199_fixed_blocks_tell_where_they_began)
  92. {
  93. using namespace lynx;
  94. FixedBlock fixed (96, 2);
  95. std::vector<float> l (1024), r (1024);
  96. float* io[2] = { l.data(), r.data() };
  97. std::vector<int> starts;
  98. int at = 0; // where the current run starts on the song's sample line
  99. for (const auto n : { 1024, 37, 987, 5, 200, 1, 1024 })
  100. {
  101. fixed.run (io, n, false, [&] (float* const*, int count, int end) {
  102. CHECK (count == 96);
  103. starts.push_back (at + end - count);
  104. });
  105. at += n;
  106. }
  107. CHECK (starts.size() == (std::size_t) (at / 96));
  108. for (std::size_t i = 0; i < starts.size(); ++i)
  109. CHECK (starts[i] == (int) i * 96); // (each block begins exactly where the one before ended)
  110. // the two-argument form is still taken (the other callers)
  111. int calls = 0;
  112. fixed.run (io, 192, false, [&] (float* const*, int) { ++calls; });
  113. CHECK (calls == 2);
  114. }
  115. // round 190od (issue #199): a chunk that runs over the pattern's end is one chunk; the plugin block that starts after
  116. // the wrap (the pattern's first note) reports the pattern's start, not its end + a few samples
  117. TEST (issues190od_199_blocks_after_the_pattern_wrap_report_its_start)
  118. {
  119. auto s = lynx::Song::makeDefault();
  120. s.mode = lynx::PlayMode::pattern;
  121. const auto length = (double) s.patterns[0].effectiveLength (s.meter());
  122. const auto wrap = lynx::hostPositionWrap (s, s.songLength());
  123. CHECK (wrap.at == length && wrap.to == 0.0);
  124. lynx::HostTimeline t;
  125. const auto tps = 960.0 * 130.0 / 60.0 / 48000.0; // 130 BPM at 48 kHz
  126. t.ticksPerSample.store (tps);
  127. t.tick.store (length - 79.0 * tps);
  128. t.wrapAt.store (wrap.at);
  129. t.wrapTo.store (wrap.to);
  130. CHECK (std::abs (t.tickAt (78) - (length - tps)) < 1e-6); // before the wrap: as before
  131. CHECK (std::abs (t.tickAt (79)) < 1e-6); // the first note's block: the start
  132. CHECK (std::abs (t.tickAt (512) - 433.0 * tps) < 1e-6); // and on from there
  133. t.wrapAt.store (0.0);
  134. CHECK (std::abs (t.tickAt (79) - length) < 1e-6); // no wrap known: unchanged
  135. // Song mode: the loop region's end goes back to its start; without a region, the song's end to 0
  136. s.mode = lynx::PlayMode::song;
  137. const auto bar = (std::int64_t) lynx::ppq * s.beatsPerBar;
  138. s.playlist = { lynx::Clip { 0, 0, 0, 4 * bar, 0 } };
  139. auto w = lynx::hostPositionWrap (s, s.songLength());
  140. CHECK (w.at == (double) s.songLength() && w.to == 0.0);
  141. s.loopStart = bar;
  142. s.loopEnd = 3 * bar;
  143. w = lynx::hostPositionWrap (s, s.songLength());
  144. CHECK (! s.loopPlays() || (w.at == (double) (3 * bar) && w.to == (double) bar));
  145. }
  146. // #203 (round 190ll, follow-up): the FL layout's scale box opens FL's View › Scale highlighting menu itself, not the
  147. // box's own item list. ComboBox marks the box as having a menu open before showPopup() and clears that mark from the
  148. // result callback of the menu it shows -- for the box's own menu that callback never ran, so the box ignored every click
  149. // after the first one (the menu did not open again). The box now closes its own menu through ComboBox::hidePopup().
  150. // (A real click needs the message loop and the GUI, so this guards the wiring in the source.)
  151. TEST (issues190ll_203_scale_box_opens_its_menu_again)
  152. {
  153. using namespace i18ntest;
  154. const auto header = readFile ("src/ui/PianoRollComponent.h");
  155. const auto box = header.find ("class ScaleBox final : public IconComboBox");
  156. CHECK (box != std::string::npos);
  157. CHECK (header.find ("std::function<juce::PopupMenu()> onPopup;", box) != std::string::npos); // (the menu to open)
  158. CHECK (header.find ("onPopup().showMenuAsync", box) != std::string::npos); // (the box shows it)
  159. CHECK (header.find ("[box] (int) { if (box != nullptr) box->hidePopup(); }", box) != std::string::npos); // (and closes it)
  160. CHECK (readFile ("src/ui/PianoRollComponent.cpp")
  161. .find ("scaleBox.onPopup = [this] { return scaleHighlightMenu(); };") != std::string::npos);
  162. }