Mixer221Shot190ng.inc 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. // --mixer221shot190ng <prefix> (round 190ng, issue #221 "Can't DEL on empty mixer channel"), offscreen: with "Show only
  2. // used inserts" on, "+" brings back an empty insert and Del (its question's choice remembered) deletes it: the blank
  3. // insert that takes its number (FL keeps the count) must not come back into view, and the selection goes to a shown
  4. // insert. Also: FL's menu item and order, and where a remembered answer is undone (Settings › General).
  5. // <prefix>-checks.txt lists the checks; pictures @100 and @150. Included in the app class of Main.cpp.
  6. bool runMixer221Shot190ng (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. const auto keptUsedOnly = MixerStrips::showUsedOnly;
  26. const auto keptHidden = messages::hiddenList();
  27. MixerStrips::showUsedOnly = true;
  28. AudioEngine offline (false);
  29. {
  30. // the issue's mixer: inserts 8, 9, 10, 17, 18 in use (a channel routed to each), the rest empty
  31. auto song = Song::makeDefault();
  32. song.mixer = Song::defaultMixer (18);
  33. for (const auto t : { 8, 9, 10, 17, 18 })
  34. {
  35. ChannelDef c;
  36. c.name = "Ch " + std::to_string (t);
  37. c.mixerTrack = t;
  38. song.channels.push_back (c);
  39. }
  40. offline.setSong (song);
  41. }
  42. MainComponent ui (offline, false);
  43. ui.setSize (1600, 900);
  44. ui.selectTabForSnapshot (3);
  45. offline.dispatchPendingMessages();
  46. auto& mixer = ui.getMixerForSnapshot();
  47. auto& strips = mixer.getStripsForSnapshot();
  48. const auto shownCount = [&strips, &offline] {
  49. int n = 0;
  50. for (int t = 1; t < (int) offline.getSong().mixer.size(); ++t)
  51. n += strips.isHidden (t) ? 0 : 1;
  52. return n;
  53. };
  54. offline.editSong ([] (Song&) {}); // (the main window's first look at the song: FL's Auto select linked modules picks the
  55. offline.dispatchPendingMessages(); // selected channel's insert once, as at start-up)
  56. strips.selectTrack (18);
  57. strips.layoutForTest();
  58. const auto before = shownCount();
  59. const auto count = (int) offline.getSong().mixer.size();
  60. // the issue's "+": a new empty insert at the end, kept in view (MixerStrips' Part::add, without the menu)
  61. offline.editSong ([] (Song& s) { auto& t = s.mixer.emplace_back(); t.name = "Insert " + std::to_string (s.mixer.size() - 1); });
  62. const auto added = (int) offline.getSong().mixer.size() - 1;
  63. strips.revealForTest (added);
  64. check ("\"+\": the new empty insert shows and is selected", ! strips.isHidden (added) && strips.getSelection() == std::vector<int> { added });
  65. check ("\"+\": one more insert shows", shownCount() == before + 1);
  66. write (mixer, mixer.getLocalBounds().withHeight (juce::jmin (mixer.getHeight(), 700)), "mixer-before-del");
  67. // Del with "Remember my choice" ticked earlier (FL's "Yes" remembered): no question, the delete runs at once
  68. messages::setShown ("DeleteMixerTrack", false);
  69. const auto countBefore = (int) offline.getSong().mixer.size();
  70. ui.runActionForSnapshot ("mixer.deleteTracks");
  71. const auto selNow = strips.getSelection();
  72. line ("selected right after Del: " + juce::String (selNow.empty() ? -1 : selNow.front()));
  73. offline.dispatchPendingMessages();
  74. strips.layoutForTest();
  75. const auto sel = strips.getSelection();
  76. line ("after Del: " + juce::String ((int) offline.getSong().mixer.size()) + " inserts (count kept as FL), selected "
  77. + juce::String (sel.empty() ? -1 : sel.front()) + ", shown " + juce::String (shownCount()) + " (before \"+\": " + juce::String (before) + ")");
  78. check ("Del: FL keeps the insert count (a blank one at the end)", (int) offline.getSong().mixer.size() == countBefore);
  79. check ("Del: the blank insert under the deleted number stays hidden (it looked as if Del did nothing)", strips.isHidden (added));
  80. check ("Del: as many inserts show as before \"+\"", shownCount() == before);
  81. check ("Del: the selection goes to the shown insert before it (18)", sel == std::vector<int> { 18 });
  82. write (mixer, mixer.getLocalBounds().withHeight (juce::jmin (mixer.getHeight(), 700)), "mixer-after-del");
  83. // two empty inserts added, the first deleted: the second (now under the first's number) stays shown and selected
  84. offline.editSong ([] (Song& s) { for (int i = 0; i < 2; ++i) { auto& t = s.mixer.emplace_back(); t.name = "Insert " + std::to_string (s.mixer.size() - 1); } });
  85. const auto a = (int) offline.getSong().mixer.size() - 2, b = a + 1;
  86. strips.revealForTest (b);
  87. strips.revealForTest (a);
  88. ui.runActionForSnapshot ("mixer.deleteTracks");
  89. offline.dispatchPendingMessages();
  90. strips.layoutForTest();
  91. check ("Del on the first of two added inserts: the second moves into its place and shows, selected",
  92. ! strips.isHidden (a) && strips.isHidden (b) && strips.getSelection() == std::vector<int> { a });
  93. // "Show only used inserts" off: FL's selection (the same number)
  94. MixerStrips::showUsedOnly = false;
  95. strips.layoutForTest();
  96. strips.selectTrack (9);
  97. ui.runActionForSnapshot ("mixer.deleteTracks");
  98. offline.dispatchPendingMessages();
  99. check ("all inserts shown: Del keeps the number selected (FL)", strips.getSelection() == std::vector<int> { 9 });
  100. MixerStrips::showUsedOnly = true;
  101. // the remembered choice: only Yes can be remembered; Settings › General › Manage messages brings the question back
  102. check ("Manage messages lists \"Delete mixer track\", unticked while remembered", [] {
  103. const auto menu = messages::manageMenu();
  104. for (juce::PopupMenu::MenuItemIterator it (menu); it.next();)
  105. if (it.getItem().text == tr ("Delete mixer track"))
  106. return ! it.getItem().isTicked;
  107. return false;
  108. }());
  109. messages::setShown ("DeleteMixerTrack", true);
  110. check ("ticked again (or Show all): the question is asked again", messages::shown ("DeleteMixerTrack"));
  111. // FL's menu: "Delete Del" in the Layout group, after Move right, before Insert one (fl-mixer-track-menu.png)
  112. {
  113. const auto menu = strips.buildMenu (18);
  114. juce::StringArray items;
  115. std::function<void (const juce::PopupMenu&)> walk = [&] (const juce::PopupMenu& m) {
  116. for (juce::PopupMenu::MenuItemIterator it (m); it.next();)
  117. if (! it.getItem().isSeparator && ! it.getItem().isSectionHeader)
  118. items.add (it.getItem().text);
  119. };
  120. walk (menu);
  121. const auto del = items.indexOf (tr ("Delete") + "\tDel");
  122. check ("the track menu has FL's \"Delete Del\"", del >= 0);
  123. check ("FL's order: Move right, Delete, Insert one", del > 0 && items[del - 1].startsWith (tr ("Move right")) && items[del + 1] == tr ("Insert one"));
  124. }
  125. // Settings › General: Manage messages and the note under it
  126. {
  127. auto page = makeGeneralPage (offline, {}, false);
  128. page->setSize (680, 3600);
  129. juce::Component* button = nullptr;
  130. std::function<void (juce::Component&)> walk = [&] (juce::Component& c) {
  131. if (auto* b = dynamic_cast<juce::Button*> (&c); b != nullptr && b->getButtonText() == tr ("Manage messages"))
  132. button = b;
  133. for (auto* child : c.getChildren())
  134. walk (*child);
  135. };
  136. walk (*page);
  137. check ("Settings › General has Manage messages", button != nullptr);
  138. if (button != nullptr)
  139. {
  140. const auto area = page->getLocalArea (button, button->getLocalBounds()).withX (0).withWidth (page->getWidth()).expanded (0, 40);
  141. write (*page, area.withHeight (area.getHeight() + 30), "settings-manage-messages");
  142. }
  143. }
  144. messages::setHiddenList (keptHidden);
  145. MixerStrips::showUsedOnly = keptUsedOnly;
  146. juce::File (prefix + "-checks.txt").replaceWithText (checks + "result=" + (allOk ? "OK" : "FAIL") + "\n");
  147. return allOk;
  148. }