Bladeren bron

Export window (WAV/MP3/OGG/FLAC, depth, rate, dither, tail, loops, range, stems, normalize), New project window and user templates, Clip properties, Arrangements and merging, Plugin performance monitor, Touch keyboard; pt-BR

Ka1-S 1 maand geleden
bovenliggende
commit
0764ebf91c

+ 154 - 0
resources/i18n/pt-BR.txt

@@ -1451,3 +1451,157 @@ countries: br
 "Manage shortcuts" = "Gerenciar atalhos"
 "(open an output device first)" = "(abra um dispositivo de saída antes)"
 "(choose)" = "(escolha)"
+
+# --- Round 84: Export options, New project, Clip properties, Arrangements, Plugin performance monitor, Touch keyboard
+"Source" = "Origem"
+"Time" = "Tempo"
+"All {0} selected clips" = "Todos os {0} clipes selecionados"
+"Uses" = "Usa"
+"Track" = "Faixa"
+"bar:beat:tick (1:1:000 is the start of the song)" = "compasso:tempo:tick (1:1:000 é o início da música)"
+"bars:beats:ticks" = "compassos:tempos:ticks"
+"How much of the source's start is skipped (bars:beats:ticks)" = "Quanto do início da origem é pulado (compassos:tempos:ticks)"
+"Muted" = "Mudo"
+"Gain" = "Ganho"
+"The audio channel's pitch: every clip of this file follows it" = "A afinação do canal de áudio: todos os clipes deste arquivo a seguem"
+"Fade in" = "Fade in"
+"Fade out" = "Fade out"
+"Stretch to" = "Esticar para"
+"0: the file plays at its own speed; otherwise the whole file lasts this many beats at the project tempo" = "0: o arquivo toca na própria velocidade; senão o arquivo inteiro dura esse número de tempos no BPM do projeto"
+"Keep the pitch" = "Manter a afinação"
+"Don't change" = "Não mudar"
+"Mute all" = "Silenciar todos"
+"Unmute all" = "Tirar o mudo de todos"
+"Flip state" = "Inverter o estado"
+"Set to" = "Definir em"
+"Change by" = "Mudar em"
+"Back to how the clip was when this window opened" = "Volta o clipe a como estava quando esta janela abriu"
+"Clip properties" = "Propriedades do clipe"
+"Merge into the current arrangement" = "Mesclar no arranjo atual"
+"Make it the current arrangement (the Playlist shows it)" = "Torna-o o arranjo atual (a Playlist o mostra)"
+"A new empty arrangement" = "Um novo arranjo vazio"
+"A copy of the selected arrangement, right after it" = "Uma cópia do arranjo selecionado, logo depois dele"
+"Source arrangement" = "Arranjo de origem"
+"Mode" = "Modo"
+"Insert (moves what follows)" = "Inserir (empurra o que vem depois)"
+"Merge (over what is there)" = "Mesclar (por cima do que já existe)"
+"Replace (clears that length first)" = "Substituir (limpa esse trecho antes)"
+"Position" = "Posição"
+"Playback position" = "Posição de reprodução"
+"{0} clips, {1} bars" = "{0} clipes, {1} compassos"
+"Merge into \"{0}\"" = "Mesclar em \"{0}\""
+"Show" = "Mostrar"
+"Duplicate" = "Duplicar"
+"Merge" = "Mesclar"
+"What to render" = "O que renderizar"
+"Output format" = "Formato de saída"
+"Song (Playlist)" = "Song (Playlist)"
+"Playlist selection" = "Seleção da Playlist"
+"What is rendered: the arrangement, the current pattern, or the Playlist's time selection" = "O que é renderizado: o arranjo, o pattern atual ou a seleção de tempo da Playlist"
+"Once" = "Uma vez"
+"{0} times" = "{0} vezes"
+"How many times the range plays in the file" = "Quantas vezes o trecho toca no arquivo"
+"Cut remainder" = "Cortar o restante"
+"Leave remainder" = "Deixar o restante"
+"Wrap remainder" = "Enrolar o restante"
+"Cut: stop exactly at the end (loops). Leave: let reverbs and releases ring out (songs). Wrap: mix the tail into the start (seamless loops)" = "Cortar: para exatamente no fim (loops). Deixar: reverbs e releases soam até o fim (músicas). Enrolar: mistura a cauda no início (loops sem emenda)"
+"Longest tail" = "Cauda máxima"
+"The tail stops earlier when the sound has faded out" = "A cauda para antes quando o som já sumiu"
+"One file (the mix)" = "Um arquivo (a mixagem)"
+"One per mixer insert (stems)" = "Um por insert do Mixer (stems)"
+"One per channel (stems)" = "Um por canal (stems)"
+"Stems: a file for each mixer insert that gets sound, or for each channel that plays" = "Stems: um arquivo para cada insert do Mixer que recebe som, ou para cada canal que toca"
+"Also the full mix" = "Também a mixagem completa"
+"Bit depth" = "Resolução"
+"16 bits (integer)" = "16 bits (inteiro)"
+"24 bits (integer)" = "24 bits (inteiro)"
+"32 bits (float)" = "32 bits (float)"
+"Bitrate" = "Taxa de bits"
+"Constant bitrate (higher: better sound, bigger file)" = "Taxa de bits constante (maior: som melhor, arquivo maior)"
+"Compression" = "Compressão"
+"0 (fastest)" = "0 (mais rápida)"
+"5 (default)" = "5 (padrão)"
+"8 (smallest)" = "8 (menor arquivo)"
+"FLAC is lossless at every level; higher levels make smaller files and take longer" = "O FLAC não perde qualidade em nenhum nível; níveis maiores fazem arquivos menores e demoram mais"
+"Channels" = "Canais"
+"Stereo" = "Estéreo"
+"Mono (both sides mixed)" = "Mono (os dois lados misturados)"
+"Mono (left only)" = "Mono (só o esquerdo)"
+"Mono (right only)" = "Mono (só o direito)"
+"Dither" = "Dither"
+"TPDF" = "TPDF"
+"TPDF + noise shaping" = "TPDF + noise shaping"
+"Hides the rounding noise of 16 and 24 bit files (noise shaping moves it where the ear is least sensitive)" = "Disfarça o ruído de arredondamento de arquivos de 16 e 24 bits (o noise shaping o leva para onde o ouvido é menos sensível)"
+"Normalize (peak to 0 dB)" = "Normalizar (pico em 0 dB)"
+"Master effects" = "Efeitos do Master"
+"Trim the delay compensation's silence" = "Cortar o silêncio da compensação de atraso"
+"Raises or lowers the whole file so its loudest peak reaches full scale" = "Sobe ou desce o arquivo inteiro para o pico mais alto chegar ao máximo"
+"Off: the Master insert's effects are bypassed for the export" = "Desligado: os efeitos do insert Master ficam de fora da exportação"
+"Removes the silence plugin latency compensation adds at the start" = "Remove o silêncio que a compensação de latência dos plugins coloca no início"
+"Total time: {0}" = "Duração total: {0}"
+"(+ tail up to {0} s)" = "(+ cauda de até {0} s)"
+"MP3 at {0} Hz" = "MP3 em {0} Hz"
+"{0} file(s)" = "{0} arquivo(s)"
+"The Master insert is muted: the file will be silent" = "O insert Master está mudo: o arquivo vai sair em silêncio"
+"There is no Playlist selection: the whole song is rendered" = "Não há seleção na Playlist: a música inteira é renderizada"
+"Save as template" = "Salvar como modelo"
+"The template appears in File › New project... (saved in {0})" = "O modelo aparece em Arquivo › Novo projeto... (salvo em {0})"
+"My template" = "Meu modelo"
+"New project..." = "Novo projeto..."
+"Save as template..." = "Salvar como modelo..."
+"Touch keyboard" = "Teclado na tela"
+"Plugin performance monitor..." = "Monitor de desempenho dos plugins..."
+"Drums and a synth on the first inserts, a limiter on Master" = "Bateria e um synth nos primeiros inserts, um limitador no Master"
+"Nothing in the patterns" = "Nada nos patterns"
+"A four-on-the-floor beat to start from" = "Uma batida four-on-the-floor para começar"
+"140 BPM, fast hats and an 808 with glide" = "140 BPM, hats rápidos e um 808 com glide"
+"124 BPM house groove with bass" = "Groove de house a 124 BPM com baixo"
+"Your template" = "Seu modelo"
+"Template" = "Modelo"
+"Name and location" = "Nome e local"
+"Information" = "Informações"
+"Templates are .lynx projects in this folder (File › Save as template... puts one there)" = "Modelos são projetos .lynx nesta pasta (Arquivo › Salvar como modelo... coloca um aqui)"
+"Folder" = "Pasta"
+"Save it there now" = "Salvar lá agora"
+"Off: the project opens unsaved and asks where to go when you first save" = "Desligado: o projeto abre sem salvar e pergunta o local no primeiro salvamento"
+"Create a folder for the project" = "Criar uma pasta para o projeto"
+"same as the name" = "igual ao nome"
+"Don't show this window for File › New" = "Não mostrar esta janela em Arquivo › Novo"
+"File › New then starts the default project at once; this window stays in File › New project..." = "Arquivo › Novo passa a abrir o projeto padrão direto; esta janela continua em Arquivo › Novo projeto..."
+"Not saved until you choose File › Save" = "Não é salvo até você escolher Arquivo › Salvar"
+"Folder for the project" = "Pasta do projeto"
+"{0} already exists. Choose another name or folder." = "{0} já existe. Escolha outro nome ou pasta."
+"Open the templates folder" = "Abrir a pasta de modelos"
+"Choose..." = "Escolher..."
+"Create" = "Criar"
+"could not create {0}" = "não foi possível criar {0}"
+"Arrangements and merging..." = "Arranjos e mesclagem..."
+"Properties..." = "Propriedades..."
+"Where" = "Onde"
+"Now" = "Agora"
+"Average" = "Média"
+"Nothing to show" = "Nada para mostrar"
+"Find" = "Buscar"
+"plugin, channel or insert" = "plugin, canal ou insert"
+"Plugins only" = "Só plugins"
+"Only third-party plugins (VST3 / CLAP), not LYNX's own instruments and effects" = "Só plugins de terceiros (VST3 / CLAP), não os instrumentos e efeitos do próprio LYNX"
+"Freeze" = "Congelar"
+"Stops updating the numbers" = "Para de atualizar os números"
+"Reset on play" = "Zerar ao tocar"
+"Averages and peaks start again each time playback starts" = "Médias e picos recomeçam cada vez que a reprodução começa"
+"100% = one processor core busy for the whole time the audio lasts" = "100% = um núcleo do processador ocupado durante todo o tempo que o áudio dura"
+"Channel {0}" = "Canal {0}"
+"slot {0}" = "slot {0}"
+"Whole rack: {0} (peak {1})" = "Rack inteiro: {0} (pico {1})"
+"Plugin performance monitor" = "Monitor de desempenho dos plugins"
+"One octave down" = "Uma oitava abaixo"
+"One octave up" = "Uma oitava acima"
+"Small keys" = "Teclas pequenas"
+"Medium keys" = "Teclas médias"
+"Large keys" = "Teclas grandes"
+"Velocity: where you touch" = "Velocity: onde você toca"
+"Velocity: fixed" = "Velocity: fixa"
+"Where you touch: near the top of a key plays soft, near the bottom loud" = "Onde você toca: perto do topo da tecla toca fraco, perto da base forte"
+"Note names" = "Nomes das notas"
+"Plays: {0}" = "Toca: {0}"
+"Select a channel in the Channel Rack" = "Selecione um canal no Channel Rack"

+ 33 - 0
src/Main.cpp

@@ -12,6 +12,10 @@
 #include "engine/SampleLibrary.h"
 #include "engine/Text.h"
 #include "platform/FileTypes.h"
+#include "ui/ClipProperties.h"
+#include "ui/NewProjectDialog.h"
+#include "ui/PluginMonitorWindow.h"
+#include "ui/TouchKeyboard.h"
 #include "ui/AutomationUi.h"
 #include "ui/ChannelSettings.h"
 #include "ui/Dialogs.h"
@@ -1393,6 +1397,8 @@ private:
             };
 
             saveWindow (lynx::makeExportPanel (offline), "-export.png");
+            saveWindow (lynx::makeExportPanel (offline, 1), "-export-mp3.png");
+            saveWindow (lynx::makeExportPanel (offline, 3), "-export-flac-stems.png");
             saveSplashFrames (prefix);
             saveIconSheet (prefix + "-icons.png", 1.0f);
             saveIconSheet (prefix + "-icons-150.png", 1.5f);
@@ -1443,6 +1449,33 @@ private:
                 saveWindow (lynx::makePluginManagerPanel (offline, false), "-plugin-manager.png");
                 saveWindow (lynx::makeShortcutManagerPanel (false), "-shortcuts.png");
             }
