IssuesShot190ng.inc 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. // --issuesshot190ng <prefix> (round 190ng, issues #215, #217, #219, #220, #222), offscreen through the real components:
  2. // Esc closes the focused panel (FL 2026; a selection is cleared first; the switch keeps them open), FL's Backspace snap
  3. // key from the key map, the icon picker's search box and the "Rename, color and icon" window, the big track icons of
  4. // tall Playlist rows, and the Export window's file name wildcards. <prefix>-checks.txt lists the checks; pictures @100
  5. // and @150. Included in the app class of Main.cpp.
  6. bool runIssuesShot190ng (const juce::String& prefix)
  7. {
  8. juce::LookAndFeel::setDefaultLookAndFeel (&lookAndFeel);
  9. const juce::ScopedValueSetter<bool> shown (lynx::ui::showingForShots(), true);
  10. juce::String checks;
  11. bool allOk = true;
  12. const auto check = [&checks, &allOk] (const juce::String& what, bool ok) {
  13. checks << (ok ? "ok " : "FAIL ") << what << "\n";
  14. allOk = allOk && ok;
  15. };
  16. const auto line = [&checks] (const juce::String& what) { checks << " " << what << "\n"; };
  17. const auto write = [&prefix] (juce::Component& c, juce::Rectangle<int> area, const juce::String& name) {
  18. area = area.getIntersection (c.getLocalBounds());
  19. if (area.isEmpty())
  20. return;
  21. savePng (c.createComponentSnapshot (area, true, 1.0f), prefix + "-" + name + ".png");
  22. savePng (c.createComponentSnapshot (area, true, 1.5f), prefix + "-" + name + "@150.png");
  23. };
  24. using namespace lynx;
  25. using workspace::Panel;
  26. // ================= #217: Esc closes the focused window =================
  27. {
  28. AudioEngine offline (false);
  29. {
  30. auto song = Song::makeDefault();
  31. Clip c;
  32. c.kind = ClipKind::pattern;
  33. c.pattern = 0;
  34. c.track = 0;
  35. c.start = 0;
  36. c.length = 4 * ppq * 4;
  37. song.playlist.push_back (c);
  38. offline.setSong (song);
  39. }
  40. MainComponent ui (offline, false);
  41. ui.setSize (1600, 900);
  42. offline.dispatchPendingMessages();
  43. auto& ws = ui.workspaceForTest();
  44. const auto esc = juce::KeyPress (juce::KeyPress::escapeKey);
  45. check ("FL 2026's default: on", escclose::enabled());
  46. for (const auto panel : { Panel::channelRack, Panel::mixer, Panel::pianoRoll })
  47. {
  48. ui.showPanelsForSnapshot ({ panel });
  49. ws.show (panel);
  50. ws.activate (panel);
  51. const auto was = ws.isPanelVisible (panel);
  52. ui.keyPressed (esc);
  53. check ("Esc closes the focused " + juce::String (panel == Panel::channelRack ? "Channel rack" : panel == Panel::mixer ? "Mixer" : "Piano roll"),
  54. was && ! ws.isPanelVisible (panel));
  55. }
  56. // the Playlist with a selection: the first Esc clears it (LYNX, issue #218), the next closes the window (FL)
  57. ws.show (Panel::playlist);
  58. ws.activate (Panel::playlist);
  59. auto& pl = ui.getPlaylistForSnapshot();
  60. pl.keyForTests (juce::KeyPress ('a', juce::ModifierKeys::commandModifier, 0));
  61. const auto selected = ! pl.getSelectedClips().empty();
  62. ui.keyPressed (esc);
  63. check ("Playlist with clips selected: the first Esc clears the selection, the Playlist stays",
  64. selected && pl.getSelectedClips().empty() && ws.isPanelVisible (Panel::playlist));
  65. ui.keyPressed (esc);
  66. check ("the next Esc closes the Playlist (FL)", ! ws.isPanelVisible (Panel::playlist));
  67. // the switch off: Esc leaves windows open
  68. workflowextras::setExtra ("general.escCloses", false);
  69. ws.show (Panel::mixer);
  70. ws.activate (Panel::mixer);
  71. ui.keyPressed (esc);
  72. check ("switch off: Esc leaves the Mixer open", ws.isPanelVisible (Panel::mixer));
  73. workflowextras::setExtra ("general.escCloses", true);
  74. check ("the switch is saved with the UI options", workflowextras::uiOptionsText().contains ("escClosesWindows=1"));
  75. // Settings: LYNX extras and General list the switch
  76. for (const auto general : { false, true })
  77. {
  78. auto page = general ? makeGeneralPage (offline, {}, false) : makeExtrasPage (offline, {}, false);
  79. page->setSize (680, 3600);
  80. juce::Component* found = nullptr;
  81. std::function<void (juce::Component&)> walk = [&] (juce::Component& c) {
  82. if (auto* b = dynamic_cast<juce::ToggleButton*> (&c); b != nullptr && b->getButtonText() == tr ("Esc closes the focused window"))
  83. found = b;
  84. for (auto* child : c.getChildren())
  85. walk (*child);
  86. };
  87. walk (*page);
  88. check (juce::String (general ? "Settings › General" : "Settings › LYNX extras") + " has \"Esc closes the focused window\", ticked",
  89. found != nullptr && dynamic_cast<juce::ToggleButton*> (found)->getToggleState());
  90. if (found != nullptr)
  91. {
  92. const auto r = page->getLocalArea (found, found->getLocalBounds());
  93. write (*page, juce::Rectangle<int> (0, r.getY() - 40, page->getWidth(), 120), general ? "esc-general" : "esc-extras");
  94. }
  95. }
  96. // ================= #219: FL's snap key, in the key map =================
  97. const auto snapOn = [] { return EditorGlobals::get().getGridOption() != grid::noneOption; };
  98. ws.show (Panel::playlist);
  99. ws.activate (Panel::playlist);
  100. const auto before = snapOn();
  101. ui.keyPressed (juce::KeyPress (juce::KeyPress::backspaceKey));
  102. check ("Backspace in the Playlist turns the main snap off / on (FL)", snapOn() != before);
  103. ui.keyPressed (juce::KeyPress (juce::KeyPress::backspaceKey));
  104. check ("again: back", snapOn() == before);
  105. ui.runActionForSnapshot ("snap.toggle");
  106. check ("\"Snap on/off, from any window\" (for a key of one's own, e.g. Alt+S) does the same", snapOn() != before);
  107. ui.runActionForSnapshot ("snap.toggle");
  108. line ("snap keys: " + juce::String (ui.getKeyMapForSnapshot().isDefault ("playlist.snapToggle") ? "Backspace (FL)" : "changed"));
  109. }
  110. // ================= #220: the icon picker's search box, the Rename, color and icon window =================
  111. {
  112. ui::TrackIconPicker picker (5, 10, nullptr);
  113. picker.setSize (picker.getWidth(), picker.getHeight());
  114. const auto all = picker.shownCount();
  115. picker.setQuery ("gu");
  116. check ("search \"gu\": the guitars only", picker.shownCount() == 2);
  117. write (picker, picker.getLocalBounds(), "icons-search-gu");
  118. picker.setQuery ("hat");
  119. check ("search \"hat\": Hi-hat", picker.shownCount() == 1 && picker.shownFlIndex (0) == 239);
  120. check ("Enter picks the one shown", picker.pickFirstShown() && picker.pickedFlIndex() == 239);
  121. picker.setQuery ("");
  122. check ("cleared: every icon again", picker.shownCount() == all);
  123. write (picker, picker.getLocalBounds(), "icons-all");
  124. auto dialog = makeNameAndColourDialog (tr ("Rename track"), "Kick", lynxPalette()[1], 5);
  125. auto* icons = iconPickerOfNameDialog (*dialog);
  126. check ("Rename, color and icon: the icon picker is in the window", icons != nullptr && icons->pickedFlIndex() == 5);
  127. if (icons != nullptr)
  128. {
  129. icons->setQuery ("sn");
  130. icons->pickFirstShown();
  131. check ("a pick in the window is what OK applies (Snare)", icons->pickedFlIndex() == 4);
  132. icons->setQuery ("");
  133. icons->pick (5);
  134. }
  135. dialog->setOpaque (true);
  136. juce::Component frame;
  137. frame.setSize (dialog->getWidth(), dialog->getHeight());
  138. frame.setOpaque (true);
  139. frame.addAndMakeVisible (*dialog);
  140. dialog->setTopLeftPosition (0, 0);
  141. write (frame, frame.getLocalBounds(), "rename-color-icon");
  142. frame.removeChildComponent (dialog.get());
  143. auto patternDialog = makeNameAndColourDialog (tr ("Rename pattern"), "Pattern 1", lynxPalette()[6]);
  144. check ("patterns keep the name and colour window (FL: no icon)", iconPickerOfNameDialog (*patternDialog) == nullptr);
  145. }
  146. // ================= #222: track icons grow with the track =================
  147. {
  148. AudioEngine engine (false);
  149. auto song = Song::makeDefault();
  150. const std::pair<const char*, int> rows[] = { { "Kick", 5 }, { "Vocals", 20 }, { "Bass", 14 }, { "FX", 93 } };
  151. song.playlistTracks.resize (6);
  152. for (int i = 0; i < 4; ++i)
  153. {
  154. song.playlistTracks[(std::size_t) i].name = rows[i].first;
  155. song.playlistTracks[(std::size_t) i].icon = rows[i].second;
  156. song.playlistTracks[(std::size_t) i].colour = lynxPalette()[(std::size_t) (1 + 2 * i)];
  157. }
  158. engine.setSong (song);
  159. engine.dispatchPendingMessages();
  160. PlaylistComponent pl (engine);
  161. pl.setBounds (0, 0, 900, 700);
  162. pl.setVisible (true);
  163. pl.setViewForSnapshot (160.0, 0, 0);
  164. const int heights[] = { 56, 92, 116, 160 };
  165. for (int i = 0; i < 4; ++i)
  166. pl.setTrackHeightsForTest ({ i }, heights[i]);
  167. engine.dispatchPendingMessages();
  168. line ("row heights: " + juce::String (pl.trackRowForSnapshot (0).getHeight()) + ", " + juce::String (pl.trackRowForSnapshot (1).getHeight()) + ", "
  169. + juce::String (pl.trackRowForSnapshot (2).getHeight()) + ", " + juce::String (pl.trackRowForSnapshot (3).getHeight()));
  170. const auto img = pl.createComponentSnapshot (pl.getLocalBounds(), true, 1.0f);
  171. // the big icon: pixels of the plate's shade in the middle of a tall header, none in a short one
  172. const auto shadeCount = [&] (int t) {
  173. const auto row = pl.trackRowForSnapshot (t);
  174. const auto plate = img.getPixelAt (8, row.getY() + 4);
  175. const auto shadeCol = trackiconscale::shade (plate);
  176. int n = 0;
  177. for (int y = row.getY() + row.getHeight() / 4; y < row.getBottom() - row.getHeight() / 4; ++y)
  178. for (int x = 20; x < pl.headerWidthForSnapshot() - 30; ++x)
  179. {
  180. const auto p = img.getPixelAt (x, y);
  181. n += std::abs (p.getRed() - shadeCol.getRed()) + std::abs (p.getGreen() - shadeCol.getGreen()) + std::abs (p.getBlue() - shadeCol.getBlue()) < 12 ? 1 : 0;
  182. }
  183. return n;
  184. };
  185. const int counts[] = { shadeCount (0), shadeCount (1), shadeCount (2), shadeCount (3) };
  186. line ("big icon pixels per row: " + juce::String (counts[0]) + " " + juce::String (counts[1]) + " " + juce::String (counts[2]) + " " + juce::String (counts[3]));
  187. check ("a 56 px row: no big icon (FL)", counts[0] < 10);
  188. check ("92 / 116 / 160 px rows: the big icon, larger with the row", counts[1] > 40 && counts[2] > counts[1] && counts[3] > counts[2]);
  189. write (pl, juce::Rectangle<int> (0, 0, pl.headerWidthForSnapshot() + 220, pl.trackRowForSnapshot (3).getBottom() + 4), "tall-track-icons");
  190. }
  191. // ================= #215: the export file name =================
  192. {
  193. AudioEngine engine (false);
  194. auto song = Song::makeDefault();
  195. song.bpm = 128.0;
  196. engine.setSong (song);
  197. juce::String preview, resolved;
  198. const auto when = juce::Time (2026, 10, 19, 21, 35, 7, 0, true); // (19 November 2026, 21:35:07)
  199. auto panel = makeExportPanelWithName (engine, "MySong", "$project_$date_$bpm", when, preview, resolved);
  200. line ("preview: " + preview);
  201. check ("the name the template gives", resolved == "MySong_2026-11-19_128");
  202. check ("the window shows it with the extension", preview.contains ("MySong_2026-11-19_128.wav"));
  203. write (*panel, panel->getLocalBounds(), "export-name");
  204. auto stems = makeExportPanelWithName (engine, "MySong", "$project_$track", when, preview, resolved, 1);
  205. line ("stems preview: " + preview);
  206. check ("stems: $track names each stem file", preview.contains ("MySong_Kick.wav"));
  207. auto plain = makeExportPanelWithName (engine, "MySong", "", when, preview, resolved);
  208. check ("empty template: the project's name, as before", resolved == "MySong");
  209. auto unsafe = makeExportPanelWithName (engine, "My:Song?", "$project $format", when, preview, resolved);
  210. check ("unsafe characters become \"_\"", resolved == "My_Song_ WAV");
  211. // (round 190qb, #215 follow-up: a "/" typed in the template is a folder now, --issuesshot190qb)
  212. }
  213. juce::File (prefix + "-checks.txt").replaceWithText (checks + "result=" + (allOk ? "OK" : "FAIL") + "\n");
  214. return allOk;
  215. }