| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403 |
- // Round 190sw (0.1.33): issue #292 the routing cables beside the Playlist, #322 macOS's menu bar, #289 the hardware outputs
- // export. Included in the app class of Main.cpp; --batch292test190sw <report> [picture prefix] and --selftest "batch292_190sw".
- // With a prefix, the pictures (100 % and @150): the cables with the Master / return rows and without them (tags), the
- // window's toolbar with the menu row as macOS's menu bar leaves it, and as it was.
- juce::String batch292Check190sw (juce::String& log, const juce::String& prefix = {})
- {
- 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;
- };
- const auto both = [&prefix] (juce::Component& c, juce::Rectangle<int> area, const juce::String& name) {
- if (prefix.isEmpty())
- return;
- area = area.getIntersection (c.getLocalBounds());
- if (area.isEmpty())
- return;
- savePng (c.createComponentSnapshot (area, true, 1.0f), prefix + "-" + name + ".png");
- savePng (c.createComponentSnapshot (area, true, 1.5f), prefix + "-" + name + "@150.png");
- };
- juce::LookAndFeel::setDefaultLookAndFeel (&lookAndFeel);
- const juce::ScopedValueSetter<bool> shown (ui::showingForShots(), true);
- const auto cablesWas = routecables::on, rowsWas = mixerrows::shown;
- const auto modeWas = macmenu::mode();
- AudioEngine engine (false);
- const auto pump = [&engine] (int ms) {
- const auto end = juce::Time::getMillisecondCounter() + (juce::uint32) ms;
- while (juce::Time::getMillisecondCounter() < end)
- {
- engine.dispatchPendingMessages();
- #if JUCE_LINUX || JUCE_WINDOWS
- for (int i = 0; i < 64 && juce::detail::dispatchNextMessageOnSystemQueue (true); ++i) {}
- #endif
- juce::Thread::sleep (5);
- }
- };
- // ---- the song: inserts 1 Kick, 2 Snare -> 3 Drum bus (off the Master), 4 Lead vocal (sends to 6 REVERB, 7 DELAY
- // pre-fader, a sidechain link to 8 Bass), 5 Backing -> 4 (off the Master); 7 is a Live return. Tracks 0-5 linked.
- auto made = [] {
- auto song = Song::makeDefault();
- song.mode = PlayMode::song;
- song.playlistTracks.resize (40);
- const char* names[] = { "Kick", "Snare", "Drum bus", "Lead vocal", "Backing", "Bass" };
- const int inserts[] = { 1, 2, 3, 4, 5, 8 };
- while (song.mixer.size() < 10)
- song.mixer.push_back ({});
- for (int t = 0; t < 6; ++t)
- {
- auto& p = song.playlistTracks[(std::size_t) t];
- p.name = names[t];
- p.mode = PlaylistTrackMode::audio;
- p.mixerTrack = inserts[t];
- song.mixer[(std::size_t) inserts[t]].name = names[t];
- }
- for (int t = 6; t < 40; ++t)
- song.playlistTracks[(std::size_t) t].name = "Track " + std::to_string (t + 1);
- song.mixer[6].name = "REVERB";
- song.mixer[7].name = "DELAY";
- song.mixer[7].liveReturn = true;
- song.mixer[1].sends = { { 3, 1.0f } };
- song.mixer[2].sends = { { 3, 1.0f } };
- song.mixer[1].toMaster = song.mixer[2].toMaster = false;
- song.mixer[4].sends = { { 6, 0.7f }, { 7, 0.4f, true }, { 8, 0.0f } };
- song.mixer[5].sends = { { 4, 1.0f } };
- song.mixer[5].toMaster = false;
- Clip last; // (a clip on the 40th track: the Playlist shows 40 tracks and scrolls)
- last.kind = ClipKind::pattern;
- last.pattern = 0;
- last.track = 39;
- last.length = 4 * ppq;
- song.playlist.push_back (last);
- return song;
- }();
- lynx::MainComponent ui (engine, false);
- ui.setSize (1920, 1080);
- pump (50);
- engine.setSong (made);
- pump (100);
- ui.selectTabForSnapshot (2);
- pump (100);
- auto& playlist = ui.getPlaylistForSnapshot();
- auto& cables = ui.routingCablesForCheck();
- auto& area = ui.playlistAreaForCheck();
- // ================= #292: the routing cables ===================================================================
- // (not on macOS: the Playlist follows the song through the message loop, which the self-test doesn't pump there)
- #if JUCE_LINUX || JUCE_WINDOWS
- {
- routecables::on = false;
- ui.applyRoutingCables();
- pump (30);
- const auto x0 = playlist.getX(), w0 = playlist.getWidth();
- check ("292 off (the default): no gutter, the Playlist where it was", ! cables.isVisible() && area.cablesWidth() == 0);
- workflowextras::setExtra ("playlist.routingCables", true);
- pump (50);
- check ("292 on: the gutter shows left of the Playlist, 40 px", cables.isVisible() && cables.getWidth() == routecables::gutterWidth
- && cables.getRight() == playlist.getX() && playlist.getX() == x0 + routecables::gutterWidth
- && playlist.getWidth() == w0 - routecables::gutterWidth,
- cables.getBounds().toString() + " / " + playlist.getBounds().toString());
- check ("292 the gutter starts under the Playlist's toolbar band", cables.getY() == playlist.getY() + PlaylistComponent::toolbarHeight);
- mixerrows::shown = true;
- playlist.refreshViewOptions();
- pump (50);
- playlist.selectTrack (3); // Lead vocal
- pump (50);
- auto l = cables.layout();
- const auto socketOf = [&l] (int track, int insert) -> const RoutingCablesView::Socket* {
- for (const auto& s : l.sockets)
- if ((track >= 0 && s.track == track) || (track < 0 && s.track < 0 && s.insert == insert))
- return &s;
- return nullptr;
- };
- check ("292 a socket on each linked row (6 tracks) and on each mixer row (REVERB, DELAY, Master)",
- socketOf (0, 1) && socketOf (5, 8) && socketOf (-1, 6) && socketOf (-1, 7) && socketOf (-1, 0) && socketOf (7, -1) == nullptr,
- juce::String ((int) l.sockets.size()));
- check ("292 the selected track's socket is the source", l.sourceTrack == 3 && l.source >= 0 && l.sockets[(std::size_t) l.source].track == 3);
- check ("292 five cables: the Master, REVERB, DELAY, the sidechain to Bass, Backing coming in", l.cables.size() == 5);
- const auto tipAt = [&l] (routecables::Kind kind, int insert) -> std::optional<juce::Point<float>> {
- for (const auto& c : l.cables)
- if (c.cable.kind == kind && c.cable.insert == insert)
- return c.arrowTip;
- return std::nullopt;
- };
- const auto near = [] (std::optional<juce::Point<float>> tip, const RoutingCablesView::Socket* s) {
- return tip.has_value() && s != nullptr && std::abs (tip->y - s->at.y) < 0.5f && tip->x <= s->at.x && tip->x > s->at.x - 10.0f;
- };
- const auto* source = l.source >= 0 ? &l.sockets[(std::size_t) l.source] : nullptr;
- check ("292 the Master cable ends at the Master row", near (tipAt (routecables::Kind::master, 0), socketOf (-1, 0)));
- check ("292 the REVERB send ends at its return row", near (tipAt (routecables::Kind::send, 6), socketOf (-1, 6)));
- check ("292 the DELAY send (pre-fader) ends at its row", near (tipAt (routecables::Kind::send, 7), socketOf (-1, 7)));
- check ("292 the sidechain ends at the Bass track", near (tipAt (routecables::Kind::sidechain, 8), socketOf (5, 8)));
- check ("292 Backing's send comes into the selected track", near (tipAt (routecables::Kind::receive, 5), source));
- check ("292 every cable stays inside the gutter", [&] {
- for (const auto& c : l.cables)
- {
- const auto b = c.path.getBounds();
- if (b.getX() < 0.0f || b.getRight() > (float) cables.getWidth())
- return false;
- }
- return true;
- }());
- // the hint of a cable's middle
- juce::String hint;
- for (const auto& c : l.cables)
- if (c.cable.kind == routecables::Kind::send && c.cable.insert == 6)
- {
- const auto p = c.path.getPointAlongPath (c.path.getLength() * 0.5f);
- hint = cables.hintAt (p.roundToInt()).text;
- }
- check ("292 a cable's hint names it and its level", hint.contains ("REVERB") && hint.contains ("dB"), hint);
- both (ui, ui.getLocalArea (&area, area.getLocalBounds()).withWidth (900), "292-cables-rows");
- // without the mixer rows: REVERB, DELAY and the Master are tags at the foot
- mixerrows::shown = false;
- playlist.refreshViewOptions();
- pump (50);
- l = cables.layout();
- int tags = 0;
- bool tagsInside = true;
- juce::String where;
- for (const auto& s : l.sockets)
- if (s.tag)
- {
- ++tags;
- tagsInside = tagsInside && cables.getLocalBounds().toFloat().contains (s.tagBounds);
- where << s.tagBounds.toString() << "; ";
- }
- check ("292 without rows, the inserts with no row are tags (REVERB, DELAY, M) at the gutter's foot", tags == 3 && tagsInside && l.cables.size() == 5,
- juce::String (tags) + " " + where + "gutter " + cables.getBounds().toString());
- both (ui, ui.getLocalArea (&area, area.getLocalBounds()).withWidth (900), "292-cables-tags");
- // a track with no insert: no cable; the bus: its inputs
- playlist.selectTrack (2);
- pump (30);
- l = cables.layout();
- int incoming = 0;
- for (const auto& c : l.cables)
- incoming += c.cable.kind == routecables::Kind::receive ? 1 : 0;
- check ("292 the Drum bus shows Kick and Snare coming in", incoming == 2);
- playlist.selectTrack (10);
- pump (30);
- check ("292 an empty track: its socket, no cable", cables.layout().cables.empty() && cables.layout().source >= 0);
- const auto sig = cables.cableSignature();
- playlist.setScrollYForSnapshot (60);
- check ("292 a scroll changes what the gutter draws", cables.cableSignature() != sig);
- playlist.setScrollYForSnapshot (0);
- workflowextras::setExtra ("playlist.routingCables", false);
- pump (30);
- check ("292 off again: the gutter goes, the Playlist back", ! cables.isVisible() && playlist.getX() == x0 && playlist.getWidth() == w0);
- }
- #else
- juce::ignoreUnused (both, playlist, cables, area);
- log << "skip 292 on macOS (checked on Linux and Windows)\n";
- #endif
- // ================= #322: macOS's menu bar =====================================================================
- {
- const auto mac = modmap::hostOs() == modmap::Os::mac;
- auto& model = ui.macMenuForCheck();
- macmenu::mode() = macmenu::Mode::systemBar;
- ui.applyMacMenu();
- #if JUCE_MAC
- check ("322 macOS: the menus are in the system menu bar", juce::MenuBarModel::getMacMainMenu() == &model && model.isInstalled());
- check ("322 macOS: the window's menu row is hidden", ui.menuRowHiddenForCheck() && ! ui.menuBarForCheck().isVisible());
- #else
- check ("322 not macOS: no system menu bar, the window's row shows", ! model.isInstalled() && ! ui.menuRowHiddenForCheck() && ui.menuBarForCheck().isVisible());
- #endif
- check ("322 the system bar's menus are the window's", model.getMenuBarNames() == ui.getMenuNamesForSnapshot());
- check ("322 every menu builds for the system bar (as JUCE builds them all when the model is installed)", [&] {
- const auto all = model.getMenuBarNames();
- for (int i = 0; i < all.size(); ++i)
- if (model.getMenuForIndex (i, all[i]).getNumItems() == 0)
- return false;
- return all.size() >= 8;
- }());
- // the File menu: no shortcut left in a title; Save (⌘S / Ctrl+S) has its key
- const auto names = ui.getMenuNamesForSnapshot();
- const auto file = model.getMenuForIndex (juce::jmax (0, names.indexOf (tr ("File"))), tr ("File"));
- bool tabs = false, saveKey = false;
- int keyed = 0;
- std::function<void (const juce::PopupMenu&)> walk = [&] (const juce::PopupMenu& menu) {
- for (juce::PopupMenu::MenuItemIterator it (menu); it.next();)
- {
- const auto& item = it.getItem();
- tabs = tabs || item.text.containsChar ('\t');
- if (item.commandManager == &model.commands())
- {
- ++keyed;
- const auto keysOf = model.commands().getKeyMappings()->getKeyPressesAssignedToCommand (item.itemID);
- if (item.text == tr ("Save") && ! keysOf.isEmpty())
- saveKey = keysOf[0] == juce::KeyPress ('s', juce::ModifierKeys::commandModifier, 0)
- || keysOf[0].getKeyCode() == 's' && keysOf[0].getModifiers() == juce::ModifierKeys (juce::ModifierKeys::commandModifier);
- }
- if (item.subMenu != nullptr)
- walk (*item.subMenu);
- }
- };
- walk (file);
- check ("322 no menu title keeps its shortcut text (macOS draws the key)", ! tabs);
- check ("322 shortcuts become key equivalents (Save: the command key + S)", saveKey && keyed >= 3, juce::String (keyed));
- check ("322 every key equivalent is one macOS takes (a nil one ends the app: macOS CI run 46366524858)", [&] {
- const auto all = model.getMenuBarNames();
- bool ok = true;
- std::function<void (const juce::PopupMenu&)> keysOf = [&] (const juce::PopupMenu& menu) {
- for (juce::PopupMenu::MenuItemIterator it (menu); it.next();)
- {
- const auto& item = it.getItem();
- if (item.commandManager != nullptr)
- for (const auto& k : item.commandManager->getKeyMappings()->getKeyPressesAssignedToCommand (item.itemID))
- ok = ok && MacMenuModel::usableKey (k);
- if (item.subMenu != nullptr)
- keysOf (*item.subMenu);
- }
- };
- for (int i = 0; i < all.size(); ++i)
- keysOf (model.getMenuForIndex (i, all[i]));
- return ok && ! MacMenuModel::usableKey (juce::KeyPress (-1, juce::ModifierKeys::commandModifier, 0))
- && ! MacMenuModel::usableKey (juce::KeyPress (juce::KeyPress::deleteKey)) && MacMenuModel::usableKey (juce::KeyPress ('s', juce::ModifierKeys::commandModifier, 's'))
- && MacMenuModel::usableKey (juce::KeyPress (juce::KeyPress::spaceKey, 0, ' '))
- #if JUCE_MAC
- && MacMenuModel::usableKey (juce::KeyPress (juce::KeyPress::F5Key)) // (NSF5FunctionKey; Linux's F-key codes are past Unicode)
- #endif
- ;
- }());
- const auto key = ui.keyForShortcutText (juce::String::fromUTF8 (keys::displayString (keys::Chord { 'S', keys::ctrl }).c_str()));
- check ("322 a shortcut text reads back as its key", key.has_value() && key->getModifiers().isCommandDown() && key->getKeyCode() == 's');
- macmenu::mode() = macmenu::Mode::both;
- ui.applyMacMenu();
- check ("322 'both' (FL Studio for Mac): the window's row shows too", ! ui.menuRowHiddenForCheck() && ui.menuBarForCheck().isVisible() && model.isInstalled() == mac);
- macmenu::mode() = macmenu::Mode::window;
- ui.applyMacMenu();
- check ("322 'in the window only': no system menu bar", ! model.isInstalled() && ui.menuBarForCheck().isVisible());
- #if JUCE_MAC
- check ("322 macOS 'in the window only': the system bar has no LYNX menus", juce::MenuBarModel::getMacMainMenu() != &model);
- #endif
- // the window as a Mac shows it with the menus in its bar: the row's room goes to the hint bar, nothing overlaps
- macmenu::mode() = macmenu::Mode::systemBar;
- ui.applyMacMenu();
- ui.forceMenuRowHiddenForCheck (false);
- pump (30);
- const auto hintBefore = ui.getHintBarForSnapshot().getBounds();
- both (ui, juce::Rectangle<int> (0, 0, 1920, 76), "322-toolbar-row");
- ui.forceMenuRowHiddenForCheck (true);
- pump (30);
- const auto hintAfter = ui.getHintBarForSnapshot().getBounds();
- check ("322 hidden row: the menu bar is hidden", ! ui.menuBarForCheck().isVisible());
- check ("322 hidden row: the toolbar's items still fit, nothing overlaps", ui.checkToolbarItemsForSnapshot().isEmpty(), ui.checkToolbarItemsForSnapshot());
- check ("322 hidden row: the hint bar keeps its place, at least FL's 240 px wide (the room of the menu titles goes to the panels)",
- hintAfter.getX() == hintBefore.getX() && hintAfter.getWidth() >= 240, hintBefore.toString() + " -> " + hintAfter.toString());
- both (ui, juce::Rectangle<int> (0, 0, 1920, 76), "322-toolbar-macbar");
- ui.forceMenuRowHiddenForCheck (mac);
- }
- // ================= #289: the hardware outputs export ==========================================================
- {
- // a synth on insert 1, which goes to output 3 alone (mono) and not to the Master; a synth on insert 2 to the Master
- auto s = Song::makeDefault();
- s.bpm = 120.0;
- s.mode = PlayMode::song;
- s.mixer = Song::defaultMixer (2);
- s.channels.clear();
- for (int c = 0; c < 2; ++c)
- {
- ChannelDef ch;
- ch.instrument = InstrumentKind::synth;
- ch.mixerTrack = c + 1;
- ch.name = c == 0 ? "to out 3" : "to the Master";
- s.channels.push_back (ch);
- }
- s.mixer[1].outputChannel = 2;
- s.mixer[1].outputMode = OutputMode::monoSum;
- s.mixer[1].toMaster = false;
- s.patterns.clear();
- s.patterns.emplace_back();
- for (int c = 0; c < 2; ++c)
- {
- Note n;
- n.channel = c;
- n.key = c == 0 ? 57 : 64;
- n.start = 0;
- n.length = 4 * ppq;
- s.patterns[0].notes.push_back (n);
- }
- Clip clip;
- clip.kind = ClipKind::pattern;
- clip.pattern = 0;
- clip.length = 4 * ppq;
- s.playlist = { clip };
- const auto render = [] (const Song& song, exportopts::Channels channels, juce::String& error) {
- exportopts::Options o;
- o.channels = channels;
- o.wavBits = 32;
- o.tail = exportopts::TailMode::cut;
- const auto file = juce::File::getSpecialLocation (juce::File::tempDirectory).getChildFile ("lynx190sw-hw-" + juce::String (juce::Random::getSystemRandom().nextInt()) + ".wav");
- juce::AudioBuffer<float> buffer;
- ExportJob job (song, o, file);
- if (job.run ([] (double) { return true; }, error))
- {
- juce::AudioFormatManager formats;
- formats.registerBasicFormats();
- if (std::unique_ptr<juce::AudioFormatReader> reader (formats.createReaderFor (file)); reader != nullptr)
- {
- buffer.setSize ((int) reader->numChannels, (int) reader->lengthInSamples);
- reader->read (&buffer, 0, buffer.getNumSamples(), 0, true, true);
- }
- }
- file.deleteFile();
- return buffer;
- };
- juce::String error;
- const auto file = render (s, exportopts::Channels::hardwareOutputs, error);
- const auto rms = [&file] (int ch) { return ch < file.getNumChannels() ? file.getRMSLevel (ch, 0, file.getNumSamples()) : -1.0f; };
- check ("289 the file has a channel per output used (the Master on 1-2, insert 1 on 3)", file.getNumChannels() == 3 && file.getNumSamples() > 44100, error + " " + juce::String (file.getNumChannels()));
- check ("289 output 3 holds insert 1, outputs 1-2 the Master", rms (2) > 0.01f && rms (0) > 0.01f && rms (1) > 0.01f,
- juce::String (rms (0), 4) + " " + juce::String (rms (1), 4) + " " + juce::String (rms (2), 4));
- auto quiet = s;
- quiet.channels[1].muted = true;
- const auto alone = render (quiet, exportopts::Channels::hardwareOutputs, error);
- check ("289 the channel on the Master muted: outputs 1-2 silent, output 3 still plays (one insert, one output)",
- alone.getNumChannels() == 3 && alone.getRMSLevel (0, 0, alone.getNumSamples()) < 1.0e-6f && alone.getRMSLevel (2, 0, alone.getNumSamples()) > 0.01f);
- // the Export window with the choice made (a picture only)
- if (prefix.isNotEmpty())
- if (auto panel = makeExportPanel (engine))
- {
- panel->setSize (juce::jmax (panel->getWidth(), 900), juce::jmax (panel->getHeight(), 640));
- std::function<juce::ComboBox* (juce::Component&)> findBox = [&] (juce::Component& c) -> juce::ComboBox* {
- if (auto* box = dynamic_cast<juce::ComboBox*> (&c); box != nullptr && box->getNumItems() == 5
- && box->getItemText (4) == tr ("Hardware outputs, one channel each (LYNX)"))
- return box;
- for (auto* child : c.getChildren())
- if (auto* found = findBox (*child))
- return found;
- return nullptr;
- };
- auto* box = findBox (*panel);
- check ("289 the Export window's Channels box has the choice", box != nullptr);
- if (box != nullptr)
- box->setSelectedItemIndex (4);
- both (*panel, panel->getLocalBounds(), "289-export-channels");
- }
- const auto stereo = render (s, exportopts::Channels::stereo, error);
- check ("289 the stereo export is the Master as before (insert 1 not in it)", stereo.getNumChannels() == 2 && stereo.getNumSamples() == file.getNumSamples()
- && [&] {
- for (int ch = 0; ch < 2; ++ch)
- for (int i = 0; i < stereo.getNumSamples(); ++i)
- if (stereo.getSample (ch, i) != file.getSample (ch, i))
- return false;
- return true;
- }());
- }
- routecables::on = cablesWas;
- mixerrows::shown = rowsWas;
- macmenu::mode() = modeWas;
- return result;
- }
|