+            {
+                // round 84: New project, Clip properties, Arrangements, Plugin performance monitor, Touch keyboard
+                saveWindow (lynx::makeNewProjectPanel(), "-new-project.png");
+                const auto& clips = offline.getSong().playlist;
+                for (int i = 0; i < (int) clips.size(); ++i)
+                    if (clips[(std::size_t) i].kind == lynx::ClipKind::pattern)
+                    {
+                        saveWindow (lynx::makeClipPropertiesPanel (offline, i, { i, (i + 1) % (int) clips.size() }), "-clip-properties.png");
+                        break;
+                    }
+                for (int i = 0; i < (int) clips.size(); ++i)
+                    if (clips[(std::size_t) i].kind == lynx::ClipKind::audio)
+                    {
+                        saveWindow (lynx::makeClipPropertiesPanel (offline, i, { i }), "-clip-properties-audio.png");
+                        break;
+                    }
+                if (offline.getSong().arrangements.size() < 2)
+                    offline.editSong ([] (lynx::Song& s) {
+                        const auto current = s.currentArrangement;
+                        s.addArrangement ("Radio edit", true);
+                        s.addArrangement ("Intro loop");
+                        s.selectArrangement (current);
+                    }, false);
+                saveWindow (lynx::makeArrangementsPanel (offline), "-arrangements.png");
+                saveWindow (lynx::makePluginMonitorPanel (offline), "-plugin-monitor.png");
+                saveWindow (lynx::makeTouchKeyboardPanel (offline), "-touch-keyboard.png");
+            }
 
             if (! offline.getSong().automations.empty())
             {

+ 54 - 0
src/core/PlaylistOps.cpp

@@ -1,6 +1,7 @@
 #include "core/PlaylistOps.h"
 
 #include <algorithm>
+#include <cstdio>
 
 namespace lynx::clipprops
 {
@@ -140,6 +141,59 @@ void changeGain (Song& song, const std::vector<int>& clips, float value, bool re
         }
 }
 
+namespace
+{
+std::string bbt (std::int64_t ticks, int beatsPerBar, int base)
+{
+    const auto beat = (std::int64_t) ppq;
+    const auto bar = beat * std::max (1, beatsPerBar);
+    const auto t = std::max<std::int64_t> (0, ticks);
+    char text[48];
+    std::snprintf (text, sizeof (text), "%lld:%lld:%03lld", (long long) (t / bar + base), (long long) ((t % bar) / beat + base), (long long) (t % beat));
+    return text;
+}
+
+std::int64_t parseBbt (const std::string& text, int beatsPerBar, int base)
+{
+    long long parts[3] = { 0, base, 0 };
+    int count = 0;
+    std::string token;
+    auto flush = [&] {
+        if (token.empty() || count >= 3)
+            return false;
+        for (auto c : token)
+            if (c < '0' || c > '9')
+                return false;
+        parts[count++] = std::stoll (token);
+        token.clear();
+        return true;
+    };
+    for (auto c : text)
+    {
+        if (c == ' ')
+            continue;
+        if (c == ':' || c == '.')
+        {
+            if (! flush())
+                return -1;
+        }
+        else
+            token += c;
+    }
+    if (! flush())
+        return -1;
+    if (parts[0] < base || parts[1] < base || parts[1] - base >= std::max (1, beatsPerBar) || parts[2] >= ppq)
+        return -1;
+    const auto beat = (std::int64_t) ppq;
+    return (parts[0] - base) * beat * std::max (1, beatsPerBar) + (parts[1] - base) * beat + parts[2];
+}
+} // namespace
+
+std::string formatPosition (std::int64_t ticks, int beatsPerBar) { return bbt (ticks, beatsPerBar, 1); }
+std::string formatLength (std::int64_t ticks, int beatsPerBar) { return bbt (ticks, beatsPerBar, 0); }
+std::int64_t parsePosition (const std::string& text, int beatsPerBar) { return parseBbt (text, beatsPerBar, 1); }
+std::int64_t parseLength (const std::string& text, int beatsPerBar) { return parseBbt (text, beatsPerBar, 0); }
+
 std::vector<std::pair<int, std::string>> sourcesFor (const Song& song, ClipKind kind)
 {
     std::vector<std::pair<int, std::string>> out;

+ 8 - 0
src/core/PlaylistOps.h

@@ -51,6 +51,14 @@ void changeMute (Song& song, const std::vector<int>& clips, MuteChange change);
 // Audio clips' gain: set to `value`, or multiply (`relative`).
 void changeGain (Song& song, const std::vector<int>& clips, float value, bool relative);
 
+// Positions and lengths as the window shows them, "bar:beat:tick" (ticks at LYNX's PPQ); a position counts from 1 ("1:1:000" is the start), a length from 0 ("2:0:000" = two bars). Time signature
+// changes from markers are not applied (bars of `beatsPerBar` beats).
+std::string formatPosition (std::int64_t ticks, int beatsPerBar);
+std::string formatLength (std::int64_t ticks, int beatsPerBar);
+// The inverse; also accepts "bar" or "bar:beat". -1 when the text is not a time.
+std::int64_t parsePosition (const std::string& text, int beatsPerBar);
+std::int64_t parseLength (const std::string& text, int beatsPerBar);
+
 // Sources a clip of this kind can switch to: their names (patterns / audio channels / automations).
 std::vector<std::pair<int, std::string>> sourcesFor (const Song& song, ClipKind kind);
 } // namespace lynx::clipprops

+ 1 - 1
src/core/TouchKeyboard.h

@@ -32,7 +32,7 @@ struct Rect
 
 struct Layout
 {
-    int lowest = 48;         // the leftmost key, always a C (48 = C3 in LYNX's naming, middle C = 60)
+    int lowest = 48;         // the leftmost key, always a C (48 = C4 as LYNX names keys: octave = key / 12)
     int whiteKeys = 21;      // white keys shown (3 octaves)
     float width = 700.0f, height = 120.0f;
     float blackLength = 0.62f; // black keys' length, part of the height

+ 689 - 0
src/ui/ClipProperties.cpp

@@ -0,0 +1,689 @@
+#include "ui/ClipProperties.h"
+
+#include "core/PlaylistOps.h"
+#include "core/RackOps.h"
+#include "engine/AudioEngine.h"
+#include "ui/I18n.h"
+#include "ui/SettingsPages.h"
+#include "ui/Theme.h"
+#include "ui/ToolWindow.h"
+
+namespace lynx
+{
+namespace
+{
+using namespace settingsui;
+
+bool sameClip (const Clip& a, const Clip& b)
+{
+    return a.kind == b.kind && a.pattern == b.pattern && a.channel == b.channel && a.automation == b.automation && a.track == b.track
+           && a.start == b.start && a.length == b.length && a.offset == b.offset;
+}
+
+// LYNX's palette as a row of swatches; the first is "automatic".
+class ColourRow final : public juce::Component
+{
+public:
+    std::function<void()> onChange;
+    std::uint32_t colour = 0;
+
+    void paint (juce::Graphics& g) override
+    {
+        const auto& palette = lynxPalette();
+        const auto n = (int) palette.size() + 1;
+        const auto w = (float) getWidth() / (float) n;
+        for (int i = 0; i < n; ++i)
+        {
+            const auto value = i == 0 ? 0u : palette[(std::size_t) i - 1];
+            auto r = juce::Rectangle<float> (w * (float) i, 0.0f, w, (float) getHeight()).reduced (2.0f);
+            if (i == 0)
+            {
+                g.setColour (theme::colour::bg4);
+                g.fillRoundedRectangle (r, theme::radius::sm);
+                g.setColour (theme::colour::textSecondary);
+                g.drawLine (r.getX() + 4, r.getBottom() - 4, r.getRight() - 4, r.getY() + 4, 1.2f);
+            }
+            else
+            {
+                g.setColour (juce::Colour (value));
+                g.fillRoundedRectangle (r, theme::radius::sm);
+            }
+            if (value == colour)
+            {
+                g.setColour (theme::colour::textPrimary);
+                g.drawRoundedRectangle (r.expanded (1.0f), theme::radius::sm, 2.0f);
+            }
+        }
+    }
+
+    void mouseDown (const juce::MouseEvent& e) override
+    {
+        const auto& palette = lynxPalette();
+        const auto n = (int) palette.size() + 1;
+        const auto i = juce::jlimit (0, n - 1, (int) ((float) e.x / ((float) getWidth() / (float) n)));
+        colour = i == 0 ? 0u : palette[(std::size_t) i - 1];
+        repaint();
+        if (onChange)
+            onChange();
+    }
+};
+
+class ClipPropertiesPanel final : public juce::Component,
+                                  private juce::ChangeListener
+{
+public:
+    ClipPropertiesPanel (AudioEngine& e, int clipIndex, std::vector<int> selected, std::function<void()> after)
+        : engine (e),
+          index (clipIndex),
+          selection (std::move (selected)),
+          afterEdit (std::move (after))
+    {
+        if (index >= 0 && index < (int) engine.getSong().playlist.size())
+            original = engine.getSong().playlist[(std::size_t) index];
+        if (std::find (selection.begin(), selection.end(), index) == selection.end())
+            selection = { index };
+
+        for (auto* t : { &sourceTitle, &timeTitle, &levelsTitle, &groupTitle })
+            addAndMakeVisible (t);
+        sourceTitle.setText (tr ("Source"));
+        timeTitle.setText (tr ("Time"));
+        levelsTitle.setText (tr ("Audio"));
+        groupTitle.setText (tr ("All {0} selected clips", { juce::String ((int) selection.size()) }));
+
+        auto label = [this] (juce::Label& l, const juce::String& text) {
+            styleLabel (l, text);
+            addAndMakeVisible (l);
+        };
+        auto editor = [this] (juce::TextEditor& ed) {
+            styleEditor (ed);
+            ed.onReturnKey = [this] { apply(); };
+            ed.onFocusLost = [this] { apply(); };
+            addAndMakeVisible (ed);
+        };
+        auto slider = [this] (juce::Slider& s, double lo, double hi, double step, const juce::String& suffix) {
+            s.setSliderStyle (juce::Slider::LinearHorizontal);
+            s.setTextBoxStyle (juce::Slider::TextBoxRight, false, 74, 22);
+            s.setRange (lo, hi, step);
+            s.setTextValueSuffix (suffix);
+            s.onDragEnd = [this] { apply(); };
+            s.onValueChange = [this, &s] { if (! s.isMouseButtonDown()) apply(); };
+            addAndMakeVisible (s);
+        };
+
+        label (nameLabel, tr ("Name"));
+        editor (name);
+        label (colourLabel, tr ("Color"));
+        colours.onChange = [this] { apply(); };
+        addAndMakeVisible (colours);
+        label (sourceLabel, tr ("Uses"));
+        source.onChange = [this] { apply(); };
+        addAndMakeVisible (source);
+        label (trackLabel, tr ("Track"));
+        slider (track, 1, 500, 1, {});
+
+        label (startLabel, tr ("Start"));
+        editor (start);
+        start.setTooltip (tr ("bar:beat:tick (1:1:000 is the start of the song)"));
+        label (lengthLabel, tr ("Length"));
+        editor (length);
+        length.setTooltip (tr ("bars:beats:ticks"));
+        label (offsetLabel, tr ("Offset"));
+        editor (offset);
+        offset.setTooltip (tr ("How much of the source's start is skipped (bars:beats:ticks)"));
+        muted.setButtonText (tr ("Muted"));
+        muted.onClick = [this] { apply(); };
+        addAndMakeVisible (muted);
+
+        label (gainLabel, tr ("Gain"));
+        slider (gain, -24.0, 12.0, 0.1, " dB");
+        gain.setDoubleClickReturnValue (true, 0.0);
+        label (pitchLabel, tr ("Pitch"));
+        slider (pitch, -24.0, 24.0, 1.0, " st");
+        pitch.setDoubleClickReturnValue (true, 0.0);
+        pitch.setTooltip (tr ("The audio channel's pitch: every clip of this file follows it"));
+        label (fadeInLabel, tr ("Fade in"));
+        slider (fadeIn, 0.0, 16.0, 0.01, " " + tr ("beats"));
+        label (fadeOutLabel, tr ("Fade out"));
+        slider (fadeOut, 0.0, 16.0, 0.01, " " + tr ("beats"));
+        label (stretchLabel, tr ("Stretch to"));
+        slider (stretch, 0.0, 256.0, 0.25, " " + tr ("beats"));
+        stretch.setTooltip (tr ("0: the file plays at its own speed; otherwise the whole file lasts this many beats at the project tempo"));
+        keepPitch.setButtonText (tr ("Keep the pitch"));
+        keepPitch.onClick = [this] { apply(); };
+        addAndMakeVisible (keepPitch);
+
+        label (groupMuteLabel, tr ("Mute"));
+        groupMute.addItemList ({ tr ("Don't change"), tr ("Mute all"), tr ("Unmute all"), tr ("Flip state") }, 1);
+        groupMute.setSelectedItemIndex (0, juce::dontSendNotification);
+        addAndMakeVisible (groupMute);
+        label (groupGainLabel, tr ("Gain"));
+        groupGainMode.addItemList ({ tr ("Don't change"), tr ("Set to"), tr ("Change by") }, 1);
+        groupGainMode.setSelectedItemIndex (0, juce::dontSendNotification);
+        addAndMakeVisible (groupGainMode);
+        groupGain.setSliderStyle (juce::Slider::LinearHorizontal);
+        groupGain.setTextBoxStyle (juce::Slider::TextBoxRight, false, 74, 22);
+        groupGain.setRange (-24.0, 12.0, 0.1);
+        groupGain.setTextValueSuffix (" dB");
+        addAndMakeVisible (groupGain);
+        groupApply.onClick = [this] { applyGroup(); };
+        addAndMakeVisible (groupApply);
+
+        reset.setTooltip (tr ("Back to how the clip was when this window opened"));
+        reset.onClick = [this] { resetClip(); };
+        close.onClick = [this] { closeToolWindowOf (*this); };
+        addAndMakeVisible (reset);
+        addAndMakeVisible (close);
+
+        engine.addChangeListener (this);
+        load();
+        setSize (440, height());
+    }
+
+    ~ClipPropertiesPanel() override { engine.removeChangeListener (this); }
+
+    void paint (juce::Graphics& g) override { g.fillAll (theme::colour::bg2); }
+
+    void resized() override
+    {
+        auto area = getLocalBounds().reduced (16, 12);
+        auto bottom = area.removeFromBottom (30);
+        close.setBounds (bottom.removeFromRight (90));
+        bottom.removeFromRight (8);
+        reset.setBounds (bottom.removeFromRight (90));
+
+        constexpr int labelWidth = 86, rowHeight = 26, gap = 6;
+        auto row = [&] (juce::Label& l, juce::Component& c) {
+            auto r = area.removeFromTop (rowHeight);
+            l.setBounds (r.removeFromLeft (labelWidth));
+            c.setBounds (r);
+            area.removeFromTop (gap);
+        };
+        auto title = [&] (juce::Component& t) {
+            t.setBounds (area.removeFromTop (24));
+            area.removeFromTop (6);
+        };
+
+        title (sourceTitle);
+        row (nameLabel, name);
+        row (colourLabel, colours);
+        row (sourceLabel, source);
+        row (trackLabel, track);
+        title (timeTitle);
+        {
+            auto r = area.removeFromTop (rowHeight);
+            startLabel.setBounds (r.removeFromLeft (labelWidth));
+            start.setBounds (r.removeFromLeft (110));
+            r.removeFromLeft (14);
+            lengthLabel.setBounds (r.removeFromLeft (60));
+            length.setBounds (r);
+            area.removeFromTop (gap);
+        }
+        {
+            auto r = area.removeFromTop (rowHeight);
+            offsetLabel.setBounds (r.removeFromLeft (labelWidth));
+            offset.setBounds (r.removeFromLeft (110));
+            r.removeFromLeft (14);
+            muted.setBounds (r);
+            area.removeFromTop (gap);
+        }
+        if (isAudio())
+        {
+            title (levelsTitle);
+            row (gainLabel, gain);
+            row (pitchLabel, pitch);
+            row (fadeInLabel, fadeIn);
+            row (fadeOutLabel, fadeOut);
+            row (stretchLabel, stretch);
+            keepPitch.setBounds (area.removeFromTop (22).withTrimmedLeft (labelWidth));
+            area.removeFromTop (gap);
+        }
+        if (selection.size() > 1)
+        {
+            title (groupTitle);
+            row (groupMuteLabel, groupMute);
+            auto r = area.removeFromTop (rowHeight);
+            groupGainLabel.setBounds (r.removeFromLeft (labelWidth));
+            groupGainMode.setBounds (r.removeFromLeft (112));
+            r.removeFromLeft (6);
+            groupApply.setBounds (r.removeFromRight (70));
+            r.removeFromRight (6);
+            groupGain.setBounds (r);
+        }
+    }
+
+private:
+    bool isAudio() const noexcept { return props.kind == ClipKind::audio; }
+
+    int height() const
+    {
+        auto h = 12 + 30 * 3 + 32 * 6 + 12 + 30 + 12; // titles, rows, buttons
+        if (isAudio())
+            h += 30 + 32 * 5 + 28;
+        if (selection.size() > 1)
+            h += 30 + 32 * 2;
+        return h;
+    }
+
+    // the clip may have moved in the list (sorting, other edits): find it again
+    int locate() const
+    {
+        const auto& list = engine.getSong().playlist;
+        if (index >= 0 && index < (int) list.size() && sameClip (list[(std::size_t) index], current))
+            return index;
+        for (int i = 0; i < (int) list.size(); ++i)
+            if (sameClip (list[(std::size_t) i], current))
+                return i;
+        // moved or resized in the Playlist: the same slot still holding a clip of the same source
+        if (index >= 0 && index < (int) list.size())
+        {
+            const auto& c = list[(std::size_t) index];
+            if (c.kind == current.kind && c.pattern == current.pattern && c.channel == current.channel && c.automation == current.automation)
+                return index;
+        }
+        return -1;
+    }
+
+    void load()
+    {
+        const auto& song = engine.getSong();
+        const auto i = locate() >= 0 ? locate() : index;
+        if (i < 0 || ! clipprops::read (song, i, props))
+            return;
+        index = i;
+        current = song.playlist[(std::size_t) i];
+        loading = true;
+        const auto n = juce::dontSendNotification;
+        name.setText (juce::String::fromUTF8 (props.name.c_str()), false);
+        colours.colour = props.colour;
+        colours.repaint();
+        colourLabel.setVisible (props.kind != ClipKind::automation);
+        colours.setVisible (props.kind != ClipKind::automation);
+        source.clear (n);
+        for (const auto& [id, text] : clipprops::sourcesFor (song, props.kind))
+            source.addItem (juce::String::fromUTF8 (text.c_str()), id + 1);
+        source.setSelectedId (props.source + 1, n);
+        track.setValue (props.track + 1, n);
+        start.setText (clipprops::formatPosition (props.start, song.beatsPerBar), false);
+        length.setText (clipprops::formatLength (props.length, song.beatsPerBar), false);
+        offset.setText (clipprops::formatLength (props.offset, song.beatsPerBar), false);
+        muted.setToggleState (props.muted, n);
+        gain.setValue (juce::Decibels::gainToDecibels (props.gain, -24.0f), n);
+        pitch.setValue (props.pitch, n);
+        fadeIn.setValue ((double) props.fadeIn / ppq, n);
+        fadeOut.setValue ((double) props.fadeOut / ppq, n);
+        stretch.setValue (props.stretchBeats, n);
+        keepPitch.setToggleState (props.keepPitch, n);
+        keepPitch.setEnabled (props.stretchBeats > 0.0f);
+        for (auto* c : std::initializer_list<juce::Component*> { &levelsTitle, &gainLabel, &gain, &pitchLabel, &pitch, &fadeInLabel, &fadeIn,
+                                                                  &fadeOutLabel, &fadeOut, &stretchLabel, &stretch, &keepPitch })
+            c->setVisible (isAudio());
+        for (auto* c : std::initializer_list<juce::Component*> { &groupTitle, &groupMuteLabel, &groupMute, &groupGainLabel, &groupGainMode, &groupGain, &groupApply })
+            c->setVisible (selection.size() > 1);
+        loading = false;
+        if (auto* w = findParentComponentOfClass<juce::DocumentWindow>())
+            w->setName (tr ("Clip properties") + " - " + name.getText());
+    }
+
+    void apply()
+    {
+        if (loading)
+            return;
+        const auto i = locate();
+        if (i < 0)
+            return;
+        const auto& song = engine.getSong();
+        auto p = props;
+        p.name = name.getText().trim().toStdString();
+        p.colour = colours.colour;
+        p.source = source.getSelectedId() - 1;
+        p.track = (int) track.getValue() - 1;
+        if (const auto t = clipprops::parsePosition (start.getText().toStdString(), song.beatsPerBar); t >= 0)
+            p.start = t;
+        if (const auto t = clipprops::parseLength (length.getText().toStdString(), song.beatsPerBar); t > 0)
+            p.length = t;
+        if (const auto t = clipprops::parseLength (offset.getText().toStdString(), song.beatsPerBar); t >= 0)
+            p.offset = t;
+        p.muted = muted.getToggleState();
+        p.gain = gain.getValue() <= -24.0 ? 0.0f : juce::Decibels::decibelsToGain ((float) gain.getValue());
+        p.pitch = (float) pitch.getValue();
+        p.fadeIn = (std::int64_t) std::llround (fadeIn.getValue() * ppq);
+        p.fadeOut = (std::int64_t) std::llround (fadeOut.getValue() * ppq);
+        p.stretchBeats = (float) stretch.getValue();
+        p.keepPitch = keepPitch.getToggleState();
+        if (p == props)
+        {
+            load(); // puts back text that did not parse
+            return;
+        }
+
+        engine.editSong ([i, p] (Song& s) { clipprops::apply (s, i, p); });
+        current = engine.getSong().playlist[(std::size_t) i];
+        index = i;
+        if (afterEdit)
+            afterEdit();
+        load();
+    }
+
+    void applyGroup()
+    {
+        const auto mute = (clipprops::MuteChange) juce::jmax (0, groupMute.getSelectedItemIndex());
+        const auto gainMode = groupGainMode.getSelectedItemIndex();
+        const auto db = (float) groupGain.getValue();
+        auto targets = selection;
+        engine.editSong ([targets, mute, gainMode, db] (Song& s) {
+            clipprops::changeMute (s, targets, mute);
+            if (gainMode == 1)
+                clipprops::changeGain (s, targets, juce::Decibels::decibelsToGain (db), false);
+            else if (gainMode == 2)
+                clipprops::changeGain (s, targets, juce::Decibels::decibelsToGain (db), true);
+        });
+        if (afterEdit)
+            afterEdit();
+        load();
+    }
+
+    void resetClip()
+    {
+        const auto i = locate();
+        if (i < 0)
+            return;
+        const auto back = original;
+        engine.editSong ([i, back] (Song& s) { s.playlist[(std::size_t) i] = back; });
+        current = original;
+        if (afterEdit)
+            afterEdit();
+        load();
+    }
+
+    void changeListenerCallback (juce::ChangeBroadcaster*) override
+    {
+        if (locate() < 0)
+        {
+            closeToolWindowOf (*this); // the clip is gone (deleted, undone)
+            return;
+        }
+        clipprops::Props now;
+        if (clipprops::read (engine.getSong(), locate(), now) && ! (now == props))
+            load(); // changed elsewhere (undo, the Playlist): show it; otherwise leave what is being typed alone
+    }
+
+    AudioEngine& engine;
+    int index = -1;
+    std::vector<int> selection;
+    std::function<void()> afterEdit;
+    Clip original, current;
+    clipprops::Props props;
+    bool loading = false;
+
+    SectionTitle sourceTitle, timeTitle, levelsTitle, groupTitle;
+    juce::Label nameLabel, colourLabel, sourceLabel, trackLabel, startLabel, lengthLabel, offsetLabel;
+    juce::Label gainLabel, pitchLabel, fadeInLabel, fadeOutLabel, stretchLabel, groupMuteLabel, groupGainLabel;
+    juce::TextEditor name, start, length, offset;
+    ColourRow colours;
+    juce::ComboBox source, groupMute, groupGainMode;
+    juce::Slider track, gain, pitch, fadeIn, fadeOut, stretch, groupGain;
+    juce::ToggleButton muted, keepPitch;
+    juce::TextButton groupApply { tr ("Apply") }, reset { tr ("Reset") }, close { tr ("Close") };
+};
+
+// --- Arrangements ---------------------------------------------------------------------------------------------------
+class ArrangementsPanel final : public juce::Component,
+                                private juce::ListBoxModel,
+                                private juce::ChangeListener
+{
+public:
+    explicit ArrangementsPanel (AudioEngine& e) : engine (e)
+    {
+        listTitle.setText (tr ("Arrangements"));
+        mergeTitle.setText (tr ("Merge into the current arrangement"));
+        addAndMakeVisible (listTitle);
+        addAndMakeVisible (mergeTitle);
+
+        list.setModel (this);
+        list.setRowHeight (30);
+        list.setColour (juce::ListBox::backgroundColourId, theme::colour::bg0);
+        list.setColour (juce::ListBox::outlineColourId, theme::colour::border);
+        list.setOutlineThickness (1);
+        addAndMakeVisible (list);
+
+        auto button = [this] (juce::TextButton& b, const juce::String& tip, std::function<void()> fn) {
+            b.setTooltip (tip);
+            b.onClick = std::move (fn);
+            addAndMakeVisible (b);
+        };
+        button (selectButton, tr ("Make it the current arrangement (the Playlist shows it)"), [this] {
+            const auto row = list.getSelectedRow();
+            if (row >= 0)
+                engine.editSong ([row] (Song& s) { s.selectArrangement (row); }, false);
+        });
+        button (addButton, tr ("A new empty arrangement"), [this] {
+            engine.editSong ([] (Song& s) { s.addArrangement ("Arrangement " + std::to_string (s.arrangements.size() + 1)); });
+            list.selectRow (engine.getSong().currentArrangement);
+        });
+        button (duplicateButton, tr ("A copy of the selected arrangement, right after it"), [this] {
+            const auto row = list.getSelectedRow();
+            int made = -1;
+            engine.editSong ([row, &made] (Song& s) { made = arrangeops::duplicate (s, row); });
+            if (made >= 0)
+                list.selectRow (made);
+        });
+        button (renameButton, {}, [this] { rename(); });
+        button (removeButton, {}, [this] {
+            const auto row = list.getSelectedRow();
+            if (row >= 0 && engine.getSong().arrangements.size() > 1)
+                engine.editSong ([row] (Song& s) { s.removeArrangement (row); });
+        });
+        button (upButton, tr ("Move up"), [this] { moveBy (-1); });
+        button (downButton, tr ("Move down"), [this] { moveBy (1); });
+
+        auto label = [this] (juce::Label& l, const juce::String& text) {
+            styleLabel (l, text);
+            addAndMakeVisible (l);
+        };
+        label (sourceLabel, tr ("Source arrangement"));
+        addAndMakeVisible (sourceBox);
+        label (modeLabel, tr ("Mode"));
+        modeBox.addItemList ({ tr ("Insert (moves what follows)"), tr ("Merge (over what is there)"), tr ("Replace (clears that length first)") }, 1);
+        modeBox.setSelectedItemIndex (0, juce::dontSendNotification);
+        addAndMakeVisible (modeBox);
+        label (positionLabel, tr ("Position"));
+        positionBox.addItemList ({ tr ("Start"), tr ("Playback position"), tr ("End") }, 1);
+        positionBox.setSelectedItemIndex (2, juce::dontSendNotification);
+        addAndMakeVisible (positionBox);
+        mergeButton.setColour (juce::TextButton::buttonColourId, theme::colour::accent);
+        mergeButton.setColour (juce::TextButton::textColourOffId, theme::colour::onAccent);
+        mergeButton.onClick = [this] { mergeNow(); };
+        addAndMakeVisible (mergeButton);
+        closeButton.onClick = [this] { closeToolWindowOf (*this); };
+        addAndMakeVisible (closeButton);
+
+        engine.addChangeListener (this);
+        refresh();
+        list.selectRow (engine.getSong().currentArrangement);
+        setSize (500, 430);
+    }
+
+    ~ArrangementsPanel() override { engine.removeChangeListener (this); }
+
+    void paint (juce::Graphics& g) override { g.fillAll (theme::colour::bg2); }
+
+    void resized() override
+    {
+        auto area = getLocalBounds().reduced (16, 12);
+        closeButton.setBounds (area.removeFromBottom (30).removeFromRight (90));
+        area.removeFromBottom (10);
+
+        auto merge = area.removeFromBottom (24 + 6 + 3 * 32 + 30);
+        mergeTitle.setBounds (merge.removeFromTop (24));
+        merge.removeFromTop (6);
+        auto row = [&merge] (juce::Label& l, juce::Component& c) {
+            auto r = merge.removeFromTop (26);
+            l.setBounds (r.removeFromLeft (132));
+            c.setBounds (r);
+            merge.removeFromTop (6);
+        };
+        row (sourceLabel, sourceBox);
+        row (modeLabel, modeBox);
+        row (positionLabel, positionBox);
+        mergeButton.setBounds (merge.removeFromTop (28).removeFromRight (128));
+        area.removeFromBottom (12);
+
+        listTitle.setBounds (area.removeFromTop (24));
+        area.removeFromTop (6);
+        auto buttons = area.removeFromRight (110);
+        area.removeFromRight (10);
+        list.setBounds (area);
+        for (auto* b : { &selectButton, &addButton, &duplicateButton, &renameButton, &removeButton, &upButton, &downButton })
+        {
+            b->setBounds (buttons.removeFromTop (26));
+            buttons.removeFromTop (4);
+        }
+    }
+
+private:
+    int getNumRows() override { return (int) engine.getSong().arrangements.size(); }
+
+    void paintListBoxItem (int row, juce::Graphics& g, int width, int height, bool selected) override
+    {
+        const auto& song = engine.getSong();
+        if (row < 0 || row >= (int) song.arrangements.size())
+            return;
+        if (selected)
+        {
+            g.setColour (theme::colour::bg5);
+            g.fillRect (0, 0, width, height);
+        }
+        const auto current = row == song.currentArrangement;
+        if (current)
+        {
+            g.setColour (theme::colour::accent);
+            g.fillRect (0, 0, 3, height);
+        }
+        g.setColour (theme::colour::textPrimary);
+        g.setFont (theme::font (theme::type::body, current));
+        g.drawText (juce::String::fromUTF8 (song.arrangements[(std::size_t) row].name.c_str()), 12, 0, width - 160, height, juce::Justification::centredLeft, true);
+        const auto bar = (std::int64_t) ppq * juce::jmax (1, song.beatsPerBar);
+        const auto bars = (arrangeops::lengthOf (song, row) + bar - 1) / bar;
+        const auto clips = (int) arrangeops::clipsOf (song, row).size();
+        g.setColour (theme::colour::textSecondary);
+        g.setFont (theme::font (theme::type::small));
+        g.drawText (tr ("{0} clips, {1} bars", { juce::String (clips), juce::String ((int) bars) }), width - 150, 0, 140, height,
+                    juce::Justification::centredRight);
+    }
+
+    void listBoxItemDoubleClicked (int row, const juce::MouseEvent&) override
+    {
+        engine.editSong ([row] (Song& s) { s.selectArrangement (row); }, false);
+    }
+
+    void selectedRowsChanged (int) override { refreshButtons(); }
+
+    void changeListenerCallback (juce::ChangeBroadcaster*) override { refresh(); }
+
+    void refresh()
+    {
+        list.updateContent();
+        list.repaint();
+        const auto& song = engine.getSong();
+        const auto previous = sourceBox.getSelectedId();
+        sourceBox.clear (juce::dontSendNotification);
+        for (int i = 0; i < (int) song.arrangements.size(); ++i)
+            if (i != song.currentArrangement)
+                sourceBox.addItem (juce::String::fromUTF8 (song.arrangements[(std::size_t) i].name.c_str()), i + 1);
+        if (previous > 0 && previous - 1 != song.currentArrangement && previous <= (int) song.arrangements.size())
+            sourceBox.setSelectedId (previous, juce::dontSendNotification);
+        else if (sourceBox.getNumItems() > 0)
+            sourceBox.setSelectedItemIndex (0, juce::dontSendNotification);
+        mergeButton.setEnabled (sourceBox.getNumItems() > 0);
+        mergeTitle.setText (tr ("Merge into \"{0}\"", { juce::String::fromUTF8 (song.arrangements[(std::size_t) juce::jlimit (0, (int) song.arrangements.size() - 1, song.currentArrangement)].name.c_str()) }));
+        refreshButtons();
+    }
+
+    void refreshButtons()
+    {
+        const auto row = list.getSelectedRow();
+        const auto count = (int) engine.getSong().arrangements.size();
+        selectButton.setEnabled (row >= 0 && row != engine.getSong().currentArrangement);
+        duplicateButton.setEnabled (row >= 0);
+        renameButton.setEnabled (row >= 0);
+        removeButton.setEnabled (row >= 0 && count > 1);
+        upButton.setEnabled (row > 0);
+        downButton.setEnabled (row >= 0 && row < count - 1);
+    }
+
+    void moveBy (int delta)
+    {
+        const auto row = list.getSelectedRow();
+        const auto to = row + delta;
+        if (row < 0 || to < 0 || to >= (int) engine.getSong().arrangements.size())
+            return;
+        engine.editSong ([row, to] (Song& s) { arrangeops::move (s, row, to); });
+        list.selectRow (to);
+    }
+
+    void rename()
+    {
+        const auto row = list.getSelectedRow();
+        if (row < 0)
+            return;
+        auto* w = new juce::AlertWindow (tr ("Rename arrangement"), {}, juce::MessageBoxIconType::NoIcon);
+        w->addTextEditor ("name", juce::String::fromUTF8 (engine.getSong().arrangements[(std::size_t) row].name.c_str()));
+        w->addButton (tr ("OK"), 1, juce::KeyPress (juce::KeyPress::returnKey));
+        w->addButton (tr ("Cancel"), 0, juce::KeyPress (juce::KeyPress::escapeKey));
+        auto* engineRef = &engine;
+        w->enterModalState (true, juce::ModalCallbackFunction::create ([w, row, engineRef] (int result) {
+            if (result == 1)
+            {
+                const auto text = w->getTextEditorContents ("name").trim().toStdString();
+                engineRef->editSong ([row, text] (Song& s) { arrangeops::rename (s, row, text); });
+            }
+        }), true);
+    }
+
+    void mergeNow()
+    {
+        const auto source = sourceBox.getSelectedId() - 1;
+        if (source < 0)
+            return;
+        const auto mode = (arrangeops::MergeMode) juce::jmax (0, modeBox.getSelectedItemIndex());
+        const auto position = (arrangeops::MergePosition) juce::jmax (0, positionBox.getSelectedItemIndex());
+        const auto at = arrangeops::positionTick (engine.getSong(), position, (std::int64_t) engine.getTransport().positionTicks.load());
+        engine.editSong ([source, mode, at] (Song& s) { arrangeops::merge (s, source, mode, at); });
+    }
+
+    AudioEngine& engine;
+    SectionTitle listTitle, mergeTitle;
+    juce::ListBox list;
+    juce::TextButton selectButton { tr ("Show") }, addButton { tr ("New") }, duplicateButton { tr ("Duplicate") }, renameButton { tr ("Rename...") },
+        removeButton { tr ("Remove") }, upButton { tr ("Move up") }, downButton { tr ("Move down") };
+    juce::Label sourceLabel, modeLabel, positionLabel;
+    juce::ComboBox sourceBox, modeBox, positionBox;
+    juce::TextButton mergeButton { tr ("Merge") }, closeButton { tr ("Close") };
+};
+} // namespace
+
+void showClipProperties (AudioEngine& engine, int clip, std::vector<int> selection, std::function<void()> afterEdit)
+{
+    if (clip < 0 || clip >= (int) engine.getSong().playlist.size())
+        return;
+    auto panel = std::make_unique<ClipPropertiesPanel> (engine, clip, std::move (selection), std::move (afterEdit));
+    auto* raw = panel.get();
+    openToolWindow (std::move (panel), tr ("Clip properties"), "clip-properties");
+    raw->resized();
+}
+
+void showArrangements (AudioEngine& engine, bool)
+{
+    openToolWindow (std::make_unique<ArrangementsPanel> (engine), tr ("Arrangements"), "arrangements");
+}
+
+std::unique_ptr<juce::Component> makeClipPropertiesPanel (AudioEngine& engine, int clip, std::vector<int> selection)
+{
+    return std::make_unique<ClipPropertiesPanel> (engine, clip, std::move (selection), std::function<void()> {});
+}
+
+std::unique_ptr<juce::Component> makeArrangementsPanel (AudioEngine& engine)
+{
+    return std::make_unique<ArrangementsPanel> (engine);
+}
+} // namespace lynx

+ 27 - 0
src/ui/ClipProperties.h

@@ -0,0 +1,27 @@
+#pragma once
+
+#include <functional>
+#include <memory>
+#include <vector>
+
+#include <juce_gui_basics/juce_gui_basics.h>
+
+namespace lynx
+{
+class AudioEngine;
+
+// Clip properties (FL's "Clip properties", interpreted; REA_rodada84): the clip's source (pattern / audio file /
+// automation) with its name and colour, track, start, length and offset, mute, and for audio clips gain, fades,
+// pitch and stretch. With several clips selected, mute and gain can change them all. `afterEdit` runs after each
+// change (the Playlist re-sorts its clips).
+void showClipProperties (AudioEngine& engine, int clip, std::vector<int> selection, std::function<void()> afterEdit = {});
+
+// Arrangements (FL's "Merge arrangement", with the arrangement list around it): select, add, duplicate, rename,
+// remove and reorder arrangements, and merge one into the current one (insert / merge / replace at the start, the
+// playback position or the end).
+void showArrangements (AudioEngine& engine, bool mergeFirst = false);
+
+// Panels for --snapshot mode.
+std::unique_ptr<juce::Component> makeClipPropertiesPanel (AudioEngine& engine, int clip, std::vector<int> selection);
+std::unique_ptr<juce::Component> makeArrangementsPanel (AudioEngine& engine);
+} // namespace lynx

+ 398 - 99
src/ui/ExportDialog.cpp

@@ -4,6 +4,7 @@
 #include "engine/Exporter.h"
 #include "engine/Text.h"
 #include "ui/I18n.h"
+#include "ui/SettingsPages.h"
 #include "ui/Theme.h"
 
 namespace lynx
@@ -59,52 +60,56 @@ private:
     bool ok = false;
 };
 
-// Stems: one file per insert that produces sound (like FL's "split mixer tracks"). Each render creates
-// its own engine; plugins are created and destroyed on the UI thread, so the background thread asks it to do that.
+// Stems: one file per insert that produces sound (FL's "split mixer tracks") or per channel that plays (each heard
+// through its mixer path), plus the full mix when asked. Each render creates its own engine; plugins are created and
+// destroyed on the UI thread, so the background thread asks it to do that.
 class StemsThread final : public juce::ThreadWithProgressWindow
 {
 public:
-    StemsThread (const AudioEngine& e, ExportSettings s, juce::File base)
+    StemsThread (const AudioEngine& e, exportopts::Options o, juce::File base)
         : juce::ThreadWithProgressWindow (tr ("Exporting stems..."), true, true),
-          settings (s),
+          options (o),
           baseFile (std::move (base)),
           song (e.getSong())
     {
-        // inserts that receive a channel or a send
-        for (int t = 1; t < (int) song.mixer.size(); ++t)
-        {
-            auto used = std::any_of (song.channels.begin(), song.channels.end(), [t] (const ChannelDef& c) { return c.mixerTrack == t; });
-
-            for (int src = 1; src < (int) song.mixer.size() && ! used; ++src)
-                used = song.routes (src, t) && src != t;
+        const auto ext = exportopts::extension (options.format);
+        const auto baseName = baseFile.getFileNameWithoutExtension().toStdString();
+        auto file = [&] (int number, const std::string& name) {
+            return baseFile.getSiblingFile (juce::String::fromUTF8 (exportopts::stemFileName (baseName, number, name, ext).c_str()));
+        };
 
-            if (used)
-                inserts.push_back (t);
-        }
+        if (options.stemsIncludeMaster)
+            items.push_back ({ juce::String ("Master"), baseFile, song });
+
+        if (options.stems == exportopts::Stems::channels)
+            for (auto c : exportopts::stemChannels (song, options.range))
+                items.push_back ({ juce::String::fromUTF8 (song.channels[(std::size_t) c].name.c_str()), file (c + 1, song.channels[(std::size_t) c].name),
+                                   exportopts::makeChannelStemSong (song, c) });
+        else
+            for (auto t : exportopts::stemTracks (song))
+                items.push_back ({ juce::String::fromUTF8 (song.mixer[(std::size_t) t].name.c_str()), file (t, song.mixer[(std::size_t) t].name),
+                                   makeBounceSong (song, t) });
     }
 
     void run() override
     {
-        for (std::size_t i = 0; i < inserts.size() && ! threadShouldExit(); ++i)
+        for (std::size_t i = 0; i < items.size() && ! threadShouldExit(); ++i)
         {
-            const auto t = inserts[i];
-            const auto name = juce::File::createLegalFileName (juce::String::fromUTF8 (song.mixer[(std::size_t) t].name.c_str()));
-            const auto file = baseFile.getSiblingFile (baseFile.getFileNameWithoutExtension() + " - " + juce::String (t) + " " + name
-                                                       + exportExtension (settings.format));
-            setStatusMessage (name);
+            auto& item = items[i];
+            setStatusMessage (item.name);
 
             std::unique_ptr<ExportJob> job;
             juce::WaitableEvent ready;
             juce::MessageManager::callAsync ([&] {
-                job = std::make_unique<ExportJob> (makeBounceSong (song, t), settings, file);
+                job = std::make_unique<ExportJob> (item.song, options, item.file);
                 ready.signal();
             });
             ready.wait();
 
             juce::String error;
-            const auto base = (double) i / (double) inserts.size();
+            const auto base = (double) i / (double) items.size();
             const auto ok = job->run ([this, base] (double p) {
-                setProgress (base + p / (double) inserts.size());
+                setProgress (base + p / (double) items.size());
                 return ! threadShouldExit();
             }, error);
 
@@ -130,76 +135,255 @@ public:
     }
 
 private:
-    ExportSettings settings;
+    struct Item
+    {
+        juce::String name;
+        juce::File file;
+        Song song;
+    };
+    exportopts::Options options;
     juce::File baseFile;
     Song song;
-    std::vector<int> inserts;
+    std::vector<Item> items;
     int written = 0;
 };
 
+juce::File exportSettingsFile()
+{
+    return juce::File::getSpecialLocation (juce::File::userApplicationDataDirectory).getChildFile ("LYNX/export-settings.txt");
+}
+
+// A row of buttons where exactly one is on (the output format).
+class Segmented final : public juce::Component
+{
+public:
+    std::function<void (int)> onChange;
+
+    explicit Segmented (const juce::StringArray& names)
+    {
+        for (int i = 0; i < names.size(); ++i)
+        {
+            auto* b = buttons.add (new juce::TextButton (names[i]));
+            b->setClickingTogglesState (true);
+            b->setRadioGroupId (8401);
+            b->setConnectedEdges ((i > 0 ? juce::Button::ConnectedOnLeft : 0) | (i < names.size() - 1 ? juce::Button::ConnectedOnRight : 0));
+            b->setColour (juce::TextButton::buttonColourId, theme::colour::bg4);
+            b->setColour (juce::TextButton::buttonOnColourId, theme::colour::accent);
+            b->setColour (juce::TextButton::textColourOnId, theme::colour::onAccent);
+            b->onClick = [this, i] {
+                if (buttons[i]->getToggleState() && onChange)
+                    onChange (i);
+            };
+            addAndMakeVisible (b);
+        }
+    }
+
+    void setSelected (int index) { if (auto* b = buttons[index]) b->setToggleState (true, juce::dontSendNotification); }
+    int getSelected() const
+    {
+        for (int i = 0; i < buttons.size(); ++i)
+            if (buttons[i]->getToggleState())
+                return i;
+        return 0;
+    }
+
+    void resized() override
+    {
+        const auto w = (float) getWidth() / (float) juce::jmax (1, buttons.size());
+        for (int i = 0; i < buttons.size(); ++i)
+            buttons[i]->setBounds (juce::roundToInt (w * (float) i), 0, juce::roundToInt (w * (float) (i + 1)) - juce::roundToInt (w * (float) i), getHeight());
+    }
+
+private:
+    juce::OwnedArray<juce::TextButton> buttons;
+};
+
+// The Export window (FL's "WAV rendering", interpreted; REA_rodada84): what to render on the left, the file format on
+// the right, mix options below; the choices are remembered (%APPDATA%\LYNX\export-settings.txt).
 class ExportPanel final : public juce::Component
 {
 public:
-    ExportPanel (AudioEngine& e, juce::File folder, juce::String name)
+    ExportPanel (AudioEngine& e, juce::File folder, juce::String name, bool remember)
         : engine (e),
           suggestedFolder (std::move (folder)),
-          suggestedName (std::move (name))
+          suggestedName (std::move (name)),
+          persistent (remember)
     {
-        formatBox.addItemList ({ tr ("WAV 16 bits"), tr ("WAV 24 bits"), tr ("WAV 32 bits (float)"), tr ("FLAC 24 bits"), "OGG Vorbis" }, 1);
-        formatBox.setSelectedItemIndex (lastFormat, juce::dontSendNotification);
-        rateBox.addItemList ({ "44100 Hz", "48000 Hz", "88200 Hz", "96000 Hz" }, 1);
-        rateBox.setSelectedItemIndex (lastRate, juce::dontSendNotification);
-        whatBox.addItem (tr ("Full song (Playlist)"), 1);
-        whatBox.addItem (tr ("Current pattern"), 2);
-        whatBox.setSelectedItemIndex (engine.getSong().mode == PlayMode::song && ! engine.getSong().playlist.empty() ? 0 : 1,
-                                      juce::dontSendNotification);
-        tailBox.addItemList ({ tr ("No tail"), tr ("Tail up to {0} s", { "3" }), tr ("Tail up to {0} s", { "6" }), tr ("Tail up to {0} s", { "12" }) }, 1);
-        tailBox.setSelectedItemIndex (lastTail, juce::dontSendNotification);
-
-        for (auto* l : { &formatLabel, &rateLabel, &whatLabel, &tailLabel })
-            addAndMakeVisible (l);
-
-        formatLabel.setText (tr ("Format"), juce::dontSendNotification);
-        rateLabel.setText (tr ("Sample rate"), juce::dontSendNotification);
-        whatLabel.setText (tr ("Export"), juce::dontSendNotification);
-        tailLabel.setText (tr ("Tail"), juce::dontSendNotification);
-
-        for (auto* c : { &formatBox, &rateBox, &whatBox, &tailBox })
-            addAndMakeVisible (c);
-
-        stemsToggle.setButtonText (tr ("One file per mixer insert (stems)"));
-        for (auto* l : { &formatLabel, &rateLabel, &whatLabel, &tailLabel })
-            l->setColour (juce::Label::textColourId, theme::colour::textSecondary);
+        using namespace exportopts;
+        if (persistent)
+            options = fromText (exportSettingsFile().loadFileAsString().toStdString());
+        const auto& song = engine.getSong();
+        // the range follows what is playing unless a selection was the last choice and still exists
+        if (options.range != Range::selection || ! hasSelection (song))
+            options.range = song.mode == PlayMode::song && ! song.playlist.empty() ? Range::song : Range::pattern;
+
+        for (auto* t : { &whatTitle, &formatTitle, &optionsTitle })
+            addAndMakeVisible (t);
+        whatTitle.setText (tr ("What to render"));
+        formatTitle.setText (tr ("Output format"));
+        optionsTitle.setText (tr ("Mix"));
+
+        auto combo = [this] (juce::Label& label, const juce::String& text, juce::ComboBox& box, const juce::StringArray& items, const juce::String& tip = {}) {
+            settingsui::styleLabel (label, text);
+            addAndMakeVisible (label);
+            box.addItemList (items, 1);
+            box.setTooltip (tip);
+            box.onChange = [this] { readControls(); };
+            addAndMakeVisible (box);
+        };
+
+        combo (rangeLabel, tr ("Range"), rangeBox, { tr ("Song (Playlist)"), tr ("Current pattern"), tr ("Playlist selection") },
+               tr ("What is rendered: the arrangement, the current pattern, or the Playlist's time selection"));
+        rangeBox.setItemEnabled (3, hasSelection (song));
+        juce::StringArray loopItems;
+        for (int i = 1; i <= 16; ++i)
+            loopItems.add (i == 1 ? tr ("Once") : tr ("{0} times", { juce::String (i) }));
+        combo (loopsLabel, tr ("Play"), loopsBox, loopItems, tr ("How many times the range plays in the file"));
+        combo (tailLabel, tr ("Tail"), tailBox, { tr ("Cut remainder"), tr ("Leave remainder"), tr ("Wrap remainder") },
+               tr ("Cut: stop exactly at the end (loops). Leave: let reverbs and releases ring out (songs). Wrap: mix the tail into the start (seamless loops)"));
+        combo (tailLengthLabel, tr ("Longest tail"), tailLengthBox, { "3 s", "6 s", "12 s", "30 s" }, tr ("The tail stops earlier when the sound has faded out"));
+        combo (stemsLabel, tr ("Files"), stemsBox, { tr ("One file (the mix)"), tr ("One per mixer insert (stems)"), tr ("One per channel (stems)") },
+               tr ("Stems: a file for each mixer insert that gets sound, or for each channel that plays"));
+        stemsMaster.setButtonText (tr ("Also the full mix"));
+        stemsMaster.onClick = [this] { readControls(); };
+        addAndMakeVisible (stemsMaster);
+
+        formatButtons.onChange = [this] (int) { readControls(); };
+        addAndMakeVisible (formatButtons);
+        combo (depthLabel, tr ("Bit depth"), depthBox, { tr ("16 bits (integer)"), tr ("24 bits (integer)"), tr ("32 bits (float)") });
+        juce::StringArray mp3Items, oggItems;
+        for (auto k : mp3Bitrates())
+            mp3Items.add (juce::String (k) + " kbps");
+        for (auto k : oggBitrates())
+            oggItems.add (juce::String (k) + " kbps");
+        combo (bitrateLabel, tr ("Bitrate"), mp3Box, mp3Items, tr ("Constant bitrate (higher: better sound, bigger file)"));
+        addAndMakeVisible (oggBox);
+        oggBox.addItemList (oggItems, 1);
+        oggBox.onChange = [this] { readControls(); };
+        combo (compressionLabel, tr ("Compression"), flacLevelBox,
+               { tr ("0 (fastest)"), "1", "2", "3", "4", tr ("5 (default)"), "6", "7", tr ("8 (smallest)") },
+               tr ("FLAC is lossless at every level; higher levels make smaller files and take longer"));
+        juce::StringArray rateItems;
+        for (auto r : sampleRates())
+            rateItems.add (juce::String ((int) r) + " Hz");
+        combo (rateLabel, tr ("Sample rate"), rateBox, rateItems);
+        combo (channelsLabel, tr ("Channels"), channelsBox, { tr ("Stereo"), tr ("Mono (both sides mixed)"), tr ("Mono (left only)"), tr ("Mono (right only)") });
+        combo (ditherLabel, tr ("Dither"), ditherBox, { tr ("Off"), tr ("TPDF"), tr ("TPDF + noise shaping") },
+               tr ("Hides the rounding noise of 16 and 24 bit files (noise shaping moves it where the ear is least sensitive)"));
+
+        for (auto* t : { &normalizeToggle, &masterFxToggle, &trimToggle })
+        {
+            t->onClick = [this] { readControls(); };
+            addAndMakeVisible (t);
+        }
+        normalizeToggle.setButtonText (tr ("Normalize (peak to 0 dB)"));
+        masterFxToggle.setButtonText (tr ("Master effects"));
+        trimToggle.setButtonText (tr ("Trim the delay compensation's silence"));
+        normalizeToggle.setTooltip (tr ("Raises or lowers the whole file so its loudest peak reaches full scale"));
+        masterFxToggle.setTooltip (tr ("Off: the Master insert's effects are bypassed for the export"));
+        trimToggle.setTooltip (tr ("Removes the silence plugin latency compensation adds at the start"));
+
+        infoLabel.setFont (theme::font (theme::type::small));
+        infoLabel.setColour (juce::Label::textColourId, theme::colour::textSecondary);
+        addAndMakeVisible (infoLabel);
+        warningLabel.setFont (theme::font (theme::type::small));
+        warningLabel.setColour (juce::Label::textColourId, theme::colour::warning);
+        addAndMakeVisible (warningLabel);
+
         exportButton.setColour (juce::TextButton::buttonColourId, theme::colour::accent);
         exportButton.setColour (juce::TextButton::textColourOffId, theme::colour::onAccent);
-        addAndMakeVisible (stemsToggle);
         addAndMakeVisible (exportButton);
         addAndMakeVisible (cancelButton);
         exportButton.onClick = [this] { chooseFile(); };
         cancelButton.onClick = [this] { close(); };
-        setSize (380, 252);
+
+        writeControls();
+        setSize (620, 452);
+    }
+
+    // --snapshot: the window with this format chosen (0 WAV, 1 MP3, 2 OGG, 3 FLAC) and a few options set
+    void setFormatForSnapshot (int format)
+    {
+        options.format = (exportopts::Format) juce::jlimit (0, 3, format);
+        if (format == 3)
+        {
+            options.tail = exportopts::TailMode::wrap;
+            options.loops = 2;
+            options.stems = exportopts::Stems::mixerTracks;
+            options.stemsIncludeMaster = true;
+            options.normalize = true;
+        }
+        writeControls();
     }
 
     void resized() override
     {
-        auto area = getLocalBounds().reduced (14);
-        auto row = [&area] (juce::Label& l, juce::ComboBox& c) {
-            auto r = area.removeFromTop (28);
-            l.setBounds (r.removeFromLeft (96));
-            c.setBounds (r);
-            area.removeFromTop (8);
+        auto area = getLocalBounds().reduced (16, 12);
+        auto buttons = area.removeFromBottom (32);
+        cancelButton.setBounds (buttons.removeFromRight (96));
+        buttons.removeFromRight (8);
+        exportButton.setBounds (buttons.removeFromRight (128));
+        infoLabel.setBounds (buttons.removeFromTop (16));
+        warningLabel.setBounds (buttons);
+        area.removeFromBottom (8);
+
+        auto mix = area.removeFromBottom (58);
+        optionsTitle.setBounds (mix.removeFromTop (26));
+        mix.removeFromTop (4);
+        auto mixRow = mix.removeFromTop (24);
+        normalizeToggle.setBounds (mixRow.removeFromLeft (200));
+        masterFxToggle.setBounds (mixRow.removeFromLeft (150));
+        trimToggle.setBounds (mixRow);
+        area.removeFromBottom (6);
+
+        auto left = area.removeFromLeft ((area.getWidth() - 24) / 2);
+        area.removeFromLeft (24);
+        auto right = area;
+        constexpr int labelWidth = 92, rowHeight = 26, gap = 7;
+
+        auto row = [&] (juce::Rectangle<int>& column, juce::Label& label, juce::Component& control) {
+            auto r = column.removeFromTop (rowHeight);
+            label.setBounds (r.removeFromLeft (labelWidth));
+            control.setBounds (r);
+            column.removeFromTop (gap);
         };
 
-        row (whatLabel, whatBox);
-        row (formatLabel, formatBox);
-        row (rateLabel, rateBox);
-        row (tailLabel, tailBox);
-        stemsToggle.setBounds (area.removeFromTop (24));
+        whatTitle.setBounds (left.removeFromTop (26));
+        left.removeFromTop (8);
+        row (left, rangeLabel, rangeBox);
+        row (left, loopsLabel, loopsBox);
+        row (left, tailLabel, tailBox);
+        row (left, tailLengthLabel, tailLengthBox);
+        row (left, stemsLabel, stemsBox);
+        stemsMaster.setBounds (left.removeFromTop (22).withTrimmedLeft (labelWidth));
+
+        formatTitle.setBounds (right.removeFromTop (26));
+        right.removeFromTop (8);
+        formatButtons.setBounds (right.removeFromTop (28));
+        right.removeFromTop (gap + 2);
+        // the format's own settings: two rows, the others hidden
+        using exportopts::Format;
+        const auto f = options.format;
+        if (f == Format::wav || f == Format::flac)
+            row (right, depthLabel, depthBox);
+        if (f == Format::mp3)
+            row (right, bitrateLabel, mp3Box);
+        if (f == Format::ogg)
+            row (right, bitrateLabel, oggBox);
+        if (f == Format::flac)
+            row (right, compressionLabel, flacLevelBox);
+        row (right, rateLabel, rateBox);
+        row (right, channelsLabel, channelsBox);
+        row (right, ditherLabel, ditherBox);
+    }
 
-        auto buttons = area.removeFromBottom (30);
-        cancelButton.setBounds (buttons.removeFromRight (100));
-        buttons.removeFromRight (8);
-        exportButton.setBounds (buttons.removeFromRight (120));
+    void paint (juce::Graphics& g) override
+    {
+        g.fillAll (theme::colour::bg2);
+        // a hairline between the two columns
+        const auto x = 16 + (getWidth() - 32 - 24) / 2 + 12;
+        g.setColour (theme::colour::border);
+        g.fillRect (x, 22, 1, getHeight() - 22 - 12 - 32 - 8 - 58 - 6 - 8);
     }
 
 private:
@@ -209,36 +393,144 @@ private:
             w->exitModalState (0);
     }
 
-    ExportSettings settings() const
+    static int indexOf (const std::vector<int>& list, int value)
+    {
+        for (int i = 0; i < (int) list.size(); ++i)
+            if (list[(std::size_t) i] == value)
+                return i;
+        return 0;
+    }
+
+    void writeControls()
+    {
+        using namespace exportopts;
+        const auto n = juce::dontSendNotification;
+        rangeBox.setSelectedItemIndex ((int) options.range, n);
+        loopsBox.setSelectedItemIndex (options.loops - 1, n);
+        tailBox.setSelectedItemIndex ((int) options.tail, n);
+        const double tails[] = { 3.0, 6.0, 12.0, 30.0 };
+        int tailIndex = 0;
+        for (int i = 0; i < 4; ++i)
+            if (std::abs (tails[i] - options.maxTailSeconds) < std::abs (tails[tailIndex] - options.maxTailSeconds))
+                tailIndex = i;
+        tailLengthBox.setSelectedItemIndex (tailIndex, n);
+        stemsBox.setSelectedItemIndex ((int) options.stems, n);
+        stemsMaster.setToggleState (options.stemsIncludeMaster, n);
+        formatButtons.setSelected ((int) options.format);
+        depthBox.setSelectedItemIndex (options.format == Format::flac ? (options.flacBits == 16 ? 0 : 1) : (options.wavBits == 16 ? 0 : options.wavBits == 24 ? 1 : 2), n);
+        mp3Box.setSelectedItemIndex (indexOf (mp3Bitrates(), options.mp3Kbps), n);
+        oggBox.setSelectedItemIndex (indexOf (oggBitrates(), options.oggKbps), n);
+        flacLevelBox.setSelectedItemIndex (options.flacLevel, n);
+        int rate = 0;
+        for (int i = 0; i < (int) sampleRates().size(); ++i)
+            if (sampleRates()[(std::size_t) i] == options.sampleRate)
+                rate = i;
+        rateBox.setSelectedItemIndex (rate, n);
+        channelsBox.setSelectedItemIndex ((int) options.channels, n);
+        ditherBox.setSelectedItemIndex ((int) options.dither, n);
+        normalizeToggle.setToggleState (options.normalize, n);
+        masterFxToggle.setToggleState (options.masterEffects, n);
+        trimToggle.setToggleState (options.trimPdc, n);
+        refresh();
+    }
+
+    void readControls()
+    {
+        using namespace exportopts;
+        const auto previousFormat = options.format;
+        options.range = (Range) juce::jmax (0, rangeBox.getSelectedItemIndex());
+        options.loops = loopsBox.getSelectedItemIndex() + 1;
+        options.tail = (TailMode) juce::jmax (0, tailBox.getSelectedItemIndex());
+        const double tails[] = { 3.0, 6.0, 12.0, 30.0 };
+        options.maxTailSeconds = tails[juce::jlimit (0, 3, tailLengthBox.getSelectedItemIndex())];
+        options.stems = (Stems) juce::jmax (0, stemsBox.getSelectedItemIndex());
+        options.stemsIncludeMaster = stemsMaster.getToggleState();
+        options.format = (Format) formatButtons.getSelected();
+        if (options.format == previousFormat)
+        {
+            const auto depth = depthBox.getSelectedItemIndex();
+            if (options.format == Format::flac)
+                options.flacBits = depth == 0 ? 16 : 24;
+            else
+                options.wavBits = depth == 0 ? 16 : depth == 1 ? 24 : 32;
+        }
+        options.mp3Kbps = mp3Bitrates()[(std::size_t) juce::jlimit (0, (int) mp3Bitrates().size() - 1, mp3Box.getSelectedItemIndex())];
+        options.oggKbps = oggBitrates()[(std::size_t) juce::jlimit (0, (int) oggBitrates().size() - 1, oggBox.getSelectedItemIndex())];
+        options.flacLevel = juce::jlimit (0, 8, flacLevelBox.getSelectedItemIndex());
+        options.sampleRate = sampleRates()[(std::size_t) juce::jlimit (0, (int) sampleRates().size() - 1, rateBox.getSelectedItemIndex())];
+        options.channels = (Channels) juce::jmax (0, channelsBox.getSelectedItemIndex());
+        options.dither = (DitherMode) juce::jmax (0, ditherBox.getSelectedItemIndex());
+        options.normalize = normalizeToggle.getToggleState();
+        options.masterEffects = masterFxToggle.getToggleState();
+        options.trimPdc = trimToggle.getToggleState();
+        options = clamped (options);
+
+        if (options.format != previousFormat)
+            writeControls(); // the bit depth list changes with the format
+        else
+            refresh();
+    }
+
+    void refresh()
     {
-        static const double rates[] = { 44100.0, 48000.0, 88200.0, 96000.0 };
-        static const double tails[] = { 0.0, 3.0, 6.0, 12.0 };
-        ExportSettings s;
-        s.format = (ExportSettings::Format) juce::jlimit (0, 4, formatBox.getSelectedItemIndex());
-        s.sampleRate = rates[juce::jlimit (0, 3, rateBox.getSelectedItemIndex())];
-        s.wholeSong = whatBox.getSelectedItemIndex() == 0;
-        s.tailSeconds = tails[juce::jlimit (0, 3, tailBox.getSelectedItemIndex())];
-        return s;
+        using namespace exportopts;
+        // the depth list: FLAC has no float
+        depthBox.setItemEnabled (3, options.format == Format::wav);
+        tailLengthBox.setEnabled (options.tail != TailMode::cut);
+        stemsMaster.setEnabled (options.stems != Stems::none);
+        loopsBox.setEnabled (true);
+        const auto ditherable = (options.format == Format::wav && options.wavBits != 32) || options.format == Format::flac;
+        ditherBox.setEnabled (ditherable);
+        ditherLabel.setEnabled (ditherable);
+        const auto f = options.format;
+        depthLabel.setVisible (f == Format::wav || f == Format::flac);
+        depthBox.setVisible (f == Format::wav || f == Format::flac);
+        bitrateLabel.setVisible (f == Format::mp3 || f == Format::ogg);
+        mp3Box.setVisible (f == Format::mp3);
+        oggBox.setVisible (f == Format::ogg);
+        compressionLabel.setVisible (f == Format::flac);
+        flacLevelBox.setVisible (f == Format::flac);
+
+        const auto& song = engine.getSong();
+        const auto seconds = exportMusicSeconds (song, options);
+        auto info = tr ("Total time: {0}", { juce::String (formatDuration (seconds)) });
+        if (options.tail == TailMode::leave)
+            info << " " << tr ("(+ tail up to {0} s)", { juce::String ((int) options.maxTailSeconds) });
+        if (options.format == Format::mp3 && mp3SampleRate (options.sampleRate) != options.sampleRate)
+            info << "  ·  " << tr ("MP3 at {0} Hz", { juce::String ((int) mp3SampleRate (options.sampleRate)) });
+        if (options.stems == Stems::mixerTracks)
+            info << "  ·  " << tr ("{0} file(s)", { juce::String ((int) stemTracks (song).size() + (options.stemsIncludeMaster ? 1 : 0)) });
+        else if (options.stems == Stems::channels)
+            info << "  ·  " << tr ("{0} file(s)", { juce::String ((int) stemChannels (song, options.range).size() + (options.stemsIncludeMaster ? 1 : 0)) });
+        infoLabel.setText (info, juce::dontSendNotification);
+
+        juce::String warning;
+        if (! song.mixer.empty() && song.mixer[0].muted)
+            warning = tr ("The Master insert is muted: the file will be silent");
+        else if (options.range == Range::selection && ! hasSelection (song))
+            warning = tr ("There is no Playlist selection: the whole song is rendered");
+        warningLabel.setText (warning, juce::dontSendNotification);
+        resized();
+        repaint();
     }
 
     void chooseFile()
     {
-        lastFormat = formatBox.getSelectedItemIndex();
-        lastRate = rateBox.getSelectedItemIndex();
-        lastTail = tailBox.getSelectedItemIndex();
+        readControls();
+        if (persistent)
+            exportSettingsFile().replaceWithText (juce::String (exportopts::toText (options)));
 
-        const auto s = settings();
-        const auto extension = exportExtension (s.format);
+        const auto o = options;
+        const auto extension = juce::String (exportopts::extension (o.format));
         auto folder = lastFolder.isDirectory() ? lastFolder
                       : suggestedFolder.isDirectory() ? suggestedFolder
                                                       : juce::File::getSpecialLocation (juce::File::userMusicDirectory);
 
-        chooser = std::make_unique<juce::FileChooser> (tr ("Export audio"), folder.getChildFile (suggestedName + extension),
-                                                       "*" + extension);
+        chooser = std::make_unique<juce::FileChooser> (tr ("Export audio"), folder.getChildFile (suggestedName + extension), "*" + extension);
         auto& engineRef = engine;
 
         chooser->launchAsync (juce::FileBrowserComponent::saveMode | juce::FileBrowserComponent::warnAboutOverwriting,
-                              [this, s, extension, &engineRef] (const juce::FileChooser& fc) {
+                              [this, o, extension, &engineRef] (const juce::FileChooser& fc) {
                                   auto file = fc.getResult();
 
                                   if (file == juce::File())
@@ -250,16 +542,14 @@ private:
                                   lastFolder = file.getParentDirectory();
                                   engineRef.capturePluginStates(); // the copy carries the current plugin state
 
-                                  if (stemsToggle.getToggleState())
+                                  if (o.stems != exportopts::Stems::none)
                                   {
-                                      auto stemSettings = s;
-                                      stemSettings.wholeSong = true;
                                       close();
-                                      (new StemsThread (engineRef, stemSettings, file))->launchThread();
+                                      (new StemsThread (engineRef, o, file))->launchThread();
                                       return;
                                   }
 
-                                  auto job = std::make_unique<ExportJob> (engineRef.getSong(), s, file);
+                                  auto job = std::make_unique<ExportJob> (engineRef.getSong(), o, file);
                                   close(); // deletes this panel: no `this` after this point
                                   (new ExportThread (std::move (job), file))->launchThread();
                               });
@@ -268,14 +558,21 @@ private:
     AudioEngine& engine;
     juce::File suggestedFolder;
     juce::String suggestedName;
-    juce::Label formatLabel, rateLabel, whatLabel, tailLabel;
-    juce::ComboBox formatBox, rateBox, whatBox, tailBox;
+    bool persistent = true;
+    exportopts::Options options;
+
+    settingsui::SectionTitle whatTitle, formatTitle, optionsTitle;
+    juce::Label rangeLabel, loopsLabel, tailLabel, tailLengthLabel, stemsLabel;
+    juce::ComboBox rangeBox, loopsBox, tailBox, tailLengthBox, stemsBox;
+    juce::ToggleButton stemsMaster;
+    Segmented formatButtons { { "WAV", "MP3", "OGG", "FLAC" } };
+    juce::Label depthLabel, bitrateLabel, compressionLabel, rateLabel, channelsLabel, ditherLabel;
+    juce::ComboBox depthBox, mp3Box, oggBox, flacLevelBox, rateBox, channelsBox, ditherBox;
+    juce::ToggleButton normalizeToggle, masterFxToggle, trimToggle;
+    juce::Label infoLabel, warningLabel;
     juce::TextButton exportButton { tr ("Export...") }, cancelButton { tr ("Cancel") };
-    juce::ToggleButton stemsToggle;
     std::unique_ptr<juce::FileChooser> chooser;
 
-    // remembers the last choice while the app is open
-    static inline int lastFormat = 1, lastRate = 0, lastTail = 2;
     static inline juce::File lastFolder;
 };
 } // namespace
@@ -313,15 +610,17 @@ void bounceInsertToAudio (AudioEngine& engine, int track)
     }, tr ("Rendering insert to audio...")))->launchThread();
 }
 
