| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903 |
- #include "ui/SettingsPages.h"
- #include "platform/Paths.h"
- #include "core/ToolbarLayout.h"
- #include "engine/AudioEngine.h"
- #include "engine/PluginHost.h"
- #include "ui/AutomationUi.h"
- #include "ui/I18n.h"
- namespace lynx
- {
- using namespace settingsui;
- juce::File autosaveFolder()
- {
- return lynx::platform::settingsFile ("autosave");
- }
- namespace
- {
- constexpr int labelWidth = 190;
- constexpr int rowHeight = 28;
- constexpr int rowGap = 8;
- constexpr int sectionHeight = 28;
- void styleCombo (juce::ComboBox& box)
- {
- box.setColour (juce::ComboBox::outlineColourId, theme::colour::borderStrong);
- }
- void styleToggle (juce::ToggleButton& t, const juce::String& text)
- {
- t.setButtonText (text);
- }
- // Lays out rows top to bottom inside a page of a given width.
- struct Rows
- {
- juce::Rectangle<int> area;
- int y = 0;
- explicit Rows (int width) : area (20, 14, width - 40, 100000), y (14) {}
- void section (juce::Component& title, bool first = false)
- {
- if (! first)
- y += 10;
- title.setBounds (area.getX(), y, area.getWidth(), sectionHeight);
- y += sectionHeight + rowGap;
- }
- // label + control (control width 0 = to the right edge)
- juce::Rectangle<int> row (juce::Label& label, int controlWidth = 260, int height = rowHeight)
- {
- label.setBounds (area.getX(), y, labelWidth, height);
- auto r = juce::Rectangle<int> (area.getX() + labelWidth, y, controlWidth > 0 ? controlWidth : area.getWidth() - labelWidth, height);
- y += height + rowGap;
- return r;
- }
- juce::Rectangle<int> full (int height = rowHeight)
- {
- auto r = juce::Rectangle<int> (area.getX(), y, area.getWidth(), height);
- y += height + rowGap;
- return r;
- }
- juce::Rectangle<int> indented (int height = rowHeight)
- {
- auto r = juce::Rectangle<int> (area.getX() + labelWidth, y, area.getWidth() - labelWidth, height);
- y += height + rowGap;
- return r;
- }
- int bottom() const { return y + 14; }
- };
- // ================================================================================================================
- // General
- // ================================================================================================================
- class GeneralPage final : public ScrollingPage
- {
- public:
- GeneralPage (AudioEngine& e, SettingsHooks h, bool keep) : engine (e), hooks (std::move (h)), persistent (keep)
- {
- if (hooks.getGeneral)
- options = hooks.getGeneral();
- else
- options.language = "en";
- for (auto* c : std::initializer_list<juce::Component*> { &languageTitle, &displayTitle, &startupTitle, &editingTitle, &backupTitle,
- &pluginsTitle, &languageLabel, &languageBox, &languageNote, &scaleLabel, &scaleBox,
- &wavesLabel, &wavesBox, &stereoWaves, &splash, &startupSound, &scanAtStart,
- &typingPiano, &keepEditors, &rememberSeek, &editInLabel, &editInBox, &undoLabel,
- &undoBox, &autosaveLabel, &autosaveBox, &keepLabel, &keepBox, &openBackups,
- &sandbox, &sandboxNote, &substitutes, &substitutesNote, &managePlugins, &manageShortcuts, &shortcutsNote })
- add (*c);
- styleLabel (languageLabel, tr ("Language"));
- styleNote (languageNote, tr ("A new language is applied when LYNX restarts."));
- int id = 1;
- for (const auto& l : i18n::languages())
- {
- languageBox.addItem (juce::String::fromUTF8 (l.nativeName), id);
- if (options.language == l.id)
- languageBox.setSelectedId (id, juce::dontSendNotification);
- ++id;
- }
- languageBox.onChange = [this] {
- const auto index = languageBox.getSelectedId() - 1;
- if (juce::isPositiveAndBelow (index, (int) i18n::languages().size()))
- change ([&] { options.language = i18n::languages()[(std::size_t) index].id; });
- };
- styleLabel (scaleLabel, tr ("Interface size"));
- for (auto percent : toolbarlayout::uiScales)
- scaleBox.addItem (juce::String (percent) + "%", percent);
- scaleBox.setSelectedId (options.uiScale, juce::dontSendNotification);
- scaleBox.onChange = [this] { change ([&] { options.uiScale = scaleBox.getSelectedId(); }); };
- styleLabel (wavesLabel, tr ("Waveforms"));
- wavesBox.addItem (tr ("Clean (the clip colour)"), 1);
- wavesBox.addItem (tr ("Spectral colours (warm = bass, cool = treble)"), 2);
- wavesBox.setSelectedId (options.waveSpectral ? 2 : 1, juce::dontSendNotification);
- wavesBox.onChange = [this] { change ([&] { options.waveSpectral = wavesBox.getSelectedId() == 2; }); };
- toggle (stereoWaves, tr ("Stereo (left and right channels apart)"), options.waveStereo, [this] (bool on) { options.waveStereo = on; });
- toggle (splash, tr ("Show the splash screen at startup"), options.splash, [this] (bool on) { options.splash = on; });
- toggle (startupSound, tr ("Play the startup sound"), options.startupSound, [this] (bool on) { options.startupSound = on; });
- toggle (scanAtStart, tr ("Look for new plugins in the background at every start"), options.scanAtStart,
- [this] (bool on) { options.scanAtStart = on; });
- toggle (typingPiano, tr ("Typing keyboard as a piano"), options.typingPiano, [this] (bool on) { options.typingPiano = on; });
- toggle (keepEditors, tr ("Keep channel editors open (a channel button click doesn't close the previous editor)"), options.keepEditorsOpen,
- [this] (bool on) { options.keepEditorsOpen = on; });
- toggle (rememberSeek, tr ("Remember seek time: Stop goes back to the position clicked on the Playlist ruler"), options.rememberSeek,
- [this] (bool on) { options.rememberSeek = on; });
- styleLabel (editInLabel, tr ("Double-click on a pattern clip opens"));
- const char* choices[] = { TR_NOOP ("Piano Roll when it has piano-roll notes, else Channel Rack"), TR_NOOP ("Channel Rack"), TR_NOOP ("Piano Roll") };
- for (int i = 0; i < 3; ++i)
- editInBox.addItem (tr (choices[i]), i + 1);
- editInBox.setSelectedId (options.editPatternsIn + 1, juce::dontSendNotification);
- editInBox.onChange = [this] { change ([&] { options.editPatternsIn = editInBox.getSelectedId() - 1; }); };
- styleLabel (undoLabel, tr ("Maximum undo levels"));
- for (auto n : { 25, 50, 100, 200, 500, 1000 })
- undoBox.addItem (juce::String (n), n);
- selectNearest (undoBox, options.undoLevels);
- undoBox.onChange = [this] { change ([&] { options.undoLevels = undoBox.getSelectedId(); }); };
- styleLabel (autosaveLabel, tr ("Save a backup copy"));
- for (auto minutes : prefs::autosaveIntervals())
- autosaveBox.addItem (minutes == 0 ? tr ("Never")
- : minutes == 1 ? tr ("Every minute")
- : tr ("Every {0} minutes", { juce::String (minutes) }),
- minutes + 1);
- autosaveBox.setSelectedId (prefs::clampAutosaveMinutes (options.autosaveMinutes) + 1, juce::dontSendNotification);
- autosaveBox.onChange = [this] {
- change ([&] { options.autosaveMinutes = autosaveBox.getSelectedId() - 1; });
- keepBox.setEnabled (options.autosaveMinutes > 0);
- };
- styleLabel (keepLabel, tr ("Backups kept per project"));
- for (auto n : { 1, 3, 5, 10, 20, 50 })
- keepBox.addItem (juce::String (n), n);
- selectNearest (keepBox, options.autosaveKeep);
- keepBox.setEnabled (options.autosaveMinutes > 0);
- keepBox.onChange = [this] { change ([&] { options.autosaveKeep = keepBox.getSelectedId(); }); };
- openBackups.onClick = [] {
- autosaveFolder().createDirectory();
- autosaveFolder().startAsProcess();
- };
- toggle (sandbox, tr ("Run plugins in a separate process (protects LYNX from crashes)"), options.pluginSandbox,
- [this] (bool on) { options.pluginSandbox = on; });
- styleNote (sandboxNote, tr ("Applies to plugins opened from now on; reopen the project to move the others."));
- toggle (substitutes, tr ("Substitute missing plugins with LYNX equivalents"), options.pluginSubstitutes,
- [this] (bool on) { options.pluginSubstitutes = on; });
- styleNote (substitutesNote, tr ("A project keeps the original plugin and uses it again once it is installed."));
- managePlugins.onClick = [this] {
- if (hooks.managePlugins)
- hooks.managePlugins();
- };
- manageShortcuts.onClick = [this] {
- if (hooks.manageShortcuts)
- hooks.manageShortcuts();
- };
- styleNote (shortcutsNote, tr ("See, search and change every keyboard shortcut."));
- for (auto* b : { &languageBox, &scaleBox, &wavesBox, &editInBox, &undoBox, &autosaveBox, &keepBox })
- styleCombo (*b);
- juce::ignoreUnused (engine, persistent);
- }
- private:
- int layout (int width) override
- {
- Rows r (width);
- r.section (languageTitle, true);
- languageBox.setBounds (r.row (languageLabel, 220));
- languageNote.setBounds (r.indented (16).translated (0, -6));
- scaleBox.setBounds (r.row (scaleLabel, 120));
- wavesBox.setBounds (r.row (wavesLabel, 0));
- stereoWaves.setBounds (r.indented (24));
- r.section (startupTitle);
- for (auto* t : { &splash, &startupSound, &scanAtStart })
- t->setBounds (r.full (24));
- r.section (editingTitle);
- for (auto* t : { &typingPiano, &keepEditors, &rememberSeek })
- t->setBounds (r.full (24));
- editInBox.setBounds (r.row (editInLabel, 0));
- undoBox.setBounds (r.row (undoLabel, 120));
- r.section (backupTitle);
- {
- auto row = r.row (autosaveLabel, 0);
- autosaveBox.setBounds (row.removeFromLeft (220));
- row.removeFromLeft (8);
- openBackups.setBounds (row.removeFromLeft (juce::jmin (row.getWidth(), 170)));
- }
- keepBox.setBounds (r.row (keepLabel, 120));
- r.section (pluginsTitle);
- sandbox.setBounds (r.full (24));
- sandboxNote.setBounds (r.full (16).translated (0, -6));
- substitutes.setBounds (r.full (24));
- substitutesNote.setBounds (r.full (16).translated (0, -6));
- {
- auto row = r.full();
- managePlugins.setBounds (row.removeFromLeft (180));
- row.removeFromLeft (8);
- manageShortcuts.setBounds (row.removeFromLeft (180));
- row.removeFromLeft (12);
- shortcutsNote.setBounds (row.withTrimmedTop (6));
- }
- displayTitle.setVisible (false);
- return r.bottom();
- }
- void toggle (juce::ToggleButton& t, const juce::String& text, bool value, std::function<void (bool)> set)
- {
- styleToggle (t, text);
- t.setToggleState (value, juce::dontSendNotification);
- t.onClick = [this, &t, set = std::move (set)] { change ([&] { set (t.getToggleState()); }); };
- }
- static void selectNearest (juce::ComboBox& box, int value)
- {
- auto best = box.getItemId (0);
- for (int i = 0; i < box.getNumItems(); ++i)
- if (std::abs (box.getItemId (i) - value) < std::abs (best - value))
- best = box.getItemId (i);
- box.setSelectedId (best, juce::dontSendNotification);
- }
- void change (const std::function<void()>& fn)
- {
- fn();
- if (hooks.setGeneral)
- hooks.setGeneral (options);
- }
- AudioEngine& engine;
- SettingsHooks hooks;
- bool persistent;
- GeneralOptions options;
- SectionTitle languageTitle { tr ("Language and display") }, displayTitle, startupTitle { tr ("Startup") }, editingTitle { tr ("Editing") },
- backupTitle { tr ("Backup") }, pluginsTitle { tr ("Plugins and shortcuts") };
- juce::Label languageLabel, languageNote, scaleLabel, wavesLabel, editInLabel, undoLabel, autosaveLabel, keepLabel, sandboxNote, substitutesNote, shortcutsNote;
- juce::ComboBox languageBox, scaleBox, wavesBox, editInBox, undoBox, autosaveBox, keepBox;
- juce::ToggleButton stereoWaves, splash, startupSound, scanAtStart, typingPiano, keepEditors, rememberSeek, sandbox, substitutes;
- juce::TextButton openBackups { tr ("Open backup folder") }, managePlugins { tr ("Plugin manager...") }, manageShortcuts { tr ("Manage shortcuts...") };
- };
- // ================================================================================================================
- // Audio
- // ================================================================================================================
- class AudioPage final : public ScrollingPage,
- private juce::ChangeListener,
- private juce::Timer
- {
- public:
- AudioPage (AudioEngine& e) : engine (e), devices (e.getDeviceManager())
- {
- for (auto* c : std::initializer_list<juce::Component*> { &deviceTitle, &statusTitle, &recordTitle, &driverLabel, &driverBox, &driverNote, &outputLabel,
- &outputBox, &inputLabel, &inputBox, &rateLabel, &rateBox, &bufferLabel, &bufferBox,
- &bufferNote, &panelButton, &testButton, &status, &load, &recordInput, &recordNote, &inputChannels })
- add (*c);
- styleLabel (driverLabel, tr ("Driver"));
- styleLabel (outputLabel, tr ("Output device"));
- styleLabel (inputLabel, tr ("Input device"));
- styleLabel (rateLabel, tr ("Sample rate"));
- styleLabel (bufferLabel, tr ("Buffer size"));
- styleNote (driverNote, {});
- styleNote (bufferNote, tr ("Smaller buffers answer faster when you play; larger ones give the CPU more room (fewer clicks)."));
- for (auto* l : { &status, &load })
- {
- styleLabel (*l, {}, false);
- l->setJustificationType (juce::Justification::centredLeft);
- }
- for (auto* b : { &driverBox, &outputBox, &inputBox, &rateBox, &bufferBox })
- {
- styleCombo (*b);
- b->setTextWhenNoChoicesAvailable (tr ("(open an output device first)"));
- b->setTextWhenNothingSelected (tr ("(choose)"));
- }
- driverBox.onChange = [this] {
- if (updating)
- return;
- auto& types = devices.getAvailableDeviceTypes();
- const auto index = driverBox.getSelectedId() - 1;
- if (juce::isPositiveAndBelow (index, types.size()))
- devices.setCurrentAudioDeviceType (types[index]->getTypeName(), true);
- refresh();
- };
- outputBox.onChange = [this] {
- apply ([this] (juce::AudioDeviceManager::AudioDeviceSetup& s) { s.outputDeviceName = outputBox.getText(); });
- };
- inputBox.onChange = [this] {
- if (updating)
- return;
- if (inputBox.getSelectedId() <= 1)
- apply ([] (juce::AudioDeviceManager::AudioDeviceSetup& s) {
- s.inputDeviceName = {};
- s.useDefaultInputChannels = false;
- s.inputChannels.clear();
- });
- else
- {
- // every channel of the device opens: each mixer insert picks its own (pair or single channel)
- const auto result = engine.openAudioInput (inputBox.getText());
- error = result.issue == AudioEngine::InputIssue::failed ? result.detail : juce::String();
- refresh();
- }
- };
- rateBox.onChange = [this] {
- apply ([this] (juce::AudioDeviceManager::AudioDeviceSetup& s) { s.sampleRate = (double) rateBox.getSelectedId(); });
- };
- bufferBox.onChange = [this] {
- apply ([this] (juce::AudioDeviceManager::AudioDeviceSetup& s) { s.bufferSize = bufferBox.getSelectedId(); });
- };
- panelButton.onClick = [this] {
- if (auto* device = devices.getCurrentAudioDevice(); device != nullptr && device->hasControlPanel())
- {
- // the driver's own window (ASIO): the device is reopened afterwards with what was set there
- devices.closeAudioDevice();
- device->showControlPanel();
- devices.restartLastAudioDevice();
- refresh();
- }
- };
- testButton.onClick = [this] { devices.playTestSound(); };
- styleToggle (recordInput, tr ("Record input audio"));
- styleNote (recordNote, tr ("Choose each mixer insert's input in the Mixer (the input box above its effect slots), arm it, then Rec + Play. "
- "This switch records the first two input channels into a new insert when nothing is armed."));
- recordInput.onClick = [this] { engine.setAudioRecordingArmed (recordInput.getToggleState()); };
- devices.addChangeListener (this);
- refresh();
- startTimerHz (2);
- }
- ~AudioPage() override { devices.removeChangeListener (this); }
- private:
- int layout (int width) override
- {
- Rows r (width);
- r.section (deviceTitle, true);
- driverBox.setBounds (r.row (driverLabel, 320));
- driverNote.setBounds (r.indented (46).translated (0, -6));
- outputBox.setBounds (r.row (outputLabel, 0));
- inputBox.setBounds (r.row (inputLabel, 0));
- rateBox.setBounds (r.row (rateLabel, 160));
- bufferBox.setBounds (r.row (bufferLabel, 260));
- bufferNote.setBounds (r.indented (18).translated (0, -6));
- {
- auto row = r.indented();
- panelButton.setBounds (row.removeFromLeft (170));
- row.removeFromLeft (8);
- testButton.setBounds (row.removeFromLeft (150));
- }
- r.section (statusTitle);
- status.setBounds (r.full (22));
- load.setBounds (r.full (22));
- r.section (recordTitle);
- inputChannels.setBounds (r.full (34));
- recordInput.setBounds (r.full (24));
- recordNote.setBounds (r.full (32).translated (0, -6));
- return r.bottom();
- }
- void apply (const std::function<void (juce::AudioDeviceManager::AudioDeviceSetup&)>& change)
- {
- if (updating)
- return;
- auto setup = devices.getAudioDeviceSetup();
- change (setup);
- error = devices.setAudioDeviceSetup (setup, true);
- refresh();
- }
- void refresh()
- {
- const juce::ScopedValueSetter<bool> guard (updating, true);
- auto* type = devices.getCurrentDeviceTypeObject();
- auto* device = devices.getCurrentAudioDevice();
- const auto setup = devices.getAudioDeviceSetup();
- driverBox.clear (juce::dontSendNotification);
- auto& types = devices.getAvailableDeviceTypes();
- for (int i = 0; i < types.size(); ++i)
- {
- driverBox.addItem (driverDisplayName (types[i]->getTypeName()), i + 1);
- if (types[i] == type)
- driverBox.setSelectedId (i + 1, juce::dontSendNotification);
- }
- outputBox.clear (juce::dontSendNotification);
- inputBox.clear (juce::dontSendNotification);
- inputBox.addItem (tr ("(none)"), 1);
- inputBox.setSelectedId (1, juce::dontSendNotification);
- if (type != nullptr)
- {
- if (type->getDeviceNames (false).isEmpty())
- type->scanForDevices(); // (a driver type not opened yet this session)
- const auto outs = type->getDeviceNames (false);
- for (int i = 0; i < outs.size(); ++i)
- {
- outputBox.addItem (outs[i], i + 1);
- if (outs[i] == setup.outputDeviceName)
- outputBox.setSelectedId (i + 1, juce::dontSendNotification);
- }
- if (type->hasSeparateInputsAndOutputs())
- {
- const auto ins = type->getDeviceNames (true);
- for (int i = 0; i < ins.size(); ++i)
- {
- inputBox.addItem (ins[i], i + 2);
- if (ins[i] == setup.inputDeviceName && ! setup.inputChannels.isZero())
- inputBox.setSelectedId (i + 2, juce::dontSendNotification);
- }
- }
- else if (setup.outputDeviceName.isNotEmpty())
- {
- // ASIO: one device does both
- inputBox.addItem (setup.outputDeviceName, 2);
- if (! setup.inputChannels.isZero())
- inputBox.setSelectedId (2, juce::dontSendNotification);
- }
- }
- rateBox.clear (juce::dontSendNotification);
- bufferBox.clear (juce::dontSendNotification);
- if (device != nullptr)
- {
- const auto rate = device->getCurrentSampleRate();
- for (auto r : device->getAvailableSampleRates())
- rateBox.addItem (juce::String ((int) r) + " Hz", (int) r);
- rateBox.setSelectedId ((int) rate, juce::dontSendNotification);
- const auto kind = prefs::driverKind (device->getTypeName().toStdString());
- std::vector<int> offered;
- for (auto b : device->getAvailableBufferSizes())
- offered.push_back (b);
- for (auto b : prefs::usableBufferSizes (kind, offered, device->getDefaultBufferSize()))
- bufferBox.addItem (tr ("{0} samples ({1} ms)", { juce::String (b), juce::String (prefs::bufferLatencyMs (b, rate), 1) }), b);
- bufferBox.setSelectedId (device->getCurrentBufferSizeSamples(), juce::dontSendNotification);
- }
- for (auto* b : { &outputBox, &inputBox, &rateBox, &bufferBox })
- b->setEnabled (b->getNumItems() > 0);
- driverNote.setText (driverExplanation (type != nullptr ? type->getTypeName() : juce::String(), device), juce::dontSendNotification);
- panelButton.setEnabled (device != nullptr && device->hasControlPanel());
- testButton.setEnabled (device != nullptr);
- recordInput.setToggleState (engine.isAudioRecordingArmed(), juce::dontSendNotification);
- {
- // what the mixer inserts can take their input from
- const auto names = engine.getInputChannelNames();
- juce::StringArray list;
- for (const auto& n : names)
- list.add (juce::String::fromUTF8 (n.c_str()));
- styleNote (inputChannels, names.empty() ? tr ("Input channels: none open. Choose an input device above to record a microphone or an instrument.")
- : tr ("Input channels ({0}): {1}", { juce::String ((int) names.size()), list.joinIntoString (", ") }));
- }
- updateStatus();
- }
- void updateStatus()
- {
- auto* device = devices.getCurrentAudioDevice();
- if (device == nullptr)
- {
- status.setText (error.isNotEmpty() ? error : tr ("No audio device is open: choose an output device."), juce::dontSendNotification);
- status.setColour (juce::Label::textColourId, theme::colour::warning);
- load.setText ({}, juce::dontSendNotification);
- return;
- }
- const auto rate = device->getCurrentSampleRate();
- const auto latency = prefs::bufferLatencyMs (device->getOutputLatencyInSamples() + device->getCurrentBufferSizeSamples(), rate);
- status.setText (tr ("{0} is running: {1} Hz, output latency {2} ms",
- { device->getName(), juce::String ((int) rate), juce::String (latency, 1) }),
- juce::dontSendNotification);
- status.setColour (juce::Label::textColourId, theme::colour::textPrimary);
- const auto xruns = device->getXRunCount();
- const auto rt = engine.getRtStats().snapshot();
- const auto dot = juce::String::fromUTF8 (" \xc2\xb7 ");
- load.setText (tr ("Audio CPU load: {0}%", { juce::String (juce::roundToInt (devices.getCpuUsage() * 100.0)) })
- + (xruns > 0 ? dot + tr ("{0} dropouts (buffer underruns) so far", { juce::String (xruns) }) : juce::String())
- + (rt.overBudget > 0 ? dot + tr ("{0} blocks over the deadline (max {1}%)", { juce::String ((juce::int64) rt.overBudget), juce::String (juce::roundToInt (rt.maxLoad * 100.0)) })
- : juce::String()),
- juce::dontSendNotification);
- load.setColour (juce::Label::textColourId, xruns > 0 || rt.overBudget > 0 ? theme::colour::warning : theme::colour::textSecondary);
- }
- void changeListenerCallback (juce::ChangeBroadcaster*) override { refresh(); }
- void timerCallback() override { updateStatus(); }
- // The driver types with what they mean (JUCE's type names stay the identity in the saved setup).
- static juce::String driverDisplayName (const juce::String& typeName)
- {
- switch (prefs::driverKind (typeName.toStdString()))
- {
- case prefs::DriverKind::wasapiShared: return tr ("Windows Audio (shared)");
- case prefs::DriverKind::wasapiLowLatency: return tr ("Windows Audio (shared, low-latency period)");
- case prefs::DriverKind::wasapiExclusive: return tr ("Windows Audio (exclusive, lowest latency)");
- case prefs::DriverKind::directSound: return tr ("DirectSound (legacy)");
- case prefs::DriverKind::asio: return "ASIO";
- case prefs::DriverKind::lynxAsio: return tr ("LYNX ASIO (built in)");
- case prefs::DriverKind::coreAudio: return "Core Audio";
- case prefs::DriverKind::alsa: return "ALSA";
- case prefs::DriverKind::jack: return tr ("JACK / PipeWire");
- case prefs::DriverKind::other: break;
- }
- return typeName;
- }
- // What the selected driver type does, and for shared mode the period this device mixes at (REA round 97).
- static juce::String driverExplanation (const juce::String& typeName, juce::AudioIODevice* device)
- {
- const auto rate = device != nullptr && device->getCurrentSampleRate() > 0 ? device->getCurrentSampleRate() : 48000.0;
- const auto period = device != nullptr ? device->getDefaultBufferSize() : 0;
- switch (prefs::driverKind (typeName.toStdString()))
- {
- case prefs::DriverKind::wasapiShared:
- return tr ("Other programs keep their sound. Windows mixes every program in steps of {0} ms on this device, so the buffer cannot go below that. "
- "For lower latency choose the exclusive mode or an ASIO driver.",
- { juce::String (prefs::bufferLatencyMs (period > 0 ? period : 480, rate), 1) });
- case prefs::DriverKind::wasapiLowLatency:
- return period > 0 && device != nullptr && device->getAvailableBufferSizes().size() <= 1
- ? tr ("This device does not support a shorter period in shared mode (it stays at {0} ms). Use the exclusive mode or an ASIO driver for lower latency.",
- { juce::String (prefs::bufferLatencyMs (period, rate), 1) })
- : tr ("Shared like the normal mode, but asks Windows for a shorter mixing period. Only some drivers support it.");
- case prefs::DriverKind::wasapiExclusive:
- return tr ("LYNX uses the device alone: the lowest latency without ASIO, but other programs go silent while LYNX plays.");
- case prefs::DriverKind::directSound:
- return tr ("Old Windows audio path with high latency. Use it only when the others fail.");
- case prefs::DriverKind::asio:
- return tr ("Low-latency drivers. LYNX ASIO, FL Studio ASIO and ASIO4ALL work with any device; a manufacturer's ASIO driver works with its own device.");
- case prefs::DriverKind::lynxAsio:
- return tr ("LYNX's own ASIO driver, with any device: playback and recording (microphone) at low latency. \"Driver settings...\" chooses shared or exclusive mode, the output and input devices and shows the latency. "
- "For other programs, run \"Register LYNX ASIO\" in LYNX's folder once.");
- case prefs::DriverKind::coreAudio:
- return tr ("macOS's own audio system: low latency with any device, shared with other programs.");
- case prefs::DriverKind::alsa:
- return tr ("Talks to the sound card directly. Choose \"default\" or \"pipewire\" to share the device with other programs; a \"hw:\" device gives the lowest latency but takes the card for LYNX alone.");
- case prefs::DriverKind::jack:
- return tr ("Low latency, shared with other programs and routable. On current distributions PipeWire answers as JACK (package pipewire-jack); otherwise start a JACK server first.");
- case prefs::DriverKind::other:
- break;
- }
- return {};
- }
- AudioEngine& engine;
- juce::AudioDeviceManager& devices;
- bool updating = false;
- juce::String error;
- SectionTitle deviceTitle { tr ("Audio device") }, statusTitle { tr ("Status") }, recordTitle { tr ("Recording") };
- juce::Label driverLabel, driverNote, outputLabel, inputLabel, rateLabel, bufferLabel, bufferNote, status, load, recordNote, inputChannels;
- juce::ComboBox driverBox, outputBox, inputBox, rateBox, bufferBox;
- juce::TextButton panelButton { tr ("Driver settings...") }, testButton { tr ("Play a test sound") };
- juce::ToggleButton recordInput;
- };
- // ================================================================================================================
- // MIDI
- // ================================================================================================================
- // One input device: on/off, which MIDI channel it listens to and what it plays.
- class MidiInputRow final : public juce::Component
- {
- public:
- MidiInputRow (const juce::String& deviceName, const prefs::MidiInputPrefs& p, const std::vector<std::string>& channels,
- std::function<void (const prefs::MidiInputPrefs&)> changed)
- : prefsNow (p), onChange (std::move (changed))
- {
- enabled.setButtonText (deviceName);
- enabled.setToggleState (p.enabled, juce::dontSendNotification);
- enabled.onClick = [this] {
- prefsNow.enabled = enabled.getToggleState();
- update();
- };
- addAndMakeVisible (enabled);
- channel.addItem (tr ("Any MIDI channel"), 1);
- for (int c = 1; c <= 16; ++c)
- channel.addItem (tr ("MIDI channel {0}", { juce::String (c) }), c + 1);
- channel.setSelectedId (p.midiChannel + 1, juce::dontSendNotification);
- channel.onChange = [this] {
- prefsNow.midiChannel = channel.getSelectedId() - 1;
- update();
- };
- plays.addItem (tr ("Plays the selected channels"), 1);
- for (int i = 0; i < (int) channels.size(); ++i)
- plays.addItem (tr ("Plays {0}", { juce::String (i + 1) + " " + juce::String::fromUTF8 (channels[(std::size_t) i].c_str()) }), i + 2);
- if (p.target >= (int) channels.size()) // a channel this project doesn't have (kept)
- plays.addItem (tr ("Plays channel {0}", { juce::String (p.target + 1) }), p.target + 2);
- plays.setSelectedId (p.target + 2, juce::dontSendNotification);
- plays.onChange = [this] {
- prefsNow.target = plays.getSelectedId() - 2;
- update();
- };
- for (auto* b : { &channel, &plays })
- {
- styleCombo (*b);
- addAndMakeVisible (b);
- }
- update (false);
- }
- void resized() override
- {
- auto r = getLocalBounds().reduced (8, 4);
- plays.setBounds (r.removeFromRight (230));
- r.removeFromRight (8);
- channel.setBounds (r.removeFromRight (150));
- r.removeFromRight (8);
- enabled.setBounds (r);
- }
- void paint (juce::Graphics& g) override
- {
- g.setColour (theme::colour::bg1);
- g.fillRoundedRectangle (getLocalBounds().toFloat(), theme::radius::md);
- }
- private:
- void update (bool notify = true)
- {
- channel.setEnabled (prefsNow.enabled);
- plays.setEnabled (prefsNow.enabled);
- if (notify && onChange)
- onChange (prefsNow);
- }
- prefs::MidiInputPrefs prefsNow;
- std::function<void (const prefs::MidiInputPrefs&)> onChange;
- juce::ToggleButton enabled;
- juce::ComboBox channel, plays;
- };
- class MidiPage final : public ScrollingPage,
- private juce::ChangeListener,
- private juce::ListBoxModel
- {
- public:
- MidiPage (AudioEngine& e, SettingsHooks h, bool keep) : engine (e), hooks (std::move (h)), persistent (keep)
- {
- for (auto* c : std::initializer_list<juce::Component*> { &inputsTitle, ¬esTitle, &controllersTitle, &inputsNote, &refresh, &noDevices,
- &velocityLabel, &velocityBox, &velocityNote, &typeLabel, &typeValue, &pickup,
- &pickupNote, &linksLabel, &links, &removeLink, &removeAll })
- add (*c);
- styleNote (inputsNote, tr ("Each input device can be turned off, listen to one MIDI channel only and play a fixed channel of the "
- "Channel Rack instead of the selected ones."));
- styleLabel (noDevices, tr ("No MIDI input devices found. Connect one and refresh the list."));
- refresh.onClick = [this] { rebuildInputs(); };
- styleLabel (velocityLabel, tr ("Velocity"));
- velocityBox.addItem (tr ("As played"), 1);
- velocityBox.addItem (tr ("Soft (light playing sounds louder)"), 2);
- velocityBox.addItem (tr ("Hard (needs harder playing)"), 3);
- velocityBox.addItem (tr ("Fixed (every note at full velocity)"), 4);
- velocityBox.onChange = [this] {
- auto p = engine.getMidiPrefs();
- p.velocity = (prefs::VelocityCurve) (velocityBox.getSelectedId() - 1);
- set (p);
- };
- styleCombo (velocityBox);
- styleNote (velocityNote, tr ("For notes from MIDI devices (the typing keyboard always plays at the Piano Roll's velocity)."));
- styleLabel (typeLabel, tr ("Controller type"));
- typeLabel.setJustificationType (juce::Justification::topLeft);
- styleLabel (typeValue, tr ("Generic controller: link a knob or fader with a control's right-click menu > Link to MIDI controller."), false);
- typeValue.setMinimumHorizontalScale (1.0f);
- typeValue.setJustificationType (juce::Justification::topLeft);
- styleToggle (pickup, tr ("Pickup (takeover mode)"));
- pickup.onClick = [this] {
- auto p = engine.getMidiPrefs();
- p.pickup = pickup.getToggleState();
- set (p);
- };
- styleNote (pickupNote, tr ("A controller moves a parameter only after reaching its current value, so nothing jumps."));
- styleLabel (linksLabel, tr ("Links in this project"));
- linksLabel.setJustificationType (juce::Justification::topLeft);
- links.setModel (this);
- links.setRowHeight (24);
- links.setColour (juce::ListBox::backgroundColourId, theme::colour::bg0);
- links.setColour (juce::ListBox::outlineColourId, theme::colour::border);
- links.setOutlineThickness (1);
- removeLink.onClick = [this] {
- const auto row = links.getSelectedRow();
- if (juce::isPositiveAndBelow (row, (int) engine.getSong().midiLinks.size()))
- engine.editSong ([row] (Song& s) { s.midiLinks.erase (s.midiLinks.begin() + row); });
- };
- removeAll.onClick = [this] { engine.editSong ([] (Song& s) { s.midiLinks.clear(); }); };
- if (! persistent)
- {
- // --snapshot: devices of a typical setup, and two links
- sampleDevices = { "Arturia KeyLab 49", "Akai MPD218" };
- engine.editSong ([] (Song& s) {
- AutomationTarget volume;
- volume.kind = AutomationTargetKind::mixerVolume;
- volume.index = 0;
- AutomationTarget pan;
- pan.kind = AutomationTargetKind::channelPan;
- pan.index = 0;
- s.midiLinks = { { 7, -1, volume }, { 10, 0, pan } };
- }, false);
- }
- engine.addChangeListener (this);
- rebuildInputs();
- load();
- }
- ~MidiPage() override { engine.removeChangeListener (this); }
- private:
- int layout (int width) override
- {
- Rows r (width);
- r.section (inputsTitle, true);
- inputsNote.setBounds (r.full (32).translated (0, -4));
- if (rows.empty())
- noDevices.setBounds (r.full (24));
- for (auto& row : rows)
- row->setBounds (r.full (34).translated (0, -4));
- refresh.setBounds (r.full().removeFromLeft (150));
- r.section (notesTitle);
- velocityBox.setBounds (r.row (velocityLabel, 300));
- velocityNote.setBounds (r.indented (16).translated (0, -6));
- r.section (controllersTitle);
- {
- auto row = r.row (typeLabel, 0, 36);
- typeLabel.setBounds (typeLabel.getBounds().withTrimmedTop (6));
- typeValue.setBounds (row.withTrimmedTop (6));
- }
- pickup.setBounds (r.full (24));
- pickupNote.setBounds (r.full (16).translated (0, -6));
- {
- auto row = r.row (linksLabel, 0, 110);
- linksLabel.setBounds (linksLabel.getBounds().withTrimmedTop (4));
- auto buttons = row.removeFromRight (120);
- row.removeFromRight (8);
- links.setBounds (row);
- removeLink.setBounds (buttons.removeFromTop (26));
- buttons.removeFromTop (6);
- removeAll.setBounds (buttons.removeFromTop (26));
- }
- return r.bottom();
- }
- void set (const prefs::MidiPrefs& p)
- {
- if (loading)
- return;
- engine.setMidiPrefs (p, persistent);
- if (hooks.midiChanged)
- hooks.midiChanged();
- }
- void load()
- {
- const juce::ScopedValueSetter<bool> guard (loading, true);
- const auto& p = engine.getMidiPrefs();
- velocityBox.setSelectedId ((int) p.velocity + 1, juce::dontSendNotification);
- pickup.setToggleState (p.pickup, juce::dontSendNotification);
- links.updateContent();
- links.repaint();
- removeLink.setEnabled (links.getSelectedRow() >= 0);
- removeAll.setEnabled (! engine.getSong().midiLinks.empty());
- }
- void rebuildInputs()
- {
- rows.clear();
- juce::StringArray names;
- if (persistent)
- for (const auto& d : juce::MidiInput::getAvailableDevices())
- names.add (d.name);
- else
- names = sampleDevices;
- std::vector<std::string> channels;
- for (const auto& c : engine.getSong().channels)
- channels.push_back (c.name);
- for (const auto& name : names)
- {
- auto row = std::make_unique<MidiInputRow> (name, engine.getMidiPrefs().input (name.toStdString()), channels,
- [this] (const prefs::MidiInputPrefs& in) {
- auto p = engine.getMidiPrefs();
- p.setInput (in);
- set (p);
- });
- add (*row);
- rows.push_back (std::move (row));
- }
- noDevices.setVisible (rows.empty());
- resized();
- }
- // links list
- int getNumRows() override { return juce::jmax (1, (int) engine.getSong().midiLinks.size()); }
- void paintListBoxItem (int row, juce::Graphics& g, int width, int height, bool selected) override
- {
- const auto& list = engine.getSong().midiLinks;
- if (list.empty())
- {
- g.setFont (theme::font (theme::type::small));
- g.setColour (theme::colour::textDisabled);
- g.drawText (tr ("(none yet)"), 10, 0, width - 20, height, juce::Justification::centredLeft);
- return;
- }
- if (selected)
- {
- g.setColour (theme::colour::accentMuted);
- g.fillRect (0, 0, width, height);
- }
- const auto& link = list[(std::size_t) row];
- g.setFont (theme::font (theme::type::body));
- g.setColour (theme::colour::info);
- const auto source = "CC " + juce::String (link.cc) + (link.channel >= 0 ? juce::String::fromUTF8 (" \xc2\xb7 ") + tr ("ch. {0}", { juce::String (link.channel + 1) }) : juce::String());
- g.drawText (source, 10, 0, 110, height, juce::Justification::centredLeft);
- g.setColour (theme::colour::textPrimary);
- g.drawText (describeAutomationTarget (engine, link.target), 124, 0, width - 134, height, juce::Justification::centredLeft, true);
- }
- void selectedRowsChanged (int) override { removeLink.setEnabled (links.getSelectedRow() >= 0 && ! engine.getSong().midiLinks.empty()); }
- void changeListenerCallback (juce::ChangeBroadcaster*) override
- {
- if (engine.getSong().channels.size() != channelCount)
- {
- channelCount = engine.getSong().channels.size();
- rebuildInputs();
- }
- load();
- }
- AudioEngine& engine;
- SettingsHooks hooks;
- bool persistent;
- bool loading = false;
- std::size_t channelCount = 0;
- juce::StringArray sampleDevices;
- std::vector<std::unique_ptr<MidiInputRow>> rows;
- SectionTitle inputsTitle { tr ("Input devices") }, notesTitle { tr ("Notes") }, controllersTitle { tr ("Controllers") };
- juce::Label inputsNote, noDevices, velocityLabel, velocityNote, typeLabel, typeValue, pickupNote, linksLabel;
- juce::TextButton refresh { tr ("Refresh device list") }, removeLink { tr ("Remove link") }, removeAll { tr ("Remove all") };
- juce::ComboBox velocityBox;
- juce::ToggleButton pickup;
- juce::ListBox links;
- };
- } // namespace
- std::unique_ptr<juce::Component> makeGeneralPage (AudioEngine& engine, const SettingsHooks& hooks, bool persistent)
- {
- return std::make_unique<GeneralPage> (engine, hooks, persistent);
- }
- std::unique_ptr<juce::Component> makeAudioPage (AudioEngine& engine, bool persistent)
- {
- juce::ignoreUnused (persistent);
- return std::make_unique<AudioPage> (engine);
- }
- std::unique_ptr<juce::Component> makeMidiPage (AudioEngine& engine, const SettingsHooks& hooks, bool persistent)
- {
- return std::make_unique<MidiPage> (engine, hooks, persistent);
- }
- } // namespace lynx
|