IssuesShot190qo.inc 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. // --issuesshot190qo <prefix> (round 190qo, issues #239, #215, #251, #270), offscreen through the real components:
  2. // Settings › LYNX extras › Automatic colors and icons adds a second, third... rule (the page used to lay itself out
  3. // before the new row, so "Add rule" ended under the section's bottom edge after the first rule), moves rules up and
  4. // down, removes one; the two new LYNX extras on the page; the typing keyboard's layouts. <prefix>-checks.txt lists
  5. // the checks; pictures @100 and @150. Included in the app class of Main.cpp.
  6. bool runIssuesShot190qo (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. const auto pump = [] {
  25. #if JUCE_LINUX || JUCE_WINDOWS
  26. for (int i = 0; i < 256 && juce::detail::dispatchNextMessageOnSystemQueue (true); ++i) {}
  27. #endif
  28. };
  29. const auto findId = [] (juce::Component& root, const juce::String& id) -> juce::Component* {
  30. std::function<juce::Component* (juce::Component&)> find = [&] (juce::Component& c) -> juce::Component* {
  31. if (c.getComponentID() == id)
  32. return &c;
  33. for (auto* child : c.getChildren())
  34. if (auto* f = find (*child))
  35. return f;
  36. return nullptr;
  37. };
  38. return find (root);
  39. };
  40. // scrolls the page's viewport so `c` sits 40 px under its top (the shots take the panel's own pixels)
  41. const auto reveal = [&pump] (juce::Component& c) {
  42. if (auto* viewport = c.findParentComponentOfClass<juce::Viewport>())
  43. if (auto* content = viewport->getViewedComponent())
  44. viewport->setViewPosition (0, juce::jmax (0, content->getLocalPoint (&c, juce::Point<int>()).y - 40));
  45. pump();
  46. };
  47. using namespace lynx;
  48. // ================= #239: several rules =================
  49. {
  50. const auto saved = autolook::current();
  51. autolook::current() = {};
  52. AudioEngine offline (false);
  53. auto panel = makeSettingsPanel (offline, SettingsPage::extras);
  54. panel->setSize (1000, 700); // (a window's height: the page scrolls, as in the reporter's picture)
  55. pump();
  56. auto* add = dynamic_cast<juce::Button*> (findId (*panel, "autoLook.add"));
  57. auto* editor = add != nullptr ? dynamic_cast<AutoLookEditor*> (add->getParentComponent()) : nullptr;
  58. check ("#239 the rules editor and its Add rule button", editor != nullptr);
  59. if (editor != nullptr)
  60. {
  61. // the editor shows all it holds: Add rule inside its bounds, its bounds as tall as it asks for
  62. const auto whole = [editor, add] {
  63. return editor->getHeight() >= editor->heightFor (editor->getWidth()) && add->getBottom() <= editor->getHeight()
  64. && add->isVisible() && add->getWidth() > 0;
  65. };
  66. check ("#239 no rule: Add rule shown", editor->rowCount() == 0 && whole());
  67. const juce::StringArray names { "BEAT", "VOX", "REC" };
  68. for (int i = 0; i < names.size(); ++i)
  69. {
  70. add->onClick();
  71. pump();
  72. autolook::current().list.back().text = names[i].toStdString();
  73. editor->refresh();
  74. pump();
  75. check ("#239 rule " + juce::String (i + 1) + " added: " + juce::String (editor->rowCount()) + " rows, Add rule still inside ("
  76. + juce::String (add->getBottom()) + " <= " + juce::String (editor->getHeight()) + ")",
  77. editor->rowCount() == i + 1 && whole());
  78. }
  79. // (the panel's own pixels: the page behind the rows has no background of its own)
  80. reveal (*editor);
  81. write (*panel, panel->getLocalArea (editor->getParentComponent(), editor->getBoundsInParent().expanded (0, 30)), "239-three-rules");
  82. // up / down: the first matching rule wins, so the order is the user's
  83. auto* up = dynamic_cast<juce::Button*> (findId (*editor, "autoLook.up2"));
  84. check ("#239 the first row can't move up, the last can't move down",
  85. findId (*editor, "autoLook.up0") != nullptr && ! findId (*editor, "autoLook.up0")->isEnabled()
  86. && findId (*editor, "autoLook.down2") != nullptr && ! findId (*editor, "autoLook.down2")->isEnabled());
  87. if (up != nullptr)
  88. {
  89. up->onClick();
  90. pump();
  91. }
  92. const auto order = [] {
  93. juce::StringArray o;
  94. for (const auto& r : autolook::current().list)
  95. o.add (juce::String::fromUTF8 (r.text.c_str()));
  96. return o.joinIntoString (",");
  97. };
  98. check ("#239 REC moved up: " + order(), order() == "BEAT,REC,VOX");
  99. if (auto* down = dynamic_cast<juce::Button*> (findId (*editor, "autoLook.down0")))
  100. {
  101. down->onClick();
  102. pump();
  103. }
  104. check ("#239 BEAT moved down: " + order(), order() == "REC,BEAT,VOX");
  105. // remove the middle one: two rows, the editor shorter, Add rule still inside
  106. const auto tall = editor->getHeight();
  107. if (auto* remove = dynamic_cast<juce::Button*> (findId (*editor, "autoLook.remove1")))
  108. {
  109. remove->onClick();
  110. pump();
  111. }
  112. check ("#239 BEAT removed: " + order() + ", height " + juce::String (tall) + " -> " + juce::String (editor->getHeight()),
  113. order() == "REC,VOX" && editor->rowCount() == 2 && editor->getHeight() < tall && whole());
  114. // a fourth rule after the removal, then the note at a narrow width (three lines in some languages)
  115. add->onClick();
  116. pump();
  117. check ("#239 adding after a removal", editor->rowCount() == 3 && whole());
  118. panel->setSize (620, 700);
  119. pump();
  120. check ("#239 narrow window: the note and the rows still fit", whole() && editor->heightFor (560) >= editor->heightFor (900));
  121. reveal (*editor);
  122. write (*panel, panel->getLocalArea (editor->getParentComponent(), editor->getBoundsInParent().expanded (0, 30)), "239-narrow");
  123. panel->setSize (1000, 700);
  124. pump();
  125. // the new extras' switches (#251, #215) sit on the same page
  126. check ("#251 / #215 switches on the page", findId (*panel, "file.alwaysCollect") != nullptr && findId (*panel, "export.noDialog") != nullptr);
  127. if (auto* collect = findId (*panel, "file.alwaysCollect"))
  128. {
  129. reveal (*collect);
  130. write (*panel, panel->getLocalArea (collect->getParentComponent(), collect->getBoundsInParent().withX (0).withWidth (1000).withHeight (190).translated (0, -40)),
  131. "251-215-extras");
  132. }
  133. }
  134. autolook::current() = saved;
  135. }
  136. // ================= #270: the typing keyboard's layouts =================
  137. {
  138. using namespace keys;
  139. check ("#270 LYNX's chord rule gives FL's own chord layouts back: " + juce::String (typingpiano::chordRuleCheck()), typingpiano::chordRuleCheck() == "OK");
  140. juce::StringArray lynxNames;
  141. for (int i = 0; i < typingpiano::layoutCount(); ++i)
  142. if (typingpiano::layoutSource (i) == typingpiano::Source::lynx)
  143. lynxNames.add (typingpiano::layoutName (i));
  144. line ("#270 LYNX layouts: " + lynxNames.joinIntoString (", "));
  145. check ("#270 Minor Melodic + Chords and Chordmap", lynxNames.contains ("Minor Melodic + Chords") && lynxNames.contains ("Minor Melodic Chordmap"));
  146. }
  147. // ================= #272: slide notes in the Piano roll (FL's ◢ mark) =================
  148. // LYNX_SHOT_FLP=<an .flp with slide notes> (round 190qo: pr/flp/slides272.flp, the project of the FL capture)
  149. if (const auto flp = juce::SystemStats::getEnvironmentVariable ("LYNX_SHOT_FLP", {}); flp.isNotEmpty() && juce::File (flp).existsAsFile())
  150. {
  151. AudioEngine offline (false);
  152. MainComponent ui (offline, false);
  153. ui.setSize (1280, 900);
  154. ui.openFile (juce::File (flp));
  155. offline.dispatchPendingMessages();
  156. pump();
  157. ui.selectTabForSnapshot (1);
  158. offline.dispatchPendingMessages();
  159. pump();
  160. int slides = 0;
  161. for (const auto& n : offline.getSong().activePattern().notes)
  162. slides += n.slide ? 1 : 0;
  163. check ("#272 the .flp's slide notes imported: " + juce::String (slides), slides == 5);
  164. write (ui, ui.getLocalBounds(), "272-pianoroll-slides");
  165. }
  166. juce::File (prefix + "-checks.txt").replaceWithText (checks);
  167. std::printf ("%s", checks.toRawUTF8());
  168. return allOk;
  169. }