-std::unique_ptr<juce::Component> makeExportPanel (AudioEngine& engine)
+std::unique_ptr<juce::Component> makeExportPanel (AudioEngine& engine, int format)
 {
-    return std::make_unique<ExportPanel> (engine, juce::File(), "LYNX");
+    auto panel = std::make_unique<ExportPanel> (engine, juce::File(), "LYNX", false);
+    panel->setFormatForSnapshot (format);
+    return panel;
 }
 
 void showExportDialog (AudioEngine& engine, const juce::File& suggestedFolder, const juce::String& suggestedName)
 {
     juce::DialogWindow::LaunchOptions options;
-    options.content.setOwned (new ExportPanel (engine, suggestedFolder, suggestedName.isNotEmpty() ? suggestedName : "LYNX"));
+    options.content.setOwned (new ExportPanel (engine, suggestedFolder, suggestedName.isNotEmpty() ? suggestedName : "LYNX", true));
     options.dialogTitle = tr ("Export audio");
     options.dialogBackgroundColour = theme::colour::bg2;
     options.useNativeTitleBar = true;

+ 2 - 2
src/ui/ExportDialog.h

@@ -12,6 +12,6 @@ void showExportDialog (AudioEngine& engine, const juce::File& suggestedFolder, c
 // routing, and the original is muted. Runs on a background thread with progress.
 void bounceInsertToAudio (AudioEngine& engine, int track);
 
-// Panel only (for --snapshot mode).
-std::unique_ptr<juce::Component> makeExportPanel (AudioEngine& engine);
+// Panel only (for --snapshot mode; `format`: 0 WAV, 1 MP3, 2 OGG, 3 FLAC with loop/stem options set). Nothing is saved.
+std::unique_ptr<juce::Component> makeExportPanel (AudioEngine& engine, int format = 0);
 } // namespace lynx

+ 400 - 1
src/ui/I18nData.h

@@ -4246,6 +4246,405 @@ inline constexpr unsigned char ptBR[] = {
 114, 115, 116, 41, 34, 32, 61, 32, 34, 40, 97, 98, 114, 97, 32, 117, 109, 32, 100, 105, 115, 112, 111, 115,
 105, 116, 105, 118, 111, 32, 100, 101, 32, 115, 97, 195, 173, 100, 97, 32, 97, 110, 116, 101, 115, 41, 34, 10,
 34, 40, 99, 104, 111, 111, 115, 101, 41, 34, 32, 61, 32, 34, 40, 101, 115, 99, 111, 108, 104, 97, 41, 34,
-10,
+10, 10, 35, 32, 45, 45, 45, 32, 82, 111, 117, 110, 100, 32, 56, 52, 58, 32, 69, 120, 112, 111, 114, 116,
+32, 111, 112, 116, 105, 111, 110, 115, 44, 32, 78, 101, 119, 32, 112, 114, 111, 106, 101, 99, 116, 44, 32, 67,
+108, 105, 112, 32, 112, 114, 111, 112, 101, 114, 116, 105, 101, 115, 44, 32, 65, 114, 114, 97, 110, 103, 101, 109,
+101, 110, 116, 115, 44, 32, 80, 108, 117, 103, 105, 110, 32, 112, 101, 114, 102, 111, 114, 109, 97, 110, 99, 101,
+32, 109, 111, 110, 105, 116, 111, 114, 44, 32, 84, 111, 117, 99, 104, 32, 107, 101, 121, 98, 111, 97, 114, 100,
+10, 34, 83, 111, 117, 114, 99, 101, 34, 32, 61, 32, 34, 79, 114, 105, 103, 101, 109, 34, 10, 34, 84, 105,
+109, 101, 34, 32, 61, 32, 34, 84, 101, 109, 112, 111, 34, 10, 34, 65, 108, 108, 32, 123, 48, 125, 32, 115,
+101, 108, 101, 99, 116, 101, 100, 32, 99, 108, 105, 112, 115, 34, 32, 61, 32, 34, 84, 111, 100, 111, 115, 32,
+111, 115, 32, 123, 48, 125, 32, 99, 108, 105, 112, 101, 115, 32, 115, 101, 108, 101, 99, 105, 111, 110, 97, 100,
+111, 115, 34, 10, 34, 85, 115, 101, 115, 34, 32, 61, 32, 34, 85, 115, 97, 34, 10, 34, 84, 114, 97, 99,
+107, 34, 32, 61, 32, 34, 70, 97, 105, 120, 97, 34, 10, 34, 98, 97, 114, 58, 98, 101, 97, 116, 58, 116,
+105, 99, 107, 32, 40, 49, 58, 49, 58, 48, 48, 48, 32, 105, 115, 32, 116, 104, 101, 32, 115, 116, 97, 114,
+116, 32, 111, 102, 32, 116, 104, 101, 32, 115, 111, 110, 103, 41, 34, 32, 61, 32, 34, 99, 111, 109, 112, 97,
+115, 115, 111, 58, 116, 101, 109, 112, 111, 58, 116, 105, 99, 107, 32, 40, 49, 58, 49, 58, 48, 48, 48, 32,
+195, 169, 32, 111, 32, 105, 110, 195, 173, 99, 105, 111, 32, 100, 97, 32, 109, 195, 186, 115, 105, 99, 97, 41,
+34, 10, 34, 98, 97, 114, 115, 58, 98, 101, 97, 116, 115, 58, 116, 105, 99, 107, 115, 34, 32, 61, 32, 34,
+99, 111, 109, 112, 97, 115, 115, 111, 115, 58, 116, 101, 109, 112, 111, 115, 58, 116, 105, 99, 107, 115, 34, 10,
+34, 72, 111, 119, 32, 109, 117, 99, 104, 32, 111, 102, 32, 116, 104, 101, 32, 115, 111, 117, 114, 99, 101, 39,
+115, 32, 115, 116, 97, 114, 116, 32, 105, 115, 32, 115, 107, 105, 112, 112, 101, 100, 32, 40, 98, 97, 114, 115,
+58, 98, 101, 97, 116, 115, 58, 116, 105, 99, 107, 115, 41, 34, 32, 61, 32, 34, 81, 117, 97, 110, 116, 111,
+32, 100, 111, 32, 105, 110, 195, 173, 99, 105, 111, 32, 100, 97, 32, 111, 114, 105, 103, 101, 109, 32, 195, 169,
+32, 112, 117, 108, 97, 100, 111, 32, 40, 99, 111, 109, 112, 97, 115, 115, 111, 115, 58, 116, 101, 109, 112, 111,
+115, 58, 116, 105, 99, 107, 115, 41, 34, 10, 34, 77, 117, 116, 101, 100, 34, 32, 61, 32, 34, 77, 117, 100,
+111, 34, 10, 34, 71, 97, 105, 110, 34, 32, 61, 32, 34, 71, 97, 110, 104, 111, 34, 10, 34, 84, 104, 101,
+32, 97, 117, 100, 105, 111, 32, 99, 104, 97, 110, 110, 101, 108, 39, 115, 32, 112, 105, 116, 99, 104, 58, 32,
+101, 118, 101, 114, 121, 32, 99, 108, 105, 112, 32, 111, 102, 32, 116, 104, 105, 115, 32, 102, 105, 108, 101, 32,
+102, 111, 108, 108, 111, 119, 115, 32, 105, 116, 34, 32, 61, 32, 34, 65, 32, 97, 102, 105, 110, 97, 195, 167,
+195, 163, 111, 32, 100, 111, 32, 99, 97, 110, 97, 108, 32, 100, 101, 32, 195, 161, 117, 100, 105, 111, 58, 32,
+116, 111, 100, 111, 115, 32, 111, 115, 32, 99, 108, 105, 112, 101, 115, 32, 100, 101, 115, 116, 101, 32, 97, 114,
+113, 117, 105, 118, 111, 32, 97, 32, 115, 101, 103, 117, 101, 109, 34, 10, 34, 70, 97, 100, 101, 32, 105, 110,
+34, 32, 61, 32, 34, 70, 97, 100, 101, 32, 105, 110, 34, 10, 34, 70, 97, 100, 101, 32, 111, 117, 116, 34,
+32, 61, 32, 34, 70, 97, 100, 101, 32, 111, 117, 116, 34, 10, 34, 83, 116, 114, 101, 116, 99, 104, 32, 116,
+111, 34, 32, 61, 32, 34, 69, 115, 116, 105, 99, 97, 114, 32, 112, 97, 114, 97, 34, 10, 34, 48, 58, 32,
+116, 104, 101, 32, 102, 105, 108, 101, 32, 112, 108, 97, 121, 115, 32, 97, 116, 32, 105, 116, 115, 32, 111, 119,
+110, 32, 115, 112, 101, 101, 100, 59, 32, 111, 116, 104, 101, 114, 119, 105, 115, 101, 32, 116, 104, 101, 32, 119,
+104, 111, 108, 101, 32, 102, 105, 108, 101, 32, 108, 97, 115, 116, 115, 32, 116, 104, 105, 115, 32, 109, 97, 110,
+121, 32, 98, 101, 97, 116, 115, 32, 97, 116, 32, 116, 104, 101, 32, 112, 114, 111, 106, 101, 99, 116, 32, 116,
+101, 109, 112, 111, 34, 32, 61, 32, 34, 48, 58, 32, 111, 32, 97, 114, 113, 117, 105, 118, 111, 32, 116, 111,
+99, 97, 32, 110, 97, 32, 112, 114, 195, 179, 112, 114, 105, 97, 32, 118, 101, 108, 111, 99, 105, 100, 97, 100,
+101, 59, 32, 115, 101, 110, 195, 163, 111, 32, 111, 32, 97, 114, 113, 117, 105, 118, 111, 32, 105, 110, 116, 101,
+105, 114, 111, 32, 100, 117, 114, 97, 32, 101, 115, 115, 101, 32, 110, 195, 186, 109, 101, 114, 111, 32, 100, 101,
+32, 116, 101, 109, 112, 111, 115, 32, 110, 111, 32, 66, 80, 77, 32, 100, 111, 32, 112, 114, 111, 106, 101, 116,
+111, 34, 10, 34, 75, 101, 101, 112, 32, 116, 104, 101, 32, 112, 105, 116, 99, 104, 34, 32, 61, 32, 34, 77,
+97, 110, 116, 101, 114, 32, 97, 32, 97, 102, 105, 110, 97, 195, 167, 195, 163, 111, 34, 10, 34, 68, 111, 110,
+39, 116, 32, 99, 104, 97, 110, 103, 101, 34, 32, 61, 32, 34, 78, 195, 163, 111, 32, 109, 117, 100, 97, 114,
+34, 10, 34, 77, 117, 116, 101, 32, 97, 108, 108, 34, 32, 61, 32, 34, 83, 105, 108, 101, 110, 99, 105, 97,
+114, 32, 116, 111, 100, 111, 115, 34, 10, 34, 85, 110, 109, 117, 116, 101, 32, 97, 108, 108, 34, 32, 61, 32,
+34, 84, 105, 114, 97, 114, 32, 111, 32, 109, 117, 100, 111, 32, 100, 101, 32, 116, 111, 100, 111, 115, 34, 10,
+34, 70, 108, 105, 112, 32, 115, 116, 97, 116, 101, 34, 32, 61, 32, 34, 73, 110, 118, 101, 114, 116, 101, 114,
+32, 111, 32, 101, 115, 116, 97, 100, 111, 34, 10, 34, 83, 101, 116, 32, 116, 111, 34, 32, 61, 32, 34, 68,
+101, 102, 105, 110, 105, 114, 32, 101, 109, 34, 10, 34, 67, 104, 97, 110, 103, 101, 32, 98, 121, 34, 32, 61,
+32, 34, 77, 117, 100, 97, 114, 32, 101, 109, 34, 10, 34, 66, 97, 99, 107, 32, 116, 111, 32, 104, 111, 119,
+32, 116, 104, 101, 32, 99, 108, 105, 112, 32, 119, 97, 115, 32, 119, 104, 101, 110, 32, 116, 104, 105, 115, 32,
+119, 105, 110, 100, 111, 119, 32, 111, 112, 101, 110, 101, 100, 34, 32, 61, 32, 34, 86, 111, 108, 116, 97, 32,
+111, 32, 99, 108, 105, 112, 101, 32, 97, 32, 99, 111, 109, 111, 32, 101, 115, 116, 97, 118, 97, 32, 113, 117,
+97, 110, 100, 111, 32, 101, 115, 116, 97, 32, 106, 97, 110, 101, 108, 97, 32, 97, 98, 114, 105, 117, 34, 10,
+34, 67, 108, 105, 112, 32, 112, 114, 111, 112, 101, 114, 116, 105, 101, 115, 34, 32, 61, 32, 34, 80, 114, 111,
+112, 114, 105, 101, 100, 97, 100, 101, 115, 32, 100, 111, 32, 99, 108, 105, 112, 101, 34, 10, 34, 77, 101, 114,
+103, 101, 32, 105, 110, 116, 111, 32, 116, 104, 101, 32, 99, 117, 114, 114, 101, 110, 116, 32, 97, 114, 114, 97,
+110, 103, 101, 109, 101, 110, 116, 34, 32, 61, 32, 34, 77, 101, 115, 99, 108, 97, 114, 32, 110, 111, 32, 97,
+114, 114, 97, 110, 106, 111, 32, 97, 116, 117, 97, 108, 34, 10, 34, 77, 97, 107, 101, 32, 105, 116, 32, 116,
+104, 101, 32, 99, 117, 114, 114, 101, 110, 116, 32, 97, 114, 114, 97, 110, 103, 101, 109, 101, 110, 116, 32, 40,
+116, 104, 101, 32, 80, 108, 97, 121, 108, 105, 115, 116, 32, 115, 104, 111, 119, 115, 32, 105, 116, 41, 34, 32,
+61, 32, 34, 84, 111, 114, 110, 97, 45, 111, 32, 111, 32, 97, 114, 114, 97, 110, 106, 111, 32, 97, 116, 117,
+97, 108, 32, 40, 97, 32, 80, 108, 97, 121, 108, 105, 115, 116, 32, 111, 32, 109, 111, 115, 116, 114, 97, 41,
+34, 10, 34, 65, 32, 110, 101, 119, 32, 101, 109, 112, 116, 121, 32, 97, 114, 114, 97, 110, 103, 101, 109, 101,
+110, 116, 34, 32, 61, 32, 34, 85, 109, 32, 110, 111, 118, 111, 32, 97, 114, 114, 97, 110, 106, 111, 32, 118,
+97, 122, 105, 111, 34, 10, 34, 65, 32, 99, 111, 112, 121, 32, 111, 102, 32, 116, 104, 101, 32, 115, 101, 108,
+101, 99, 116, 101, 100, 32, 97, 114, 114, 97, 110, 103, 101, 109, 101, 110, 116, 44, 32, 114, 105, 103, 104, 116,
+32, 97, 102, 116, 101, 114, 32, 105, 116, 34, 32, 61, 32, 34, 85, 109, 97, 32, 99, 195, 179, 112, 105, 97,
+32, 100, 111, 32, 97, 114, 114, 97, 110, 106, 111, 32, 115, 101, 108, 101, 99, 105, 111, 110, 97, 100, 111, 44,
+32, 108, 111, 103, 111, 32, 100, 101, 112, 111, 105, 115, 32, 100, 101, 108, 101, 34, 10, 34, 83, 111, 117, 114,
+99, 101, 32, 97, 114, 114, 97, 110, 103, 101, 109, 101, 110, 116, 34, 32, 61, 32, 34, 65, 114, 114, 97, 110,
+106, 111, 32, 100, 101, 32, 111, 114, 105, 103, 101, 109, 34, 10, 34, 77, 111, 100, 101, 34, 32, 61, 32, 34,
+77, 111, 100, 111, 34, 10, 34, 73, 110, 115, 101, 114, 116, 32, 40, 109, 111, 118, 101, 115, 32, 119, 104, 97,
+116, 32, 102, 111, 108, 108, 111, 119, 115, 41, 34, 32, 61, 32, 34, 73, 110, 115, 101, 114, 105, 114, 32, 40,
+101, 109, 112, 117, 114, 114, 97, 32, 111, 32, 113, 117, 101, 32, 118, 101, 109, 32, 100, 101, 112, 111, 105, 115,
+41, 34, 10, 34, 77, 101, 114, 103, 101, 32, 40, 111, 118, 101, 114, 32, 119, 104, 97, 116, 32, 105, 115, 32,
+116, 104, 101, 114, 101, 41, 34, 32, 61, 32, 34, 77, 101, 115, 99, 108, 97, 114, 32, 40, 112, 111, 114, 32,
+99, 105, 109, 97, 32, 100, 111, 32, 113, 117, 101, 32, 106, 195, 161, 32, 101, 120, 105, 115, 116, 101, 41, 34,
+10, 34, 82, 101, 112, 108, 97, 99, 101, 32, 40, 99, 108, 101, 97, 114, 115, 32, 116, 104, 97, 116, 32, 108,
+101, 110, 103, 116, 104, 32, 102, 105, 114, 115, 116, 41, 34, 32, 61, 32, 34, 83, 117, 98, 115, 116, 105, 116,
+117, 105, 114, 32, 40, 108, 105, 109, 112, 97, 32, 101, 115, 115, 101, 32, 116, 114, 101, 99, 104, 111, 32, 97,
+110, 116, 101, 115, 41, 34, 10, 34, 80, 111, 115, 105, 116, 105, 111, 110, 34, 32, 61, 32, 34, 80, 111, 115,
+105, 195, 167, 195, 163, 111, 34, 10, 34, 80, 108, 97, 121, 98, 97, 99, 107, 32, 112, 111, 115, 105, 116, 105,
+111, 110, 34, 32, 61, 32, 34, 80, 111, 115, 105, 195, 167, 195, 163, 111, 32, 100, 101, 32, 114, 101, 112, 114,
+111, 100, 117, 195, 167, 195, 163, 111, 34, 10, 34, 123, 48, 125, 32, 99, 108, 105, 112, 115, 44, 32, 123, 49,
+125, 32, 98, 97, 114, 115, 34, 32, 61, 32, 34, 123, 48, 125, 32, 99, 108, 105, 112, 101, 115, 44, 32, 123,
+49, 125, 32, 99, 111, 109, 112, 97, 115, 115, 111, 115, 34, 10, 34, 77, 101, 114, 103, 101, 32, 105, 110, 116,
+111, 32, 92, 34, 123, 48, 125, 92, 34, 34, 32, 61, 32, 34, 77, 101, 115, 99, 108, 97, 114, 32, 101, 109,
+32, 92, 34, 123, 48, 125, 92, 34, 34, 10, 34, 83, 104, 111, 119, 34, 32, 61, 32, 34, 77, 111, 115, 116,
+114, 97, 114, 34, 10, 34, 68, 117, 112, 108, 105, 99, 97, 116, 101, 34, 32, 61, 32, 34, 68, 117, 112, 108,
+105, 99, 97, 114, 34, 10, 34, 77, 101, 114, 103, 101, 34, 32, 61, 32, 34, 77, 101, 115, 99, 108, 97, 114,
+34, 10, 34, 87, 104, 97, 116, 32, 116, 111, 32, 114, 101, 110, 100, 101, 114, 34, 32, 61, 32, 34, 79, 32,
+113, 117, 101, 32, 114, 101, 110, 100, 101, 114, 105, 122, 97, 114, 34, 10, 34, 79, 117, 116, 112, 117, 116, 32,
+102, 111, 114, 109, 97, 116, 34, 32, 61, 32, 34, 70, 111, 114, 109, 97, 116, 111, 32, 100, 101, 32, 115, 97,
+195, 173, 100, 97, 34, 10, 34, 83, 111, 110, 103, 32, 40, 80, 108, 97, 121, 108, 105, 115, 116, 41, 34, 32,
+61, 32, 34, 83, 111, 110, 103, 32, 40, 80, 108, 97, 121, 108, 105, 115, 116, 41, 34, 10, 34, 80, 108, 97,
+121, 108, 105, 115, 116, 32, 115, 101, 108, 101, 99, 116, 105, 111, 110, 34, 32, 61, 32, 34, 83, 101, 108, 101,
+195, 167, 195, 163, 111, 32, 100, 97, 32, 80, 108, 97, 121, 108, 105, 115, 116, 34, 10, 34, 87, 104, 97, 116,
+32, 105, 115, 32, 114, 101, 110, 100, 101, 114, 101, 100, 58, 32, 116, 104, 101, 32, 97, 114, 114, 97, 110, 103,
+101, 109, 101, 110, 116, 44, 32, 116, 104, 101, 32, 99, 117, 114, 114, 101, 110, 116, 32, 112, 97, 116, 116, 101,
+114, 110, 44, 32, 111, 114, 32, 116, 104, 101, 32, 80, 108, 97, 121, 108, 105, 115, 116, 39, 115, 32, 116, 105,
+109, 101, 32, 115, 101, 108, 101, 99, 116, 105, 111, 110, 34, 32, 61, 32, 34, 79, 32, 113, 117, 101, 32, 195,
+169, 32, 114, 101, 110, 100, 101, 114, 105, 122, 97, 100, 111, 58, 32, 111, 32, 97, 114, 114, 97, 110, 106, 111,
+44, 32, 111, 32, 112, 97, 116, 116, 101, 114, 110, 32, 97, 116, 117, 97, 108, 32, 111, 117, 32, 97, 32, 115,
+101, 108, 101, 195, 167, 195, 163, 111, 32, 100, 101, 32, 116, 101, 109, 112, 111, 32, 100, 97, 32, 80, 108, 97,
+121, 108, 105, 115, 116, 34, 10, 34, 79, 110, 99, 101, 34, 32, 61, 32, 34, 85, 109, 97, 32, 118, 101, 122,
+34, 10, 34, 123, 48, 125, 32, 116, 105, 109, 101, 115, 34, 32, 61, 32, 34, 123, 48, 125, 32, 118, 101, 122,
+101, 115, 34, 10, 34, 72, 111, 119, 32, 109, 97, 110, 121, 32, 116, 105, 109, 101, 115, 32, 116, 104, 101, 32,
+114, 97, 110, 103, 101, 32, 112, 108, 97, 121, 115, 32, 105, 110, 32, 116, 104, 101, 32, 102, 105, 108, 101, 34,
+32, 61, 32, 34, 81, 117, 97, 110, 116, 97, 115, 32, 118, 101, 122, 101, 115, 32, 111, 32, 116, 114, 101, 99,
+104, 111, 32, 116, 111, 99, 97, 32, 110, 111, 32, 97, 114, 113, 117, 105, 118, 111, 34, 10, 34, 67, 117, 116,
+32, 114, 101, 109, 97, 105, 110, 100, 101, 114, 34, 32, 61, 32, 34, 67, 111, 114, 116, 97, 114, 32, 111, 32,
+114, 101, 115, 116, 97, 110, 116, 101, 34, 10, 34, 76, 101, 97, 118, 101, 32, 114, 101, 109, 97, 105, 110, 100,
+101, 114, 34, 32, 61, 32, 34, 68, 101, 105, 120, 97, 114, 32, 111, 32, 114, 101, 115, 116, 97, 110, 116, 101,
+34, 10, 34, 87, 114, 97, 112, 32, 114, 101, 109, 97, 105, 110, 100, 101, 114, 34, 32, 61, 32, 34, 69, 110,
+114, 111, 108, 97, 114, 32, 111, 32, 114, 101, 115, 116, 97, 110, 116, 101, 34, 10, 34, 67, 117, 116, 58, 32,
+115, 116, 111, 112, 32, 101, 120, 97, 99, 116, 108, 121, 32, 97, 116, 32, 116, 104, 101, 32, 101, 110, 100, 32,
+40, 108, 111, 111, 112, 115, 41, 46, 32, 76, 101, 97, 118, 101, 58, 32, 108, 101, 116, 32, 114, 101, 118, 101,
+114, 98, 115, 32, 97, 110, 100, 32, 114, 101, 108, 101, 97, 115, 101, 115, 32, 114, 105, 110, 103, 32, 111, 117,
+116, 32, 40, 115, 111, 110, 103, 115, 41, 46, 32, 87, 114, 97, 112, 58, 32, 109, 105, 120, 32, 116, 104, 101,
+32, 116, 97, 105, 108, 32, 105, 110, 116, 111, 32, 116, 104, 101, 32, 115, 116, 97, 114, 116, 32, 40, 115, 101,
+97, 109, 108, 101, 115, 115, 32, 108, 111, 111, 112, 115, 41, 34, 32, 61, 32, 34, 67, 111, 114, 116, 97, 114,
+58, 32, 112, 97, 114, 97, 32, 101, 120, 97, 116, 97, 109, 101, 110, 116, 101, 32, 110, 111, 32, 102, 105, 109,
+32, 40, 108, 111, 111, 112, 115, 41, 46, 32, 68, 101, 105, 120, 97, 114, 58, 32, 114, 101, 118, 101, 114, 98,
+115, 32, 101, 32, 114, 101, 108, 101, 97, 115, 101, 115, 32, 115, 111, 97, 109, 32, 97, 116, 195, 169, 32, 111,
+32, 102, 105, 109, 32, 40, 109, 195, 186, 115, 105, 99, 97, 115, 41, 46, 32, 69, 110, 114, 111, 108, 97, 114,
+58, 32, 109, 105, 115, 116, 117, 114, 97, 32, 97, 32, 99, 97, 117, 100, 97, 32, 110, 111, 32, 105, 110, 195,
+173, 99, 105, 111, 32, 40, 108, 111, 111, 112, 115, 32, 115, 101, 109, 32, 101, 109, 101, 110, 100, 97, 41, 34,
+10, 34, 76, 111, 110, 103, 101, 115, 116, 32, 116, 97, 105, 108, 34, 32, 61, 32, 34, 67, 97, 117, 100, 97,
+32, 109, 195, 161, 120, 105, 109, 97, 34, 10, 34, 84, 104, 101, 32, 116, 97, 105, 108, 32, 115, 116, 111, 112,
+115, 32, 101, 97, 114, 108, 105, 101, 114, 32, 119, 104, 101, 110, 32, 116, 104, 101, 32, 115, 111, 117, 110, 100,
+32, 104, 97, 115, 32, 102, 97, 100, 101, 100, 32, 111, 117, 116, 34, 32, 61, 32, 34, 65, 32, 99, 97, 117,
+100, 97, 32, 112, 97, 114, 97, 32, 97, 110, 116, 101, 115, 32, 113, 117, 97, 110, 100, 111, 32, 111, 32, 115,
+111, 109, 32, 106, 195, 161, 32, 115, 117, 109, 105, 117, 34, 10, 34, 79, 110, 101, 32, 102, 105, 108, 101, 32,
+40, 116, 104, 101, 32, 109, 105, 120, 41, 34, 32, 61, 32, 34, 85, 109, 32, 97, 114, 113, 117, 105, 118, 111,
+32, 40, 97, 32, 109, 105, 120, 97, 103, 101, 109, 41, 34, 10, 34, 79, 110, 101, 32, 112, 101, 114, 32, 109,
+105, 120, 101, 114, 32, 105, 110, 115, 101, 114, 116, 32, 40, 115, 116, 101, 109, 115, 41, 34, 32, 61, 32, 34,
+85, 109, 32, 112, 111, 114, 32, 105, 110, 115, 101, 114, 116, 32, 100, 111, 32, 77, 105, 120, 101, 114, 32, 40,
+115, 116, 101, 109, 115, 41, 34, 10, 34, 79, 110, 101, 32, 112, 101, 114, 32, 99, 104, 97, 110, 110, 101, 108,
+32, 40, 115, 116, 101, 109, 115, 41, 34, 32, 61, 32, 34, 85, 109, 32, 112, 111, 114, 32, 99, 97, 110, 97,
+108, 32, 40, 115, 116, 101, 109, 115, 41, 34, 10, 34, 83, 116, 101, 109, 115, 58, 32, 97, 32, 102, 105, 108,
+101, 32, 102, 111, 114, 32, 101, 97, 99, 104, 32, 109, 105, 120, 101, 114, 32, 105, 110, 115, 101, 114, 116, 32,
+116, 104, 97, 116, 32, 103, 101, 116, 115, 32, 115, 111, 117, 110, 100, 44, 32, 111, 114, 32, 102, 111, 114, 32,
+101, 97, 99, 104, 32, 99, 104, 97, 110, 110, 101, 108, 32, 116, 104, 97, 116, 32, 112, 108, 97, 121, 115, 34,
+32, 61, 32, 34, 83, 116, 101, 109, 115, 58, 32, 117, 109, 32, 97, 114, 113, 117, 105, 118, 111, 32, 112, 97,
+114, 97, 32, 99, 97, 100, 97, 32, 105, 110, 115, 101, 114, 116, 32, 100, 111, 32, 77, 105, 120, 101, 114, 32,
+113, 117, 101, 32, 114, 101, 99, 101, 98, 101, 32, 115, 111, 109, 44, 32, 111, 117, 32, 112, 97, 114, 97, 32,
+99, 97, 100, 97, 32, 99, 97, 110, 97, 108, 32, 113, 117, 101, 32, 116, 111, 99, 97, 34, 10, 34, 65, 108,
+115, 111, 32, 116, 104, 101, 32, 102, 117, 108, 108, 32, 109, 105, 120, 34, 32, 61, 32, 34, 84, 97, 109, 98,
+195, 169, 109, 32, 97, 32, 109, 105, 120, 97, 103, 101, 109, 32, 99, 111, 109, 112, 108, 101, 116, 97, 34, 10,
+34, 66, 105, 116, 32, 100, 101, 112, 116, 104, 34, 32, 61, 32, 34, 82, 101, 115, 111, 108, 117, 195, 167, 195,
+163, 111, 34, 10, 34, 49, 54, 32, 98, 105, 116, 115, 32, 40, 105, 110, 116, 101, 103, 101, 114, 41, 34, 32,
+61, 32, 34, 49, 54, 32, 98, 105, 116, 115, 32, 40, 105, 110, 116, 101, 105, 114, 111, 41, 34, 10, 34, 50,
+52, 32, 98, 105, 116, 115, 32, 40, 105, 110, 116, 101, 103, 101, 114, 41, 34, 32, 61, 32, 34, 50, 52, 32,
+98, 105, 116, 115, 32, 40, 105, 110, 116, 101, 105, 114, 111, 41, 34, 10, 34, 51, 50, 32, 98, 105, 116, 115,
+32, 40, 102, 108, 111, 97, 116, 41, 34, 32, 61, 32, 34, 51, 50, 32, 98, 105, 116, 115, 32, 40, 102, 108,
+111, 97, 116, 41, 34, 10, 34, 66, 105, 116, 114, 97, 116, 101, 34, 32, 61, 32, 34, 84, 97, 120, 97, 32,
+100, 101, 32, 98, 105, 116, 115, 34, 10, 34, 67, 111, 110, 115, 116, 97, 110, 116, 32, 98, 105, 116, 114, 97,
+116, 101, 32, 40, 104, 105, 103, 104, 101, 114, 58, 32, 98, 101, 116, 116, 101, 114, 32, 115, 111, 117, 110, 100,
+44, 32, 98, 105, 103, 103, 101, 114, 32, 102, 105, 108, 101, 41, 34, 32, 61, 32, 34, 84, 97, 120, 97, 32,
+100, 101, 32, 98, 105, 116, 115, 32, 99, 111, 110, 115, 116, 97, 110, 116, 101, 32, 40, 109, 97, 105, 111, 114,
+58, 32, 115, 111, 109, 32, 109, 101, 108, 104, 111, 114, 44, 32, 97, 114, 113, 117, 105, 118, 111, 32, 109, 97,
+105, 111, 114, 41, 34, 10, 34, 67, 111, 109, 112, 114, 101, 115, 115, 105, 111, 110, 34, 32, 61, 32, 34, 67,
+111, 109, 112, 114, 101, 115, 115, 195, 163, 111, 34, 10, 34, 48, 32, 40, 102, 97, 115, 116, 101, 115, 116, 41,
+34, 32, 61, 32, 34, 48, 32, 40, 109, 97, 105, 115, 32, 114, 195, 161, 112, 105, 100, 97, 41, 34, 10, 34,
+53, 32, 40, 100, 101, 102, 97, 117, 108, 116, 41, 34, 32, 61, 32, 34, 53, 32, 40, 112, 97, 100, 114, 195,
+163, 111, 41, 34, 10, 34, 56, 32, 40, 115, 109, 97, 108, 108, 101, 115, 116, 41, 34, 32, 61, 32, 34, 56,
+32, 40, 109, 101, 110, 111, 114, 32, 97, 114, 113, 117, 105, 118, 111, 41, 34, 10, 34, 70, 76, 65, 67, 32,
+105, 115, 32, 108, 111, 115, 115, 108, 101, 115, 115, 32, 97, 116, 32, 101, 118, 101, 114, 121, 32, 108, 101, 118,
+101, 108, 59, 32, 104, 105, 103, 104, 101, 114, 32, 108, 101, 118, 101, 108, 115, 32, 109, 97, 107, 101, 32, 115,
+109, 97, 108, 108, 101, 114, 32, 102, 105, 108, 101, 115, 32, 97, 110, 100, 32, 116, 97, 107, 101, 32, 108, 111,
+110, 103, 101, 114, 34, 32, 61, 32, 34, 79, 32, 70, 76, 65, 67, 32, 110, 195, 163, 111, 32, 112, 101, 114,
+100, 101, 32, 113, 117, 97, 108, 105, 100, 97, 100, 101, 32, 101, 109, 32, 110, 101, 110, 104, 117, 109, 32, 110,
+195, 173, 118, 101, 108, 59, 32, 110, 195, 173, 118, 101, 105, 115, 32, 109, 97, 105, 111, 114, 101, 115, 32, 102,
+97, 122, 101, 109, 32, 97, 114, 113, 117, 105, 118, 111, 115, 32, 109, 101, 110, 111, 114, 101, 115, 32, 101, 32,
+100, 101, 109, 111, 114, 97, 109, 32, 109, 97, 105, 115, 34, 10, 34, 67, 104, 97, 110, 110, 101, 108, 115, 34,
+32, 61, 32, 34, 67, 97, 110, 97, 105, 115, 34, 10, 34, 83, 116, 101, 114, 101, 111, 34, 32, 61, 32, 34,
+69, 115, 116, 195, 169, 114, 101, 111, 34, 10, 34, 77, 111, 110, 111, 32, 40, 98, 111, 116, 104, 32, 115, 105,
+100, 101, 115, 32, 109, 105, 120, 101, 100, 41, 34, 32, 61, 32, 34, 77, 111, 110, 111, 32, 40, 111, 115, 32,
+100, 111, 105, 115, 32, 108, 97, 100, 111, 115, 32, 109, 105, 115, 116, 117, 114, 97, 100, 111, 115, 41, 34, 10,
+34, 77, 111, 110, 111, 32, 40, 108, 101, 102, 116, 32, 111, 110, 108, 121, 41, 34, 32, 61, 32, 34, 77, 111,
+110, 111, 32, 40, 115, 195, 179, 32, 111, 32, 101, 115, 113, 117, 101, 114, 100, 111, 41, 34, 10, 34, 77, 111,
+110, 111, 32, 40, 114, 105, 103, 104, 116, 32, 111, 110, 108, 121, 41, 34, 32, 61, 32, 34, 77, 111, 110, 111,
+32, 40, 115, 195, 179, 32, 111, 32, 100, 105, 114, 101, 105, 116, 111, 41, 34, 10, 34, 68, 105, 116, 104, 101,
+114, 34, 32, 61, 32, 34, 68, 105, 116, 104, 101, 114, 34, 10, 34, 84, 80, 68, 70, 34, 32, 61, 32, 34,
+84, 80, 68, 70, 34, 10, 34, 84, 80, 68, 70, 32, 43, 32, 110, 111, 105, 115, 101, 32, 115, 104, 97, 112,
+105, 110, 103, 34, 32, 61, 32, 34, 84, 80, 68, 70, 32, 43, 32, 110, 111, 105, 115, 101, 32, 115, 104, 97,
+112, 105, 110, 103, 34, 10, 34, 72, 105, 100, 101, 115, 32, 116, 104, 101, 32, 114, 111, 117, 110, 100, 105, 110,
+103, 32, 110, 111, 105, 115, 101, 32, 111, 102, 32, 49, 54, 32, 97, 110, 100, 32, 50, 52, 32, 98, 105, 116,
+32, 102, 105, 108, 101, 115, 32, 40, 110, 111, 105, 115, 101, 32, 115, 104, 97, 112, 105, 110, 103, 32, 109, 111,
+118, 101, 115, 32, 105, 116, 32, 119, 104, 101, 114, 101, 32, 116, 104, 101, 32, 101, 97, 114, 32, 105, 115, 32,
+108, 101, 97, 115, 116, 32, 115, 101, 110, 115, 105, 116, 105, 118, 101, 41, 34, 32, 61, 32, 34, 68, 105, 115,
+102, 97, 114, 195, 167, 97, 32, 111, 32, 114, 117, 195, 173, 100, 111, 32, 100, 101, 32, 97, 114, 114, 101, 100,
+111, 110, 100, 97, 109, 101, 110, 116, 111, 32, 100, 101, 32, 97, 114, 113, 117, 105, 118, 111, 115, 32, 100, 101,
+32, 49, 54, 32, 101, 32, 50, 52, 32, 98, 105, 116, 115, 32, 40, 111, 32, 110, 111, 105, 115, 101, 32, 115,
+104, 97, 112, 105, 110, 103, 32, 111, 32, 108, 101, 118, 97, 32, 112, 97, 114, 97, 32, 111, 110, 100, 101, 32,
+111, 32, 111, 117, 118, 105, 100, 111, 32, 195, 169, 32, 109, 101, 110, 111, 115, 32, 115, 101, 110, 115, 195, 173,
+118, 101, 108, 41, 34, 10, 34, 78, 111, 114, 109, 97, 108, 105, 122, 101, 32, 40, 112, 101, 97, 107, 32, 116,
+111, 32, 48, 32, 100, 66, 41, 34, 32, 61, 32, 34, 78, 111, 114, 109, 97, 108, 105, 122, 97, 114, 32, 40,
+112, 105, 99, 111, 32, 101, 109, 32, 48, 32, 100, 66, 41, 34, 10, 34, 77, 97, 115, 116, 101, 114, 32, 101,
+102, 102, 101, 99, 116, 115, 34, 32, 61, 32, 34, 69, 102, 101, 105, 116, 111, 115, 32, 100, 111, 32, 77, 97,
+115, 116, 101, 114, 34, 10, 34, 84, 114, 105, 109, 32, 116, 104, 101, 32, 100, 101, 108, 97, 121, 32, 99, 111,
+109, 112, 101, 110, 115, 97, 116, 105, 111, 110, 39, 115, 32, 115, 105, 108, 101, 110, 99, 101, 34, 32, 61, 32,
+34, 67, 111, 114, 116, 97, 114, 32, 111, 32, 115, 105, 108, 195, 170, 110, 99, 105, 111, 32, 100, 97, 32, 99,
+111, 109, 112, 101, 110, 115, 97, 195, 167, 195, 163, 111, 32, 100, 101, 32, 97, 116, 114, 97, 115, 111, 34, 10,
+34, 82, 97, 105, 115, 101, 115, 32, 111, 114, 32, 108, 111, 119, 101, 114, 115, 32, 116, 104, 101, 32, 119, 104,
+111, 108, 101, 32, 102, 105, 108, 101, 32, 115, 111, 32, 105, 116, 115, 32, 108, 111, 117, 100, 101, 115, 116, 32,
+112, 101, 97, 107, 32, 114, 101, 97, 99, 104, 101, 115, 32, 102, 117, 108, 108, 32, 115, 99, 97, 108, 101, 34,
+32, 61, 32, 34, 83, 111, 98, 101, 32, 111, 117, 32, 100, 101, 115, 99, 101, 32, 111, 32, 97, 114, 113, 117,
+105, 118, 111, 32, 105, 110, 116, 101, 105, 114, 111, 32, 112, 97, 114, 97, 32, 111, 32, 112, 105, 99, 111, 32,
+109, 97, 105, 115, 32, 97, 108, 116, 111, 32, 99, 104, 101, 103, 97, 114, 32, 97, 111, 32, 109, 195, 161, 120,
+105, 109, 111, 34, 10, 34, 79, 102, 102, 58, 32, 116, 104, 101, 32, 77, 97, 115, 116, 101, 114, 32, 105, 110,
+115, 101, 114, 116, 39, 115, 32, 101, 102, 102, 101, 99, 116, 115, 32, 97, 114, 101, 32, 98, 121, 112, 97, 115,
+115, 101, 100, 32, 102, 111, 114, 32, 116, 104, 101, 32, 101, 120, 112, 111, 114, 116, 34, 32, 61, 32, 34, 68,
+101, 115, 108, 105, 103, 97, 100, 111, 58, 32, 111, 115, 32, 101, 102, 101, 105, 116, 111, 115, 32, 100, 111, 32,
+105, 110, 115, 101, 114, 116, 32, 77, 97, 115, 116, 101, 114, 32, 102, 105, 99, 97, 109, 32, 100, 101, 32, 102,
+111, 114, 97, 32, 100, 97, 32, 101, 120, 112, 111, 114, 116, 97, 195, 167, 195, 163, 111, 34, 10, 34, 82, 101,
+109, 111, 118, 101, 115, 32, 116, 104, 101, 32, 115, 105, 108, 101, 110, 99, 101, 32, 112, 108, 117, 103, 105, 110,
+32, 108, 97, 116, 101, 110, 99, 121, 32, 99, 111, 109, 112, 101, 110, 115, 97, 116, 105, 111, 110, 32, 97, 100,
+100, 115, 32, 97, 116, 32, 116, 104, 101, 32, 115, 116, 97, 114, 116, 34, 32, 61, 32, 34, 82, 101, 109, 111,
+118, 101, 32, 111, 32, 115, 105, 108, 195, 170, 110, 99, 105, 111, 32, 113, 117, 101, 32, 97, 32, 99, 111, 109,
+112, 101, 110, 115, 97, 195, 167, 195, 163, 111, 32, 100, 101, 32, 108, 97, 116, 195, 170, 110, 99, 105, 97, 32,
+100, 111, 115, 32, 112, 108, 117, 103, 105, 110, 115, 32, 99, 111, 108, 111, 99, 97, 32, 110, 111, 32, 105, 110,
+195, 173, 99, 105, 111, 34, 10, 34, 84, 111, 116, 97, 108, 32, 116, 105, 109, 101, 58, 32, 123, 48, 125, 34,
+32, 61, 32, 34, 68, 117, 114, 97, 195, 167, 195, 163, 111, 32, 116, 111, 116, 97, 108, 58, 32, 123, 48, 125,
+34, 10, 34, 40, 43, 32, 116, 97, 105, 108, 32, 117, 112, 32, 116, 111, 32, 123, 48, 125, 32, 115, 41, 34,
+32, 61, 32, 34, 40, 43, 32, 99, 97, 117, 100, 97, 32, 100, 101, 32, 97, 116, 195, 169, 32, 123, 48, 125,
+32, 115, 41, 34, 10, 34, 77, 80, 51, 32, 97, 116, 32, 123, 48, 125, 32, 72, 122, 34, 32, 61, 32, 34,
+77, 80, 51, 32, 101, 109, 32, 123, 48, 125, 32, 72, 122, 34, 10, 34, 123, 48, 125, 32, 102, 105, 108, 101,
+40, 115, 41, 34, 32, 61, 32, 34, 123, 48, 125, 32, 97, 114, 113, 117, 105, 118, 111, 40, 115, 41, 34, 10,
+34, 84, 104, 101, 32, 77, 97, 115, 116, 101, 114, 32, 105, 110, 115, 101, 114, 116, 32, 105, 115, 32, 109, 117,
+116, 101, 100, 58, 32, 116, 104, 101, 32, 102, 105, 108, 101, 32, 119, 105, 108, 108, 32, 98, 101, 32, 115, 105,
+108, 101, 110, 116, 34, 32, 61, 32, 34, 79, 32, 105, 110, 115, 101, 114, 116, 32, 77, 97, 115, 116, 101, 114,
+32, 101, 115, 116, 195, 161, 32, 109, 117, 100, 111, 58, 32, 111, 32, 97, 114, 113, 117, 105, 118, 111, 32, 118,
+97, 105, 32, 115, 97, 105, 114, 32, 101, 109, 32, 115, 105, 108, 195, 170, 110, 99, 105, 111, 34, 10, 34, 84,
+104, 101, 114, 101, 32, 105, 115, 32, 110, 111, 32, 80, 108, 97, 121, 108, 105, 115, 116, 32, 115, 101, 108, 101,
+99, 116, 105, 111, 110, 58, 32, 116, 104, 101, 32, 119, 104, 111, 108, 101, 32, 115, 111, 110, 103, 32, 105, 115,
+32, 114, 101, 110, 100, 101, 114, 101, 100, 34, 32, 61, 32, 34, 78, 195, 163, 111, 32, 104, 195, 161, 32, 115,
+101, 108, 101, 195, 167, 195, 163, 111, 32, 110, 97, 32, 80, 108, 97, 121, 108, 105, 115, 116, 58, 32, 97, 32,
+109, 195, 186, 115, 105, 99, 97, 32, 105, 110, 116, 101, 105, 114, 97, 32, 195, 169, 32, 114, 101, 110, 100, 101,
+114, 105, 122, 97, 100, 97, 34, 10, 34, 83, 97, 118, 101, 32, 97, 115, 32, 116, 101, 109, 112, 108, 97, 116,
+101, 34, 32, 61, 32, 34, 83, 97, 108, 118, 97, 114, 32, 99, 111, 109, 111, 32, 109, 111, 100, 101, 108, 111,
+34, 10, 34, 84, 104, 101, 32, 116, 101, 109, 112, 108, 97, 116, 101, 32, 97, 112, 112, 101, 97, 114, 115, 32,
+105, 110, 32, 70, 105, 108, 101, 32, 226, 128, 186, 32, 78, 101, 119, 32, 112, 114, 111, 106, 101, 99, 116, 46,
+46, 46, 32, 40, 115, 97, 118, 101, 100, 32, 105, 110, 32, 123, 48, 125, 41, 34, 32, 61, 32, 34, 79, 32,
+109, 111, 100, 101, 108, 111, 32, 97, 112, 97, 114, 101, 99, 101, 32, 101, 109, 32, 65, 114, 113, 117, 105, 118,
+111, 32, 226, 128, 186, 32, 78, 111, 118, 111, 32, 112, 114, 111, 106, 101, 116, 111, 46, 46, 46, 32, 40, 115,
+97, 108, 118, 111, 32, 101, 109, 32, 123, 48, 125, 41, 34, 10, 34, 77, 121, 32, 116, 101, 109, 112, 108, 97,
+116, 101, 34, 32, 61, 32, 34, 77, 101, 117, 32, 109, 111, 100, 101, 108, 111, 34, 10, 34, 78, 101, 119, 32,
+112, 114, 111, 106, 101, 99, 116, 46, 46, 46, 34, 32, 61, 32, 34, 78, 111, 118, 111, 32, 112, 114, 111, 106,
+101, 116, 111, 46, 46, 46, 34, 10, 34, 83, 97, 118, 101, 32, 97, 115, 32, 116, 101, 109, 112, 108, 97, 116,
+101, 46, 46, 46, 34, 32, 61, 32, 34, 83, 97, 108, 118, 97, 114, 32, 99, 111, 109, 111, 32, 109, 111, 100,
+101, 108, 111, 46, 46, 46, 34, 10, 34, 84, 111, 117, 99, 104, 32, 107, 101, 121, 98, 111, 97, 114, 100, 34,
+32, 61, 32, 34, 84, 101, 99, 108, 97, 100, 111, 32, 110, 97, 32, 116, 101, 108, 97, 34, 10, 34, 80, 108,
+117, 103, 105, 110, 32, 112, 101, 114, 102, 111, 114, 109, 97, 110, 99, 101, 32, 109, 111, 110, 105, 116, 111, 114,
+46, 46, 46, 34, 32, 61, 32, 34, 77, 111, 110, 105, 116, 111, 114, 32, 100, 101, 32, 100, 101, 115, 101, 109,
+112, 101, 110, 104, 111, 32, 100, 111, 115, 32, 112, 108, 117, 103, 105, 110, 115, 46, 46, 46, 34, 10, 34, 68,
+114, 117, 109, 115, 32, 97, 110, 100, 32, 97, 32, 115, 121, 110, 116, 104, 32, 111, 110, 32, 116, 104, 101, 32,
+102, 105, 114, 115, 116, 32, 105, 110, 115, 101, 114, 116, 115, 44, 32, 97, 32, 108, 105, 109, 105, 116, 101, 114,
+32, 111, 110, 32, 77, 97, 115, 116, 101, 114, 34, 32, 61, 32, 34, 66, 97, 116, 101, 114, 105, 97, 32, 101,
+32, 117, 109, 32, 115, 121, 110, 116, 104, 32, 110, 111, 115, 32, 112, 114, 105, 109, 101, 105, 114, 111, 115, 32,
+105, 110, 115, 101, 114, 116, 115, 44, 32, 117, 109, 32, 108, 105, 109, 105, 116, 97, 100, 111, 114, 32, 110, 111,
+32, 77, 97, 115, 116, 101, 114, 34, 10, 34, 78, 111, 116, 104, 105, 110, 103, 32, 105, 110, 32, 116, 104, 101,
+32, 112, 97, 116, 116, 101, 114, 110, 115, 34, 32, 61, 32, 34, 78, 97, 100, 97, 32, 110, 111, 115, 32, 112,
+97, 116, 116, 101, 114, 110, 115, 34, 10, 34, 65, 32, 102, 111, 117, 114, 45, 111, 110, 45, 116, 104, 101, 45,
+102, 108, 111, 111, 114, 32, 98, 101, 97, 116, 32, 116, 111, 32, 115, 116, 97, 114, 116, 32, 102, 114, 111, 109,
+34, 32, 61, 32, 34, 85, 109, 97, 32, 98, 97, 116, 105, 100, 97, 32, 102, 111, 117, 114, 45, 111, 110, 45,
+116, 104, 101, 45, 102, 108, 111, 111, 114, 32, 112, 97, 114, 97, 32, 99, 111, 109, 101, 195, 167, 97, 114, 34,
+10, 34, 49, 52, 48, 32, 66, 80, 77, 44, 32, 102, 97, 115, 116, 32, 104, 97, 116, 115, 32, 97, 110, 100,
+32, 97, 110, 32, 56, 48, 56, 32, 119, 105, 116, 104, 32, 103, 108, 105, 100, 101, 34, 32, 61, 32, 34, 49,
+52, 48, 32, 66, 80, 77, 44, 32, 104, 97, 116, 115, 32, 114, 195, 161, 112, 105, 100, 111, 115, 32, 101, 32,
+117, 109, 32, 56, 48, 56, 32, 99, 111, 109, 32, 103, 108, 105, 100, 101, 34, 10, 34, 49, 50, 52, 32, 66,
+80, 77, 32, 104, 111, 117, 115, 101, 32, 103, 114, 111, 111, 118, 101, 32, 119, 105, 116, 104, 32, 98, 97, 115,
+115, 34, 32, 61, 32, 34, 71, 114, 111, 111, 118, 101, 32, 100, 101, 32, 104, 111, 117, 115, 101, 32, 97, 32,
+49, 50, 52, 32, 66, 80, 77, 32, 99, 111, 109, 32, 98, 97, 105, 120, 111, 34, 10, 34, 89, 111, 117, 114,
+32, 116, 101, 109, 112, 108, 97, 116, 101, 34, 32, 61, 32, 34, 83, 101, 117, 32, 109, 111, 100, 101, 108, 111,
+34, 10, 34, 84, 101, 109, 112, 108, 97, 116, 101, 34, 32, 61, 32, 34, 77, 111, 100, 101, 108, 111, 34, 10,
+34, 78, 97, 109, 101, 32, 97, 110, 100, 32, 108, 111, 99, 97, 116, 105, 111, 110, 34, 32, 61, 32, 34, 78,
+111, 109, 101, 32, 101, 32, 108, 111, 99, 97, 108, 34, 10, 34, 73, 110, 102, 111, 114, 109, 97, 116, 105, 111,
+110, 34, 32, 61, 32, 34, 73, 110, 102, 111, 114, 109, 97, 195, 167, 195, 181, 101, 115, 34, 10, 34, 84, 101,
+109, 112, 108, 97, 116, 101, 115, 32, 97, 114, 101, 32, 46, 108, 121, 110, 120, 32, 112, 114, 111, 106, 101, 99,
+116, 115, 32, 105, 110, 32, 116, 104, 105, 115, 32, 102, 111, 108, 100, 101, 114, 32, 40, 70, 105, 108, 101, 32,
+226, 128, 186, 32, 83, 97, 118, 101, 32, 97, 115, 32, 116, 101, 109, 112, 108, 97, 116, 101, 46, 46, 46, 32,
+112, 117, 116, 115, 32, 111, 110, 101, 32, 116, 104, 101, 114, 101, 41, 34, 32, 61, 32, 34, 77, 111, 100, 101,
+108, 111, 115, 32, 115, 195, 163, 111, 32, 112, 114, 111, 106, 101, 116, 111, 115, 32, 46, 108, 121, 110, 120, 32,
+110, 101, 115, 116, 97, 32, 112, 97, 115, 116, 97, 32, 40, 65, 114, 113, 117, 105, 118, 111, 32, 226, 128, 186,
+32, 83, 97, 108, 118, 97, 114, 32, 99, 111, 109, 111, 32, 109, 111, 100, 101, 108, 111, 46, 46, 46, 32, 99,
+111, 108, 111, 99, 97, 32, 117, 109, 32, 97, 113, 117, 105, 41, 34, 10, 34, 70, 111, 108, 100, 101, 114, 34,
+32, 61, 32, 34, 80, 97, 115, 116, 97, 34, 10, 34, 83, 97, 118, 101, 32, 105, 116, 32, 116, 104, 101, 114,
+101, 32, 110, 111, 119, 34, 32, 61, 32, 34, 83, 97, 108, 118, 97, 114, 32, 108, 195, 161, 32, 97, 103, 111,
+114, 97, 34, 10, 34, 79, 102, 102, 58, 32, 116, 104, 101, 32, 112, 114, 111, 106, 101, 99, 116, 32, 111, 112,
+101, 110, 115, 32, 117, 110, 115, 97, 118, 101, 100, 32, 97, 110, 100, 32, 97, 115, 107, 115, 32, 119, 104, 101,
+114, 101, 32, 116, 111, 32, 103, 111, 32, 119, 104, 101, 110, 32, 121, 111, 117, 32, 102, 105, 114, 115, 116, 32,
+115, 97, 118, 101, 34, 32, 61, 32, 34, 68, 101, 115, 108, 105, 103, 97, 100, 111, 58, 32, 111, 32, 112, 114,
+111, 106, 101, 116, 111, 32, 97, 98, 114, 101, 32, 115, 101, 109, 32, 115, 97, 108, 118, 97, 114, 32, 101, 32,
+112, 101, 114, 103, 117, 110, 116, 97, 32, 111, 32, 108, 111, 99, 97, 108, 32, 110, 111, 32, 112, 114, 105, 109,
+101, 105, 114, 111, 32, 115, 97, 108, 118, 97, 109, 101, 110, 116, 111, 34, 10, 34, 67, 114, 101, 97, 116, 101,
+32, 97, 32, 102, 111, 108, 100, 101, 114, 32, 102, 111, 114, 32, 116, 104, 101, 32, 112, 114, 111, 106, 101, 99,
+116, 34, 32, 61, 32, 34, 67, 114, 105, 97, 114, 32, 117, 109, 97, 32, 112, 97, 115, 116, 97, 32, 112, 97,
+114, 97, 32, 111, 32, 112, 114, 111, 106, 101, 116, 111, 34, 10, 34, 115, 97, 109, 101, 32, 97, 115, 32, 116,
+104, 101, 32, 110, 97, 109, 101, 34, 32, 61, 32, 34, 105, 103, 117, 97, 108, 32, 97, 111, 32, 110, 111, 109,
+101, 34, 10, 34, 68, 111, 110, 39, 116, 32, 115, 104, 111, 119, 32, 116, 104, 105, 115, 32, 119, 105, 110, 100,
+111, 119, 32, 102, 111, 114, 32, 70, 105, 108, 101, 32, 226, 128, 186, 32, 78, 101, 119, 34, 32, 61, 32, 34,
+78, 195, 163, 111, 32, 109, 111, 115, 116, 114, 97, 114, 32, 101, 115, 116, 97, 32, 106, 97, 110, 101, 108, 97,
+32, 101, 109, 32, 65, 114, 113, 117, 105, 118, 111, 32, 226, 128, 186, 32, 78, 111, 118, 111, 34, 10, 34, 70,
+105, 108, 101, 32, 226, 128, 186, 32, 78, 101, 119, 32, 116, 104, 101, 110, 32, 115, 116, 97, 114, 116, 115, 32,
+116, 104, 101, 32, 100, 101, 102, 97, 117, 108, 116, 32, 112, 114, 111, 106, 101, 99, 116, 32, 97, 116, 32, 111,
+110, 99, 101, 59, 32, 116, 104, 105, 115, 32, 119, 105, 110, 100, 111, 119, 32, 115, 116, 97, 121, 115, 32, 105,
+110, 32, 70, 105, 108, 101, 32, 226, 128, 186, 32, 78, 101, 119, 32, 112, 114, 111, 106, 101, 99, 116, 46, 46,
+46, 34, 32, 61, 32, 34, 65, 114, 113, 117, 105, 118, 111, 32, 226, 128, 186, 32, 78, 111, 118, 111, 32, 112,
+97, 115, 115, 97, 32, 97, 32, 97, 98, 114, 105, 114, 32, 111, 32, 112, 114, 111, 106, 101, 116, 111, 32, 112,
+97, 100, 114, 195, 163, 111, 32, 100, 105, 114, 101, 116, 111, 59, 32, 101, 115, 116, 97, 32, 106, 97, 110, 101,
+108, 97, 32, 99, 111, 110, 116, 105, 110, 117, 97, 32, 101, 109, 32, 65, 114, 113, 117, 105, 118, 111, 32, 226,
+128, 186, 32, 78, 111, 118, 111, 32, 112, 114, 111, 106, 101, 116, 111, 46, 46, 46, 34, 10, 34, 78, 111, 116,
+32, 115, 97, 118, 101, 100, 32, 117, 110, 116, 105, 108, 32, 121, 111, 117, 32, 99, 104, 111, 111, 115, 101, 32,
+70, 105, 108, 101, 32, 226, 128, 186, 32, 83, 97, 118, 101, 34, 32, 61, 32, 34, 78, 195, 163, 111, 32, 195,
+169, 32, 115, 97, 108, 118, 111, 32, 97, 116, 195, 169, 32, 118, 111, 99, 195, 170, 32, 101, 115, 99, 111, 108,
+104, 101, 114, 32, 65, 114, 113, 117, 105, 118, 111, 32, 226, 128, 186, 32, 83, 97, 108, 118, 97, 114, 34, 10,
+34, 70, 111, 108, 100, 101, 114, 32, 102, 111, 114, 32, 116, 104, 101, 32, 112, 114, 111, 106, 101, 99, 116, 34,
+32, 61, 32, 34, 80, 97, 115, 116, 97, 32, 100, 111, 32, 112, 114, 111, 106, 101, 116, 111, 34, 10, 34, 123,
+48, 125, 32, 97, 108, 114, 101, 97, 100, 121, 32, 101, 120, 105, 115, 116, 115, 46, 32, 67, 104, 111, 111, 115,
+101, 32, 97, 110, 111, 116, 104, 101, 114, 32, 110, 97, 109, 101, 32, 111, 114, 32, 102, 111, 108, 100, 101, 114,
+46, 34, 32, 61, 32, 34, 123, 48, 125, 32, 106, 195, 161, 32, 101, 120, 105, 115, 116, 101, 46, 32, 69, 115,
+99, 111, 108, 104, 97, 32, 111, 117, 116, 114, 111, 32, 110, 111, 109, 101, 32, 111, 117, 32, 112, 97, 115, 116,
+97, 46, 34, 10, 34, 79, 112, 101, 110, 32, 116, 104, 101, 32, 116, 101, 109, 112, 108, 97, 116, 101, 115, 32,
+102, 111, 108, 100, 101, 114, 34, 32, 61, 32, 34, 65, 98, 114, 105, 114, 32, 97, 32, 112, 97, 115, 116, 97,
+32, 100, 101, 32, 109, 111, 100, 101, 108, 111, 115, 34, 10, 34, 67, 104, 111, 111, 115, 101, 46, 46, 46, 34,
+32, 61, 32, 34, 69, 115, 99, 111, 108, 104, 101, 114, 46, 46, 46, 34, 10, 34, 67, 114, 101, 97, 116, 101,
+34, 32, 61, 32, 34, 67, 114, 105, 97, 114, 34, 10, 34, 99, 111, 117, 108, 100, 32, 110, 111, 116, 32, 99,
+114, 101, 97, 116, 101, 32, 123, 48, 125, 34, 32, 61, 32, 34, 110, 195, 163, 111, 32, 102, 111, 105, 32, 112,
+111, 115, 115, 195, 173, 118, 101, 108, 32, 99, 114, 105, 97, 114, 32, 123, 48, 125, 34, 10, 34, 65, 114, 114,
+97, 110, 103, 101, 109, 101, 110, 116, 115, 32, 97, 110, 100, 32, 109, 101, 114, 103, 105, 110, 103, 46, 46, 46,
+34, 32, 61, 32, 34, 65, 114, 114, 97, 110, 106, 111, 115, 32, 101, 32, 109, 101, 115, 99, 108, 97, 103, 101,
+109, 46, 46, 46, 34, 10, 34, 80, 114, 111, 112, 101, 114, 116, 105, 101, 115, 46, 46, 46, 34, 32, 61, 32,
+34, 80, 114, 111, 112, 114, 105, 101, 100, 97, 100, 101, 115, 46, 46, 46, 34, 10, 34, 87, 104, 101, 114, 101,
+34, 32, 61, 32, 34, 79, 110, 100, 101, 34, 10, 34, 78, 111, 119, 34, 32, 61, 32, 34, 65, 103, 111, 114,
+97, 34, 10, 34, 65, 118, 101, 114, 97, 103, 101, 34, 32, 61, 32, 34, 77, 195, 169, 100, 105, 97, 34, 10,
+34, 78, 111, 116, 104, 105, 110, 103, 32, 116, 111, 32, 115, 104, 111, 119, 34, 32, 61, 32, 34, 78, 97, 100,
+97, 32, 112, 97, 114, 97, 32, 109, 111, 115, 116, 114, 97, 114, 34, 10, 34, 70, 105, 110, 100, 34, 32, 61,
+32, 34, 66, 117, 115, 99, 97, 114, 34, 10, 34, 112, 108, 117, 103, 105, 110, 44, 32, 99, 104, 97, 110, 110,
+101, 108, 32, 111, 114, 32, 105, 110, 115, 101, 114, 116, 34, 32, 61, 32, 34, 112, 108, 117, 103, 105, 110, 44,
+32, 99, 97, 110, 97, 108, 32, 111, 117, 32, 105, 110, 115, 101, 114, 116, 34, 10, 34, 80, 108, 117, 103, 105,
+110, 115, 32, 111, 110, 108, 121, 34, 32, 61, 32, 34, 83, 195, 179, 32, 112, 108, 117, 103, 105, 110, 115, 34,
+10, 34, 79, 110, 108, 121, 32, 116, 104, 105, 114, 100, 45, 112, 97, 114, 116, 121, 32, 112, 108, 117, 103, 105,
+110, 115, 32, 40, 86, 83, 84, 51, 32, 47, 32, 67, 76, 65, 80, 41, 44, 32, 110, 111, 116, 32, 76, 89,
+78, 88, 39, 115, 32, 111, 119, 110, 32, 105, 110, 115, 116, 114, 117, 109, 101, 110, 116, 115, 32, 97, 110, 100,
+32, 101, 102, 102, 101, 99, 116, 115, 34, 32, 61, 32, 34, 83, 195, 179, 32, 112, 108, 117, 103, 105, 110, 115,
+32, 100, 101, 32, 116, 101, 114, 99, 101, 105, 114, 111, 115, 32, 40, 86, 83, 84, 51, 32, 47, 32, 67, 76,
+65, 80, 41, 44, 32, 110, 195, 163, 111, 32, 111, 115, 32, 105, 110, 115, 116, 114, 117, 109, 101, 110, 116, 111,
+115, 32, 101, 32, 101, 102, 101, 105, 116, 111, 115, 32, 100, 111, 32, 112, 114, 195, 179, 112, 114, 105, 111, 32,
+76, 89, 78, 88, 34, 10, 34, 70, 114, 101, 101, 122, 101, 34, 32, 61, 32, 34, 67, 111, 110, 103, 101, 108,
+97, 114, 34, 10, 34, 83, 116, 111, 112, 115, 32, 117, 112, 100, 97, 116, 105, 110, 103, 32, 116, 104, 101, 32,
+110, 117, 109, 98, 101, 114, 115, 34, 32, 61, 32, 34, 80, 97, 114, 97, 32, 100, 101, 32, 97, 116, 117, 97,
+108, 105, 122, 97, 114, 32, 111, 115, 32, 110, 195, 186, 109, 101, 114, 111, 115, 34, 10, 34, 82, 101, 115, 101,
+116, 32, 111, 110, 32, 112, 108, 97, 121, 34, 32, 61, 32, 34, 90, 101, 114, 97, 114, 32, 97, 111, 32, 116,
+111, 99, 97, 114, 34, 10, 34, 65, 118, 101, 114, 97, 103, 101, 115, 32, 97, 110, 100, 32, 112, 101, 97, 107,
+115, 32, 115, 116, 97, 114, 116, 32, 97, 103, 97, 105, 110, 32, 101, 97, 99, 104, 32, 116, 105, 109, 101, 32,
+112, 108, 97, 121, 98, 97, 99, 107, 32, 115, 116, 97, 114, 116, 115, 34, 32, 61, 32, 34, 77, 195, 169, 100,
+105, 97, 115, 32, 101, 32, 112, 105, 99, 111, 115, 32, 114, 101, 99, 111, 109, 101, 195, 167, 97, 109, 32, 99,
+97, 100, 97, 32, 118, 101, 122, 32, 113, 117, 101, 32, 97, 32, 114, 101, 112, 114, 111, 100, 117, 195, 167, 195,
+163, 111, 32, 99, 111, 109, 101, 195, 167, 97, 34, 10, 34, 49, 48, 48, 37, 32, 61, 32, 111, 110, 101, 32,
+112, 114, 111, 99, 101, 115, 115, 111, 114, 32, 99, 111, 114, 101, 32, 98, 117, 115, 121, 32, 102, 111, 114, 32,
+116, 104, 101, 32, 119, 104, 111, 108, 101, 32, 116, 105, 109, 101, 32, 116, 104, 101, 32, 97, 117, 100, 105, 111,
+32, 108, 97, 115, 116, 115, 34, 32, 61, 32, 34, 49, 48, 48, 37, 32, 61, 32, 117, 109, 32, 110, 195, 186,
+99, 108, 101, 111, 32, 100, 111, 32, 112, 114, 111, 99, 101, 115, 115, 97, 100, 111, 114, 32, 111, 99, 117, 112,
+97, 100, 111, 32, 100, 117, 114, 97, 110, 116, 101, 32, 116, 111, 100, 111, 32, 111, 32, 116, 101, 109, 112, 111,
+32, 113, 117, 101, 32, 111, 32, 195, 161, 117, 100, 105, 111, 32, 100, 117, 114, 97, 34, 10, 34, 67, 104, 97,
+110, 110, 101, 108, 32, 123, 48, 125, 34, 32, 61, 32, 34, 67, 97, 110, 97, 108, 32, 123, 48, 125, 34, 10,
+34, 115, 108, 111, 116, 32, 123, 48, 125, 34, 32, 61, 32, 34, 115, 108, 111, 116, 32, 123, 48, 125, 34, 10,
+34, 87, 104, 111, 108, 101, 32, 114, 97, 99, 107, 58, 32, 123, 48, 125, 32, 40, 112, 101, 97, 107, 32, 123,
+49, 125, 41, 34, 32, 61, 32, 34, 82, 97, 99, 107, 32, 105, 110, 116, 101, 105, 114, 111, 58, 32, 123, 48,
+125, 32, 40, 112, 105, 99, 111, 32, 123, 49, 125, 41, 34, 10, 34, 80, 108, 117, 103, 105, 110, 32, 112, 101,
+114, 102, 111, 114, 109, 97, 110, 99, 101, 32, 109, 111, 110, 105, 116, 111, 114, 34, 32, 61, 32, 34, 77, 111,
+110, 105, 116, 111, 114, 32, 100, 101, 32, 100, 101, 115, 101, 109, 112, 101, 110, 104, 111, 32, 100, 111, 115, 32,
+112, 108, 117, 103, 105, 110, 115, 34, 10, 34, 79, 110, 101, 32, 111, 99, 116, 97, 118, 101, 32, 100, 111, 119,
+110, 34, 32, 61, 32, 34, 85, 109, 97, 32, 111, 105, 116, 97, 118, 97, 32, 97, 98, 97, 105, 120, 111, 34,
+10, 34, 79, 110, 101, 32, 111, 99, 116, 97, 118, 101, 32, 117, 112, 34, 32, 61, 32, 34, 85, 109, 97, 32,
+111, 105, 116, 97, 118, 97, 32, 97, 99, 105, 109, 97, 34, 10, 34, 83, 109, 97, 108, 108, 32, 107, 101, 121,
+115, 34, 32, 61, 32, 34, 84, 101, 99, 108, 97, 115, 32, 112, 101, 113, 117, 101, 110, 97, 115, 34, 10, 34,
+77, 101, 100, 105, 117, 109, 32, 107, 101, 121, 115, 34, 32, 61, 32, 34, 84, 101, 99, 108, 97, 115, 32, 109,
+195, 169, 100, 105, 97, 115, 34, 10, 34, 76, 97, 114, 103, 101, 32, 107, 101, 121, 115, 34, 32, 61, 32, 34,
+84, 101, 99, 108, 97, 115, 32, 103, 114, 97, 110, 100, 101, 115, 34, 10, 34, 86, 101, 108, 111, 99, 105, 116,
+121, 58, 32, 119, 104, 101, 114, 101, 32, 121, 111, 117, 32, 116, 111, 117, 99, 104, 34, 32, 61, 32, 34, 86,
+101, 108, 111, 99, 105, 116, 121, 58, 32, 111, 110, 100, 101, 32, 118, 111, 99, 195, 170, 32, 116, 111, 99, 97,
+34, 10, 34, 86, 101, 108, 111, 99, 105, 116, 121, 58, 32, 102, 105, 120, 101, 100, 34, 32, 61, 32, 34, 86,
+101, 108, 111, 99, 105, 116, 121, 58, 32, 102, 105, 120, 97, 34, 10, 34, 87, 104, 101, 114, 101, 32, 121, 111,
+117, 32, 116, 111, 117, 99, 104, 58, 32, 110, 101, 97, 114, 32, 116, 104, 101, 32, 116, 111, 112, 32, 111, 102,
+32, 97, 32, 107, 101, 121, 32, 112, 108, 97, 121, 115, 32, 115, 111, 102, 116, 44, 32, 110, 101, 97, 114, 32,
+116, 104, 101, 32, 98, 111, 116, 116, 111, 109, 32, 108, 111, 117, 100, 34, 32, 61, 32, 34, 79, 110, 100, 101,
+32, 118, 111, 99, 195, 170, 32, 116, 111, 99, 97, 58, 32, 112, 101, 114, 116, 111, 32, 100, 111, 32, 116, 111,
+112, 111, 32, 100, 97, 32, 116, 101, 99, 108, 97, 32, 116, 111, 99, 97, 32, 102, 114, 97, 99, 111, 44, 32,
+112, 101, 114, 116, 111, 32, 100, 97, 32, 98, 97, 115, 101, 32, 102, 111, 114, 116, 101, 34, 10, 34, 78, 111,
+116, 101, 32, 110, 97, 109, 101, 115, 34, 32, 61, 32, 34, 78, 111, 109, 101, 115, 32, 100, 97, 115, 32, 110,
+111, 116, 97, 115, 34, 10, 34, 80, 108, 97, 121, 115, 58, 32, 123, 48, 125, 34, 32, 61, 32, 34, 84, 111,
+99, 97, 58, 32, 123, 48, 125, 34, 10, 34, 83, 101, 108, 101, 99, 116, 32, 97, 32, 99, 104, 97, 110, 110,
+101, 108, 32, 105, 110, 32, 116, 104, 101, 32, 67, 104, 97, 110, 110, 101, 108, 32, 82, 97, 99, 107, 34, 32,
+61, 32, 34, 83, 101, 108, 101, 99, 105, 111, 110, 101, 32, 117, 109, 32, 99, 97, 110, 97, 108, 32, 110, 111,
+32, 67, 104, 97, 110, 110, 101, 108, 32, 82, 97, 99, 107, 34, 10,
 };
 } // namespace lynx::i18n::data

