#include #include "engine/FileSort.h" #include "platform/Paths.h" #include "core/PlaylistOps.h" #include "core/Drumaxx.h" #include "core/PatternBlocks.h" #include "core/LoadTrace.h" #include "core/Patcher.h" #include "core/Patcherize.h" #include "core/Performance.h" #include "core/VideoPlayer.h" #include "core/Effects.h" #include "core/MixSuite.h" #include "core/HardwareInsert.h" #include "core/EchoSuite.h" #include "core/LynxTune.h" #include "core/FlEffects.h" #include "core/FlpImport.h" #include "core/NoteEdit.h" #include "core/MaximusFx.h" #include "core/Harmor.h" #include "flp/Flp.h" #include "core/SynthPresets.h" #include "core/FlWrapper.h" #include "engine/AudioEngine.h" #include "engine/Metronome.h" #include "engine/AudioLogger.h" #include "engine/DllAsioDevice.h" #include "engine/PipeWireDevice.h" #include "platform/LinuxRealtime.h" #include "engine/Exporter.h" #include "engine/FlStudioExport.h" #include "engine/MidiFileIo.h" #include "engine/PluginHost.h" #include "engine/PluginSandbox.h" #include "engine/Bridge32Test.h" #include "engine/ProjectFile.h" #include "core/Sha256.h" #include "engine/SessionPack.h" #include "engine/LiveTest.h" #include "core/SessionIds.h" #include "core/SessionParts.h" #include "engine/SampleLibrary.h" #include "engine/Text.h" #include "platform/FileTypes.h" #include "platform/Package.h" #include "ui/VideoPlayerView.h" #include "ui/PatcherEditor.h" #include "ui/VisualEditors.h" #include "ui/FlExtraEditors.h" #include "ui/VisualGl.h" #include "ui/DanceView.h" #include "ui/PluginPresetMenu.h" #include "ui/PluginWindow.h" #include "ui/PluginThumbs.h" #include "ui/ClipProperties.h" #include "ui/NewProjectDialog.h" #include "ui/PluginMonitorWindow.h" #include "ui/TouchKeyboard.h" #include "ui/AutomationUi.h" #include "ui/PluginSkin.h" #include "ui/ChannelSettings.h" #include "core/LynxBanks.h" #include "core/NativeEngines.h" #include "ui/ControllerEditors.h" #include "ui/NewtoneEditor.h" #include "core/NewtoneFx.h" #include "core/FormulaController.h" #include "core/MidiControls.h" #include "core/FlSynths.h" #include "core/SoundFont.h" #include "core/Sfz.h" #include "ui/Dialogs.h" #include "ui/FileChoosers.h" #include "ui/TrackIcons.h" #include "core/RackOps.h" #include "core/Layer.h" #include "core/XyController.h" #include "core/FlCurve.h" #include "core/ControlSurface.h" #include "core/VoltageController.h" #include "ui/Controllers164.h" #include "ui/ExportDialog.h" #include "ui/QuickAddPalette.h" #include "ui/I18n.h" #include "ui/MainComponent.h" #include "ui/FrameProbe.h" #include "ui/UiTrace.h" #include "core/MixerOps.h" #include "ui/QuickPick.h" #include "core/NoteTools.h" #include "engine/ProjectPackage.h" #include "ui/SetupWizard.h" #include "engine/FlStudio.h" #include "ui/HistoryPanel.h" #include "ui/MissingFilesDialog.h" #include "ui/SettingsDialog.h" #include "ui/PluginManager.h" #include "ui/ShortcutManager.h" #include "ui/NoteToolDialogs.h" #include "ui/EventEditor.h" #include "ui/AudioEditor.h" #include "ui/TempoTapper.h" #include "core/EventEdit.h" #include "core/FacetEq.h" #include "ui/FacetEqEditor.h" #include "core/RackRenderer.h" #include "ui/ProEditors.h" #include "ui/ParametricEqEditor.h" #include "ui/PluginEditors.h" #include "core/PluginLayout.h" #include "core/EffectPresets.h" #include "core/Vfx.h" #include "ui/Splash.h" #include "ui/Theme.h" #include "ui/ThemeSettings.h" #include "ui/WaveformView.h" #include "ui/WindowOwner.h" #include "ui/Toolbar.h" #include "ui/ToolWindow.h" #include "platform/CrashGuard.h" #include "ui/CrashReporter.h" #include "ui/Updater.h" #include "ui/StemExtract.h" #include #include #include #include #include #include namespace { lynx::AudioEngine* crashEngine = nullptr; // Startup trace (REA round 116): with LYNX_TRACE_STARTUP set, the time of each startup step since the C++ runtime // started is written to %APPDATA%\LYNX\startup.log (the loader's own time before that is not included). struct StartupTrace { using clock = std::chrono::steady_clock; const clock::time_point t0 = clock::now(); // static initialisation: no JUCE yet, standard library only const bool on = std::getenv ("LYNX_TRACE_STARTUP") != nullptr; juce::String text; clock::time_point last = t0; double seconds() const { return std::chrono::duration (clock::now() - t0).count(); } // since the process started void mark (const char* step) { if (! on) return; const auto now = clock::now(); const auto ms = [] (clock::duration d) { return std::chrono::duration (d).count(); }; text << juce::String (ms (now - t0), 1).paddedLeft (' ', 8) << " ms +" << juce::String (ms (now - last), 1).paddedLeft (' ', 7) << " " << step << "\n"; last = now; lynx::platform::settingsFile ("startup.log").replaceWithText (text); } }; StartupTrace startupTrace; void startupMarkHook (const char* step) { startupTrace.mark (step); } // Crashed: try to save the project and write the backtrace (like FL's "emergency save"). void onCrash (void* exceptionPointers) { const auto folder = lynx::platform::settingsFile ("autosave"); folder.createDirectory(); const auto stamp = juce::Time::getCurrentTime().formatted ("%Y-%m-%d %H-%M-%S"); // JUCE's backtrace (named frames only), then every frame of the faulting thread as module+offset (round 157a: a // release LYNX.exe has no symbols, so its own frames were missing from the file) folder.getChildFile ("crash " + stamp + ".txt").replaceWithText (juce::SystemStats::getStackBacktrace() + "\n--- frames (module+offset)\n" + juce::String::fromUTF8 (lynx::crashguard::exceptionBacktrace (exceptionPointers).c_str())); lynx::crashguard::note (("crashed: backtrace in autosave\\crash " + stamp + ".txt").toStdString()); if (crashEngine != nullptr) { juce::String error; lynx::ProjectFile::save (crashEngine->getSong(), folder.getChildFile ("recovered " + stamp + lynx::ProjectFile::extension), error); } } juce::File sessionsFolder() { return lynx::PluginHost::settingsFolder().getChildFile ("sessions"); } // Sessions of earlier runs whose process is gone without closing (a fail-fast, a crash, a forced end): each is appended // to %APPDATA%\LYNX\crash-history.log and its file removed. Returns the last step of the newest one ("" when none). juce::StringArray uncleanSteps; // the newest unclean session's steps (without their times) juce::String uncleanSessionText; // the newest unclean session's whole file (round 159: the crash report reads it) // What the newest unclean session tells (round 157a): the plugin whose editor was opening / shown when it ended, and // whether its crash file blames a graphics driver struct UncleanCause { juce::String editorPlugin; // the last steps were that plugin's editor bool gpuDriver = false; // the crash file's top frames are in a GPU driver / Direct3D / Direct2D module juce::String driverModule; }; UncleanCause uncleanCause() { UncleanCause cause; juce::File crashFile; for (int i = uncleanSteps.size(); --i >= 0 && i >= uncleanSteps.size() - 4;) { const auto& step = uncleanSteps[i]; if (step.startsWith ("crashed: backtrace in ")) crashFile = lynx::platform::settingsFolder().getChildFile (step.fromFirstOccurrenceOf ("backtrace in ", false, false).replaceCharacter ('\\', '/')); for (const auto* prefix : { "opening the editor of ", "editor open: ", "editor shown: " }) if (cause.editorPlugin.isEmpty() && step.startsWith (prefix)) cause.editorPlugin = step.fromFirstOccurrenceOf (prefix, false, false).trim(); if (step.startsWith ("closing the editor of ") || step.startsWith ("loaded plugin") || step.startsWith ("opening project")) break; // older steps than these did not end the session } // issue #32 (round 174a): a plugin whose editor already faulted in this session (caught, LYNX went on) is the // likely cause when the session then ended without a word: offer it a separate process too for (int i = uncleanSteps.size(); --i >= 0 && cause.editorPlugin.isEmpty();) if (const auto editor = lynx::crashreport::parseEditorCrashStep (uncleanSteps[i].toStdString()); ! editor.plugin.empty()) cause.editorPlugin = juce::String::fromUTF8 (editor.plugin.c_str()); if (crashFile.existsAsFile()) { // the first frames after the crash handler's own (the "--- frames" part lists the faulting thread) auto text = crashFile.loadFileAsString(); if (text.contains ("--- frames")) text = text.fromFirstOccurrenceOf ("--- frames", false, false); auto lines = juce::StringArray::fromLines (text); int looked = 0; for (const auto& line : lines) { const auto module = line.fromFirstOccurrenceOf (": ", false, false).upToFirstOccurrenceOf ("+", false, false).trim().toLowerCase(); if (module.isEmpty() || ! module.endsWith (".dll")) continue; if (++looked > 12) break; for (const auto* driver : { "igd", "ig9icd", "ig7icd", "igxelp", "nvwgf2um", "nvoglv", "nvd3dum", "atidxx", "atio6axx", "amdxx", "aticfx", "d3d11.dll", "d3d10warp", "dxgi.dll", "d2d1.dll", "opengl32.dll", "dcomp.dll" }) if (module.startsWith (driver)) { cause.gpuDriver = true; cause.driverModule = module; break; } if (cause.gpuDriver) break; } } return cause; } juce::String collectUncleanSessions() { juce::String lastStep; juce::Time newest; for (const auto& file : sessionsFolder().findChildFiles (juce::File::findFiles, false, "session-*.txt")) { const auto text = file.loadFileAsString(); juce::StringPairArray values; juce::StringArray steps; for (const auto& line : juce::StringArray::fromLines (text)) { if (line.startsWith ("step=")) steps.add (line.fromFirstOccurrenceOf ("=", false, false)); else if (line.contains ("=")) values.set (line.upToFirstOccurrenceOf ("=", false, false), line.fromFirstOccurrenceOf ("=", false, false)); } const auto pid = (std::uint32_t) values["pid"].getLargeIntValue(); const auto start = (std::uint64_t) values["start"].getLargeIntValue(); if (pid == lynx::crashguard::processId() || lynx::crashguard::processRunning (pid, start)) continue; // this run, or another LYNX window still open lynx::PluginHost::settingsFolder().getChildFile ("crash-history.log") .appendText (juce::Time::getCurrentTime().toISO8601 (true) + " previous session ended without closing\n" + text + "\n"); file.deleteFile(); if (const auto modified = file.getLastModificationTime(); lastStep.isEmpty() || modified > newest) { newest = modified; lastStep = steps.isEmpty() ? juce::String ("start-up") : steps[steps.size() - 1].fromFirstOccurrenceOf (" ", false, false); uncleanSessionText = text; uncleanSteps.clear(); for (const auto& step : steps) uncleanSteps.add (step.fromFirstOccurrenceOf (" ", false, false)); } } return lastStep; } } // namespace // --uiperf (round 173f, discussion #10): a mixer fader dragged up and down with the mouse while the pattern plays. A // high-resolution timer delivers 125 moves a second to the message thread through the window's own mouse path // (ComponentPeer::handleMouseEvent), at most one waiting at a time as Windows does with WM_MOUSEMOVE; every frame the // window paints tells whether it covered the fader. Measured: how long a move waited for the message thread, the time // from a move to the first frame that shows the fader after it (input → paint), and whether the value stays put when // the mouse is released. struct UiPerfDrag final : public std::enable_shared_from_this, private juce::HighResolutionTimer { ~UiPerfDrag() override { stopTimer(); } void start (juce::Component& windowIn, juce::Component& strips, juce::Rectangle rail, lynx::AudioEngine* engineIn, int trackIn) { window = &windowIn; engine = engineIn; track = trackIn; railInWindow = window->getLocalArea (&strips, rail); watch = railInWindow.expanded (6, 40); // the cap, its tip above and the dB read-out below visible = strips.isShowing() && window->getLocalArea (&strips, strips.getLocalBounds()).contains (railInWindow.getCentre()); const auto volume = engine->getSong().mixer[(std::size_t) track].volume; x = (float) railInWindow.getCentreX(); startY = (float) railInWindow.getBottom() - volume * (float) railInWindow.getHeight(); // on the cap: no jump amplitude = 0.4f * (float) railInWindow.getHeight(); centreY = juce::jlimit ((float) railInWindow.getY() + amplitude, (float) railInWindow.getBottom() - amplitude, startY); t0 = juce::Time::getMillisecondCounterHiRes(); inject (x, startY, false); juce::ModifierKeys::currentModifiers = juce::ModifierKeys (juce::ModifierKeys::leftButtonModifier); inject (x, startY, true); active = true; startTimer (8); } // message thread void framePainted (double now, juce::Rectangle area) { if (pending.empty() || ! area.intersects (watch)) return; for (const auto t : pending) latencies.push_back (now - t); pending.clear(); ++framesOverFader; } // the moves end; as in the reporter's clip, the song is stopped while the button is still down juce::String stop() { stopTimer(); active = false; valueAtRelease = engine->getSong().mixer[(std::size_t) track].volume; engine->stop(); juce::String text; text << " drag of insert " << track << "'s fader" << (visible ? "" : " (NOT VISIBLE)") << ": " << moves << " moves handled, " << dropped << " folded into the next (the message thread still busy with the previous one)\n" << " move waited for the message thread: " << describe (queueDelays) << "\n" << " input -> paint (move to the first frame over the fader): " << describe (latencies) << ", " << framesOverFader << " frames over the fader\n"; return text; } juce::String release() { const auto now = engine->getSong().mixer[(std::size_t) track].volume; juce::ModifierKeys::currentModifiers = {}; inject (x, lastY, false); return " song stopped, button still down: fader " + juce::String (now, 4) + " (" + juce::String (valueAtRelease, 4) + " at the last move) " + (std::abs (now - valueAtRelease) < 1.0e-4f ? "kept" : "CHANGED") + "\n"; } juce::String released() const { const auto now = engine->getSong().mixer[(std::size_t) track].volume; return " after the release: fader " + juce::String (now, 4) + " (" + juce::String (valueAtRelease, 4) + " when released) " + (std::abs (now - valueAtRelease) < 1.0e-4f ? "kept" : "CHANGED") + "\n"; } private: juce::Component* window = nullptr; lynx::AudioEngine* engine = nullptr; int track = 1; juce::Rectangle railInWindow, watch; bool visible = false; float x = 0.0f, startY = 0.0f, centreY = 0.0f, amplitude = 0.0f, lastY = 0.0f; double t0 = 0.0; std::atomic active { false }, posted { false }; std::atomic dropped { 0 }; int moves = 0, framesOverFader = 0; float valueAtRelease = 0.0f; std::vector pending, latencies, queueDelays; static juce::String describe (std::vector v) { if (v.empty()) return "none"; std::sort (v.begin(), v.end()); const auto at = [&v] (double q) { return v[std::min (v.size() - 1, (std::size_t) (q * (double) v.size()))]; }; return "p50 " + juce::String (at (0.5), 1) + " / p95 " + juce::String (at (0.95), 1) + " / p99 " + juce::String (at (0.99), 1) + " / max " + juce::String (v.back(), 1) + " ms"; } void inject (float px, float py, bool down) { lastY = py; if (auto* peer = window != nullptr ? window->getPeer() : nullptr) { const auto local = peer->globalToLocal (window->localPointToGlobal (juce::Point (px, py))); peer->handleMouseEvent (juce::MouseInputSource::InputSourceType::mouse, local, down ? juce::ModifierKeys (juce::ModifierKeys::leftButtonModifier) : juce::ModifierKeys(), juce::MouseInputSource::defaultPressure, juce::MouseInputSource::defaultOrientation, juce::Time::currentTimeMillis()); } } void hiResTimerCallback() override { if (! active.load()) return; if (posted.exchange (true)) { ++dropped; return; } const auto postedAt = juce::Time::getMillisecondCounterHiRes(); juce::MessageManager::callAsync ([self = shared_from_this(), postedAt] { self->posted = false; if (! self->active.load()) return; const auto now = juce::Time::getMillisecondCounterHiRes(); self->queueDelays.push_back (now - postedAt); // up and down ~1.3 times a second, like the reporter's hand const auto y = self->centreY + self->amplitude * (float) std::sin (2.0 * juce::MathConstants::pi * 1.3 * (now - self->t0) / 1000.0); self->inject (self->x, y, true); self->pending.push_back (postedAt); ++self->moves; }); } }; class LynxApplication final : public juce::JUCEApplication { public: const juce::String getApplicationName() override { return JUCE_APPLICATION_NAME_STRING; } const juce::String getApplicationVersion() override { return JUCE_APPLICATION_VERSION_STRING; } // the plugin scan runs copies of LYNX as child processes bool moreThanOneInstanceAllowed() override { return true; } void initialise (const juce::String& commandLine) override { // round 166b: the copy of LYNX.exe that installs an update (ui/Updater.h) waits, installs, starts LYNX again if (commandLine.contains ("--apply-update") && lynx::updater::runApplyHelper (juce::StringArray::fromTokens (commandLine, true))) { updateHelper = true; quit(); return; } // Windows, LYNX.exe in a folder with accents: run again from its ASCII short path (Waves editors crash otherwise) if (int code = 0; lynx::platform::relaunchFromAsciiPath (code)) { relaunched = true; setApplicationReturnValue (code); quit(); return; } // a crash in any mode (UI, command line) writes its backtrace to %APPDATA%\LYNX\autosave juce::SystemStats::setApplicationCrashHandler (onCrash); // SFZ instruments (round 167o): their FLAC / OGG / AIFF / MP3 samples through JUCE's readers lynx::sfz::setDecoder ([] (const std::string& path, lynx::sfz::Audio& out) { juce::AudioFormatManager formats; formats.registerBasicFormats(); std::unique_ptr reader (formats.createReaderFor (juce::File (juce::String::fromUTF8 (path.c_str())))); if (reader == nullptr || reader->lengthInSamples <= 0 || reader->lengthInSamples > (1 << 28) || reader->numChannels == 0) return false; const auto frames = (int) reader->lengthInSamples; juce::AudioBuffer buffer ((int) std::min (2u, reader->numChannels), frames); if (! reader->read (&buffer, 0, frames, 0, true, buffer.getNumChannels() > 1)) return false; out.channels.clear(); for (int ch = 0; ch < buffer.getNumChannels(); ++ch) out.channels.emplace_back (buffer.getReadPointer (ch), buffer.getReadPointer (ch) + frames); out.sampleRate = reader->sampleRate; out.loopStart = out.loopEnd = -1; return true; }); // child process of a sandboxed plugin: no window or audio of its own if (lynx::runPluginSandboxWorker (commandLine)) { lynx::crashguard::quietCrashReports(); sandboxChild = true; return; } const auto args = juce::StringArray::fromTokens (commandLine, true); // interface language: saved in %APPDATA%\LYNX\language.txt; --lang pt-BR overrides it for this run lynx::i18n::initialise (args); lookAndFeel.applyLanguageFont (lynx::i18n::current()); if (args.contains ("--showcase")) { // LYNX's own demo project (README screenshots): --showcase output.lynx [pattern] const auto i = args.indexOf ("--showcase"); runShowcase (args[i + 1].unquoted(), args[i + 2].getIntValue()); return; } if (args.contains ("--sandboxtest")) { const auto i = args.indexOf ("--sandboxtest"); runSandboxTest (args[i + 1].unquoted(), args[i + 2].unquoted()); return; } if (args.contains ("--bridge32test")) { // LYNX.exe --bridge32test "LYNX Test Synth 32.dll" report.txt [--compare "LYNX Test Synth.dll"] (round 176a): // the 32-bit plugin bridge (engine/Bridge32Test.cpp) const auto i = args.indexOf ("--bridge32test"); const auto compare = args.contains ("--compare") ? args[args.indexOf ("--compare") + 1].unquoted() : juce::String(); setApplicationReturnValue (lynx::runBridge32Test (args[i + 1].unquoted(), args[i + 2].unquoted(), compare)); quit(); return; } if (args.contains ("--rtstress")) { // LYNX.exe --rtstress project.(flp|lynx) report.txt [seconds] [--buffer N] [--type "driver type"] [--device "output"] // [--no-window] [--record take.wav]: the real app (window, audio device) plays the project and reports the callbacks // that missed their deadline (REA round 87); --type/--device pick another driver for this run only (round 97); // --record also records the input during the run, like Rec + Play, and moves the take to take.wav (round 106) const auto i = args.indexOf ("--rtstress"); const auto seconds = args[i + 3].getDoubleValue(); const auto buffer = args.contains ("--buffer") ? args[args.indexOf ("--buffer") + 1].getIntValue() : 0; juce::LookAndFeel::setDefaultLookAndFeel (&lookAndFeel); const auto option = [&args] (const char* name) { return args.contains (name) ? args[args.indexOf (name) + 1].unquoted() : juce::String(); }; runRealtimeStress (juce::File (args[i + 1].unquoted()), juce::File (args[i + 2].unquoted()), seconds > 0.0 ? seconds : 30.0, buffer, option ("--type"), option ("--device"), option ("--record")); return; } if (args.contains ("--cliplooptest")) { // LYNX --cliplooptest report.txt [export.wav] (round 167q, issue #25: 0.1.21 drew the repeats of a stretched // pattern clip but played the pattern once). The real engine's device callback (a stand-in device, driven // block by block) plays a synth's 1-bar pattern in a 4-bar clip: every repeat must sound as bar 1, also // starting inside a repeat, after a jump mid-clip and in a loop region; the WAV export (written to // export.wav and read back) the same. With the LYNX extra off, bars 2-4 must be silent (FL's behaviour). const auto i = args.indexOf ("--cliplooptest"); runClipLoopTest (juce::File (args[i + 1].unquoted()), args.size() > i + 2 && ! args[i + 2].startsWith ("--") ? juce::File (args[i + 2].unquoted()) : juce::File()); return; } if (args.contains ("--countinrectest")) { // LYNX --countinrectest report.txt (round 170d, the Busy Works video: the chord on the downbeat after the // pre-count was lost). The real engine's device callback (a stand-in device: 48 kHz, blocks of 512, 256 // samples of output latency) records a Song-mode take from bar 3 with a 1-bar count-in. Pass 1 finds where // the metronome's bar-3 click is heard; pass 2 plays MIDI notes stamped at the times they are heard around // it (a chord 15 ms early, a note in the count-in, one 3 ms after beat 2, one a bar for 6 bars) through // LYNX's MIDI input. Every note must land on the tick it was heard at (the chord on bar 3). const auto i = args.indexOf ("--countinrectest"); runCountInRecordTest (juce::File (args[i + 1].unquoted())); return; } if (args.contains ("--bendrectest")) { // LYNX --bendrectest report.txt [song|pattern] (round 167a, issue #12): pitch bend recording end to end. A // controller's pitch wheel is injected into LYNX's MIDI input (as a device would send it) while recording // plays: a held note and a wheel sweep 0 → full up → full down → centre. The recorded lane (pattern mode) or // automation clip (song mode) of the channel's pitch bend must follow the sweep. const auto i = args.indexOf ("--bendrectest"); const auto songMode = args.size() > i + 2 && args[i + 2] == "song"; runBendRecordTest (juce::File (args[i + 1].unquoted()), songMode); return; } if (args.contains ("--rectest")) { // LYNX --rectest report.txt [seconds] [--type T] [--device D] [--input I] [--loop] [--buffer N] // (round 163): records a click track through a loopback (cable, interface loopback or PipeWire's // pw-loopback): pings the round trip, plays a click on every beat from an audio clip, records it on Insert 1, // stops, and checks every recorded click's song position on the Playlist against its beat (samples). // --loop: loop recording over bars 2-4 (take lanes). --punch: punch in/out on bars 3-4 with 1 bar of pre-roll // and 1 of post-roll (playback stops by itself after the post-roll). const auto i = args.indexOf ("--rectest"); const auto option = [&args] (const char* name) { return args.contains (name) ? args[args.indexOf (name) + 1].unquoted() : juce::String(); }; const auto seconds = args.size() > i + 2 && ! args[i + 2].startsWith ("--") ? args[i + 2].getDoubleValue() : 20.0; runRecordTest (juce::File (args[i + 1].unquoted()), seconds > 0.0 ? seconds : 20.0, option ("--type"), option ("--device"), option ("--input"), args.contains ("--loop") ? 1 : args.contains ("--punch") ? 2 : 0, option ("--pdc").getIntValue(), option ("--buffer").getIntValue()); return; } if (args.contains ("--hwinserttest")) { // LYNX --hwinserttest report.txt [seconds] [--type T] [--device D] [--input I] [--buffer N] (round 164d): a // hardware insert through a loopback cable (output pair 1-2 -> input pair 1-2; the Master plays nowhere, so // the cable carries the send only). The same click track plays on two inserts: Insert 1 through the // hardware insert (panned left), Insert 2 dry (panned right). The insert's own ping measures the round // trip, PDC delays the dry path by it, and every click of the Master's left side must sit on the same // sample as the right side's. const auto i = args.indexOf ("--hwinserttest"); const auto option = [&args] (const char* name) { return args.contains (name) ? args[args.indexOf (name) + 1].unquoted() : juce::String(); }; const auto seconds = args.size() > i + 2 && ! args[i + 2].startsWith ("--") ? args[i + 2].getDoubleValue() : 10.0; // round 165c: --patcher puts the insert inside a Patcher on Insert 1; --bounce file.wav then exports the song in real // time through the device (Export › "Render through the hardware in real time") and offline, and compares them runHwInsertTest (juce::File (args[i + 1].unquoted()), seconds > 0.0 ? seconds : 10.0, option ("--type"), option ("--device"), option ("--input"), option ("--buffer").getIntValue(), args.contains ("--patcher"), args.contains ("--bounce") ? juce::File (option ("--bounce")) : juce::File()); return; } if (args.contains ("--uiperf")) { // LYNX --uiperf project.(flp|lynx) report.txt: the heavy UI cases in the real window, every frame timed (round 161) const auto i = args.indexOf ("--uiperf"); juce::LookAndFeel::setDefaultLookAndFeel (&lookAndFeel); runUiPerf (juce::File (args[i + 1].unquoted()), juce::File (args[i + 2].unquoted())); return; } if (args.contains ("--livetest")) { // LYNX --livetest report.txt [--relay URL]: a live session of four peers over the relay (round 169b) setApplicationReturnValue (lynx::livetest::run (args)); quit(); return; } if (args.contains ("--selftest")) { const auto i = args.indexOf ("--selftest"); runSelfTest (args[i + 1].unquoted(), args[i + 2].unquoted()); return; } if (args.contains ("--scan-one")) { // child process of the plugin scan (see PluginHost::scan) const auto i = args.indexOf ("--scan-one"); // no crash dialogs from the plugin being examined; and once the result is written, the process ends without // unloading it: a Waves shell crashed in its own teardown at exit (Intel GPU driver fail-fast, 0xC0000409), // which showed Windows' crash dialog and made the scan reject the whole shell (round 111) lynx::crashguard::quietCrashReports(); lynx::PluginHost::scanOneFile (args[i + 1].unquoted(), args[i + 2].unquoted(), juce::File (args[i + 3].unquoted())); lynx::crashguard::exitNow (0); } if (args.contains ("--packageinfo")) { // round 165n: the Microsoft Store (MSIX) build's identity and folders (platform/Package.h); the release // workflow runs it inside the installed test package juce::File (args[args.indexOf ("--packageinfo") + 1].unquoted()).replaceWithText (lynx::platform::packageReport()); quit(); return; } if (args.contains ("--paths")) { // diagnostics: folders LYNX searches const auto programs = juce::File::getSpecialLocation (juce::File::globalApplicationsDirectory); juce::String report; report << "programs=" << programs.getFullPathName() << "\n"; for (const auto& dir : programs.getChildFile ("Image-Line").findChildFiles (juce::File::findDirectories, false, "FL Studio*")) report << "fl=" << dir.getFullPathName() << " packs=" << (int) dir.getChildFile ("Data").getChildFile ("Patches").getChildFile ("Packs").isDirectory() << "\n"; juce::File (args[args.indexOf ("--paths") + 1].unquoted()).replaceWithText (report); quit(); return; } if (args.contains ("--fldb")) { // diagnostics: LYNX.exe --fldb report.txt [project.flp]: the FL Studio installation, its plugin database, // the suggested plugin folders and, for a project, how each of its plugins resolves (read-only) const auto i = args.indexOf ("--fldb"); const auto fl = lynx::findFlStudio(); lynx::PluginHost host (false); juce::String report; report << "install=" << fl.installDir.getFullPathName() << "\nuserdata=" << fl.userData.getFullPathName() << "\n"; for (const auto& f : fl.vstFolders) report << "flvstfolder=" << f << "\n"; report << "dbfiles=" << host.flPluginDatabaseFiles() << " entries=" << (int) host.flPluginDatabase().entries().size() << "\n"; for (const auto& e : host.flPluginDatabase().entries()) report << " entry: " << juce::String::fromUTF8 (e.name.c_str()) << " | " << juce::String::fromUTF8 (e.path.c_str()) << " | role=" << e.role << "\n"; const auto suggested = host.suggestedFolders(); for (int k = 0; k < suggested.getNumPaths(); ++k) report << "folder=" << suggested[k].getFullPathName() << "\n"; if (const juce::File project (args[i + 2].unquoted()); project.existsAsFile()) { juce::MemoryBlock data; project.loadFileAsData (data); try { for (const auto& use : lynx::flpForeignPlugins (flp::parseProject ({ static_cast (data.getData()), data.getSize() }))) { juce::String how; const auto d = host.findForeign (use.plugin, use.instrument, &how); const auto* entry = host.flPluginDatabase().match (use.plugin, use.instrument); report << "plugin: " << juce::String::fromUTF8 (use.plugin.name.c_str()) << " -> " << (d ? d->fileOrIdentifier + " (" + how + ")" : juce::String ("not known")) << (entry != nullptr ? " | fl db: " + juce::String::fromUTF8 (entry->path.c_str()) : juce::String()) << "\n"; } const auto uses = lynx::flpForeignPlugins (flp::parseProject ({ static_cast (data.getData()), data.getSize() })); const auto candidates = host.filesToScanFor (uses); report << "scan_candidates=" << candidates.joinIntoString (";") << "\n"; if (args.contains ("--scan")) { // the targeted scan an open would run (child processes; the user's plugin list is not touched) report << "scanned_new=" << host.scanFiles (candidates, {}) << "\n"; for (const auto& use : uses) { juce::String how; const auto d = host.findForeign (use.plugin, use.instrument, &how); report << "after_scan: " << juce::String::fromUTF8 (use.plugin.name.c_str()) << " -> " << (d ? d->fileOrIdentifier + " (" + how + ")" : juce::String ("not known")) << "\n"; } } } catch (const flp::Error& e) { report << "error=" << e.what() << "\n"; } } juce::File (args[i + 1].unquoted()).replaceWithText (report); quit(); return; } if (args.contains ("--midisync-test")) { // LYNX --midisync-test report.txt ["output device"] ["input device"] (round 165f): MIDI clock timing const auto i = args.indexOf ("--midisync-test"); const auto out = args.size() > i + 2 && ! args[i + 2].startsWith ("--") ? args[i + 2].unquoted() : juce::String(); const auto in = args.size() > i + 3 && ! args[i + 3].startsWith ("--") ? args[i + 3].unquoted() : juce::String(); juce::File (args[i + 1].unquoted()).replaceWithText (lynx::MidiSyncIo::selfTest (out, in)); quit(); return; } if (args.contains ("--devices") || args.contains ("--dispositivos")) // --dispositivos: legacy alias { // diagnostics: driver types and output devices JUCE offers (without opening any) juce::AudioDeviceManager manager; juce::String report; manager.getAvailableDeviceTypes(); if (auto pipeWire = lynx::makePipeWireDeviceType()) // Linux: LYNX's own PipeWire client (round 161) manager.addAudioDeviceType (std::move (pipeWire)); #if JUCE_LINUX report << lynx::describePipeWire() << "\n"; #endif for (auto* type : manager.getAvailableDeviceTypes()) { type->scanForDevices(); report << "type=" << type->getTypeName() << "\n"; for (const auto& name : type->getDeviceNames (false)) report << " output=" << name << "\n"; for (const auto& name : type->getDeviceNames (true)) report << " input=" << name << "\n"; } for (const auto& d : juce::MidiInput::getAvailableDevices()) report << "midi-in=" << d.name << "\n"; for (const auto& d : juce::MidiOutput::getAvailableDevices()) report << "midi-out=" << d.name << "\n"; const auto flag = args.contains ("--devices") ? args.indexOf ("--devices") : args.indexOf ("--dispositivos"); juce::File (args[flag + 1].unquoted()).replaceWithText (report); quit(); return; } if (args.contains ("--devicetest")) { // LYNX.exe --devicetest "type" "device" report.txt ["input device"] [--buffer N] [--roundtrip]: opens that output device (and, with the // 4th argument, an input: "*" = the same device / the driver's default input), receives 1 s of callbacks // writing silence, closes it and reports rate, block size, latency, callbacks and the input channels with // their peak level (driver check, no sound). --roundtrip: clicks out, found again on input 1 through a loopback // cable / PipeWire link: the round-trip latency (3 s) const auto i = args.indexOf ("--devicetest"); const auto typeName = args[i + 1].unquoted(), deviceName = args[i + 2].unquoted(); auto inputName = args.size() > i + 4 && ! args[i + 4].startsWith ("--") ? args[i + 4].unquoted() : juce::String(); const auto wantInput = inputName.isNotEmpty(); juce::String report; const juce::File reportFile (args[i + 3].unquoted()); auto step = [&] (const juce::String& line) { report << line << "\n"; reportFile.replaceWithText (report); }; // progress survives a driver that ends the process step ("step=start"); juce::AudioDeviceManager manager; manager.getAvailableDeviceTypes(); if (auto pipeWire = lynx::makePipeWireDeviceType()) manager.addAudioDeviceType (std::move (pipeWire)); std::unique_ptr device; for (auto* type : manager.getAvailableDeviceTypes()) if (type->getTypeName() == typeName) { type->scanForDevices(); if (wantInput && type->hasSeparateInputsAndOutputs()) { const auto inputs = type->getDeviceNames (true); if (inputName == "*" || ! inputs.contains (inputName)) { const auto index = type->getDefaultDeviceIndex (true); inputName = juce::isPositiveAndBelow (index, inputs.size()) ? inputs[index] : juce::String(); } for (const auto& n : inputs) step ("input_device=" + n); step ("input_chosen=" + inputName); } else if (wantInput) inputName = deviceName; step ("step=create"); device.reset (type->createDevice (deviceName, type->hasSeparateInputsAndOutputs() ? inputName : juce::String())); step ("step=created"); } struct Silence final : juce::AudioIODeviceCallback { std::atomic calls { 0 }, inputs { 0 }; std::array, 64> peaks {}; // --roundtrip (round 161): a click every quarter second on the outputs, found again on input 1 through a // loopback; the delays in samples bool roundtrip = false; int period = 12000; std::int64_t position = 0, lastClick = -1; std::vector delays; void audioDeviceIOCallbackWithContext (const float* const* in, int numIn, float* const* out, int channels, int n, const juce::AudioIODeviceCallbackContext&) override { for (int c = 0; c < channels; ++c) if (out[c] != nullptr) juce::FloatVectorOperations::clear (out[c], n); if (roundtrip) { for (int i = 0; i < n; ++i) { if (numIn > 0 && in[0] != nullptr && lastClick >= 0 && std::abs (in[0][i]) > 0.5f) { if (delays.size() < delays.capacity()) delays.push_back ((int) (position + i - lastClick)); lastClick = -1; } if ((position + i) % period == 0 && position + i > 0) { for (int c = 0; c < channels; ++c) if (out[c] != nullptr) out[c][i] = 0.9f; lastClick = position + i; } } position += n; } inputs.store (numIn); for (int c = 0; c < juce::jmin (numIn, 64); ++c) if (in[c] != nullptr) { const auto range = juce::FloatVectorOperations::findMinAndMax (in[c], n); const auto peak = juce::jmax (std::abs (range.getStart()), std::abs (range.getEnd())); if (peak > peaks[(std::size_t) c].load()) peaks[(std::size_t) c].store (peak); } ++calls; } void audioDeviceAboutToStart (juce::AudioIODevice*) override {} void audioDeviceStopped() override {} } silence; bool ok = false; if (device == nullptr) step ("error=device not found"); else { step ("step=open"); juce::BigInteger outputs; outputs.setRange (0, 2, true); const auto rates = device->getAvailableSampleRates(); const auto rate = device->getCurrentSampleRate() > 0 ? device->getCurrentSampleRate() : rates.contains (48000.0) ? 48000.0 : rates.isEmpty() ? 44100.0 : rates[0]; step ("rates=" + juce::String (rates.size()) + " chosen=" + juce::String (rate) + " default_block=" + juce::String (device->getDefaultBufferSize())); juce::BigInteger inputs; if (wantInput) { const auto names = device->getInputChannelNames(); step ("input_channels=" + juce::String (names.size())); for (int c = 0; c < names.size(); ++c) step (" in" + juce::String (c + 1) + "=" + names[c]); inputs.setRange (0, juce::jmin (64, names.size()), true); } // --buffer N: ask for that block size (REA round 97 latency survey); default: the driver's default const auto wantedBlock = args.contains ("--buffer") ? args[args.indexOf ("--buffer") + 1].getIntValue() : 0; const auto error = device->open (inputs, outputs, rate, wantedBlock > 0 ? wantedBlock : device->getDefaultBufferSize()); if (error.isNotEmpty()) step ("error=" + error); else { step ("step=start_callbacks"); silence.roundtrip = args.contains ("--roundtrip"); silence.period = juce::jmax (1, (int) (rate / 4)); silence.delays.reserve (64); device->start (&silence); juce::Thread::sleep (silence.roundtrip ? 3000 : 1000); device->stop(); if (silence.roundtrip) { auto d = silence.delays; std::sort (d.begin(), d.end()); report << "roundtrip_clicks=" << (int) d.size() << "\n"; if (! d.empty()) report << "roundtrip_samples=min " << d.front() << " median " << d[d.size() / 2] << " max " << d.back() << "\n" << "roundtrip_ms=" << juce::String (1000.0 * d[d.size() / 2] / device->getCurrentSampleRate(), 2) << "\n"; } report << "rate=" << device->getCurrentSampleRate() << "\n" << "block=" << device->getCurrentBufferSizeSamples() << "\n" << "output_latency=" << device->getOutputLatencyInSamples() << "\n" << "callbacks=" << silence.calls.load() << "\n"; if (wantInput) { report << "input_latency=" << device->getInputLatencyInSamples() << "\n" << "active_inputs=" << device->getActiveInputChannels().countNumberOfSetBits() << "\n" << "callback_inputs=" << silence.inputs.load() << "\n"; for (int c = 0; c < juce::jmin (64, silence.inputs.load()); ++c) report << " peak_in" << (c + 1) << "=" << juce::Decibels::gainToDecibels (silence.peaks[(std::size_t) c].load(), -150.0f) << " dB\n"; } ok = silence.calls.load() > 0 && (! wantInput || silence.inputs.load() > 0); device->close(); } } step (juce::String ("result=") + (ok ? "OK" : "FAILED")); setApplicationReturnValue (ok ? 0 : 1); quit(); return; } if (args.contains ("--scantest")) { // LYNX.exe --scantest folder report.txt: scan (in child processes) without touching the user's list const auto i = args.indexOf ("--scantest"); lynx::PluginHost host (false); const auto found = host.scan (juce::FileSearchPath (args[i + 1].unquoted()), {}); juce::String report; report << "found=" << found << "\n"; for (const auto& t : host.getKnownPlugins().getTypes()) report << " " << (t.isInstrument ? "instrument: " : "effect: ") << t.name << "\n"; for (const auto& f : host.getKnownPlugins().getBlacklistedFiles()) report << " blacklisted: " << f << "\n"; juce::File (args[i + 2].unquoted()).replaceWithText (report); setApplicationReturnValue (found > 0 ? 0 : 1); quit(); return; } if (args.contains ("--vst2test")) { const auto i = args.indexOf ("--vst2test"); runVst2Test (args[i + 1].unquoted(), args[i + 2].unquoted()); return; } if (args.contains ("--wrappertest")) { const auto i = args.indexOf ("--wrappertest"); runWrapperTest (args[i + 1].unquoted(), args[i + 2].unquoted()); return; } if (args.contains ("--plugintest")) { const auto i = args.indexOf ("--plugintest"); // optional 3rd argument: the plugin's name inside a shell (e.g. "CLA-2A Stereo" in a WaveShell) const auto only = i + 3 < args.size() && ! args[i + 3].startsWith ("--") ? args[i + 3].unquoted() : juce::String(); runPluginTest (args[i + 1].unquoted(), args[i + 2].unquoted(), only); return; } if (args.contains ("--claprestarttest")) { // LYNX.exe --claprestarttest "LYNX Test Restart.clap" report.txt (tools/testplugin/lynx_test_restart.c) const auto i = args.indexOf ("--claprestarttest"); runClapRestartTest (args[i + 1].unquoted(), args[i + 2].unquoted()); return; } if (args.contains ("--editortest")) { // LYNX.exe --editortest plugin.vst3 report.txt ["name"]: opens the plugin's own editor in a window for a few // seconds, then closes it (a plugin whose UI crashes the host ends the process before the report says OK) const auto i = args.indexOf ("--editortest"); const auto only = i + 3 < args.size() && ! args[i + 3].startsWith ("--") ? args[i + 3].unquoted() : juce::String(); runEditorTest (args[i + 1].unquoted(), args[i + 2].unquoted(), only); return; } if (args.contains ("--editorcrashtest")) { // LYNX.exe --editorcrashtest "LYNX Test Crash.clap" report.txt (issue #32, round 174a; Windows): the test // plugin's editor faults in its own window procedure (LYNX_TEST_CRASH=editor). LYNX must catch it, close // that editor, record the trace and keep running its message loop. const auto i = args.indexOf ("--editorcrashtest"); runEditorCrashTest (args[i + 1].unquoted(), args[i + 2].unquoted()); return; } if (args.contains ("--plugwintest")) { // LYNX --plugwintest plugin report.txt ["name"] [seconds]: round 162d. Puts the plugin in a channel (an // instrument) or on insert 1 (an effect) of an offline engine, opens its plugin window (wrapper header, // presets), checks a preset round trip, keeps the window `seconds` on screen (default 15: time for xdotool / // screenshots), then removes the plugin from the song and reports whether its window closed by itself. const auto i = args.indexOf ("--plugwintest"); const auto only = i + 3 < args.size() && ! args[i + 3].startsWith ("--") && ! args[i + 3].containsOnly ("0123456789") ? args[i + 3].unquoted() : juce::String(); auto seconds = 15; for (int k = i + 3; k < juce::jmin (args.size(), i + 5); ++k) if (args[k].containsOnly ("0123456789")) seconds = args[k].getIntValue(); runPlugWinTest (args[i + 1].unquoted(), args[i + 2].unquoted(), only, seconds); return; } if (args.contains ("--fittest")) { // LYNX.exe --fittest report.txt [percent]: round 163 — at that UI zoom (default 150) a window taller than // the screen and a big resizable window that grows with a zoom change keep their title bar and close // button on the screen. The windows show for about two seconds. const auto i = args.indexOf ("--fittest"); runFitTest (args[i + 1].unquoted(), i + 2 < args.size() ? args[i + 2].getIntValue() : 150); return; } if (args.contains ("--windowtest")) { // LYNX.exe --windowtest report.txt: opens the Quick-add palette, the Audio editor, a plugin-like window and a name dialog // over the main window and checks that each one stays in front, owned by the main window, with the // keyboard focus (issue #4). The windows appear on screen for a few seconds. runWindowTest (args[args.indexOf ("--windowtest") + 1].unquoted()); return; } if (args.contains ("--pluginstyle")) // round 126: force one style for this run (glow, neon, hardware, vivid; auto = per plugin) { const auto i = args.indexOf ("--pluginstyle"); if (i + 1 < args.size()) { const auto name = args[i + 1].unquoted(); lynx::skin::setForcedStyle (name.equalsIgnoreCase ("auto") ? -1 : (int) lynx::skin::styleFromName (name)); } } if (args.contains ("--gfxprobe")) { // LYNX.exe --gfxprobe report.txt (round 170c, issue #11): renderer checks on this platform's native images — // text drawn with a gradient fill (a word with a space in it) and an empty path filled with a gradient must // stay inside their shapes. JUCE 8.0.4's CoreGraphics renderer (macOS) clipped to an empty glyph or path as // "no clip" and flooded the whole component (Facet EQ's blank pink window). const auto i = args.indexOf ("--gfxprobe"); juce::File (args[i + 1].unquoted()).replaceWithText (lynx::skin::rendererProbeReport()); quit(); return; } if (args.contains ("--steppertest")) { // LYNX.exe --steppertest : round 170c (#14) — every value stepper of every generated effect editor // driven by synthetic input (arrows, click on the value, drag, wheel, trackpad); ends with result=OK / FAIL const auto i = args.indexOf ("--steppertest"); juce::LookAndFeel::setDefaultLookAndFeel (&lookAndFeel); juce::String report; int fails = 0, count = 0, skips = 0; { lynx::AudioEngine offline (false); auto kinds = lynx::plugui::flLayoutKinds(); for (const auto own : lynx::plugui::ownLayoutKinds()) kinds.push_back (own); // FL's Default preset when the installation has one (the state-backed controls need FL's state) const auto roots = lynx::findFlStudioRoots(); const auto presets = juce::File (juce::String::fromUTF8 (roots.data.c_str())).getChildFile ("Patches/Plugin presets/Effects"); for (const auto kind : kinds) { auto fx = lynx::makeEffectSlot (kind); for (const auto& plugin : lynx::flPluginsForEffect (kind)) { juce::MemoryBlock data; const auto file = presets.getChildFile (juce::String::fromUTF8 (plugin.c_str())).getChildFile ("Default.fst"); if (file.existsAsFile() && file.loadFileAsData (data)) { const auto* bytes = static_cast (data.getData()); if (auto loaded = lynx::effectFromFlPreset (std::vector (bytes, bytes + data.getSize()), 130.0); loaded && loaded->kind == kind) fx = *loaded; } break; } lynx::Song song; song.mixer.resize (2); song.mixer[0].name = "Master"; song.mixer[1].name = "Insert 1"; song.mixer[1].effects.push_back (fx); offline.setSong (std::move (song)); offline.dispatchPendingMessages(); const auto lines = lynx::stepperSelfTest (offline, 1, 0, (int) lynx::plugui::layoutFor (kind).pages.size()); for (const auto& line : juce::StringArray::fromLines (lines)) if (line.isNotEmpty()) { ++count; fails += line.contains (": FAIL") ? 1 : 0; skips += line.contains (": SKIP") ? 1 : 0; } report << lines; juce::PopupMenu::dismissAllActiveMenus(); offline.dispatchPendingMessages(); } } report << "steppers=" << count << " failures=" << fails << " skipped=" << skips << "\nresult=" << (fails == 0 && count > 0 ? "OK" : "FAIL") << "\n"; juce::File (args[i + 1].unquoted()).replaceWithText (report); quit(); return; } if (args.contains ("--plugui")) { // LYNX.exe --plugui : the native effect editors at FL's size (one PNG per editor and page), each // loaded with the FL plugin's Default preset when the FL installation has one const auto i = args.indexOf ("--plugui"); runPluginEditorSnapshots (args[i + 1].unquoted()); return; } if (args.contains ("--parityshot")) { // LYNX.exe --parityshot []: one built-in effect's editor with the given // parameters ("index value" lines, tools/fxrender --dump), its displays fed by the demo song — the LYNX side // of the third-party parity pictures (round tp172b) const auto i = args.indexOf ("--parityshot"); runParityShot (args[i + 1].unquoted(), args[i + 2].unquoted(), i + 3 < args.size() ? args[i + 3].unquoted() : juce::String()); quit(); return; } if (args.contains ("--design168rshot")) { // LYNX.exe --design168rshot : round 168r's editors (FL effects that had a generated page and LYNX's own // simple built-ins) at 100 % and 200 %, with their default settings and, when they have one, the first // preset of LYNX's own bank. "--design168rshot generated": the generated pages they had before const auto i = args.indexOf ("--design168rshot"); if (i + 2 < args.size() && args[i + 2] == "generated") lynx::plugui::showGeneratedLayoutsOnly (true); runDesign168rShots (args[i + 1].unquoted()); quit(); return; } if (args.contains ("--eq166fshot")) { // LYNX.exe --eq166fshot : round 166f's pictures (issue #16) — Parametric EQ 2's spectrum and heatmap // (flat, a +12 dB band, a -12 dB band, Top position) and Facet EQ's comparative EQ (listening to the target, // its spectrum over the source's), each fed by the demo song rendered offline const auto i = args.indexOf ("--eq166fshot"); runEq166fShots (args[i + 1].unquoted()); quit(); return; } if (args.contains ("--editorcpu")) { // LYNX.exe --editorcpu report.txt: opens built-in plugin editors one at a time in a small window (no audio // device: a silent, idle editor) and writes the process CPU each costs while idle and while its display // animates (demo signal) — round 122's check that an idle editor burns no CPU const auto i = args.indexOf ("--editorcpu"); runEditorCpu (args[i + 1].unquoted()); return; } if (args.contains ("--precomputeshot")) { // LYNX.exe --precomputeshot project.(flp|lynx) : round 167h — -precompute.png (channel 1's // Precomputed effects panel) and -project.png (Options › Project with "Fast declick for cut groups") const auto i = args.indexOf ("--precomputeshot"); juce::LookAndFeel::setDefaultLookAndFeel (&lookAndFeel); lynx::AudioEngine shotEngine (false); const juce::File input (args[i + 1].unquoted()); const auto prefix = args[i + 2].unquoted(); juce::String error; bool ok = false; if (input.hasFileExtension ("flp")) ok = shotEngine.importFlpFile (input, error); else if (auto song = lynx::ProjectFile::load (input, error)) shotEngine.setSong (std::move (*song)), ok = true; shotEngine.dispatchPendingMessages(); auto shoot = [&] (std::unique_ptr c, const juce::String& name) { if (c == nullptr) return false; if (c->getWidth() <= 0) c->setSize (520, 600); savePng (c->createComponentSnapshot (c->getLocalBounds()), prefix + name); return true; }; ok = ok && shoot (lynx::makeChannelPrecomputePanel (shotEngine, 0), "-precompute.png"); ok = ok && shoot (lynx::makeSettingsPanel (shotEngine, lynx::SettingsPage::project), "-project.png"); setApplicationReturnValue (ok ? 0 : 1); quit(); return; } if (args.contains ("--pluginthumbs")) { // LYNX.exe --pluginthumbs [key,key...]: the Plugin picker's pictures of LYNX's own plugins (round 171c, // ui/PluginThumbs.h), each editor drawn off-screen and kept as /.png; the picker starts this in // the background when pictures are missing. One line per plugin on stdout. const auto i = args.indexOf ("--pluginthumbs"); lynx::crashguard::quietCrashReports(); juce::LookAndFeel::setDefaultLookAndFeel (&lookAndFeel); juce::StringArray only; if (i + 2 < args.size() && ! args[i + 2].startsWith ("--")) only.addTokens (args[i + 2].unquoted(), ",", ""); const auto t0 = juce::Time::getMillisecondCounterHiRes(); const auto drawn = lynx::pluginthumbs::renderNative (juce::File (args[i + 1].unquoted()), only, [] (const juce::String& line) { std::printf ("%s\n", line.toRawUTF8()); std::fflush (stdout); }); std::printf ("drawn %d in %.0f ms\n", drawn, juce::Time::getMillisecondCounterHiRes() - t0); setApplicationReturnValue (0); quit(); return; } if (args.contains ("--artshot")) { // LYNX.exe --artshot [before|after] [name,name...]: every editor with art of its own (round 170j/170k: the // Themed style; or only the named ones, e.g. "sakura,facet-eq") drawn off-screen at 100 % and 200 % as // /--.png. "before" draws each in the style it had before the Themed style const auto i = args.indexOf ("--artshot"); juce::LookAndFeel::setDefaultLookAndFeel (&lookAndFeel); const auto mode = i + 2 < args.size() && ! args[i + 2].startsWith ("--") ? args[i + 2].unquoted() : juce::String ("after"); if (i + 3 < args.size() && ! args[i + 3].startsWith ("--")) // [name,name...]: only these arts artOnly().addTokens (args[i + 3].unquoted(), ",", ""); setApplicationReturnValue (runArtShots (juce::File (args[i + 1].unquoted()), mode == "before") ? 0 : 1); quit(); return; } if (args.contains ("--artgui")) { // LYNX.exe --artgui [before|after|still] [name,name...]: the same editors in REAL windows on the desktop, one at a // time (always on top, no focus taken), each held while an outside script screenshots it (it writes // /.ready with the window's bounds and waits up to 10 s for /.done), then the // process CPU it costs over 6 s is written to /cpu-.txt. "still": Themed with the motion off const auto i = args.indexOf ("--artgui"); juce::LookAndFeel::setDefaultLookAndFeel (&lookAndFeel); const auto mode = i + 2 < args.size() && ! args[i + 2].startsWith ("--") ? args[i + 2].unquoted() : juce::String ("after"); if (i + 3 < args.size() && ! args[i + 3].startsWith ("--")) // [name,name...]: only these arts artOnly().addTokens (args[i + 3].unquoted(), ",", ""); runArtGui (juce::File (args[i + 1].unquoted()), mode); return; } if (args.contains ("--instrumentshot")) { // LYNX.exe --instrumentshot [lynx|fl]: round 168n — the channel window of // each engine (its Plugin tab) at 100 %, 150 % and 200 %, as /--.png. Source // "lynx" starts from the engine's LYNX bank (what a PC without FL gets), "fl" from FL's Default preset. const auto i = args.indexOf ("--instrumentshot"); juce::LookAndFeel::setDefaultLookAndFeel (&lookAndFeel); const auto source = i + 3 < args.size() && ! args[i + 3].startsWith ("--") ? args[i + 3].unquoted() : juce::String ("lynx"); setApplicationReturnValue (runInstrumentShots (juce::File (args[i + 1].unquoted()), args[i + 2].unquoted(), source) ? 0 : 1); quit(); return; } if (args.contains ("--flextrashot")) { // LYNX.exe --flextrashot : pictures of the editors of round 165g (Big Clock, Tuner, HTML NoteBook, Mute 2, Scratcher, Transmitter) + round 167n Transporter const auto i = args.indexOf ("--flextrashot"); juce::LookAndFeel::setDefaultLookAndFeel (&lookAndFeel); lynx::AudioEngine shotEngine (false); const auto ok = lynx::runFlExtraShots (shotEngine, juce::File (args[i + 1].unquoted())); setApplicationReturnValue (ok ? 0 : 1); quit(); return; } if (args.contains ("--visualtest")) { // LYNX.exe --visualtest [project.flp]: the visual plugins (round 164c) — the audio path's CPU, every // Wave Candy mode and Visualizer scene drawn from a test signal (PNG + the editor's CPU each), and the video // export of a project (default: FL's first ZGameEditor demo) with ffmpeg and as images. Writes report.txt. const auto i = args.indexOf ("--visualtest"); juce::LookAndFeel::setDefaultLookAndFeel (&lookAndFeel); const auto project = i + 2 < args.size() && ! args[i + 2].startsWith ("--") ? juce::File (args[i + 2].unquoted()) : juce::File(); lynx::runVisualTest (juce::File (args[i + 1].unquoted()), project, [this] (bool ok) { setApplicationReturnValue (ok ? 0 : 1); quit(); }); return; } if (args.contains ("--menu-entry")) { // LYNX.AppImage --menu-entry on|off: puts the AppImage in the applications menu (and .lynx files on it) or // takes it out again, without opening a window; the same as the switch in Options › General (round 161) const auto i = args.indexOf ("--menu-entry"); const auto on = args[i + 1].unquoted() != "off"; const auto ok = lynx::runningAsAppImage() && lynx::setAppImageMenuEntry (on); std::fprintf (ok ? stdout : stderr, "%s\n", ok ? (on ? "LYNX SHARE added to the applications menu" : "LYNX SHARE removed from the applications menu") : "only the LYNX SHARE AppImage on Linux can do this"); setApplicationReturnValue (ok ? 0 : 1); quit(); return; } if (args.contains ("--send-test-report")) { // LYNX.exe --send-test-report out.txt [--dry]: builds a crash report marked "test" from the newest crash / // hang file and this computer's facts, writes its JSON to out.txt.json and (without --dry) sends it to // lynx-share.com (LYNX_CRASH_ENDPOINT overrides); out.txt gets "id=…" and "result=OK" or the error (round 159) const auto i = args.indexOf ("--send-test-report"); const juce::File out (args[i + 1].unquoted()); lynx::crashreporter::Session session; session.version = getApplicationVersion(); for (const auto* pattern : { "crash *.txt", "hang *.txt" }) { auto files = lynx::platform::settingsFile ("autosave").findChildFiles (juce::File::findFiles, false, pattern); lynx::filesort::byTime (files, lynx::filesort::By::modificationTime, true); if (! files.isEmpty()) (juce::String (pattern).startsWith ("crash") ? session.crashFile : session.hangFile) = files[0]; } session.steps = { "00:00:01 test report (LYNX.exe --send-test-report)", "00:00:02 opening project " + out.getFileName() }; auto input = lynx::crashreporter::makeInput (session, session.crashFile.existsAsFile() ? "crash" : "manual", nullptr); input.test = true; const auto json = lynx::crashreporter::buildJson (input, false); out.withFileExtension (out.getFileExtension() + ".json").replaceWithText (json); const auto error = args.contains ("--dry") ? juce::String() : lynx::crashreporter::sendNow (json); out.replaceWithText ("id=" + juce::String::fromUTF8 (input.id.c_str()) + "\nendpoint=" + lynx::crashreporter::endpoint() + "\nbytes=" + juce::String (json.getNumBytesAsUTF8()) + "\nresult=" + (error.isEmpty() ? juce::String ("OK") : error) + "\n"); setApplicationReturnValue (error.isEmpty() ? 0 : 1); quit(); return; } if (args.contains ("--symbolize")) { // LYNX.exe --symbolize "crash … .txt" out.txt: names the LYNX.exe+offset frames of a user's crash / hang file // (needs this build's LYNX.pdb next to LYNX.exe — the release's "LYNX-symbols" CI artifact; round 157a) const auto i = args.indexOf ("--symbolize"); const auto text = juce::File (args[i + 1].unquoted()).loadFileAsString(); juce::File (args[i + 2].unquoted()).replaceWithText (juce::String::fromUTF8 (lynx::crashguard::symbolizeOwnFrames (text.toStdString()).c_str())); quit(); return; } if (args.contains ("--opentest")) { // LYNX.exe --opentest report.txt [--visible]: every built-in effect and instrument window opened as the mixer / // Channel rack open them, with default, extreme, random and old-project states; a watchdog fails the test on // a hang (round 157a: opening the Parametric EQ froze LYNX). Windows stay off-screen without --visible. const auto i = args.indexOf ("--opentest"); runOpenTest (args[i + 1].unquoted(), args.contains ("--visible"), [this] (bool ok) { setApplicationReturnValue (ok ? 0 : 1); quit(); }); return; } if (args.contains ("--fxfuzz")) { // LYNX.exe --fxfuzz report.txt [rounds] [--drags]: every built-in effect in its editor, parameters swept (and // dragged with the mouse), audio rendered at several rates; a crash ends the process (round 111) const auto i = args.indexOf ("--fxfuzz"); const auto rounds = args.size() > i + 2 ? juce::jmax (1, args[i + 2].getIntValue()) : 6; // --drags: also mouse drags over the editors (their menus may flash on screen: not for the selftest) const auto ok = runEffectFuzz (rounds, args[i + 1].unquoted(), args.contains ("--drags")); setApplicationReturnValue (ok ? 0 : 1); quit(); return; } if (args.contains ("--controllershot")) { // LYNX.exe --controllershot prefix: the built-in controllers' editors (round 133) as PNGs const auto i = args.indexOf ("--controllershot"); runControllerShot (args[i + 1].unquoted()); quit(); return; } if (args.contains ("--edisonshot")) { // LYNX.exe --edisonshot prefix [audio.wav]: the audio editor's Edison tool windows (round 165l) and the // editor before / after some of them, as PNGs (a synthetic drum loop without a file) const auto i = args.indexOf ("--edisonshot"); runEdisonShot (args[i + 1].unquoted(), i + 2 < args.size() ? args[i + 2].unquoted() : juce::String()); quit(); return; } if (args.contains ("--danceshot")) { // LYNX.exe --danceshot prefix: LYNX Dance (round 165e) — every move as a contact sheet, the channel's editor, // and a demo project with two dance channels (for --snapshot) const auto i = args.indexOf ("--danceshot"); runDanceShot (args[i + 1].unquoted()); quit(); return; } if (args.contains ("--videoshot") && args.indexOf ("--videoshot") + 2 < args.size()) { // LYNX.exe --videoshot prefix video: the Video Player's editor (round 165g) at a few song positions, with // the user's ffmpeg, as PNGs + report.txt (frames decoded, the sound track) const auto i = args.indexOf ("--videoshot"); runVideoShot (args[i + 1].unquoted(), args[i + 2].unquoted()); return; } if (args.contains ("--vfxshot")) { // LYNX.exe --vfxshot prefix: the VFX note effects' editors (round 164b), on channels and in a Patcher, as PNGs const auto i = args.indexOf ("--vfxshot"); runVfxShot (args[i + 1].unquoted()); quit(); return; } if (args.contains ("--patchershot")) { // LYNX.exe --patchershot prefix [project]: every Patcher's editor (round 141) as PNGs (a demo one without a project) const auto i = args.indexOf ("--patchershot"); runPatcherShot (args[i + 1].unquoted(), i + 2 < args.size() ? args[i + 2].unquoted() : juce::String()); quit(); return; } if (args.contains ("--feat166shot")) { // LYNX.exe --feat166shot prefix [project]: round 166d (issue #14) — the Piano Roll with a scale, folded to // it, with one ghost channel, the ghost channels menu, and the Mixer filled to 500 inserts (its start and // its end, and the time a full repaint takes) const auto i = args.indexOf ("--feat166shot"); runFeat166Shot (args[i + 1].unquoted(), i + 2 < args.size() ? args[i + 2].unquoted() : juce::String()); quit(); return; } if (args.contains ("--perfshot")) { // LYNX.exe --perfshot prefix project: the Playlist in Performance mode with a few clips launched and waiting, // then the project patcherized (every insert's effects, the first channels) saved as prefix-patcherized.lynx // for --patchershot (round 165m) const auto i = args.indexOf ("--perfshot"); runPerfShot (args[i + 1].unquoted(), i + 2 < args.size() ? args[i + 2].unquoted() : juce::String()); quit(); return; } if (args.contains ("--typeaheadtest")) { // LYNX.exe --typeaheadtest out.txt: issue #64 — a real popup menu (headings, a submenu) driven by key presses // through its window's peer, as the OS delivers them; writes what got the highlight and what was picked const auto i = args.indexOf ("--typeaheadtest"); runTypeAheadTest (juce::File (args[i + 1].unquoted())); return; } if (args.contains ("--choosertest")) { // LYNX --choosertest out.txt file: issue #72 — opens LYNX's file chooser as the UI does (makeFileChooser + // launchChooser) and reports which dialog came up and what reached the callback. A built-in dialog is shot // (out.txt.png), `file` typed into it and confirmed; a native one (zenity / kdialog) is left to answer. const auto i = args.indexOf ("--choosertest"); runChooserTest (juce::File (args[i + 1].unquoted()), juce::File (args[i + 2].unquoted())); return; } if (args.contains ("--snapshot")) { const auto i = args.indexOf ("--snapshot"); runSnapshot (args[i + 1].unquoted(), args[i + 2].unquoted()); return; } if (args.contains ("--stemsplit")) { // LYNX.exe --stemsplit input.wav folder: the stem separation of the clip menu, without the window const auto i = args.indexOf ("--stemsplit"); lynx::AudioEngine loader (false); const auto error = lynx::extractStemsToFolder (loader, juce::File (args[i + 1].unquoted()), juce::File (args[i + 2].unquoted())); juce::File (args[i + 2].unquoted()).getSiblingFile ("stemsplit.txt").replaceWithText (error.isEmpty() ? "result=OK\n" : "result=FAIL " + error + "\n"); setApplicationReturnValue (error.isEmpty() ? 0 : 1); quit(); return; } if (args.contains ("--stems")) { // LYNX.exe --stems project base.wav: one WAV per insert that has sound (like "Export stems") const auto i = args.indexOf ("--stems"); juce::String error, report; int written = 0; { lynx::AudioEngine loader (false); const juce::File input (args[i + 1].unquoted()), base (args[i + 2].unquoted()); auto ok = input.hasFileExtension ("flp") ? loader.importFlpFile (input, error) : false; if (! input.hasFileExtension ("flp")) if (auto song = lynx::ProjectFile::load (input, error)) { loader.setSong (std::move (*song)); ok = true; } const auto& song = loader.getSong(); for (int t = 1; ok && t < (int) song.mixer.size(); ++t) { if (std::none_of (song.channels.begin(), song.channels.end(), [t] (const lynx::ChannelDef& c) { return c.mixerTrack == t; })) continue; const auto file = base.getSiblingFile (base.getFileNameWithoutExtension() + " - " + juce::String (t) + ".wav"); lynx::ExportSettings settings; lynx::ExportJob job (lynx::makeBounceSong (song, t), settings, file); if (job.run ({}, error)) { ++written; report << file.getFileName() << " peak=" << job.getPeak() << "\n"; } } } report << "stems=" << written << "\n"; juce::File (args[i + 2].unquoted() + ".txt").replaceWithText (report); setApplicationReturnValue (written > 0 ? 0 : 1); quit(); return; } if (args.contains ("--export-flp")) { const auto i = args.indexOf ("--export-flp"); runFlExport (args[i + 1].unquoted(), args[i + 2].unquoted(), args.contains ("--substitute")); return; } if (args.contains ("--export")) { const auto i = args.indexOf ("--export"); const auto insert = args.contains ("--insert") ? args[args.indexOf ("--insert") + 1].getIntValue() : 0; runExport (args[i + 1].unquoted(), args[i + 2].unquoted(), args.contains ("--pattern"), insert); return; } if (args.contains ("--render")) { const auto i = args.indexOf ("--render"); runRender (args[i + 1].unquoted(), args[i + 2].unquoted(), args[i + 3].getDoubleValue()); return; } // session breadcrumb: a fail-fast (no crash handler runs) still leaves the last steps behind (round 111) uncleanLastStep = collectUncleanSessions(); sessionsFolder().createDirectory(); lynx::crashguard::beginSession ( sessionsFolder().getChildFile ("session-" + juce::String (lynx::crashguard::processId()) + ".txt").getFullPathName().toStdString(), ("LYNX session\nversion=" + getApplicationVersion() + "\npid=" + juce::String (lynx::crashguard::processId()) + "\nstart=" + juce::String ((juce::int64) lynx::crashguard::processStartTime()) + "\nstarted=" + juce::Time::getCurrentTime().toISO8601 (true) + "\n").toStdString()); startHangWatch(); startupTrace.mark ("initialise (normal start)"); if (startupTrace.on) lynx::startupMark = startupMarkHook; juce::LookAndFeel::setDefaultLookAndFeel (&lookAndFeel); lynx::themeui::loadSaved(); // the user's theme (Options › Theme, round 162d) startupOptions = lynx::StartupOptions::load(); lynx::registerFileTypes(); startupTrace.mark ("options + file types"); // Double-clicking a .lynx/.flp opens LYNX with the file as an argument. if (args.size() > 0 && juce::File::isAbsolutePath (args[0].unquoted())) fileToOpen = juce::File (args[0].unquoted()); // LYNX --opentime project.(flp|lynx)|- report.txt [idle seconds] (round 165i): the normal start-up (splash, audio // device, window) opens the project, waits until it is loaded and LYNX has gone quiet, measures the idle CPU and // memory, writes the times and quits normally (a benchmark that killed LYNX left "closed unexpectedly" behind) if (args.contains ("--opentime")) { const auto i = args.indexOf ("--opentime"); const auto project = args[i + 1].unquoted(); fileToOpen = project != "-" && juce::File::isAbsolutePath (project) ? juce::File (project) : juce::File(); openTimeReport = juce::File (args[i + 2].unquoted()); if (args.size() > i + 3 && ! args[i + 3].startsWith ("--")) openTimeIdleSeconds = juce::jlimit (1, 120, args[i + 3].getIntValue()); } if (! startupOptions.splash) { startEngine(); createMainWindow(); mainWindow->reveal(); showUncleanNotice(); startupTrace.mark ("window revealed"); openStartupFile(); startupTrace.mark ("startup file opened"); startOpenTimeProbe(); startUpdateCheck(); juce::MessageManager::callAsync ([] { startupTrace.mark ("first message loop turn"); }); return; } // the splash first, so it is on screen while the audio device opens; the main window is built // once the pepper has landed (the scene is still for a moment then) and shown when the splash ends splash = std::make_unique(); startupTrace.mark ("splash made"); splash->showOnDesktop(); startupTrace.mark ("splash on the desktop"); juce::Timer::callAfterDelay (40, [this] { startEngine(); if (splash == nullptr) // quit meanwhile return; splash->setStatus (lynx::tr ("Loading the workspace...")); splash->startClock(); // the minimum counts from the process start (the audio device took part of it already) splashDuration = lynx::SplashScreen::remainingDuration (startupTrace.seconds()); splash->setBarDuration (splashDuration); juce::Timer::callAfterDelay (1050, [this] { if (splash == nullptr || engine == nullptr) return; createMainWindow(); const auto wait = juce::jmax (0.0, splashDuration - splash->getElapsed()); juce::Timer::callAfterDelay ((int) (wait * 1000.0), [this] { if (splash == nullptr || mainWindow == nullptr) return; mainWindow->reveal(); startupTrace.mark ("window revealed (after the splash)"); splash->toFront (false); splash->finish ([this] { splash = nullptr; }); showUncleanNotice(); openStartupFile(); startupTrace.mark ("startup file opened"); startOpenTimeProbe(); startUpdateCheck(); juce::MessageManager::callAsync ([] { startupTrace.mark ("first message loop turn"); }); // first run: language, audio, plugin folders (FL Studio's included) and a background scan if (! lynx::setupWizardDone() && lynx::platform::testMode()) lynx::platform::testModeLog ("setup wizard"); else if (! lynx::setupWizardDone()) mainWindow->showSetupWizard(); }); }); }); } void startEngine() { startupTrace.mark ("before the audio engine"); engine = std::make_unique(); lynx::videoview::install (*engine); // (Fruity Video Player channels: their sound tracks) startupTrace.mark ("audio engine + device"); crashEngine = engine.get(); lynx::crashreporter::watchAudioDevice (engine->getDeviceManager()); // (the session file names the device: crash reports) addDriverFileDeviceType(); if (startupOptions.sound) { // Options › Theme › Startup sound (issue #12): the user's file, else (or when it can't be read) LYNX's own std::shared_ptr sound; if (const auto& own = lynx::themeui::current().startupSound; ! own.empty() && juce::File (juce::String::fromUTF8 (own.c_str())).existsAsFile()) sound = engine->getSampleLibrary().load (juce::String::fromUTF8 (own.c_str())); engine->previewSample (sound != nullptr ? sound : lynx::makeStartupSample()); } startupTrace.mark ("startup sound"); // a project given on the command line: its slow plugin modules (a Waves shell) start now, on their own // thread, while the splash and the main window come up (round 121) if (fileToOpen.hasFileExtension ("flp")) if (juce::MemoryBlock data; fileToOpen.loadFileAsData (data)) try { engine->getPluginHost().startModulesFor (lynx::flpForeignPlugins (flp::parseProject ({ static_cast (data.getData()), data.getSize() }))); startupTrace.mark ("plugin modules started ahead"); } catch (const flp::Error&) { } } void createMainWindow() { mainWindow = std::make_unique ("LYNX SHARE", *engine); // the brand; getApplicationName() stays "LYNX" (an id: instance lock, X11 WM_CLASS, ALSA client) lynx::setMainWindowForOwnership (mainWindow.get()); lynx::applyRenderingChoice (*mainWindow); // (GPU rendering off: GDI; round 157a) lynx::startRenderingWatch(); startupTrace.mark ("main window built"); } // the previous run ended without closing (see collectUncleanSessions): say so once, with its last step — and, as // Settings › General › "Crash reports" says (round 159), ask whether to send a report, send it unasked, or not void showUncleanNotice() { if (lynx::platform::testMode()) // LYNX_TEST_MODE: no prompt, no report sent (written to test-mode.log) { if (uncleanLastStep.isNotEmpty()) lynx::platform::testModeLog ("\"closed unexpectedly\" notice (last step: " + uncleanLastStep + ")"); return; } if (uncleanLastStep.isEmpty()) { lynx::crashreporter::retryPending(); // (reports an earlier run could not send: once more) return; } auto message = lynx::tr ("The last session ended without closing normally. Last step: {0}. Backup copies of your project are in " "LYNX SHARE's autosave folder; details in crash-history.log.", { uncleanLastStep }); uncleanLastStep.clear(); const auto cause = uncleanCause(); // round 157a: a plugin's editor was opening — it crashed (often in the graphics driver, inside the plugin's own // OpenGL window): offer to keep that plugin in its own process, where a crash takes only the plugin down juce::String separatePlugin; if (cause.editorPlugin.isNotEmpty() && ! lynx::pluginSandboxEnabled() && ! lynx::pluginAlwaysSeparate (cause.editorPlugin)) separatePlugin = cause.editorPlugin; // LYNX's own drawing crashed in the graphics driver (Direct2D / Direct3D): draw with the CPU from now on else if (cause.gpuDriver && lynx::gpuRenderingEnabled()) { lynx::setGpuRenderingEnabled (false); message << "\n\n" << lynx::tr ("The crash was in the graphics driver ({0}). LYNX SHARE now draws its windows without the GPU; you can turn GPU " "rendering back on in Options > General settings (after a driver update, for example).", { cause.driverModule }); } // round 165e: the Visualizer's GPU view was drawing when the session ended (a driver crash, a hang, the machine // going down): the Visualizer draws with the 2D renderer from now on (its GPU button turns it back on) for (int i = uncleanSteps.size(); --i >= 0;) { if (uncleanSteps[i].contains (lynx::visualgl::stopNote)) break; if (uncleanSteps[i].contains (lynx::visualgl::startNote)) { if (lynx::visualgl::enabled()) { lynx::visualgl::setEnabled (false); message << "\n\n" << lynx::tr ("The Visualizer was drawing with the GPU (OpenGL) when it happened. It now draws without the GPU; its GPU " "button turns it back on."); } break; } } const auto session = lynx::crashreporter::parseSession (uncleanSessionText); auto* devices = engine != nullptr ? &engine->getDeviceManager() : nullptr; const auto action = lynx::crashreport::actionFor (lynx::crashreporter::consent()); lynx::crashreporter::retryPending(); if (action == lynx::crashreport::Action::askUser) { if (separatePlugin.isNotEmpty()) message << "\n\n" << lynx::tr ("It happened while the window of {0} was opening{1}.", { separatePlugin, cause.gpuDriver ? lynx::tr (" (in the graphics driver, {0})", { cause.driverModule }) : juce::String() }); lynx::crashreporter::showStartupDialog (session, message, separatePlugin, [separatePlugin] { lynx::setPluginAlwaysSeparate (separatePlugin, true); }, devices); return; } if (action == lynx::crashreport::Action::sendSilently) { const auto input = lynx::crashreporter::makeInput (session, session.kind(), devices); lynx::crashreporter::send (lynx::crashreporter::buildJson (input, false), juce::String::fromUTF8 (input.id.c_str())); message << "\n\n" << lynx::tr ("A crash report is being sent to help fix it (Options > General settings > Crash reports)."); } if (separatePlugin.isNotEmpty()) { juce::AlertWindow::showOkCancelBox ( juce::MessageBoxIconType::WarningIcon, lynx::tr ("LYNX SHARE closed unexpectedly"), message + "\n\n" + lynx::tr ("It happened while the window of {0} was opening{1}. Run {0} in a separate process from now on? If it " "crashes again, only the plugin stops and LYNX SHARE keeps running (Plugin wrapper menu: \"Always run in a " "separate process\").", { separatePlugin, cause.gpuDriver ? lynx::tr (" (in the graphics driver, {0})", { cause.driverModule }) : juce::String() }), lynx::tr ("Run separately"), lynx::tr ("No"), nullptr, juce::ModalCallbackFunction::create ([separatePlugin] (int result) { if (result != 0) lynx::setPluginAlwaysSeparate (separatePlugin, true); })); return; } juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, lynx::tr ("LYNX SHARE closed unexpectedly"), message); } // --opentime: after the start-up file was handed to the window void startOpenTimeProbe() { if (openTimeReport == juce::File()) return; struct Probe final : juce::Timer { LynxApplication& app; juce::File report, project; int idleSeconds; int phase = 0; // 0 loading, 1 settling, 2 idle measurement double revealedS = 0.0, loadedS = -1.0, settledS = -1.0, cpuAtLoaded = 0.0; double lastCpu = 0.0, lastT = 0.0, quietSince = -1.0, idleCpu0 = 0.0, idleT0 = 0.0; Probe (LynxApplication& a, juce::File r, juce::File p, int idle) : app (a), report (std::move (r)), project (std::move (p)), idleSeconds (idle) { revealedS = startupTrace.seconds(); startTimer (250); } bool loaded() const { if (project == juce::File()) return true; return app.mainWindow != nullptr && app.mainWindow->getName().containsIgnoreCase (project.getFileNameWithoutExtension()); } void finish (const juce::String& result) { stopTimer(); const auto now = startupTrace.seconds(); const auto cpu = lynx::processCpuSeconds(); juce::String text; text << "project=" << (project == juce::File() ? juce::String ("-") : project.getFullPathName()) << "\n" << "window_s=" << juce::String (revealedS, 3) << "\n" << "loaded_s=" << juce::String (loadedS, 3) << "\n" << "settled_s=" << juce::String (settledS, 3) << "\n" << "cpu_at_loaded_s=" << juce::String (cpuAtLoaded, 3) << "\n" << "idle_s=" << juce::String (now - idleT0, 2) << "\n" << "idle_cpu_pct=" << juce::String (phase == 2 && now > idleT0 ? 100.0 * (cpu - idleCpu0) / (now - idleT0) : -1.0, 1) << "\n" << "working_set_mb=" << juce::String ((double) lynx::toolbar::PerformanceMeter::processMemoryBytes() / 1048576.0, 0) << "\n" << "cpu_total_s=" << juce::String (cpu, 3) << "\n" << "result=" << result << "\n"; report.replaceWithText (text); app.setApplicationReturnValue (result == "OK" ? 0 : 1); app.quit(); } void timerCallback() override { const auto now = startupTrace.seconds(); const auto cpu = lynx::processCpuSeconds(); if (phase == 0) { if (loaded()) { loadedS = now; cpuAtLoaded = cpu; phase = 1; lastCpu = cpu; lastT = now; } else if (now - revealedS > 240.0) finish ("TIMEOUT loading"); return; } if (phase == 1) { // quiet = under 10 % of one core for 1.5 s (the harness's rule), at most 30 s after loading const auto use = now > lastT ? 100.0 * (cpu - lastCpu) / (now - lastT) : 0.0; lastCpu = cpu; lastT = now; if (use < 10.0) { if (quietSince < 0.0) quietSince = now - 0.25; if (now - quietSince >= 1.5) settledS = quietSince; } else quietSince = -1.0; if (settledS >= 0.0 || now - loadedS > 30.0) { phase = 2; idleCpu0 = cpu; idleT0 = now; } return; } if (now - idleT0 >= (double) idleSeconds) finish ("OK"); } }; perf = std::make_unique (*this, openTimeReport, fileToOpen, openTimeIdleSeconds); } // round 166b: the update check of a normal start (never in --opentime and the other command-line modes), a few // seconds after the window is up so it never competes with the start-up; and the result of an update just installed void startUpdateCheck() { if (openTimeReport != juce::File()) return; lynx::updater::afterStart(); juce::Timer::callAfterDelay (3000, [] { lynx::updater::startAutomaticCheck(); }); } void openStartupFile() { if (fileToOpen != juce::File() && mainWindow != nullptr) mainWindow->openFile (fileToOpen); } void shutdown() override { if (relaunched || updateHelper) return; // the copy that ran owns the session (its crash notes stay for the next start) lynx::crashguard::note ("closing"); lynx::shutdownPluginSandboxWorker(); splash = nullptr; lynx::shutdownStemExtraction(); // (a separation in flight stops before its window and the engine go) if (mainWindow != nullptr && mainWindow->isVisible()) mainWindow->saveState(); mainWindow = nullptr; // the UI goes before the engine lynx::updater::shutdown(); // (a check or download in flight stops) crashEngine = nullptr; engine = nullptr; juce::LookAndFeel::setDefaultLookAndFeel (nullptr); heartbeat.stopTimer(); lynx::crashreporter::shutdown(); // (an upload in flight gets a moment, never long) lynx::crashguard::stopHangWatch(); lynx::crashguard::endSession(); // a clean exit: no breadcrumb left behind // everything is saved and closed: a process that loaded third-party plugins ends here, before the DLLs' own // teardown runs (some crash in it at exit, round 111) if (sandboxChild || lynx::PluginHost::pluginsWereLoaded()) lynx::crashguard::exitNow (getApplicationReturnValue()); } void systemRequestedQuit() override { if (mainWindow != nullptr) mainWindow->confirmDiscard ([] { juce::JUCEApplication::quit(); }); else quit(); } private: // round 157a: a frozen UI (Windows' "not responding") writes the message thread's stack to autosave\hang