DetailsShot190mp.inc 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. // --details190mpshot <prefix> <project.flp> (round 190mp, details pass 7): the tempo menu's Half speed, the Playlist
  2. // track menu's Auto name clips, the picker's Alt+right-hold preview, the editors' tool gestures (right-hold + wheel,
  3. // middle + right menu, the Zoom icon's quick-zoom menu), the Piano roll's Magic lasso, the rack's Restretch all and
  4. // the Mixer's FX slot menu in FL's order. <prefix>-checks.txt lists the checks. Included in the app class of Main.cpp.
  5. bool runDetailsShot190mp (const juce::String& prefix, const juce::String& project)
  6. {
  7. juce::LookAndFeel::setDefaultLookAndFeel (&lookAndFeel);
  8. const juce::ScopedValueSetter<bool> shown (lynx::ui::showingForShots(), true);
  9. juce::String checks;
  10. bool allOk = true;
  11. const auto check = [&checks, &allOk] (const juce::String& what, bool ok) {
  12. checks << (ok ? "ok " : "FAIL ") << what << "\n";
  13. allOk = allOk && ok;
  14. };
  15. const auto line = [&checks] (const juce::String& what) { checks << " " << what << "\n"; };
  16. const auto zoomShot = [&prefix] (juce::Component& c, juce::Rectangle<int> r, float k, const juce::String& name) {
  17. savePng (c.createComponentSnapshot (r.getIntersection (c.getLocalBounds()), true, k), prefix + "-" + name + ".png");
  18. };
  19. const auto texts = [] (const juce::PopupMenu& menu, bool recurse = false) {
  20. juce::StringArray items;
  21. for (juce::PopupMenu::MenuItemIterator it (menu, recurse); it.next();)
  22. items.add (it.getItem().isSectionHeader ? "[" + it.getItem().text + "]" : it.getItem().isSeparator ? juce::String ("-") : it.getItem().text);
  23. return items;
  24. };
  25. const auto find = [] (const juce::PopupMenu& menu, const juce::String& text) -> const juce::PopupMenu::Item* {
  26. for (juce::PopupMenu::MenuItemIterator it (menu); it.next();)
  27. if (it.getItem().text.upToFirstOccurrenceOf ("\t", false, false) == text)
  28. return &it.getItem();
  29. return nullptr;
  30. };
  31. const auto mouseOn = [] (juce::Component& target, juce::Point<int> p, juce::ModifierKeys mods) {
  32. auto source = juce::Desktop::getInstance().getMainMouseSource();
  33. const auto now = juce::Time::getCurrentTime();
  34. return juce::MouseEvent (source, p.toFloat(), mods, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, &target, &target, now, p.toFloat(), now, 1, false);
  35. };
  36. using namespace lynx;
  37. if (project.isEmpty())
  38. return false;
  39. AudioEngine offline (false);
  40. MainComponent ui (offline, false);
  41. ui.setSize (1920, 1080);
  42. ui.openFile (juce::File (project));
  43. offline.dispatchPendingMessages();
  44. // ---- the tempo menu's Half speed (DF-16)
  45. {
  46. const auto menu = ui.tempoMenuForSnapshot();
  47. const auto items = texts (menu);
  48. const auto at160 = items.indexOf ("160 BPM"), atHalf = items.indexOf (tr ("Half speed"));
  49. line ("tempo menu: " + items.joinIntoString (" | "));
  50. check ("tempo menu: Half speed after 160 BPM, behind a line", at160 >= 0 && atHalf == at160 + 2 && items[at160 + 1] == "-");
  51. const auto tpsBefore = offline.getTransport().ticksPerSample();
  52. const auto shownBefore = offline.shownTempo();
  53. if (const auto* item = find (menu, tr ("Half speed")); item != nullptr && item->action)
  54. item->action();
  55. check ("Half speed on: the transport moves at half the rate, the tempo shown stays",
  56. offline.isHalfSpeed() && std::abs (offline.getTransport().ticksPerSample() * 2.0 - tpsBefore) < 1.0e-9 && offline.shownTempo() == shownBefore
  57. && offline.getSong().bpm == shownBefore);
  58. const auto ticked = ui.tempoMenuForSnapshot();
  59. const auto* on = find (ticked, tr ("Half speed"));
  60. check ("the menu ticks Half speed while it is on", on != nullptr && on->isTicked);
  61. saveMenus (juce::StringArray { tr ("Tempo") }, { ticked }, prefix + "-menu-tempo-halfspeed.png");
  62. offline.setHalfSpeed (false);
  63. check ("Half speed off: the rate as before", std::abs (offline.getTransport().ticksPerSample() - tpsBefore) < 1.0e-12);
  64. }
  65. // ---- the Playlist track menu's Auto name clips (DE-127)
  66. {
  67. auto& pl = ui.getPlaylistForSnapshot();
  68. const auto& song = offline.getSong();
  69. int track = -1, channel = -1;
  70. for (const auto& c : song.playlist)
  71. if (c.kind == ClipKind::audio && c.channel >= 0 && c.track >= 0 && c.track < (int) song.playlistTracks.size()
  72. && ! song.playlistTracks[(std::size_t) c.track].name.empty()
  73. && song.playlistTracks[(std::size_t) c.track].name != song.channels[(std::size_t) c.channel].name)
  74. {
  75. track = c.track;
  76. channel = c.channel;
  77. break;
  78. }
  79. const auto menu = pl.trackMenuForSnapshot (juce::jmax (0, track));
  80. const auto items = texts (menu);
  81. const auto autoName = items.indexOf (theme::mnemonic (tr ("Auto name"), 'A')), clips = items.indexOf (tr ("Auto name clips"));
  82. line ("track menu: " + items.joinIntoString (" | ").substring (0, 260));
  83. check ("track menu: Auto name clips right after Auto name, before Reset", autoName >= 0 && clips == autoName + 1 && items[clips + 1] == tr ("Reset"));
  84. saveMenus (juce::StringArray { tr ("Playlist track") }, { menu }, prefix + "-menu-track.png");
  85. if (track >= 0)
  86. {
  87. const auto trackName = song.playlistTracks[(std::size_t) track].name;
  88. const auto before = song.channels[(std::size_t) channel].name;
  89. line ("track " + juce::String (track + 1) + " \"" + juce::String::fromUTF8 (trackName.c_str()) + "\": audio clip channel \""
  90. + juce::String::fromUTF8 (before.c_str()) + "\"");
  91. pl.autoNameClipsForSnapshot (track);
  92. offline.dispatchPendingMessages();
  93. const auto after = offline.getSong().channels[(std::size_t) channel].name;
  94. line ("after Auto name clips: \"" + juce::String::fromUTF8 (after.c_str()) + "\"");
  95. check ("Auto name clips: the audio clip's channel takes the track's name (FL: Main Vox -> Thief Vox)",
  96. after == trackName || after.rfind (trackName + " #", 0) == 0);
  97. offline.undo();
  98. offline.dispatchPendingMessages();
  99. check ("one undo step puts the name back", offline.getSong().channels[(std::size_t) channel].name == before);
  100. }
  101. else
  102. line ("no named track with an audio clip of another name");
  103. }
  104. // ---- the picker's Alt+right-hold preview (DE-134)
  105. {
  106. auto& picker = ui.getPickerForSnapshot();
  107. ui.showPanelsForSnapshot ({ workspace::Panel::playlist });
  108. offline.dispatchPendingMessages();
  109. picker.setView (0);
  110. const auto pattern = offline.getSong().patterns.size() > 1 ? 1 : 0;
  111. const auto y = picker.rowCentreForSnapshot (pattern);
  112. const auto modeBefore = offline.getSong().mode;
  113. line ("picker row of pattern " + juce::String (pattern + 1) + " at y " + juce::String (y) + ", picker " + picker.getBounds().toString());
  114. if (y > 0)
  115. {
  116. const auto mods = juce::ModifierKeys (juce::ModifierKeys::altModifier | juce::ModifierKeys::rightButtonModifier);
  117. picker.mouseDown (mouseOn (picker, { 30, y }, mods));
  118. offline.dispatchPendingMessages();
  119. const auto playingHeld = offline.getTransport().playing.load();
  120. check ("Alt+right-hold: the pattern plays in pattern mode while held", playingHeld && offline.getSong().mode == PlayMode::pattern
  121. && offline.getSong().currentPattern == pattern);
  122. picker.mouseUp (mouseOn (picker, { 30, y }, juce::ModifierKeys (juce::ModifierKeys::altModifier)));
  123. offline.dispatchPendingMessages();
  124. check ("the release stops it and puts the mode back", ! offline.getTransport().playing.load() && offline.getSong().mode == modeBefore);
  125. }
  126. }
  127. // ---- the Piano roll's tool gestures (DE-61, DE-62, DE-74) and Magic lasso (DE-71)
  128. {
  129. auto& pr = ui.getPianoRollForSnapshot();
  130. ui.showPanelsForSnapshot ({ workspace::Panel::pianoRoll });
  131. offline.dispatchPendingMessages();
  132. // a channel with notes in a pattern
  133. for (int p = 0; p < (int) offline.getSong().patterns.size(); ++p)
  134. if (! offline.getSong().patterns[(std::size_t) p].notes.empty())
  135. {
  136. const auto ch = offline.getSong().patterns[(std::size_t) p].notes.front().channel;
  137. offline.editSong ([p] (Song& s) { s.currentPattern = p; }, false);
  138. offline.setSelectedChannel (ch);
  139. break;
  140. }
  141. offline.dispatchPendingMessages();
  142. pr.runAction ("pianoRoll.zoomAll"); // (the pattern's notes in view)
  143. pr.scrollToNotes();
  144. offline.dispatchPendingMessages();
  145. line ("piano roll " + pr.getBounds().toString());
  146. pr.setToolForSnapshot (EditTool::pencil);
  147. const auto& strip = pr.toolsForSnapshot();
  148. const auto list = strip.toolList();
  149. juce::MouseWheelDetails down {}, up {};
  150. down.deltaY = -0.5f;
  151. up.deltaY = 0.5f;
  152. const auto at = juce::Point<int> (pr.getWidth() / 2, pr.getHeight() / 2);
  153. const auto right = juce::ModifierKeys (juce::ModifierKeys::rightButtonModifier);
  154. pr.mouseWheelMove (mouseOn (pr, at, right), down);
  155. const auto first = strip.getTool();
  156. pr.mouseWheelMove (mouseOn (pr, at, right), down);
  157. const auto second = strip.getTool();
  158. pr.mouseWheelMove (mouseOn (pr, at, right), up);
  159. pr.mouseWheelMove (mouseOn (pr, at, right), up);
  160. pr.mouseWheelMove (mouseOn (pr, at, right), up);
  161. line ("right-hold + wheel: " + juce::String (tr (editToolInfo (first).name)) + ", " + tr (editToolInfo (second).name) + ", back to "
  162. + tr (editToolInfo (strip.getTool()).name));
  163. check ("right-hold + wheel down: the next tools to the right (Draw -> Paint -> the next)", list.size() > 2 && first == list[1] && second == list[2]);
  164. check ("wheel up goes back and stops at the first tool (no wrap)", strip.getTool() == list[0]);
  165. const auto mode = toolModeMenu (strip, nullptr, pr.mainMenu != nullptr ? pr.mainMenu() : juce::PopupMenu());
  166. const auto modeItems = texts (mode);
  167. line ("middle + right menu: " + modeItems.joinIntoString (" | ").substring (0, 300));
  168. const auto* draw = find (mode, tr (editToolInfo (list[0]).name));
  169. check ("middle + right: a Mode column of the tools (the one in use ticked), then the main menu",
  170. modeItems[0] == "[" + tr ("Mode") + "]" && draw != nullptr && draw->isTicked && modeItems.size() > (int) list.size() + 3);
  171. saveMenus (juce::StringArray { tr ("Mode") }, { mode }, prefix + "-menu-pr-mode.png");
  172. const auto zoom = quickZoomMenu ("pianoRoll.", nullptr, PianoRollComponent::shortcutText, false);
  173. const auto zoomItems = texts (zoom);
  174. line ("Zoom icon menu (Piano roll): " + zoomItems.joinIntoString (" | "));
  175. const auto* stepZoom = find (zoom, tr ("Step sequencer mode zoom"));
  176. check ("Zoom icon menu: FL's 8 items in FL's order (Step sequencer mode zoom greyed)",
  177. zoomItems.size() == 11 && zoomItems[0].startsWith (tr ("Zoom in")) && zoomItems[3].startsWith (tr ("Quick zoom 1"))
  178. && zoomItems[7].startsWith (tr ("Zoom out far")) && stepZoom != nullptr && ! stepZoom->isEnabled);
  179. saveMenus (juce::StringArray { tr ("Zoom") }, { zoom }, prefix + "-menu-pr-zoom.png");
  180. const auto plZoom = quickZoomMenu ("playlist.", nullptr, PlaylistComponent::shortcutText, false);
  181. check ("Zoom icon menu (Playlist): Zoom on performance clips last", texts (plZoom)[10].startsWith (tr ("Zoom on performance clips")));
  182. saveMenus (juce::StringArray { tr ("Zoom") }, { plZoom }, prefix + "-menu-pl-zoom.png");
  183. // Magic lasso: the Select submenu's last item; on, a loop drawn around a note (no button) selects it
  184. const auto select = pr.selectMenuForSnapshot();
  185. const auto selectItems = texts (select);
  186. check ("Select submenu: Magic lasso last, after a line, off", selectItems.size() > 2 && selectItems[selectItems.size() - 1] == tr ("Magic lasso")
  187. && selectItems[selectItems.size() - 2] == "-" && ! EditorGlobals::get().pianoRollMagicLasso);
  188. EditorGlobals::get().pianoRollMagicLasso = true;
  189. pr.setSelectionForSnapshot ({});
  190. // (FL's rule: with nothing selected a loop has to hold two notes or more)
  191. const auto target = pr.firstVisibleNoteForSnapshot();
  192. const auto other = pr.firstVisibleNoteForSnapshot (target.index, target.bounds.getCentre());
  193. line ("lasso notes " + juce::String (target.index) + " at " + target.bounds.toString() + ", " + juce::String (other.index) + " at " + other.bounds.toString());
  194. check ("two notes of the channel on screen for the lasso", target.index >= 0 && other.index >= 0);
  195. if (target.index >= 0 && other.index >= 0)
  196. {
  197. const auto both = target.bounds.getUnion (other.bounds);
  198. const auto c = both.getCentre();
  199. const auto rx = 40.0 + 0.75 * both.getWidth(), ry = 30.0 + 0.75 * both.getHeight();
  200. for (int k = 0; k <= 46; ++k) // a loop around them, then a little past the start so the trail closes
  201. {
  202. const auto a = juce::MathConstants<double>::twoPi * k / 40.0;
  203. pr.mouseMove (mouseOn (pr, { c.x + juce::roundToInt (rx * std::cos (a)), c.y + juce::roundToInt (ry * std::sin (a)) }, {}));
  204. }
  205. const auto chosen = pr.selectionForTests();
  206. line ("selected after the loop: " + juce::String ((int) chosen.size()) + " note(s)");
  207. check ("Magic lasso: a loop around two notes selects them", std::find (chosen.begin(), chosen.end(), target.index) != chosen.end()
  208. && std::find (chosen.begin(), chosen.end(), other.index) != chosen.end());
  209. zoomShot (pr, both.expanded (juce::roundToInt (rx * 0.6) + 20, juce::roundToInt (ry * 0.6) + 20), 1.5f, "pr-magic-lasso@150");
  210. }
  211. EditorGlobals::get().pianoRollMagicLasso = false;
  212. }
  213. // ---- the rack's Restretch all (DE-38)
  214. {
  215. const auto menu = ui.rackMenuForSnapshot();
  216. const auto items = texts (menu);
  217. int unzip = -1;
  218. for (int i = 0; i < items.size() && unzip < 0; ++i)
  219. if (items[i].startsWith (tr ("Unzip all")))
  220. unzip = i;
  221. const auto* restretch = find (menu, tr ("Restretch all"));
  222. line ("rack menu around it: " + items.joinIntoString (" | ").fromFirstOccurrenceOf (tr ("Zip selected"), true, false).substring (0, 200));
  223. check ("rack menu: Restretch all Ctrl+Alt+R after Unzip all, behind a line", restretch != nullptr && unzip >= 0 && items[unzip + 1] == "-"
  224. && items[unzip + 2].startsWith (tr ("Restretch all")));
  225. saveMenus (juce::StringArray { tr ("Channel Rack") }, { menu }, prefix + "-menu-rack.png");
  226. const auto count = restretchableChannels (offline.getSong());
  227. line ("channels stretched ahead of time: " + juce::String (count));
  228. check ("Restretch all is greyed exactly when no channel is stretched ahead of time", restretch != nullptr && restretch->isEnabled == (count > 0));
  229. const auto bpm = offline.getSong().bpm;
  230. const auto done = offline.restretchAll();
  231. offline.dispatchPendingMessages();
  232. check ("Restretch all runs on those channels and changes nothing in the song", done == count && offline.getSong().bpm == bpm);
  233. }
  234. // ---- the Mixer's FX slot menu in FL's order (DF-77)
  235. {
  236. auto& mixer = ui.getMixerForSnapshot();
  237. ui.showPanelsForSnapshot ({ workspace::Panel::mixer });
  238. mixer.selectFirstTrackWithEffects();
  239. offline.dispatchPendingMessages();
  240. const auto t = mixer.getSelectedTrack();
  241. int slot = -1;
  242. if (t >= 0 && t < (int) offline.getSong().mixer.size())
  243. slot = offline.getSong().mixer[(std::size_t) t].effects.empty() ? -1 : 0;
  244. line ("slot menu of insert " + juce::String (t) + " slot " + juce::String (slot + 1));
  245. if (slot >= 0)
  246. {
  247. const auto menu = mixer.slotMenuForSnapshot (slot);
  248. const auto items = texts (menu);
  249. line ("slot menu: " + items.joinIntoString (" | ").substring (0, 600));
  250. const juce::StringArray fl { tr ("Replace"), tr ("Delete..."), tr ("Patcherize"), tr ("Patcherize all"), "[" + tr ("Presets") + "]", tr ("Presets"),
  251. tr ("Browse presets"), tr ("Save preset as..."), tr ("Add to plugin database (flag as favorite)"),
  252. tr ("Display preset name in preset selector"), "[" + tr ("Spare state") + "]", tr ("Store in spare state"),
  253. tr ("Flip with spare state"), "[" + tr ("Parameters") + "]", tr ("Link all parameters..."), tr ("Browse parameters"),
  254. "[" + tr ("CPU") + "]", tr ("Allow threaded processing"), tr ("Smart disable"), tr ("Move up"), tr ("Move down"),
  255. tr ("View editor"), tr ("Rename, color and icon..."), tr ("Change color..."), tr ("Random color"), tr ("Change icon..."),
  256. tr ("Scaling"), tr ("Help") };
  257. juce::StringArray got;
  258. for (const auto& i : items)
  259. if (i != "-")
  260. got.add (i.upToFirstOccurrenceOf ("\t", false, false));
  261. bool inOrder = got.size() >= fl.size();
  262. for (int i = 0; i < fl.size() && inOrder; ++i)
  263. inOrder = got[i] == fl[i];
  264. check ("FX slot menu: FL's 28 items in FL's order first, LYNX's own after", inOrder);
  265. saveMenus (juce::StringArray { "FX slot " + juce::String (slot + 1) }, { menu }, prefix + "-menu-mixer-slot.png");
  266. }
  267. }
  268. juce::File (prefix + "-checks.txt").replaceWithText (checks + "result=" + (allOk ? "OK" : "FAIL") + "\n");
  269. return allOk;
  270. }