+ 61 - 9
src/ui/MainComponent.cpp

@@ -20,6 +20,9 @@
 
 #include "core/RackOps.h"
 #include "core/Templates.h"
+#include "ui/NewProjectDialog.h"
+#include "ui/PluginMonitorWindow.h"
+#include "ui/TouchKeyboard.h"
 #include "engine/MidiFileIo.h"
 #include "engine/ProjectFile.h"
 #include "ui/AutomationUi.h"
@@ -2080,19 +2083,64 @@ void MainComponent::autosave()
         folder.getChildFile (juce::String::fromUTF8 (old.c_str()) + ProjectFile::extension).deleteFile();
 }
 
-void MainComponent::newProject()
+void MainComponent::newProject (bool askAlways)
 {
-    confirmDiscard ([this] {
-        engine.stop();
-        engine.rewind();
-        engine.setSong (Song::makeDefault());
-        currentFile = juce::File();
-        projectName = {};
-        importedSuffix = {};
-        updateTitle();
+    confirmDiscard ([this, askAlways] {
+        if (! askAlways && ! newProjectDialogEnabled())
+        {
+            startNewProject (Song::makeDefault(), {});
+            return;
+        }
+        showNewProjectDialog ([safe = juce::Component::SafePointer<MainComponent> (this)] (Song song, juce::File file) {
+            if (safe != nullptr)
+                safe->startNewProject (std::move (song), file);
+        });
     });
 }
 
+void MainComponent::startNewProject (Song song, const juce::File& file)
+{
+    engine.stop();
+    engine.rewind();
+    engine.setSong (std::move (song));
+    currentFile = juce::File();
+    projectName = {};
+    importedSuffix = {};
+
+    if (file != juce::File())
+    {
+        juce::String error;
+        file.getParentDirectory().createDirectory();
+        if (ProjectFile::save (engine.getSong(), file, error))
+        {
+            engine.markSaved();
+            rememberRecent (file);
+            currentFile = file;
+            projectName = file.getFileNameWithoutExtension();
+        }
+        else
+            juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, tr ("Could not save"), error);
+    }
+    updateTitle();
+}
+
+void MainComponent::saveAsTemplate()
+{
+    auto* w = new juce::AlertWindow (tr ("Save as template"), tr ("The template appears in File › New project... (saved in {0})", { userTemplatesFolder().getFullPathName() }),
+                                     juce::MessageBoxIconType::NoIcon);
+    w->addTextEditor ("name", projectName.isNotEmpty() ? projectName : tr ("My template"));
+    w->addButton (tr ("Save"), 1, juce::KeyPress (juce::KeyPress::returnKey));
+    w->addButton (tr ("Cancel"), 0, juce::KeyPress (juce::KeyPress::escapeKey));
+    w->enterModalState (true, juce::ModalCallbackFunction::create ([w, safe = juce::Component::SafePointer<MainComponent> (this)] (int result) {
+        if (result != 1 || safe == nullptr)
+            return;
+        safe->engine.capturePluginStates();
+        juce::String error;
+        if (! saveUserTemplate (safe->engine.getSong(), w->getTextEditorContents ("name"), error))
+            juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, tr ("Could not save"), error);
+    }), true);
+}
+
 void MainComponent::chooseFileToOpen()
 {
     confirmDiscard ([this] { chooseFileToOpenNow(); });
@@ -2438,6 +2486,7 @@ juce::PopupMenu MainComponent::getMenuForIndex (int index, const juce::String&)
     if (index == 0)
     {
         menu.addItem (tr ("New") + shortcutText ("file.new"), [this] { newProject(); });
+        menu.addItem (tr ("New project..."), [this] { newProject (true); });
 
         juce::PopupMenu templates;
         const auto names = templateNames();
@@ -2469,6 +2518,7 @@ juce::PopupMenu MainComponent::getMenuForIndex (int index, const juce::String&)
 
         menu.addItem (tr ("Save") + shortcutText ("file.save"), [this] { save (false); });
         menu.addItem (tr ("Save as...") + shortcutText ("file.saveAs"), [this] { save (true); });
+        menu.addItem (tr ("Save as template..."), [this] { saveAsTemplate(); });
         menu.addSeparator();
         menu.addItem (tr ("Export audio...") + shortcutText ("file.export"), [this] { exportAudio(); });
         menu.addItem (tr ("Open autosave folder"), [] {
@@ -2518,6 +2568,7 @@ juce::PopupMenu MainComponent::getMenuForIndex (int index, const juce::String&)
         menu.addItem (tr ("Bring back off-screen panels"), [this] { workspace.bringBackOffscreen(); });
         menu.addSeparator();
         menu.addItem (tr ("Typing keyboard as a piano") + shortcutText ("view.typingPiano"), true, typingPiano, [this] { setTypingPiano (! typingPiano); });
+        menu.addItem (tr ("Touch keyboard"), true, isTouchKeyboardOpen(), [this] { toggleTouchKeyboard (engine); });
     }
     else if (index == 3)
     {
@@ -2542,6 +2593,7 @@ juce::PopupMenu MainComponent::getMenuForIndex (int index, const juce::String&)
                 engine.getPluginHost().startBackgroundScan(); // progress in the hint bar; LYNX stays usable
         });
         menu.addItem (tr ("Manage shortcuts..."), [this] { showShortcutManager(); });
+        menu.addItem (tr ("Plugin performance monitor..."), [this] { showPluginMonitor (engine); });
         menu.addSeparator();
         menu.addItem (tr ("Record input audio"), true, engine.isAudioRecordingArmed(), [this] {
             engine.setAudioRecordingArmed (! engine.isAudioRecordingArmed());

+ 3 - 1
src/ui/MainComponent.h

@@ -185,7 +185,9 @@ private:
     juce::PopupMenu makeToolbarMenu();
     void showToolbarMenu();
     void showCustomizeToolbar();
-    void newProject();
+    void newProject (bool askAlways = false); // File › New: the New project window unless turned off
+    void startNewProject (Song song, const juce::File& file);
+    void saveAsTemplate();
     void chooseFileToOpen();
     void chooseFileToOpenNow();
     void save (bool askForFile);

+ 453 - 0
src/ui/NewProjectDialog.cpp

@@ -0,0 +1,453 @@
+#include "ui/NewProjectDialog.h"
+
+#include "core/Preferences.h"
+#include "core/Templates.h"
+#include "engine/ProjectFile.h"
+#include "ui/I18n.h"
+#include "ui/SettingsPages.h"
+#include "ui/Theme.h"
+#include "ui/ToolWindow.h"
+
+namespace lynx
+{
+namespace
+{
+using namespace settingsui;
+
+juce::File newProjectSettingsFile()
+{
+    return juce::File::getSpecialLocation (juce::File::userApplicationDataDirectory).getChildFile ("LYNX/new-project.txt");
+}
+
+struct Remembered
+{
+    bool show = true;
+    juce::String folder, author;
+    bool ownFolder = true;
+};
+
+Remembered loadRemembered()
+{
+    Remembered r;
+    const auto kv = prefs::parseKeyValues (newProjectSettingsFile().loadFileAsString().toStdString());
+    auto get = [&kv] (const char* key) { const auto it = kv.find (key); return it == kv.end() ? juce::String() : juce::String::fromUTF8 (it->second.c_str()); };
+    r.show = get ("show") != "0";
+    r.folder = get ("folder");
+    r.author = get ("author");
+    r.ownFolder = get ("ownFolder") != "0";
+    return r;
+}
+
+void saveRemembered (const Remembered& r)
+{
+    juce::String text;
+    text << "show=" << (r.show ? 1 : 0) << "\nfolder=" << r.folder << "\nauthor=" << r.author << "\nownFolder=" << (r.ownFolder ? 1 : 0) << "\n";
+    newProjectSettingsFile().getParentDirectory().createDirectory();
+    newProjectSettingsFile().replaceWithText (text);
+}
+
+struct TemplateItem
+{
+    juce::String name, description;
+    int builtIn = -2; // -1 = LYNX's default song, 0.. = makeTemplate(index), -2 = a user file
+    juce::File file;
+};
+
+std::vector<TemplateItem> templateItems (bool sample)
+{
+    std::vector<TemplateItem> items;
+    items.push_back ({ tr ("Default"), tr ("Drums and a synth on the first inserts, a limiter on Master"), -1, {} });
+    const auto names = templateNames();
+    const char* const descriptions[] = { TR_NOOP ("Nothing in the patterns"), TR_NOOP ("A four-on-the-floor beat to start from"),
+                                         TR_NOOP ("140 BPM, fast hats and an 808 with glide"), TR_NOOP ("124 BPM house groove with bass") };
+    for (int i = 0; i < (int) names.size(); ++i)
+        items.push_back ({ tr (juce::String::fromUTF8 (names[(std::size_t) i].c_str())), i < 4 ? tr (descriptions[i]) : juce::String(), i, {} });
+
+    if (sample)
+    {
+        items.push_back ({ "Night Drive kit", tr ("Your template"), -2, juce::File() });
+        items.push_back ({ "Vocal session", tr ("Your template"), -2, juce::File() });
+        return items;
+    }
+
+    for (const auto& f : userTemplatesFolder().findChildFiles (juce::File::findFiles, false, juce::String ("*") + ProjectFile::extension))
+        items.push_back ({ juce::String::fromUTF8 (templateDisplayName (f.getFileName().toStdString()).c_str()), tr ("Your template"), -2, f });
+
+    std::stable_sort (items.begin() + 1 + (long) names.size(), items.end(), [] (const TemplateItem& a, const TemplateItem& b) {
+        return a.name.compareNatural (b.name) < 0;
+    });
+    return items;
+}
+
+class TemplateList final : public juce::ListBox,
+                           private juce::ListBoxModel
+{
+public:
+    std::vector<TemplateItem> items;
+    std::function<void()> onPick;
+
+    TemplateList()
+    {
+        setModel (this);
+        setRowHeight (40);
+        setColour (juce::ListBox::backgroundColourId, theme::colour::bg0);
+        setColour (juce::ListBox::outlineColourId, theme::colour::border);
+        setOutlineThickness (1);
+    }
+
+    int getNumRows() override { return (int) items.size(); }
+
+    void paintListBoxItem (int row, juce::Graphics& g, int width, int height, bool selected) override
+    {
+        if (row < 0 || row >= (int) items.size())
+            return;
+        const auto& item = items[(std::size_t) row];
+        if (selected)
+        {
+            g.setColour (theme::colour::accentMuted);
+            g.fillRect (0, 0, width, height);
+            g.setColour (theme::colour::accent);
+            g.fillRect (0, 0, 3, height);
+        }
+        g.setColour (theme::colour::textPrimary);
+        g.setFont (theme::font (theme::type::body, true));
+        g.drawText (item.name, 12, 4, width - 20, 18, juce::Justification::centredLeft, true);
+        g.setColour (theme::colour::textSecondary);
+        g.setFont (theme::font (theme::type::small));
+        g.drawText (item.description, 12, 21, width - 20, 15, juce::Justification::centredLeft, true);
+        // the line between the built-in templates and the user's
+        if (row + 1 < (int) items.size() && item.builtIn != -2 && items[(std::size_t) row + 1].builtIn == -2)
+        {
+            g.setColour (theme::colour::borderStrong);
+            g.fillRect (8, height - 1, width - 16, 1);
+        }
+    }
+
+    void selectedRowsChanged (int) override
+    {
+        if (onPick)
+            onPick();
+    }
+};
+
+class NewProjectPanel final : public juce::Component
+{
+public:
+    NewProjectPanel (NewProjectCallback callback, bool persistentState)
+        : onCreate (std::move (callback)),
+          persistent (persistentState)
+    {
+        const auto remembered = persistent ? loadRemembered() : Remembered { true, "C:/Users/me/Music/LYNX Projects", "Me", true };
+
+        for (auto* t : { &templateTitle, &nameTitle, &timeTitle, &infoTitle })
+            addAndMakeVisible (t);
+        templateTitle.setText (tr ("Template"));
+        nameTitle.setText (tr ("Name and location"));
+        timeTitle.setText (tr ("Time settings"));
+        infoTitle.setText (tr ("Information"));
+
+        templates.items = templateItems (! persistent);
+        templates.updateContent();
+        templates.selectRow (0);
+        templates.onPick = [this] { templateChosen(); };
+        addAndMakeVisible (templates);
+        templatesFolder.setTooltip (tr ("Templates are .lynx projects in this folder (File › Save as template... puts one there)"));
+        templatesFolder.onClick = [] {
+            userTemplatesFolder().createDirectory();
+            userTemplatesFolder().startAsProcess();
+        };
+        addAndMakeVisible (templatesFolder);
+
+        auto label = [this] (juce::Label& l, const juce::String& text) {
+            styleLabel (l, text);
+            addAndMakeVisible (l);
+        };
+        auto editor = [this] (juce::TextEditor& e, const juce::String& placeholder = {}) {
+            styleEditor (e);
+            e.setTextToShowWhenEmpty (placeholder, theme::colour::textDisabled);
+            addAndMakeVisible (e);
+        };
+
+        label (nameLabel, tr ("Name"));
+        editor (name, tr ("Untitled"));
+        name.onTextChange = [this] { updatePath(); };
+        label (folderLabel, tr ("Folder"));
+        folder = juce::File::isAbsolutePath (remembered.folder) ? juce::File (remembered.folder)
+                                                                 : juce::File::getSpecialLocation (juce::File::userDocumentsDirectory).getChildFile ("LYNX Projects");
+        if (! persistent)
+            folderText = remembered.folder;
+        folderValue.setFont (theme::font (theme::type::body));
+        folderValue.setColour (juce::Label::textColourId, theme::colour::textPrimary);
+        folderValue.setColour (juce::Label::backgroundColourId, theme::colour::bg0);
+        folderValue.setMinimumHorizontalScale (0.6f);
+        addAndMakeVisible (folderValue);
+        chooseFolder.onClick = [this] { pickFolder(); };
+        addAndMakeVisible (chooseFolder);
+        saveNow.setButtonText (tr ("Save it there now"));
+        saveNow.setTooltip (tr ("Off: the project opens unsaved and asks where to go when you first save"));
+        saveNow.setToggleState (persistent ? remembered.folder.isNotEmpty() : true, juce::dontSendNotification);
+        saveNow.onClick = [this] { updatePath(); };
+        addAndMakeVisible (saveNow);
+        ownFolder.setButtonText (tr ("Create a folder for the project"));
+        ownFolder.setToggleState (remembered.ownFolder, juce::dontSendNotification);
+        ownFolder.onClick = [this] { updatePath(); };
+        addAndMakeVisible (ownFolder);
+        pathNote.setFont (theme::font (theme::type::small));
+        pathNote.setColour (juce::Label::textColourId, theme::colour::textDisabled);
+        pathNote.setMinimumHorizontalScale (0.5f);
+        addAndMakeVisible (pathNote);
+
+        label (tempoLabel, tr ("Tempo"));
+        tempo.setSliderStyle (juce::Slider::IncDecButtons);
+        tempo.setRange (10.0, 522.0, 1.0);
+        tempo.setTextValueSuffix (" BPM");
+        tempo.setIncDecButtonsMode (juce::Slider::incDecButtonsDraggable_Vertical);
+        tempo.setTextBoxStyle (juce::Slider::TextBoxLeft, false, 90, 26);
+        addAndMakeVisible (tempo);
+        label (meterLabel, tr ("Time signature"));
+        for (int i = 1; i <= 16; ++i)
+            meter.addItem (juce::String (i) + "/4", i);
+        addAndMakeVisible (meter);
+
+        label (titleLabel, tr ("Title"));
+        editor (title, tr ("same as the name"));
+        label (authorLabel, tr ("Author"));
+        editor (author);
+        author.setText (remembered.author, false);
+        label (genreLabel, tr ("Genre"));
+        editor (genre);
+        label (urlLabel, tr ("Web link"));
+        editor (url, "https://");
+
+        dontShow.setButtonText (tr ("Don't show this window for File › New"));
+        dontShow.setTooltip (tr ("File › New then starts the default project at once; this window stays in File › New project..."));
+        dontShow.setToggleState (! remembered.show, juce::dontSendNotification);
+        addAndMakeVisible (dontShow);
+
+        create.setColour (juce::TextButton::buttonColourId, theme::colour::accent);
+        create.setColour (juce::TextButton::textColourOffId, theme::colour::onAccent);
+        create.onClick = [this] { createProject(); };
+        cancel.onClick = [this] { closeToolWindowOf (*this); };
+        addAndMakeVisible (create);
+        addAndMakeVisible (cancel);
+
+        if (! persistent)
+        {
+            name.setText ("Night Drive", false);
+            genre.setText ("Synthwave", false);
+            templates.selectRow (2);
+        }
+        templateChosen();
+        setSize (700, 520);
+    }
+
+    void resized() override
+    {
+        auto area = getLocalBounds().reduced (16, 12);
+        auto bottom = area.removeFromBottom (32);
+        cancel.setBounds (bottom.removeFromRight (96));
+        bottom.removeFromRight (8);
+        create.setBounds (bottom.removeFromRight (128));
+        dontShow.setBounds (bottom.removeFromLeft (360));
+        area.removeFromBottom (10);
+
+        auto left = area.removeFromLeft (240);
+        area.removeFromLeft (20);
+        templateTitle.setBounds (left.removeFromTop (26));
+        left.removeFromTop (8);
+        templatesFolder.setBounds (left.removeFromBottom (28));
+        left.removeFromBottom (8);
+        templates.setBounds (left);
+
+        constexpr int labelWidth = 104, rowHeight = 26, gap = 6;
+        auto row = [&] (juce::Label& l, juce::Component& c) {
+            auto r = area.removeFromTop (rowHeight);
+            l.setBounds (r.removeFromLeft (labelWidth));
+            c.setBounds (r);
+            area.removeFromTop (gap);
+        };
+
+        nameTitle.setBounds (area.removeFromTop (26));
+        area.removeFromTop (8);
+        row (nameLabel, name);
+        {
+            auto r = area.removeFromTop (rowHeight);
+            folderLabel.setBounds (r.removeFromLeft (labelWidth));
+            chooseFolder.setBounds (r.removeFromRight (90));
+            r.removeFromRight (6);
+            folderValue.setBounds (r);
+            area.removeFromTop (gap);
+        }
+        auto toggles = area.removeFromTop (22).withTrimmedLeft (labelWidth);
+        saveNow.setBounds (toggles.removeFromLeft (toggles.getWidth() / 2 - 10));
+        ownFolder.setBounds (toggles);
+        pathNote.setBounds (area.removeFromTop (18).withTrimmedLeft (labelWidth));
+        area.removeFromTop (6);
+
+        timeTitle.setBounds (area.removeFromTop (26));
+        area.removeFromTop (8);
+        {
+            auto r = area.removeFromTop (rowHeight);
+            tempoLabel.setBounds (r.removeFromLeft (labelWidth));
+            tempo.setBounds (r.removeFromLeft (150));
+            r.removeFromLeft (16);
+            meterLabel.setBounds (r.removeFromLeft (100));
+            meter.setBounds (r);
+            area.removeFromTop (gap + 4);
+        }
+
+        infoTitle.setBounds (area.removeFromTop (26));
+        area.removeFromTop (8);
+        row (titleLabel, title);
+        row (authorLabel, author);
+        row (genreLabel, genre);
+        row (urlLabel, url);
+    }
+
+    void paint (juce::Graphics& g) override { g.fillAll (theme::colour::bg2); }
+
+private:
+    void templateChosen()
+    {
+        const auto row = templates.getSelectedRow();
+        if (row < 0 || row >= (int) templates.items.size())
+            return;
+        const auto song = makeSong (templates.items[(std::size_t) row]);
+        tempo.setValue (song.bpm, juce::dontSendNotification);
+        meter.setSelectedId (juce::jlimit (1, 16, song.beatsPerBar), juce::dontSendNotification);
+        updatePath();
+    }
+
+    Song makeSong (const TemplateItem& item) const
+    {
+        if (item.builtIn == -1)
+            return Song::makeDefault();
+        if (item.builtIn >= 0)
+            return makeTemplate (item.builtIn);
+        juce::String error;
+        if (auto song = ProjectFile::load (item.file, error))
+            return std::move (*song);
+        return Song::makeDefault();
+    }
+
+    NewProjectSetup setup() const
+    {
+        NewProjectSetup s;
+        s.name = name.getText().trim().toStdString();
+        s.folder = saveNow.getToggleState() ? (folderText.isNotEmpty() ? folderText : folder.getFullPathName()).toStdString() : std::string();
+        s.ownFolder = ownFolder.getToggleState();
+        s.bpm = tempo.getValue();
+        s.beatsPerBar = meter.getSelectedId();
+        s.info.title = title.getText().trim().toStdString();
+        s.info.author = author.getText().trim().toStdString();
+        s.info.genre = genre.getText().trim().toStdString();
+        s.info.url = url.getText().trim().toStdString();
+        return s;
+    }
+
+    void updatePath()
+    {
+        ownFolder.setEnabled (saveNow.getToggleState());
+        folderValue.setText ("  " + (folderText.isNotEmpty() ? folderText : folder.getFullPathName()), juce::dontSendNotification);
+        const auto path = newProjectPath (setup(), ProjectFile::extension);
+        pathNote.setText (path.empty() ? tr ("Not saved until you choose File › Save") : juce::String::fromUTF8 (path.c_str()).replaceCharacter ('/', juce::File::getSeparatorChar()),
+                          juce::dontSendNotification);
+        create.setEnabled (true);
+    }
+
+    void pickFolder()
+    {
+        chooser = std::make_unique<juce::FileChooser> (tr ("Folder for the project"), folder);
+        chooser->launchAsync (juce::FileBrowserComponent::openMode | juce::FileBrowserComponent::canSelectDirectories, [this] (const juce::FileChooser& fc) {
+            if (fc.getResult() == juce::File())
+                return;
+            folder = fc.getResult();
+            folderText = {};
+            saveNow.setToggleState (true, juce::dontSendNotification);
+            updatePath();
+        });
+    }
+
+    void createProject()
+    {
+        const auto row = templates.getSelectedRow();
+        if (row < 0 || row >= (int) templates.items.size())
+            return;
+        const auto s = setup();
+        auto song = makeSong (templates.items[(std::size_t) row]);
+        applySetup (song, s);
+        if (s.info.title.empty() && name.getText().trim().isEmpty())
+            song.info.title.clear();
+
+        juce::File file;
+        if (const auto path = newProjectPath (s, ProjectFile::extension); ! path.empty())
+        {
+            file = juce::File (juce::String::fromUTF8 (path.c_str()).replaceCharacter ('/', juce::File::getSeparatorChar()));
+            if (file.existsAsFile())
+            {
+                juce::AlertWindow::showMessageBoxAsync (juce::MessageBoxIconType::WarningIcon, tr ("New project"),
+                                                        tr ("{0} already exists. Choose another name or folder.", { file.getFullPathName() }));
+                return;
+            }
+        }
+
+        if (persistent)
+            saveRemembered ({ ! dontShow.getToggleState(), saveNow.getToggleState() ? folder.getFullPathName() : juce::String(), author.getText().trim(),
+                              ownFolder.getToggleState() });
+
+        auto callback = onCreate;
+        closeToolWindowOf (*this); // deletes this panel
+        if (callback)
+            callback (std::move (song), file);
+    }
+
+    NewProjectCallback onCreate;
+    bool persistent = true;
+    juce::File folder;
+    juce::String folderText; // snapshot mode: a fixed path to show
+    SectionTitle templateTitle, nameTitle, timeTitle, infoTitle;
+    TemplateList templates;
+    juce::TextButton templatesFolder { tr ("Open the templates folder") };
+    juce::Label nameLabel, folderLabel, folderValue, pathNote, tempoLabel, meterLabel, titleLabel, authorLabel, genreLabel, urlLabel;
+    juce::TextEditor name, title, author, genre, url;
+    juce::TextButton chooseFolder { tr ("Choose...") };
+    juce::ToggleButton saveNow, ownFolder, dontShow;
+    juce::Slider tempo;
+    juce::ComboBox meter;
+    juce::TextButton create { tr ("Create") }, cancel { tr ("Cancel") };
+    std::unique_ptr<juce::FileChooser> chooser;
+};
+} // namespace
+
+juce::File userTemplatesFolder()
+{
+    return juce::File::getSpecialLocation (juce::File::userDocumentsDirectory).getChildFile ("LYNX/Templates");
+}
+
+bool newProjectDialogEnabled()
+{
+    return loadRemembered().show;
+}
+
+bool saveUserTemplate (const Song& song, const juce::String& name, juce::String& error)
+{
+    const auto legal = juce::String::fromUTF8 (legalProjectName (name.toStdString()).c_str());
+    const auto folder = userTemplatesFolder();
+    if (! folder.createDirectory())
+    {
+        error = tr ("could not create {0}", { folder.getFullPathName() });
+        return false;
+    }
+    return ProjectFile::save (song, folder.getChildFile (legal + ProjectFile::extension), error);
+}
+
+void showNewProjectDialog (NewProjectCallback onCreate)
+{
+    openToolWindow (std::make_unique<NewProjectPanel> (std::move (onCreate), true), tr ("New project"), "new-project");
+}
+
+std::unique_ptr<juce::Component> makeNewProjectPanel()
+{
+    return std::make_unique<NewProjectPanel> (NewProjectCallback {}, false);
+}
+} // namespace lynx

+ 27 - 0
src/ui/NewProjectDialog.h

@@ -0,0 +1,27 @@
+#pragma once
+
+#include <functional>
+#include <memory>
+
+#include <juce_gui_basics/juce_gui_basics.h>
+
+#include "core/Song.h"
+
+namespace lynx
+{
+// The New project window (FL's "New project", interpreted; REA_rodada84): a template (LYNX's default, the built-in
+// ones, or the user's own .lynx files in Documents\LYNX\Templates), name and folder, tempo and time signature, the
+// project's credits. `onCreate` receives the new song and, when a folder was chosen, the file it should be saved to.
+using NewProjectCallback = std::function<void (Song song, juce::File file)>;
+void showNewProjectDialog (NewProjectCallback onCreate);
+
+// Whether File › New opens the window (the "Don't show this again" choice), and the user templates' folder.
+bool newProjectDialogEnabled();
+juce::File userTemplatesFolder();
+
+// Saves `song` as a user template named `name` (File › Save as template...). False with `error` on failure.
+bool saveUserTemplate (const Song& song, const juce::String& name, juce::String& error);
+
+// The window's content, for --snapshot mode (sample user templates, nothing saved).
+std::unique_ptr<juce::Component> makeNewProjectPanel();
+} // namespace lynx

+ 14 - 1
src/ui/PlaylistComponent.cpp

@@ -1,3 +1,4 @@
+#include "ui/ClipProperties.h"
 #include "ui/PlaylistComponent.h"
 
 #include "core/ClipOps.h"
@@ -166,7 +167,8 @@ enum ArrangementAction
     newArrangement = 1001,
     cloneArrangement,
     renameArrangementAction,
-    removeArrangementAction
+    removeArrangementAction,
+    manageArrangements
 };
 } // namespace
 
@@ -195,6 +197,8 @@ void PlaylistComponent::refreshArrangementBox()
         arrangementBox.addItem (tr ("Clone this one"), cloneArrangement);
         arrangementBox.addItem (tr ("Rename..."), renameArrangementAction);
         arrangementBox.addItem (tr ("Remove this one"), removeArrangementAction);
+        arrangementBox.addSeparator();
+        arrangementBox.addItem (tr ("Arrangements and merging..."), manageArrangements);
         arrangementBox.setItemEnabled (removeArrangementAction, names.size() > 1);
     }
 
@@ -227,6 +231,9 @@ void PlaylistComponent::arrangementChosen()
         case renameArrangementAction:
             renameArrangement();
             break;
+        case manageArrangements:
+            showArrangements (engine);
+            break;
         case removeArrangementAction:
             engine.editSong ([] (Song& s) { s.removeArrangement (s.currentArrangement); });
             break;
@@ -2295,6 +2302,12 @@ juce::PopupMenu PlaylistComponent::buildClipMenu (int index, int mouseX)
     else if (clip.kind == ClipKind::automation && clip.automation >= 0 && clip.automation < (int) song.automations.size())
         sourceName = juce::String::fromUTF8 (song.automations[(std::size_t) clip.automation].name.c_str());
     menu.addSectionHeader (sourceName);
+    menu.addItem (tr ("Properties..."), [this, index, targets] {
+        showClipProperties (engine, index, targets, [safe = juce::Component::SafePointer<PlaylistComponent> (this)] {
+            if (safe != nullptr)
+                safe->sortClips();
+        });
+    });
 
     if (clip.kind == ClipKind::pattern && onRenamePattern)
         menu.addItem (tr ("Rename and color..."), [this, p = clip.pattern] { onRenamePattern (p); });

+ 310 - 0
src/ui/PluginMonitorWindow.cpp

@@ -0,0 +1,310 @@
+#include "ui/PluginMonitorWindow.h"
+
+#include "core/PluginMonitor.h"
+#include "core/RackRenderer.h"
+#include "engine/AudioEngine.h"
+#include "ui/I18n.h"
+#include "ui/SettingsPages.h"
+#include "ui/Theme.h"
+#include "ui/ToolWindow.h"
+
+namespace lynx
+{
+namespace
+{
+using namespace settingsui;
+
+juce::String percent (double v)
+{
+    return v < 0.05 ? juce::String ("-") : juce::String (v, v < 10.0 ? 1 : 0) + "%";
+}
+
+juce::Colour loadColour (double v)
+{
+    return v < 25.0 ? theme::colour::meterLow : v < 60.0 ? theme::colour::meterMid : theme::colour::meterClip;
+}
+
+class MonitorTable final : public juce::Component
+{
+public:
+    std::vector<perfmon::Row> rows;
+    perfmon::SortBy sort = perfmon::SortBy::current;
+    std::function<void()> onSort;
+    std::function<juce::String (const perfmon::Source&)> describe;
+    static constexpr int headerHeight = 24, rowHeight = 22;
+
+    void paint (juce::Graphics& g) override
+    {
+        g.fillAll (theme::colour::bg0);
+        const auto cols = columns();
+        // header
+        g.setColour (theme::colour::bg3);
+        g.fillRect (0, 0, getWidth(), headerHeight);
+        g.setFont (theme::font (theme::type::small, true));
+        const juce::String names[] = { tr ("Plugin"), tr ("Where"), tr ("Now"), tr ("Average"), tr ("Peak") };
+        const perfmon::SortBy keys[] = { perfmon::SortBy::name, perfmon::SortBy::name, perfmon::SortBy::current, perfmon::SortBy::average, perfmon::SortBy::peak };
+        for (int c = 0; c < 5; ++c)
+        {
+            const auto on = keys[c] == sort && c != 1;
+            g.setColour (on ? theme::colour::textPrimary : theme::colour::textSecondary);
+            g.drawText (names[c].toUpperCase() + (on ? juce::String::fromUTF8 (c == 0 ? " \xe2\x96\xb4" : " \xe2\x96\xbe") : juce::String()),
+                        cols[c].withTrimmedLeft (8).withTrimmedRight (8).withHeight (headerHeight), c >= 2 ? juce::Justification::centredRight : juce::Justification::centredLeft);
+        }
+        g.setColour (theme::colour::border);
+        g.fillRect (0, headerHeight - 1, getWidth(), 1);
+
+        if (rows.empty())
+        {
+            g.setColour (theme::colour::textDisabled);
+            g.setFont (theme::font (theme::type::body));
+            g.drawText (tr ("Nothing to show"), getLocalBounds().withTrimmedTop (headerHeight), juce::Justification::centred);
+            return;
+        }
+
+        for (int i = 0; i < (int) rows.size(); ++i)
+        {
+            const auto y = headerHeight + i * rowHeight;
+            if (y > getHeight())
+                break;
+            const auto& r = rows[(std::size_t) i];
+            if (i % 2 == 1)
+            {
+                g.setColour (theme::colour::bg1);
+                g.fillRect (0, y, getWidth(), rowHeight);
+            }
+            g.setFont (theme::font (theme::type::body, r.source.plugin));
+            g.setColour (theme::colour::textPrimary);
+            g.drawText (juce::String::fromUTF8 (r.source.name.c_str()), cols[0].withY (y).withHeight (rowHeight).reduced (8, 0), juce::Justification::centredLeft, true);
+            g.setFont (theme::font (theme::type::small));
+            g.setColour (theme::colour::textSecondary);
+            g.drawText (describe ? describe (r.source) : juce::String::fromUTF8 (r.source.where.c_str()), cols[1].withY (y).withHeight (rowHeight).reduced (8, 0),
+                        juce::Justification::centredLeft, true);
+
+            // "now": a bar under the number (full width = 100% of one core)
+            auto now = cols[2].withY (y).withHeight (rowHeight).reduced (8, 5);
+            g.setColour (theme::colour::bg4);
+            g.fillRoundedRectangle (now.toFloat(), 2.0f);
+            g.setColour (loadColour (r.current).withAlpha (0.55f));
+            g.fillRoundedRectangle (now.toFloat().withWidth ((float) now.getWidth() * (float) juce::jlimit (0.0, 1.0, r.current / 100.0)), 2.0f);
+            g.setColour (theme::colour::textPrimary);
+            g.setFont (theme::monoFont (theme::type::small));
+            g.drawText (percent (r.current), now.reduced (4, 0), juce::Justification::centredRight);
+            g.setColour (theme::colour::textSecondary);
+            g.drawText (percent (r.average), cols[3].withY (y).withHeight (rowHeight).reduced (8, 0), juce::Justification::centredRight);
+            g.setColour (r.peak >= 60.0 ? theme::colour::meterClip : theme::colour::textSecondary);
+            g.drawText (percent (r.peak), cols[4].withY (y).withHeight (rowHeight).reduced (8, 0), juce::Justification::centredRight);
+        }
+    }
+
+    void mouseUp (const juce::MouseEvent& e) override
+    {
+        if (e.y >= headerHeight)
+            return;
+        const auto cols = columns();
+        const perfmon::SortBy keys[] = { perfmon::SortBy::name, perfmon::SortBy::name, perfmon::SortBy::current, perfmon::SortBy::average, perfmon::SortBy::peak };
+        for (int c = 0; c < 5; ++c)
+            if (cols[c].contains (e.x, cols[c].getY()))
+            {
+                sort = keys[c];
+                if (onSort)
+                    onSort();
+            }
+    }
+
+    int idealHeight() const { return headerHeight + juce::jmax (1, (int) rows.size()) * rowHeight; }
+
+private:
+    std::array<juce::Rectangle<int>, 5> columns() const
+    {
+        const auto w = getWidth();
+        const auto num = 92;
+        const auto name = juce::jmax (120, (w - 3 * num) * 45 / 100);
+        std::array<juce::Rectangle<int>, 5> c;
+        c[0] = { 0, 0, name, getHeight() };
+        c[1] = { name, 0, w - name - 3 * num, getHeight() };
+        c[2] = { w - 3 * num, 0, num + 20, getHeight() };
+        c[3] = { w - 2 * num + 20, 0, num - 20, getHeight() };
+        c[4] = { w - num, 0, num, getHeight() };
+        return c;
+    }
+};
+
+class PluginMonitorPanel final : public juce::Component,
+                                 private juce::Timer
+{
+public:
+    PluginMonitorPanel (AudioEngine& e, bool live) : engine (e), measuring (live)
+    {
+        styleLabel (findLabel, tr ("Find"));
+        addAndMakeVisible (findLabel);
+        styleEditor (find);
+        find.setTextToShowWhenEmpty (tr ("plugin, channel or insert"), theme::colour::textDisabled);
+        find.onTextChange = [this] { refreshRows(); };
+        addAndMakeVisible (find);
+        pluginsOnly.setButtonText (tr ("Plugins only"));
+        pluginsOnly.setTooltip (tr ("Only third-party plugins (VST3 / CLAP), not LYNX's own instruments and effects"));
+        pluginsOnly.onClick = [this] { refreshRows(); };
+        addAndMakeVisible (pluginsOnly);
+        freeze.setButtonText (tr ("Freeze"));
+        freeze.setTooltip (tr ("Stops updating the numbers"));
+        addAndMakeVisible (freeze);
+        resetOnPlay.setButtonText (tr ("Reset on play"));
+        resetOnPlay.setTooltip (tr ("Averages and peaks start again each time playback starts"));
+        resetOnPlay.setToggleState (true, juce::dontSendNotification);
+        addAndMakeVisible (resetOnPlay);
+        reset.onClick = [this] {
+            monitor.reset();
+            refreshRows();
+        };
+        addAndMakeVisible (reset);
+
+        total.setFont (theme::font (theme::type::body, true));
+        total.setColour (juce::Label::textColourId, theme::colour::textPrimary);
+        addAndMakeVisible (total);
+        note.setFont (theme::font (theme::type::small));
+        note.setColour (juce::Label::textColourId, theme::colour::textDisabled);
+        note.setText (tr ("100% = one processor core busy for the whole time the audio lasts"), juce::dontSendNotification);
+        addAndMakeVisible (note);
+
+        table.describe = [this] (const perfmon::Source& s) { return describe (s); };
+        table.onSort = [this] { refreshRows(); };
+        viewport.setViewedComponent (&table, false);
+        viewport.setScrollBarsShown (true, false);
+        addAndMakeVisible (viewport);
+
+        if (measuring)
+        {
+            if (auto* times = engine.getProcessTimes())
+                times->enabled.store (true);
+            startTimerHz (4);
+        }
+        timerCallback();
+        setSize (640, 380);
+    }
+
+    ~PluginMonitorPanel() override
+    {
+        if (measuring)
+            if (auto* times = engine.getProcessTimes())
+                times->enabled.store (false);
+    }
+
+    // --snapshot: plausible numbers for the demo project
+    void fillWithSamples()
+    {
+        const auto list = perfmon::sources (engine.getSong());
+        std::vector<std::uint64_t> busy (perfmon::keyCount, 0);
+        monitor.update (list, busy, 0, 0);
+        std::uint64_t audio = 0, wall = 0;
+        for (int step = 1; step <= 6; ++step)
+        {
+            audio += 250'000'000;
+            std::uint64_t sum = 0;
+            for (const auto& s : list)
+            {
+                const auto weight = (double) ((s.key * 2654435761u) % 97) / 97.0;
+                const auto load = (s.plugin ? 0.09 : 0.012) + weight * weight * (s.track >= 0 ? 0.05 : 0.035) * (1.0 + 0.3 * std::sin (step + s.key));
+                const auto ns = (std::uint64_t) (load * 250'000'000.0);
+                busy[(std::size_t) s.key] += ns;
+                sum += ns;
+            }
+            wall += sum + 4'000'000;
+            monitor.update (list, busy, audio, wall);
+        }
+        refreshRows();
+    }
+
+    void paint (juce::Graphics& g) override { g.fillAll (theme::colour::bg2); }
+
+    void resized() override
+    {
+        auto area = getLocalBounds().reduced (14, 12);
+        auto top = area.removeFromTop (28);
+        findLabel.setBounds (top.removeFromLeft (44));
+        find.setBounds (top.removeFromLeft (220));
+        top.removeFromLeft (12);
+        pluginsOnly.setBounds (top.removeFromLeft (120));
+        reset.setBounds (top.removeFromRight (80));
+        top.removeFromRight (8);
+        resetOnPlay.setBounds (top.removeFromRight (120));
+        freeze.setBounds (top.removeFromRight (80));
+        area.removeFromTop (10);
+        auto bottom = area.removeFromBottom (20);
+        total.setBounds (bottom.removeFromLeft (bottom.getWidth() / 2));
+        note.setBounds (bottom);
+        area.removeFromBottom (6);
+        viewport.setBounds (area);
+        table.setSize (area.getWidth() - (table.idealHeight() > area.getHeight() ? viewport.getScrollBarThickness() : 0), juce::jmax (area.getHeight(), table.idealHeight()));
+    }
+
+private:
+    juce::String describe (const perfmon::Source& s) const
+    {
+        const auto& song = engine.getSong();
+        if (s.channel >= 0)
+        {
+            const auto name = s.channel < (int) song.channels.size() ? juce::String::fromUTF8 (song.channels[(std::size_t) s.channel].name.c_str()) : juce::String();
+            return tr ("Channel {0}", { juce::String (s.channel + 1) }) + (name.isNotEmpty() && name != juce::String::fromUTF8 (s.name.c_str()) ? " - " + name : juce::String());
+        }
+        const auto track = s.track == 0 ? tr ("Master") : tr ("Insert {0}", { juce::String (s.track) });
+        return track + "  ·  " + tr ("slot {0}", { juce::String (s.slot + 1) });
+    }
+
+    void timerCallback() override
+    {
+        if (! measuring)
+            return;
+        const auto playing = engine.getTransport().playing.load();
+        if (playing && ! wasPlaying && resetOnPlay.getToggleState())
+            monitor.reset();
+        wasPlaying = playing;
+        if (freeze.getToggleState())
+            return;
+
+        auto* times = engine.getProcessTimes();
+        if (times == nullptr)
+            return;
+        std::vector<std::uint64_t> busy (perfmon::keyCount, 0);
+        for (int c = 0; c < perfmon::channelKeys && c < ProcessTimes::channels; ++c)
+            busy[(std::size_t) c] = times->channelNs[(std::size_t) c].load (std::memory_order_relaxed);
+        for (std::size_t k = 0; k < times->effectNs.size(); ++k)
+            busy[(std::size_t) perfmon::channelKeys + k] = times->effectNs[k].load (std::memory_order_relaxed);
+        monitor.update (perfmon::sources (engine.getSong()), busy, times->audioNs.load(), times->wallNs.load());
+        refreshRows();
+    }
+
+    void refreshRows()
+    {
+        auto rows = monitor.rows (find.getText().toStdString(), table.sort);
+        if (pluginsOnly.getToggleState())
+            rows.erase (std::remove_if (rows.begin(), rows.end(), [] (const perfmon::Row& r) { return ! r.source.plugin; }), rows.end());
+        table.rows = std::move (rows);
+        total.setText (tr ("Whole rack: {0} (peak {1})", { percent (monitor.rackCurrent()), percent (monitor.rackPeak()) }), juce::dontSendNotification);
+        resized();
+        table.repaint();
+    }
+
+    AudioEngine& engine;
+    bool measuring = true, wasPlaying = false;
+    perfmon::Monitor monitor;
+    juce::Label findLabel, total, note;
+    juce::TextEditor find;
+    juce::ToggleButton pluginsOnly, freeze, resetOnPlay;
+    juce::TextButton reset { tr ("Reset") };
+    juce::Viewport viewport;
+    MonitorTable table;
+};
+} // namespace
+
+void showPluginMonitor (AudioEngine& engine)
+{
+    openToolWindow (std::make_unique<PluginMonitorPanel> (engine, true), tr ("Plugin performance monitor"), "plugin-monitor");
+}
+
+std::unique_ptr<juce::Component> makePluginMonitorPanel (AudioEngine& engine)
+{
+    auto panel = std::make_unique<PluginMonitorPanel> (engine, false);
+    panel->fillWithSamples();
+    return panel;
+}
+} // namespace lynx

+ 18 - 0
src/ui/PluginMonitorWindow.h

@@ -0,0 +1,18 @@
+#pragma once
+
+#include <memory>
+
+#include <juce_gui_basics/juce_gui_basics.h>
+
+namespace lynx
+{
+class AudioEngine;
+
+// Plugin performance monitor (FL's, interpreted; REA_rodada84): how much processing time each instrument and effect
+// slot takes, as a share of real time (now, average, peak), with a search, Freeze, Reset and "Reset on play". The
+// rack measures only while the window is open.
+void showPluginMonitor (AudioEngine& engine);
+
+// The content for --snapshot mode, filled with sample measurements.
+std::unique_ptr<juce::Component> makePluginMonitorPanel (AudioEngine& engine);
+} // namespace lynx

+ 322 - 0
src/ui/TouchKeyboard.cpp

@@ -0,0 +1,322 @@
+#include "ui/TouchKeyboard.h"
+
+#include <map>
+
+#include "core/HeldNotes.h"
+#include "core/TouchKeyboard.h"
+#include "engine/AudioEngine.h"
+#include "ui/I18n.h"
+#include "ui/SettingsPages.h"
+#include "ui/Theme.h"
+#include "ui/ToolWindow.h"
+
+namespace lynx
+{
+namespace
+{
+juce::String keyName (int key)
+{
+    static const char* names[] = { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" };
+    return juce::String (names[((key % 12) + 12) % 12]) + juce::String (key / 12);
+}
+
+class Keys final : public juce::Component
+{
+public:
+    std::function<int()> channel;              // the channel to play (-1: none)
+    std::function<float (float)> fixedVelocity; // returns < 0 when the position decides
+    bool labels = true;
+    touchkb::Layout layout;
+    std::map<int, float> shown;               // key → velocity, for drawing (also the snapshot's pressed keys)
+
+    explicit Keys (AudioEngine& e) : engine (e), notes ([this] (int ch, int key, float velocity, bool on) {
+                                                    if (live)
+                                                        engine.sendLiveNote (ch, key, velocity, on, true);
+                                                    if (on)
+                                                        shown[key] = velocity;
+                                                    else
+                                                        shown.erase (key);
+                                                    repaint();
+                                                })
+    {
+        setRepaintsOnMouseActivity (false);
+    }
+
+    ~Keys() override { notes.releaseAll(); }
+
+    void setLive (bool on) { live = on; }
+    void releaseAll() { notes.releaseAll(); }
+    bool holding() const { return ! notes.empty(); }
+
+    void resized() override
+    {
+        layout.width = (float) getWidth();
+        layout.height = (float) getHeight();
+    }
+
+    void paint (juce::Graphics& g) override
+    {
+        g.fillAll (theme::colour::bg0);
+        const auto top = layout.lowest, last = layout.highest();
+        auto draw = [&] (bool black) {
+            for (int key = top; key <= last + 1 && key <= 127; ++key)
+            {
+                if (touchkb::isBlack (key) != black || (key > last && ! black))
+                    continue;
+                const auto r = layout.keyRect (key);
+                if (r.x + r.w > layout.width + 0.5f)
+                    continue;
+                auto box = juce::Rectangle<float> (r.x, r.y, r.w, r.h);
+                const auto held = shown.find (key);
+                if (! black)
+                {
+                    box = box.reduced (1.0f, 0.0f).withTrimmedBottom (1.0f);
+                    g.setColour (held != shown.end() ? theme::colour::keyWhite.interpolatedWith (theme::colour::accent, 0.35f + 0.5f * held->second)
+                                                     : theme::colour::keyWhite);
+                    g.fillRoundedRectangle (box, 3.0f);
+                    if (labels && (key % 12 == 0 || held != shown.end()))
+                    {
+                        g.setColour (held != shown.end() ? theme::colour::onAccent : juce::Colour (0xff6b707a));
+                        g.setFont (theme::font (theme::type::caption, key % 12 == 0));
+                        g.drawText (keyName (key), box.withTrimmedBottom (6.0f).toNearestInt(), juce::Justification::centredBottom);
+                    }
+                }
+                else
+                {
+                    g.setColour (held != shown.end() ? theme::colour::accent.withMultipliedBrightness (0.6f + 0.4f * held->second) : theme::colour::keyBlack);
+                    g.fillRoundedRectangle (box.withTrimmedTop (-3.0f), 3.0f);
+                    g.setColour (juce::Colours::white.withAlpha (0.07f));
+                    g.fillRect (box.reduced (3.0f, 0.0f).withTrimmedTop (box.getHeight() - 6.0f));
+                }
+            }
+        };
+        draw (false);
+        draw (true);
+        // the window's top edge over the keys
+        g.setColour (theme::colour::accent.withAlpha (0.8f));
+        g.fillRect (0, 0, getWidth(), 2);
+    }
+
+    void mouseDown (const juce::MouseEvent& e) override { touch (e); }
+    void mouseDrag (const juce::MouseEvent& e) override { touch (e); }
+    void mouseUp (const juce::MouseEvent& e) override { notes.releaseTag (e.source.getIndex()); }
+    void mouseExit (const juce::MouseEvent& e) override
+    {
+        if (! e.mods.isAnyMouseButtonDown())
+            notes.releaseTag (e.source.getIndex());
+    }
+    void focusLost (FocusChangeType) override { notes.releaseAll(); }
+    void visibilityChanged() override
+    {
+        if (! isShowing())
+            notes.releaseAll();
+    }
+    void parentHierarchyChanged() override
+    {
+        if (! isShowing())
+            notes.releaseAll();
+    }
+
+private:
+    void touch (const juce::MouseEvent& e)
+    {
+        const auto tag = e.source.getIndex();
+        const auto ch = channel ? channel() : -1;
+        const auto pos = e.position;
+        const auto key = getLocalBounds().toFloat().contains (pos) ? layout.noteAt (pos.x, pos.y) : -1;
+        const auto currentKey = keyOf (tag);
+
+        if (key < 0 || ch < 0)
+        {
+            notes.releaseTag (tag); // dragged off the keys
+            return;
+        }
+        if (key == currentKey)
+            return;
+
+        notes.releaseTag (tag); // glide: the previous key stops before the next starts
+        const auto fixed = fixedVelocity ? fixedVelocity (0.0f) : -1.0f;
+        notes.press (ch, key, fixed >= 0.0f ? fixed : layout.velocityAt (key, pos.y), tag);
+        tagKeys[tag] = key;
+    }
+
+    int keyOf (int tag) const
+    {
+        const auto it = tagKeys.find (tag);
+        return it != tagKeys.end() && notes.hasTag (tag) ? it->second : -1;
+    }
+
+    AudioEngine& engine;
+    HeldNotes notes;
+    std::map<int, int> tagKeys;
+    bool live = true;
+};
+
+class TouchKeyboardPanel final : public juce::Component,
+                                 private juce::Timer
+{
+public:
+    TouchKeyboardPanel (AudioEngine& e, bool liveMode) : engine (e), keys (e)
+    {
+        keys.setLive (liveMode);
+        keys.channel = [this] { return engine.getSelectedChannel(); };
+        keys.fixedVelocity = [this] (float) { return velocityMode.getSelectedItemIndex() == 0 ? -1.0f : (float) fixedVelocity.getValue() / 100.0f; };
+        addAndMakeVisible (keys);
+
+        octaveDown.setTooltip (tr ("One octave down"));
+        octaveUp.setTooltip (tr ("One octave up"));
+        octaveDown.onClick = [this] { shift (-1); };
+        octaveUp.onClick = [this] { shift (1); };
+        addAndMakeVisible (octaveDown);
+        addAndMakeVisible (octaveUp);
+        range.setFont (theme::monoFont (theme::type::small));
+        range.setJustificationType (juce::Justification::centred);
+        range.setColour (juce::Label::textColourId, theme::colour::textPrimary);
+        addAndMakeVisible (range);
+
+        sizeBox.addItemList ({ tr ("Small keys"), tr ("Medium keys"), tr ("Large keys") }, 1);
+        sizeBox.setSelectedItemIndex (1, juce::dontSendNotification);
+        sizeBox.onChange = [this] { layoutKeys(); };
+        addAndMakeVisible (sizeBox);
+        velocityMode.addItemList ({ tr ("Velocity: where you touch"), tr ("Velocity: fixed") }, 1);
+        velocityMode.setSelectedItemIndex (0, juce::dontSendNotification);
+        velocityMode.setTooltip (tr ("Where you touch: near the top of a key plays soft, near the bottom loud"));
+        velocityMode.onChange = [this] { fixedVelocity.setEnabled (velocityMode.getSelectedItemIndex() == 1); };
+        addAndMakeVisible (velocityMode);
+        fixedVelocity.setSliderStyle (juce::Slider::LinearHorizontal);
+        fixedVelocity.setTextBoxStyle (juce::Slider::TextBoxRight, false, 44, 20);
+        fixedVelocity.setRange (1.0, 100.0, 1.0);
+        fixedVelocity.setValue (80.0, juce::dontSendNotification);
+        fixedVelocity.setEnabled (false);
+        addAndMakeVisible (fixedVelocity);
+        labels.setButtonText (tr ("Note names"));
+        labels.setToggleState (true, juce::dontSendNotification);
+        labels.onClick = [this] {
+            keys.labels = labels.getToggleState();
+            keys.repaint();
+        };
+        addAndMakeVisible (labels);
+        target.setFont (theme::font (theme::type::small));
+        target.setColour (juce::Label::textColourId, theme::colour::textSecondary);
+        target.setJustificationType (juce::Justification::centredRight);
+        addAndMakeVisible (target);
+
+        if (liveMode)
+            startTimerHz (10);
+        timerCallback();
+        setSize (820, 210);
+        layoutKeys();
+    }
+
+    ~TouchKeyboardPanel() override { keys.releaseAll(); }
+
+    void showPressedForSnapshot()
+    {
+        keys.shown = { { 60, 0.95f }, { 64, 0.7f }, { 67, 0.45f }, { 70, 0.8f } };
+        keys.repaint();
+    }
+
+    void paint (juce::Graphics& g) override { g.fillAll (theme::colour::bg3); }
+
+    void resized() override
+    {
+        auto area = getLocalBounds();
+        auto bar = area.removeFromTop (38).reduced (10, 6);
+        octaveDown.setBounds (bar.removeFromLeft (30));
+        range.setBounds (bar.removeFromLeft (92));
+        octaveUp.setBounds (bar.removeFromLeft (30));
+        bar.removeFromLeft (12);
+        sizeBox.setBounds (bar.removeFromLeft (124));
+        bar.removeFromLeft (8);
+        velocityMode.setBounds (bar.removeFromLeft (196));
+        bar.removeFromLeft (6);
+        fixedVelocity.setBounds (bar.removeFromLeft (120));
+        bar.removeFromLeft (8);
+        labels.setBounds (bar.removeFromLeft (110));
+        target.setBounds (bar);
+        keys.setBounds (area);
+    }
+
+private:
+    void layoutKeys()
+    {
+        static const int whites[] = { 35, 28, 21 };
+        keys.layout.whiteKeys = whites[juce::jlimit (0, 2, sizeBox.getSelectedItemIndex())];
+        keys.layout.lowest = touchkb::shiftOctave (keys.layout.lowest, 0, keys.layout.whiteKeys);
+        keys.releaseAll();
+        updateRange();
+        keys.repaint();
+    }
+
+    void shift (int octaves)
+    {
+        keys.releaseAll(); // the held keys would otherwise change under the finger
+        keys.layout.lowest = touchkb::shiftOctave (keys.layout.lowest, octaves, keys.layout.whiteKeys);
+        updateRange();
+        keys.repaint();
+    }
+
+    void updateRange()
+    {
+        range.setText (keyName (keys.layout.lowest) + " - " + keyName (keys.layout.highest()), juce::dontSendNotification);
+        octaveDown.setEnabled (keys.layout.lowest >= 12);
+        touchkb::Layout probe = keys.layout;
+        probe.lowest += 12;
+        octaveUp.setEnabled (probe.highest() <= 127);
+    }
+
+    void timerCallback() override
+    {
+        const auto channel = engine.getSelectedChannel();
+        if (channel != lastChannel)
+        {
+            keys.releaseAll(); // the notes go to the channel that started them; stop them before switching
+            lastChannel = channel;
+        }
+        const auto& song = engine.getSong();
+        target.setText (channel >= 0 && channel < (int) song.channels.size()
+                            ? tr ("Plays: {0}", { juce::String::fromUTF8 (song.channels[(std::size_t) channel].name.c_str()) })
+                            : tr ("Select a channel in the Channel Rack"),
+                        juce::dontSendNotification);
+    }
+
+    AudioEngine& engine;
+    Keys keys;
+    int lastChannel = -2;
+    juce::TextButton octaveDown { "-" }, octaveUp { "+" };
+    juce::Label range, target;
+    juce::ComboBox sizeBox, velocityMode;
+    juce::Slider fixedVelocity;
+    juce::ToggleButton labels;
+};
+} // namespace
+
+bool isTouchKeyboardOpen()
+{
+    return findToolWindow ("touch-keyboard") != nullptr;
+}
+
+void toggleTouchKeyboard (AudioEngine& engine)
+{
+    if (auto* w = findToolWindow ("touch-keyboard"))
+    {
+        if (auto* content = w->getContentComponent())
+            closeToolWindowOf (*content);
+        return;
+    }
+    if (auto* window = openToolWindow (std::make_unique<TouchKeyboardPanel> (engine, true), tr ("Touch keyboard"), "touch-keyboard"))
+        if (auto* main = juce::TopLevelWindow::getTopLevelWindow (0))
+        {
+            // along the bottom of the main window, where an on-screen keyboard is expected
+            const auto area = main->getScreenBounds();
+            window->setTopLeftPosition (area.getCentreX() - window->getWidth() / 2, area.getBottom() - window->getHeight() - 40);
+        }
+}
+
+std::unique_ptr<juce::Component> makeTouchKeyboardPanel (AudioEngine& engine)
+{
+    auto panel = std::make_unique<TouchKeyboardPanel> (engine, false);
+    panel->showPressedForSnapshot();
+    return panel;
+}
+} // namespace lynx

+ 20 - 0
src/ui/TouchKeyboard.h

@@ -0,0 +1,20 @@
+#pragma once
+
+#include <memory>
+
+#include <juce_gui_basics/juce_gui_basics.h>
+
+namespace lynx
+{
+class AudioEngine;
+
+// Touch keyboard (FL's "Touch keyboard", interpreted; REA_rodada84): an on-screen piano that plays the selected
+// channel. How far down a key is touched sets the velocity (or a fixed velocity), several fingers play at once, a
+// drag glides from key to key, octave buttons shift it. Every note it starts is stopped when the finger or mouse is
+// released, leaves the keys, the selected channel changes or the window closes. Toggled from View.
+void toggleTouchKeyboard (AudioEngine& engine);
+bool isTouchKeyboardOpen();
+
+// The content for --snapshot mode (`pressed` keys drawn as held, nothing is played).
+std::unique_ptr<juce::Component> makeTouchKeyboardPanel (AudioEngine& engine);
+} // namespace lynx

+ 15 - 0
tests/DialogsTests84.inc

@@ -455,3 +455,18 @@ TEST (touch_keyboard_geometry_velocity_and_no_stuck_notes)
     CHECK (ons == 4);
     CHECK (std::all_of (balance.begin(), balance.end(), [] (const auto& e) { return e.second == 0; }));
 }
+
+TEST (clipprops_bar_beat_tick_text)
+{
+    using namespace lynx;
+    using namespace lynx::clipprops;
+    const auto beat = (std::int64_t) ppq, bar = beat * 4;
+    CHECK (formatPosition (0, 4) == "1:1:000" && formatLength (0, 4) == "0:0:000");
+    CHECK (formatPosition (2 * bar + beat + 5, 4) == "3:2:005" && formatLength (2 * bar + beat + 5, 4) == "2:1:005");
+    CHECK (parsePosition ("3:2:005", 4) == 2 * bar + beat + 5 && parseLength ("2:1:005", 4) == 2 * bar + beat + 5);
+    CHECK (parsePosition ("5", 4) == 4 * bar && parsePosition ("5:3", 4) == 4 * bar + 2 * beat && parseLength ("2", 4) == 2 * bar);
+    CHECK (parsePosition ("0:1:000", 4) == -1 && parsePosition ("1:5:000", 4) == -1 && parsePosition ("1:1:x", 4) == -1 && parsePosition ("", 4) == -1);
+    CHECK (parsePosition ("1:4", 3) == -1 && parsePosition ("2:3", 3) == 3 * beat + 2 * beat);
+    for (std::int64_t t : { (std::int64_t) 0, beat * 7 + 33, bar * 100 + 1 })
+        CHECK (parsePosition (formatPosition (t, 4), 4) == t && parseLength (formatLength (t, 7), 7) == t);
+}