| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321 |
- // Round 190sk (Discord norenkae 11-28: "export to DAWproject does nothing in lynx"): File › Export › "DAWproject
- // (.dawproject)..." opened nothing in 0.1.31.x and the 0.1.32 rollup: its chooser was a local std::shared_ptr its own
- // callback did not keep, so it died (and its dialog with it) when the menu action returned. "Save a copy as FL Studio
- // Mobile project (.flm)..." had the same fault behind its first window. The selftests wrote both files without the
- // menu, so nothing saw it. This check drives the real menu (MainComponent::getMenuForIndex, the items' own actions)
- // with JUCE's built-in chooser (LYNX_FILE_DIALOG=builtin):
- // 1. every item of File, File › New from template, Open in new window, Import and Export whose name ends in "..."
- // (FL's sign for "opens a window") opens one: a modal component, a window on the desktop or a panel in the main
- // window that was not there before, still there after the message loop ran; then it is cancelled;
- // 2. the export items whose first window leads to a chooser (FLM's losses window, Export to FL Studio, Ableton Live
- // set, Save a copy for an older LYNX) reach their chooser;
- // 3. DAWproject end to end: the menu item, the chooser given a file name, the file written on the worker (a zip with
- // project.xml and metadata.xml) and the report window; FLM the same way.
- // Included in the app class of Main.cpp; --menuwindows190sktest <report> and --selftest "menuwindows190sk". The windows
- // show on the desktop for a moment: on Windows it runs only on CI or with LYNX_MENUSWEEP=1 (the owner's screen).
- juce::String menuWindows190skCheck (juce::String& log)
- {
- using namespace lynx;
- juce::String result = "OK";
- const auto check = [&] (const juce::String& what, bool ok, const juce::String& detail = {}) {
- log << (ok ? "ok " : "FAIL ") << what << (detail.isNotEmpty() ? " (" + detail + ")" : juce::String()) << "\n";
- if (! ok && result == "OK")
- result = "ERROR " + what;
- };
- #if JUCE_MAC
- log << "skipped on macOS (the selftest has no message pump there)\n";
- return result;
- #else
- #if JUCE_WINDOWS
- if (juce::SystemStats::getEnvironmentVariable ("CI", {}).isEmpty() && juce::SystemStats::getEnvironmentVariable ("GITHUB_ACTIONS", {}).isEmpty()
- && juce::SystemStats::getEnvironmentVariable ("LYNX_MENUSWEEP", {}) != "1")
- {
- log << "skipped on this Windows desktop (windows would show on the owner's screen): LYNX_MENUSWEEP=1 runs it\n";
- return result;
- }
- #endif
- const auto setEnv = [] (const char* name, const juce::String& value) {
- #if JUCE_WINDOWS
- _putenv_s (name, value.toRawUTF8());
- #else
- if (value.isEmpty())
- unsetenv (name);
- else
- setenv (name, value.toRawUTF8(), 1);
- #endif
- };
- const auto oldDialog = juce::SystemStats::getEnvironmentVariable ("LYNX_FILE_DIALOG", {});
- setEnv ("LYNX_FILE_DIALOG", "builtin");
- const auto root = juce::File::getSpecialLocation (juce::File::tempDirectory).getChildFile ("lynx-menu190sk-" + juce::String (juce::Random::getSystemRandom().nextInt64()));
- root.createDirectory();
- {
- AudioEngine offline (false);
- MainComponent ui (offline, false);
- ui.setSize (1600, 900);
- ui.setVisible (true);
- const auto settle = [&offline] {
- for (int k = 0; k < 4; ++k)
- offline.dispatchPendingMessages();
- for (int i = 0; i < 256 && juce::detail::dispatchNextMessageOnSystemQueue (true); ++i) {}
- };
- const auto pump = [&settle] (int ms) {
- const auto end = juce::Time::getMillisecondCounter() + (juce::uint32) ms;
- while (juce::Time::getMillisecondCounter() < end)
- {
- settle();
- juce::Thread::sleep (10);
- }
- };
- // a short song: a pattern of four notes on the first channel, once on the playlist
- offline.editSong ([] (Song& s) {
- if (s.channels.empty())
- return;
- Pattern p;
- p.name = "Pattern 1";
- for (int i = 0; i < 4; ++i)
- {
- Note n;
- n.channel = 0;
- n.key = 60 + i * 2;
- n.start = i * ppq;
- n.length = ppq / 2;
- p.notes.push_back (n);
- }
- s.patterns = { p };
- Clip c;
- c.kind = ClipKind::pattern;
- c.pattern = 0;
- c.track = 0;
- c.start = 0;
- c.length = 4 * ppq;
- s.playlist = { c };
- s.mode = PlayMode::song;
- });
- pump (300);
- auto* modal = juce::ModalComponentManager::getInstance();
- const auto desktop = [] {
- std::set<juce::Component*> s;
- auto& d = juce::Desktop::getInstance();
- for (int i = 0; i < d.getNumComponents(); ++i)
- if (auto* c = d.getComponent (i); c != nullptr && c->isVisible())
- s.insert (c);
- return s;
- };
- const auto panels = [&ui] {
- std::set<juce::Component*> s;
- for (auto* c : ui.getChildren())
- if (c->isVisible() && c->getWidth() >= 120 && c->getHeight() >= 60)
- s.insert (c);
- return s;
- };
- const auto nameOf = [] (juce::Component* c) {
- if (auto* w = dynamic_cast<juce::TopLevelWindow*> (c); w != nullptr && w->getName().isNotEmpty())
- return w->getName();
- return c->getName().isNotEmpty() ? c->getName() : juce::String ("unnamed");
- };
- std::function<juce::Component* (juce::Component*, const std::function<bool (juce::Component*)>&)> find;
- find = [&find] (juce::Component* in, const std::function<bool (juce::Component*)>& pred) -> juce::Component* {
- if (in == nullptr)
- return nullptr;
- if (pred (in))
- return in;
- for (auto* c : in->getChildren())
- if (auto* f = find (c, pred))
- return f;
- return nullptr;
- };
- const auto chooserBox = [modal]() -> juce::FileChooserDialogBox* {
- for (int i = 0; i < modal->getNumModalComponents(); ++i)
- if (auto* b = dynamic_cast<juce::FileChooserDialogBox*> (modal->getModalComponent (i)); b != nullptr && b->isVisible())
- return b;
- return nullptr;
- };
- const auto baseModal = modal->getNumModalComponents();
- const auto baseDesktop = desktop();
- const auto basePanels = panels();
- // closes whatever the item opened: Cancel (result 0) on every modal window, the close button of new windows,
- // new panels of the main window hidden
- const auto closeAll = [&] {
- for (int round = 0; round < 6; ++round)
- {
- modal->cancelAllModalComponents();
- pump (120);
- for (auto* c : desktop())
- if (baseDesktop.count (c) == 0)
- {
- if (auto* w = dynamic_cast<juce::DocumentWindow*> (c))
- w->closeButtonPressed();
- else
- c->setVisible (false);
- }
- for (auto* c : panels())
- if (basePanels.count (c) == 0)
- c->setVisible (false);
- pump (80);
- if (modal->getNumModalComponents() <= baseModal && desktop().size() <= baseDesktop.size())
- return true;
- }
- return false;
- };
- // what opened since the baseline ("" = nothing)
- const auto opened = [&]() -> juce::String {
- juce::StringArray what;
- if (modal->getNumModalComponents() > baseModal)
- for (int i = 0; i < modal->getNumModalComponents() - baseModal; ++i)
- if (auto* c = modal->getModalComponent (i))
- what.add ("modal " + nameOf (c));
- for (auto* c : desktop())
- if (baseDesktop.count (c) == 0)
- what.addIfNotAlreadyThere ("window " + nameOf (c));
- for (auto* c : panels())
- if (basePanels.count (c) == 0)
- what.add ("panel " + nameOf (c));
- return what.joinIntoString (", ");
- };
- // the menu's items: (path, action) for every "..." item of the submenus named here
- struct Entry
- {
- juce::String path;
- std::function<void()> action;
- };
- const auto bare = [] (const juce::String& text) { return text.upToFirstOccurrenceOf ("\t", false, false).trim(); };
- const auto collect = [&] {
- std::vector<Entry> out;
- const auto menu = ui.menuForCheck (0, "File");
- const juce::StringArray walk { "New from template", "Open in new window", "Import", "Export" };
- std::function<void (const juce::PopupMenu&, const juce::String&)> add = [&] (const juce::PopupMenu& m, const juce::String& prefix) {
- for (juce::PopupMenu::MenuItemIterator it (m); it.next();)
- {
- const auto& item = it.getItem();
- const auto text = bare (item.text);
- if (item.subMenu != nullptr)
- {
- if (walk.contains (text))
- add (*item.subMenu, prefix + text + " > ");
- continue;
- }
- if (item.isEnabled && item.action && (text.endsWith ("...") || text.endsWith (juce::String::fromUTF8 ("\xe2\x80\xa6"))))
- out.push_back ({ prefix + text, item.action });
- }
- };
- add (menu, "File > ");
- return out;
- };
- const auto entries = collect();
- check ("the File menu lists its '...' items", entries.size() >= 25, juce::String ((int) entries.size()));
- for (const auto* must : { "File > Export > DAWproject (.dawproject)...", "File > Save a copy as FL Studio Mobile project (.flm)...",
- "File > Export > Ableton Live set (.als)...", "File > Export > FL Studio project...", "File > Export > Wave file...",
- "File > Open...", "File > Save as..." })
- check (juce::String ("listed: ") + must, std::any_of (entries.begin(), entries.end(), [must] (const Entry& e) { return e.path == must; }));
- // 1. every "..." item opens its window, and it is still open after the message loop ran
- // (the song counts as saved: "New project..." and "Open..." then open their own window, not "save changes?")
- for (const auto& e : entries)
- {
- offline.markSaved();
- e.action();
- pump (250);
- const auto what = opened();
- check ("opens its window: " + e.path, what.isNotEmpty(), what);
- check ("and it closes again: " + e.path, closeAll());
- }
- // 2. the items whose first window leads to a chooser reach it (Export... / OK)
- const auto byPath = [&entries] (const juce::String& path) -> std::function<void()> {
- for (const auto& e : entries)
- if (e.path == path)
- return e.action;
- return {};
- };
- for (const auto* path : { "File > Save a copy as FL Studio Mobile project (.flm)...", "File > Export > FL Studio project...",
- "File > Export > Ableton Live set (.als)...", "File > Save a copy for an older LYNX..." })
- {
- const auto action = byPath (path);
- if (! action)
- continue;
- action();
- pump (250);
- juce::Component* first = modal->getNumModalComponents() > baseModal ? modal->getModalComponent (0) : nullptr;
- auto* exportButton = dynamic_cast<juce::Button*> (find (first, [] (juce::Component* c) {
- auto* b = dynamic_cast<juce::TextButton*> (c);
- return b != nullptr && b->isEnabled() && b->getButtonText().startsWith ("Export");
- }));
- if (exportButton != nullptr)
- exportButton->triggerClick();
- else if (first != nullptr)
- first->exitModalState (1); // (an AlertWindow: its OK / Save button)
- pump (300);
- check (juce::String ("reaches its chooser: ") + path, chooserBox() != nullptr, opened());
- closeAll();
- }
- // 3. end to end through the menu: the chooser given a name, the file written, the report shown
- const auto throughChooser = [&] (const juce::String& path, const juce::String& fileName, bool alertFirst, const juce::String& reportTitle) -> juce::File {
- const auto action = byPath (path);
- if (! action)
- return {};
- action();
- pump (250);
- if (alertFirst && modal->getNumModalComponents() > baseModal)
- {
- modal->getModalComponent (0)->exitModalState (1);
- pump (250);
- }
- auto* box = chooserBox();
- check ("the chooser is open: " + path, box != nullptr, opened());
- auto* browser = dynamic_cast<juce::FileBrowserComponent*> (find (box, [] (juce::Component* c) { return dynamic_cast<juce::FileBrowserComponent*> (c) != nullptr; }));
- if (box == nullptr || browser == nullptr)
- {
- closeAll();
- return {};
- }
- browser->setRoot (root);
- browser->setFileName (fileName);
- pump (100);
- box->exitModalState (1); // (the chooser's Save button)
- const auto target = root.getChildFile (fileName);
- const auto end = juce::Time::getMillisecondCounter() + 60000u;
- // done: the file is there and nothing is still being written (DAWproject: its report window, "Export
- // DAWproject"; FLM: the saved-file hint, no window)
- bool done = false;
- juce::String report;
- while (juce::Time::getMillisecondCounter() < end && ! done)
- {
- pump (100);
- for (int i = 0; i < modal->getNumModalComponents(); ++i)
- if (auto* a = dynamic_cast<juce::AlertWindow*> (modal->getModalComponent (i)))
- report = a->getName();
- done = target.existsAsFile() && (reportTitle.isEmpty() || report == reportTitle);
- }
- check ("done through the menu: " + path, done, report.isNotEmpty() ? "report window: " + report : opened());
- closeAll();
- return target;
- };
- const auto daw = throughChooser ("File > Export > DAWproject (.dawproject)...", "menu190sk.dawproject", false, tr ("Export DAWproject"));
- bool zipOk = false;
- if (daw.existsAsFile())
- {
- juce::ZipFile zip (daw);
- zipOk = zip.getIndexOfFileName ("project.xml") >= 0 && zip.getIndexOfFileName ("metadata.xml") >= 0;
- if (zipOk)
- {
- std::unique_ptr<juce::InputStream> in (zip.createStreamForEntry (zip.getIndexOfFileName ("project.xml")));
- const auto xml = in != nullptr ? in->readEntireStreamAsString() : juce::String();
- zipOk = xml.contains ("<Project") && xml.contains ("<Notes") && xml.contains ("<Note ");
- }
- }
- check ("File > Export > DAWproject writes the file through the menu (a zip: project.xml with the notes, metadata.xml)", zipOk,
- daw.getFullPathName() + (daw.existsAsFile() ? " " + juce::String (daw.getSize()) + " bytes" : " missing"));
- const auto flm = throughChooser ("File > Save a copy as FL Studio Mobile project (.flm)...", "menu190sk.flm", true, {});
- check ("File > Save a copy as FL Studio Mobile project writes the file through the menu", flm.existsAsFile() && flm.getSize() > 0,
- flm.getFullPathName());
- closeAll();
- }
- root.deleteRecursively();
- setEnv ("LYNX_FILE_DIALOG", oldDialog);
- return result;
- #endif
- }
|