Selaa lähdekoodia

Merge origin/main into feature/extfx164

Ka1-S 1 kuukausi sitten
vanhempi
sitoutus
bfe10c1a3d

+ 3 - 0
CMakeLists.txt

@@ -127,6 +127,8 @@ add_library(lynx_core STATIC
     src/core/LynxVerbs.cpp
     src/core/FlPatcher.cpp
     src/core/Patcher.cpp
+    src/core/Vfx.cpp
+    src/core/VfxSequencer.cpp
     src/core/ThreeOsc.cpp
     src/core/Plucked.cpp
     src/core/SoundFont.cpp
@@ -309,6 +311,7 @@ if(LYNX_BUILD_APP)
         src/ui/NewtoneEditor.cpp
         src/ui/ChannelSettings.cpp
         src/ui/SoundFontEditor.cpp
+        src/ui/VfxEditors.cpp
         src/ui/BrowserComponent.cpp
         src/ui/Theme.cpp
         src/ui/ThemeSettings.cpp

BIN
Vfx.o


BIN
VfxSequencer.o


+ 163 - 0
docs/analise/REA_rodada164b.md

@@ -0,0 +1,163 @@
+# Round 164b — FL's VFX note effects (vfx164)
+
+Goal: FL Studio's **VFX** plugins are note-level processors. They sit in a Patcher between "From FL Studio" and the
+generators, or on a Channel Rack channel, and they change, split, create or animate notes. This round lists the family
+and builds a LYNX equivalent of each one. Each equivalent gets:
+- its own editor;
+- FL's presets;
+- .flp import;
+- entries in the plugin picker, in the Patcher's "Add plugin" columns and in the Browser;
+- tests, screenshots and pt-BR strings.
+
+Evidence markers:
+- [DECOMP fn]: Ghidra decompile of FL's plugin DLL (clean-room: behaviour only, our own code);
+- [PRESET]: FL's factory presets / plugin database states, parsed;
+- [EXEC FL]: seen in a running FL Studio 2026;
+- [TEST]: LYNX unit test;
+- [RUN]: measured with LYNX;
+- [HYP]: inferred, not proven.
+
+The full specs written for this round are in the job folder (`tmp/vfx164/spec-*.md`, not in the repo). The sections
+below record what LYNX does and where it differs.
+
+## 1. The family
+
+FL Studio 2026 installs seven VFX plugins: `Plugins/Fruity/Effects/VFX *`, and `Data/Patches/Plugin database/Effects/Patcher/VFX *.fst`.
+VFX Pads is not installed.
+
+| FL plugin | What it does | LYNX | FL presets |
+|---|---|---|---|
+| VFX Key Mapper | each input pitch class → a set of output notes (transpose, scales, chords, harmony); multimode all / gain-compensated / random / cycle up / cycle down; base key, offset, pitch slide | ✅ processor + editor | ✅ 33 factory .fst read and written back byte for byte [TEST] |
+| VFX Color Mapper | note colour → voice output 1…16 and a new colour | ✅ | ✅ (Default) |
+| VFX Level Scaler | per property (velocity, release, fine pitch, pan, Mod X, Mod Y) a transfer curve: center, multiply, offset, tension, humanize (subtract / spread / add) | ✅ (applied at note-on; release at note-off) | ✅ FL's curves to 1e-6 [TEST]; LYNX's own presets (humanize, softer, compress…) |
+| VFX Keyboard Splitter | 16 zones, each a keyboard map and a velocity map (FL's TMMap curves), transpose, random, absolute; one output per zone | ✅ (except Manual mapping) | ✅ factory presets read; the zones are written back equal [TEST] |
+| VFX Envelope | 16 articulators (note colour + key range) × 5 targets (velocity, pitch, pan, Mod X, Mod Y), each with an envelope and an LFO, as in the Envelope Controller | ✅ (loop points ignored, see §4) | ✅ factory presets round-trip [TEST] |
+| VFX Sequencer | FL's port of BlueARP: a bank of 128 step programs (scale step, octave, step type, key select, velocity, gate lanes × 64 steps) that turn held notes into arpeggios / sequences | ✅ engine + editor (chains not played, see §4) | ✅ FL's factory bank (plugin database state) read and written back byte for byte; "Factory bank" in the preset menu [TEST] |
+| VFX Script | Python 3.12 note scripts (`import flvfx`) | ⚠️ the script and its control values are kept and editable; **LYNX does not run Python**: notes pass through | ✅ 89 factory scripts read and written back byte for byte [TEST] |
+
+## 2. Where they live in LYNX
+
+- **Engine**: `src/core/Vfx.h` / `Vfx.cpp` (states, the processors of six kinds), `VfxSequencer.cpp` (the
+  Sequencer), and `VfxDetail.h` (byte reader and the lock-free settings hand-over).
+  - The processors never allocate or lock on the audio thread.
+  - New settings are handed over through an atomic pending/retired pair, the same pattern as the Patcher graph.
+  - The Envelope's runtime is about 1.7 MB, so it is built on the heap on the UI thread.
+- **State**: `ChannelDef::pluginState` = "LVFX" header (kind, the channel's output MIDI port), then FL's own 0xD5 bytes.
+  An .flp / .fst state therefore loads unchanged, and LYNX saves it unchanged.
+- **Patcher**: VFX nodes take the notes of "From LYNX" or of another VFX node, and their outputs cable to generators
+  or to other VFX nodes. Output pins:
+  - Color Mapper and Keyboard Splitter have 16 outputs. Four are shown, as in FL, and the zone names become the pin names.
+  - The other kinds have one output.
+
+  Voice properties that change over time (the Envelope, the Key Mapper's pitch slide) reach the instruments through
+  `Instrument::voiceProperty`. The Synth and the Sampler implement it.
+- **Channel Rack**: "VFX (note effects)" submenu. A VFX channel sends output k to MIDI port `port + k`, and its
+  editor has an "Output port" control and "Send to a plugin...".
+- **.flp import**: VFX channels and Patcher VFX nodes, with their states, ports and cables.
+- **Lists**:
+  - the plugin picker (vendor LYNX, ids `lynx:vfx:<kind>`);
+  - the Patcher's Add plugin › Patcher column;
+  - the Browser's Generators › "VFX (note effects)" folder.
+- **CLI**: `LYNX --vfxshot <prefix>` saves an editor per kind, plus a Patcher with Color Mapper → 3 synths and its menus.
+
+## 3. Behaviour notes (what FL does, rebuilt)
+
+- **Velocity ↔ volume**: FL's law vol = (11^(1.28·v) − 1) / 10, so velocity 100/128 is volume 1.
+  - Keyboard Splitter map gain: g(m) = (11^m − 1) / 10 [DECOMP].
+  - The Sequencer's "MIDI velocity" is volume × 100 [DECOMP].
+- **Key Mapper**:
+  - row = (key − base + 12) mod 12;
+  - out = key − row + value + offset;
+  - the cycle modes walk the row's stored order;
+  - pitch slide: the new note starts at the played pitch and glides at 0.01^(beats·192/slide) per block [DECOMP, TEST].
+- **Level Scaler**:
+  - T(x) = clamp(sign(d)·shape(|d|·S)·mul + off) around the center;
+  - tension uses (8193^t − 1);
+  - the identity skip happens when Multiply = 8192, Offset = Tension = Humanize = 0;
+  - humanize draws one random value per note and tab [DECOMP, TEST].
+- **Keyboard Splitter**:
+  - every active zone whose gain > 0 plays a copy on its output;
+  - random zones: one is picked, weighted by g(map);
+  - absolute: the velocity map gives the volume [DECOMP, TEST].
+- **Envelope**: the Envelope Controller's articulator code (FlSynths.h `controllerValue` …) drives each target.
+  - Pitch: ±48 semitones at 100 %, Init.Pitch clamped to 0…12000 cents.
+  - Velocity: multiplicative, 0…4.
+  - Pan / Mod: additive [DECOMP, TEST].
+- **Sequencer** (BlueARP):
+  - step = floor(position / step length) mod steps, swing on step pairs;
+  - key list: held keys in the chosen order (pitch, played, velocity, chord normalized / as played, with the chord
+    table of 38 chords), missing keys N1…N5 filled (cyclic, first, last, fixed);
+  - pitch: scale forcing (snap down, then move by scale steps), transpose, output wrap;
+  - per step: Off / Rest / Note / Tie / Chord / Random, octave bits, velocity mode, random velocity / gate / start;
+  - a rest lengthens the previous note by a step, and a tie stretches it to 1.25 steps (legato);
+  - restart on beat / key / first key / play;
+  - stopped transport: its own clock, kept for one second after the last key [DECOMP].
+  - Notes start at their exact sample. FL starts them at the processing block, so LYNX is tighter.
+
+## 4. Differences and limits (honest list)
+
+- **VFX Script does not run**. Python is not embedded, so the script's notes pass through unchanged and the editor
+  says so. The script text and control values are kept, editable and saved, and FL still runs them on that project.
+  The next steps are written in "Where I stopped".
+- **Sequencer chains** (the 16 chains of 8 programs) are kept in the state but not played. No FL preset uses them; only
+  the plugin database bank defines 8. Also not reproduced:
+  - incoming program changes;
+  - sustain pedal / CC filters (LYNX's VFX events carry notes only);
+  - Smart bend's "cut all but the first note" on change.
+- **Envelope**: the loop points of its envelopes are ignored, so FL's "Pumping" preset does not loop. A free (non-tempo)
+  envelope's time is in seconds.
+- **Level Scaler** is applied at note-on; FL re-evaluates it every tick, so automating it moves held notes.
+- **Keyboard Splitter**:
+  - "Manual mapping" (press keys to map zones) is not implemented.
+  - When no random zone wins, FL plays zone 1. LYNX plays no random zone.
+- **Voice properties over time** (Envelope, pitch slide) reach instruments inside a Patcher only. On a Channel Rack VFX
+  channel the notes are routed by MIDI port and the property changes are dropped.
+- VFX outputs to the Patcher's "To LYNX" MIDI ports are not supported.
+- The Level Scaler's "Event persistence" lollipop display is not drawn.
+
+## 5. Verification
+
+- `tests/Vfx164Tests.inc` [TEST]: 19 tests. Among them:
+  - FL's factory presets for Key Mapper / Splitter / Envelope / Script / the Sequencer bank, round-tripped;
+  - the Level Scaler's test vectors;
+  - the Sequencer's FL vectors T1–T12: up-arp of program 3, missing keys, thru, scale forcing, swing, output wrap,
+    rest / tie, chord normalized, stopped clock;
+  - Patcher and channel routing.
+- **CPU** [RUN]: the Sequencer runs 1 s of audio (4 keys, chords on every step, 140 bpm) in 0.74 ms, 0.07 % of one core.
+  The other processors only work at note events. The Envelope works per block for the voices it matches.
+- Screenshots: `--vfxshot` saves an editor per kind, plus the Sequencer with FL's factory bank and the Script with
+  FL's "Snap To Scale". They were compared with FL 2026 running (`/mnt/d/lynx-work/vfx164/shots/`, sequencer/ and
+  script/) [EXEC FL]. The layout follows FL's, drawn with our own controls:
+  - program selector, Latch, pages, Page lock, shift;
+  - the big grid of the selected lane over six overview lanes;
+  - MODE / INPUT / ARPEGGIATOR / OUTPUT panel.
+- Used in the Windows app like a user [RUN]:
+  - Channel Rack › + › VFX (note effects) › VFX Sequencer adds the channel and opens its editor;
+  - clicking a Note select cell sets the step (N2 → R);
+  - picking the Velocity lane shows its bars;
+  - a click on a bar sets the velocity (96 → 42), and the overview row follows.
+
+## Where I stopped
+
+Landed: the seven kinds, each with:
+- state;
+- processor (the Script passes notes through);
+- editor;
+- FL presets;
+- .flp import;
+- picker / Patcher / Browser entries;
+- tests;
+- pt-BR strings.
+
+Left for later, in order of value:
+1. **VFX Script running Python.** This needs an embedded CPython 3.12 (about 30 MB, its own licence and packaging on the
+   three platforms) and a clean-room `flvfx` module: voices, `onTriggerVoice` / `onReleaseVoice` / `onTick`, and
+   `createDialog` surface controls. The state and the editor are ready for it. `ScriptSettings::parameters()` already reads
+   the control values. Running a script must stay off the audio thread (a worker with a lock-free event queue), and a
+   slow script must not glitch audio.
+2. **Sequencer chains and program changes**: the 16 × 8 chain tables are parsed (`SequencerSettings::chains`); an
+   incoming program change would select the program or chain step.
+3. **Envelope loop points** (FL's "Pumping" preset).
+4. **Level Scaler re-evaluated per tick** (automation on held notes) and the "Event persistence" lollipop display.
+5. **Keyboard Splitter Manual mapping**, and FL's zone-1 fallback for random zones.
+6. **Voice property changes** on Channel Rack VFX channels (now Patcher only) and VFX → "To LYNX" MIDI ports.

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

@@ -4869,6 +4869,157 @@ countries: br
 "Round trip: {0} samples" = "Ida e volta: {0} amostras"
 "Ping" = "Ping"
 
+# Round 164b: FL's VFX note effects
+"Enable" = "Ativar"
+"All (gain-compensated)" = "Todas (ganho compensado)"
+"Cycle up" = "Ciclo para cima"
+"Cycle down" = "Ciclo para baixo"
+"Multimode: how an input mapped to several notes plays them" = "Multimodo: como uma entrada mapeada para várias notas as toca"
+"Multimode" = "Multimodo"
+"Base key" = "Tom base"
+"Pitch slide" = "Deslize de altura"
+"{0} plays {1} - left-click: add / remove, right-click: only this note, middle-click or Alt+click: reset the row" = "{0} toca {1} - clique esquerdo: adiciona / remove, clique direito: só esta nota, clique do meio ou Alt+clique: restaura a linha"
+"Offset (transpose)" = "Deslocamento (transpor)"
+"Base key: the note the rows and their octaves start on" = "Tom base: a nota em que as linhas e suas oitavas começam"
+"Pitch slide: the new notes start at the played pitch and glide to their own (in steps)" = "Deslize de altura: as notas novas começam na altura tocada e deslizam até a sua (em passos)"
+"Voice {0}" = "Voz {0}"
+"The voice output the notes of colour {0} go to" = "A saída de voz para onde vão as notas da cor {0}"
+"The colour the notes of colour {0} leave with" = "A cor com que saem as notas da cor {0}"
+"Voice output" = "Saída de voz"
+"Multiply" = "Multiplicar"
+"Subtract" = "Subtrair"
+"Humanize mode: the random part goes below the value, around it or above it" = "Modo de humanização: a parte aleatória fica abaixo do valor, em volta dele ou acima"
+"Reset all controls of this property" = "Restaura todos os controles desta propriedade"
+"in" = "entrada"
+"out" = "saída"
+"Center: the input level the curve turns around" = "Centro: o nível de entrada em torno do qual a curva gira"
+"Multiply: the slope around the center (negative inverts)" = "Multiplicar: a inclinação em torno do centro (negativo inverte)"
+"Offset: moves every value up or down" = "Deslocamento: move todos os valores para cima ou para baixo"
+"Tension: bends the curve (positive rises fast, negative starts slow)" = "Tensão: curva a linha (positivo sobe rápido, negativo começa devagar)"
+"Humanize: a random amount for each note" = "Humanizar: uma quantidade aleatória para cada nota"
+"sustain" = "sustentação"
+"Keyboard" = "Teclado"
+"Zone {0}" = "Zona {0}"
+"The zone's name (its output's name in the Patcher)" = "O nome da zona (o nome da saída dela no Patcher)"
+"Whole keyboard" = "Teclado inteiro"
+"The whole range at full level" = "A faixa inteira no nível máximo"
+"Back to the map's default (the zone is off when both maps are)" = "Volta ao padrão do mapa (a zona fica desligada quando os dois mapas estão assim)"
+"Random (the map is a probability)" = "Aleatório (o mapa é uma probabilidade)"
+"Absolute (the map sets the volume)" = "Absoluto (o mapa define o volume)"
+"Random: each note goes to one of the random zones, picked by their keyboard maps" = "Aleatório: cada nota vai para uma das zonas aleatórias, sorteada pelos mapas de teclado delas"
+"Absolute: the velocity map gives the volume instead of scaling the note's" = "Absoluto: o mapa de velocidade dá o volume em vez de escalar o da nota"
+"Transpose (semitones)" = "Transpor (semitons)"
+"Articulator {0}" = "Articulador {0}"
+"The note colour this articulator works on (the MIDI channel)" = "A cor de nota em que este articulador atua (o canal MIDI)"
+"Off: the notes pass unchanged" = "Desligado: as notas passam sem mudança"
+"Tempo: the time in beats (else in seconds)" = "Tempo: o tempo em batidas (senão em segundos)"
+"Pulse width" = "Largura de pulso"
+"seconds" = "segundos"
+"Time in {0}. Drag a point, double-click to add one, right-click to remove it, drag a segment to bend it." = "Tempo em {0}. Arraste um ponto, clique duas vezes para adicionar um, clique direito para removê-lo, arraste um segmento para curvá-lo."
+"Low key: the lowest note this articulator works on" = "Tecla baixa: a nota mais grave em que este articulador atua"
+"High key: the highest note this articulator works on" = "Tecla alta: a nota mais aguda em que este articulador atua"
+"Base level" = "Nível base"
+"Envelope level" = "Nível do envelope"
+"LFO level" = "Nível do LFO"
+"Attack: scales the time up to the decay point" = "Ataque: escala o tempo até o ponto de decaimento"
+"Decay: scales the time up to the sustain point" = "Decaimento: escala o tempo até o ponto de sustentação"
+"Sustain: raises or lowers the sustain level" = "Sustentação: sobe ou desce o nível de sustentação"
+"Release: scales the time after the sustain point" = "Liberação: escala o tempo depois do ponto de sustentação"
+"LYNX keeps this plugin's settings (from FL Studio) and passes its notes through unchanged." = "O LYNX guarda as configurações deste plugin (do FL Studio) e deixa as notas passarem sem mudança."
+"Maps each played note to other notes: transpose, scales, chords" = "Mapeia cada nota tocada para outras notas: transpor, escalas, acordes"
+"Sends each note colour to its own voice output" = "Manda cada cor de nota para a sua própria saída de voz"
+"Envelopes and LFOs on the notes' velocity, pitch, pan and Mod X / Y" = "Envelopes e LFOs na velocidade, altura, pan e Mod X / Y das notas"
+"Splits the keyboard and the velocity into zones, one output each" = "Divide o teclado e a velocidade em zonas, uma saída para cada"
+"Reshapes the notes' velocity, release, fine pitch, pan and Mod X / Y" = "Remodela a velocidade, liberação, afinação fina, pan e Mod X / Y das notas"
+"Plays step patterns and arpeggios from the held notes" = "Toca padrões de passos e arpejos com as notas seguradas"
+"FL's Python note scripts" = "Scripts de notas em Python do FL"
+"Presets: LYNX's own and, with FL Studio installed, FL's factory presets" = "Presets: os do LYNX e, com o FL Studio instalado, os de fábrica do FL"
+"Output port: output 1 goes out on this MIDI port, output 2 on the next one…; the plugins and Patchers that take that port play it" = "Porta de saída: a saída 1 sai nesta porta MIDI, a saída 2 na seguinte…; os plugins e Patchers que recebem essa porta tocam o que chega"
+"Sets a plugin channel's MIDI input port to this port, so it plays what this channel sends" = "Define a porta de entrada MIDI de um canal de plugin para esta porta, para ele tocar o que este canal manda"
+"VFX (note effects)" = "VFX (efeitos de nota)"
+"The sequence (program) of the bank that plays; the bank keeps 128" = "A sequência (programa) do banco que toca; o banco guarda 128"
+"A random sequence" = "Uma sequência aleatória"
+"Steps {0} to {1}" = "Passos {0} a {1}"
+"Page lock" = "Travar página"
+"Plays only the page shown" = "Toca só a página mostrada"
+"Latch: the notes keep playing after the keys are released, until a new chord" = "Trava: as notas continuam tocando depois de soltar as teclas, até um novo acorde"
+"Poly" = "Poli"
+"Several octaves per step (else one)" = "Várias oitavas por passo (senão uma)"
+"Several keys per step (else one)" = "Várias teclas por passo (senão uma)"
+"The gate lane sets each step's output channel instead of its length" = "A faixa de gate define o canal de saída de cada passo em vez da duração"
+"Shift the pattern one step earlier" = "Desloca o padrão um passo para trás"
+"Shift the pattern one step later" = "Desloca o padrão um passo para frente"
+"Thru" = "Direto"
+"On from 2 keys, else off" = "Ligado com 2 teclas, senão desligado"
+"On from 2 keys, else thru" = "Ligado com 2 teclas, senão direto"
+"On from 3 keys, else off" = "Ligado com 3 teclas, senão desligado"
+"On from 3 keys, else thru" = "Ligado com 3 teclas, senão direto"
+"By pitch" = "Por altura"
+"By pitch, descending" = "Por altura, descendo"
+"As played, reversed" = "Como tocado, invertido"
+"By velocity" = "Por velocidade"
+"By velocity, descending" = "Por velocidade, descendo"
+"Chord, normalized" = "Acorde, normalizado"
+"Chord, as played" = "Acorde, como tocado"
+"Missing keys" = "Teclas que faltam"
+"Not played" = "Não tocadas"
+"Cyclic" = "Cíclico"
+"First key" = "Primeira tecla"
+"Last key" = "Última tecla"
+"Fixed key" = "Tecla fixa"
+"Missing octave" = "Oitava das que faltam"
+"Same" = "Igual"
+"Restart on" = "Reiniciar em"
+"Detect" = "Detectar"
+"Scale key" = "Tom da escala"
+"Chromatic" = "Cromática"
+"Melodic minor" = "Menor melódica"
+"Pentatonic major" = "Pentatônica maior"
+"Pentatonic minor" = "Pentatônica menor"
+"Pentatonic neutral" = "Pentatônica neutra"
+"Blues" = "Blues"
+"Lydian" = "Lídio"
+"Mixolydian" = "Mixolídio"
+"Locrian" = "Lócrio"
+"Scale mode" = "Modo da escala"
+"All notes" = "Todas as notas"
+"Scale steps only" = "Só os passos de escala"
+"From the lane" = "Da faixa"
+"From the keys" = "Das teclas"
+"Keys + lane" = "Teclas + faixa"
+"Input quantize" = "Quantizar entrada"
+"The held keys" = "As teclas seguradas"
+"The fixed key" = "A tecla fixa"
+"Mode: Thru passes the notes (transposed); the auto modes play only while enough keys are held" = "Modo: Direto deixa as notas passarem (transpostas); os modos automáticos só tocam com teclas suficientes seguradas"
+"Order: how the held keys are numbered N1, N2…" = "Ordem: como as teclas seguradas são numeradas N1, N2…"
+"What the steps of a key that is not held play" = "O que tocam os passos de uma tecla que não está segurada"
+"Where the sequence starts: on the song's beats, at each new key, at the first key, at play" = "Onde a sequência começa: nas batidas da música, a cada tecla nova, na primeira tecla, no play"
+"Scale key: Detect takes the held chord's root" = "Tom da escala: Detectar usa a tônica do acorde segurado"
+"Scale: the notes snap to it and the scale-step lane moves along it" = "Escala: as notas se ajustam a ela e a faixa de passos de escala anda por ela"
+"Input quantize: chord changes wait for this grid" = "Quantizar entrada: as trocas de acorde esperam esta grade"
+"Rand. vel." = "Vel. aleat."
+"Rand. gate" = "Gate aleat."
+"Rand. start" = "Início aleat."
+"Smart bend" = "Smart bend"
+"Out low" = "Saída mín."
+"Out high" = "Saída máx."
+"Step type" = "Tipo de passo"
+"Scale step" = "Passo de escala"
+"Tie" = "Ligadura"
+"Rest" = "Pausa"
+"Semitones / scale steps" = "Semitons / passos de escala"
+"Factory bank" = "Banco de fábrica"
+"Chan." = "Can."
+"Note select" = "Seleção de nota"
+"Edit this lane in the grid above" = "Edita esta faixa na grade acima"
+"Save the script" = "Salvar o script"
+"Keeps the edited script in the project (FL Studio runs it when the project opens there)" = "Guarda o script editado no projeto (o FL Studio o executa quando o projeto é aberto lá)"
+"(with an embedded Control Surface)" = "(com um Control Surface embutido)"
+"(no saved control values)" = "(nenhum valor de controle salvo)"
+"LYNX keeps the script and its settings but does not run Python scripts yet: the notes pass through unchanged." = "O LYNX guarda o script e as configurações dele, mas ainda não executa scripts Python: as notas passam sem mudança."
+"Control values" = "Valores dos controles"
+"Root" = "Tônica"
+"Script" = "Script"
 # round 164e (misc164): Browser folders window
 "Show folders..." = "Mostrar pastas..."
 "Remove this folder from the Browsers" = "Remover esta pasta dos Browsers"

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 0 - 0
scripts/build-local.sh


Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 0 - 0
scripts/build-windows-zig.sh


+ 120 - 0
src/Main.cpp

@@ -68,6 +68,7 @@
 #include "ui/ParametricEqEditor.h"
 #include "ui/PluginEditors.h"
 #include "core/PluginLayout.h"
+#include "core/Vfx.h"
 #include "ui/Splash.h"
 #include "ui/Theme.h"
 #include "ui/ThemeSettings.h"
@@ -824,6 +825,15 @@ public:
             return;
         }
 
+        if (args.contains ("--vfxshot"))
+        {
+            // LYNX.exe --vfxshot prefix: the VFX note effects' editors (round 164b), on channels and in a Patcher, as PNGs
+            const auto i = args.indexOf ("--vfxshot");
+            runVfxShot (args[i + 1].unquoted());
+            quit();
+            return;
+        }
+
         if (args.contains ("--patchershot"))
         {
             // LYNX.exe --patchershot prefix [project]: every Patcher's editor (round 141) as PNGs (a demo one without a project)
@@ -4740,6 +4750,116 @@ private:
         lynx::FormulaControllerWindows::closeAll();
     }
 
+    void runVfxShot (const juce::String& prefix)
+    {
+        juce::LookAndFeel::setDefaultLookAndFeel (&lookAndFeel);
+        lynx::AudioEngine offline (false);
+        lynx::MainComponent ui (offline, false);
+        ui.setSize (1280, 720);
+        auto song = lynx::Song::makeDefault();
+        song.channels.clear();
+        for (const auto kind : lynx::vfx::allKinds)
+        {
+            lynx::ChannelDef c;
+            lynx::vfx::makeChannel (c, kind);
+            if (kind == lynx::vfx::Kind::keyMapper) // a chord on every key: something to see in the grid
+                for (const auto& p : lynx::vfx::builtInPresets (kind))
+                    if (p.name == "Major triad")
+                    {
+                        auto st = *lynx::vfx::readState (c.pluginState);
+                        st.fl = p.fl;
+                        c.pluginState = lynx::vfx::writeState (st);
+                    }
+            song.channels.push_back (c);
+        }
+        // a Patcher: its notes through a Color Mapper to three synths
+        lynx::ChannelDef patcher;
+        patcher.name = "Patcher";
+        patcher.instrument = lynx::InstrumentKind::patcher;
+        lynx::PatchNode mapper;
+        mapper.generator = true;
+        lynx::vfx::makeChannel (mapper.channel, lynx::vfx::Kind::colorMapper);
+        mapper.x = 260.0f;
+        patcher.patcher.nodes.push_back (mapper);
+        lynx::PatchWire notes;
+        notes.kind = lynx::PatchWire::Kind::midi, notes.to = 0;
+        patcher.patcher.wires.push_back (notes);
+        for (int k = 0; k < 3; ++k)
+        {
+            lynx::PatchNode synth;
+            synth.generator = true;
+            synth.channel.instrument = lynx::InstrumentKind::synth;
+            synth.channel.name = "Synth " + std::to_string (k + 1);
+            synth.x = 520.0f, synth.y = (float) k * 90.0f;
+            patcher.patcher.nodes.push_back (synth);
+            lynx::PatchWire in, out;
+            in.kind = lynx::PatchWire::Kind::midi, in.from = 0, in.fromPort = k, in.to = 1 + k;
+            out.from = 1 + k, out.to = lynx::patchToHost;
+            patcher.patcher.wires.push_back (in);
+            patcher.patcher.wires.push_back (out);
+        }
+        patcher.patcher.outputX = 760.0f;
+        song.channels.push_back (patcher);
+        offline.setSong (std::move (song));
+        offline.dispatchPendingMessages();
+        for (int c = 0; c < lynx::vfx::kindCount; ++c)
+            if (auto panel = lynx::makeChannelSettingsPanel (offline, c))
+            {
+                offline.dispatchPendingMessages();
+                savePng (panel->createComponentSnapshot (panel->getLocalBounds()),
+                         prefix + "-" + juce::String (lynx::vfx::flName (*lynx::vfx::kindOf (offline.getSong().channels[(std::size_t) c]))).replaceCharacter (' ', '-').toLowerCase() + ".png");
+            }
+        // with FL Studio installed: the Sequencer with FL's factory bank (to compare with FL's own editor) and
+        // a Script with FL's "Snap To Scale"
+        if (const auto roots = lynx::findFlStudioRoots(); ! roots.data.empty())
+        {
+            const auto data = juce::File (juce::String::fromUTF8 (roots.data.c_str()));
+            const std::pair<lynx::vfx::Kind, juce::String> extra[] = {
+                { lynx::vfx::Kind::sequencer, "Patches/Plugin database/Effects/Patcher/VFX Sequencer.fst" },
+                { lynx::vfx::Kind::script, "Patches/Plugin presets/Effects/VFX Script/Snap To Scale.fst" },
+            };
+            for (const auto& [kind, path] : extra)
+            {
+                juce::MemoryBlock bytes;
+                if (! data.getChildFile (path).loadFileAsData (bytes))
+                    continue;
+                const auto* b = static_cast<const std::uint8_t*> (bytes.getData());
+                const auto fl = lynx::vfx::stateFromFlPreset (std::vector<std::uint8_t> (b, b + bytes.getSize()), kind);
+                int index = -1;
+                for (int c = 0; c < lynx::vfx::kindCount; ++c)
+                    if (lynx::vfx::kindOf (offline.getSong().channels[(std::size_t) c]) == kind)
+                        index = c;
+                if (! fl || index < 0)
+                    continue;
+                offline.editSong ([&] (lynx::Song& s) {
+                    auto st = *lynx::vfx::readState (s.channels[(std::size_t) index].pluginState);
+                    st.fl = *fl;
+                    s.channels[(std::size_t) index].pluginState = lynx::vfx::writeState (st);
+                });
+                offline.dispatchPendingMessages();
+                if (auto panel = lynx::makeChannelSettingsPanel (offline, index))
+                {
+                    offline.dispatchPendingMessages();
+                    savePng (panel->createComponentSnapshot (panel->getLocalBounds()),
+                             prefix + "-" + juce::String (lynx::vfx::flName (kind)).replaceCharacter (' ', '-').toLowerCase() + "-fl.png");
+                }
+            }
+        }
+        lynx::PatcherWindows::openChannel (offline, lynx::vfx::kindCount);
+        for (int k = 0; k < juce::TopLevelWindow::getNumTopLevelWindows(); ++k)
+            if (auto* w = dynamic_cast<juce::DocumentWindow*> (juce::TopLevelWindow::getTopLevelWindow (k)))
+                if (w->getName().startsWith (lynx::tr ("Patcher")) && w->getContentComponent() != nullptr)
+                {
+                    auto* content = w->getContentComponent();
+                    savePng (content->createComponentSnapshot (content->getLocalBounds()), prefix + "-patcher.png");
+                    delete w;
+                    break;
+                }
+        lynx::PatcherWindows::shootMenus (offline, true, lynx::vfx::kindCount, 0, [&] (const juce::Image& image, const juce::String& name) {
+            savePng (image, prefix + "-patcher-menu-" + name + ".png");
+        });
+    }
+
     void runPatcherShot (const juce::String& prefix, const juce::String& projectPath)
     {
         juce::LookAndFeel::setDefaultLookAndFeel (&lookAndFeel);

+ 39 - 4
src/core/FlpImport.cpp

@@ -1,4 +1,5 @@
 #include "core/FlpImport.h"
+#include "core/Vfx.h"
 #include "core/Patcher.h"
 #include <filesystem>
 #include "core/EditorPolish.h"
@@ -1247,6 +1248,16 @@ Song importFlp (const flp::Project& input, const FlpImportOptions& options)
             def.pluginState = c.pluginState;
         }
 
+        // FL's VFX plugins (round 164b): note processors, with FL's state as it is
+        if (const auto kind = vfx::kindOfFlName (c.pluginName))
+        {
+            def.instrument = InstrumentKind::vfx;
+            vfx::State vs;
+            vs.kind = *kind;
+            vs.fl = c.pluginState.empty() ? vfx::defaultState (*kind) : c.pluginState;
+            def.pluginState = vfx::writeState (vs);
+        }
+
         // Fruit Kick, MiniSynth, ... (REA_rodada10): approximated by the internal synth; the channel LFOs are kept
         bool adoptedFromPlugin = false;
         if (def.instrument == InstrumentKind::synth)
@@ -1863,6 +1874,8 @@ Song importFlp (const flp::Project& input, const FlpImportOptions& options)
                 ++r.unsupported["Fruity Wrapper (plugin state not readable)"]; // e.g. a wrapper version newer than 12
             else if (plugin == "midi out" && def.instrument == InstrumentKind::midiOut)
                 ++r.converted[c.pluginName];
+            else if (def.instrument == InstrumentKind::vfx)
+                ++r.converted[c.pluginName];
             else if (plugin != "fruity wrapper" && plugin != "fruity keyboard controller" && plugin != "midi out"
                      && def.instrument == InstrumentKind::synth)
                 ++r.unsupported[c.pluginName]; // (Keyboard Controller only sends notes to other channels)
@@ -2044,7 +2057,23 @@ Song importFlp (const flp::Project& input, const FlpImportOptions& options)
             constexpr float spreadX = 2.0f, spreadY = 1.6f;
             node.x = fl.x * spreadX;
             node.y = fl.y * spreadY;
-            if (fl.generator)
+            if (const auto kind = vfx::kindOfFlName (fl.plugin)) // a VFX node (an effect in FL's graph): voices in, voices out
+            {
+                node.generator = true;
+                vfx::makeChannel (node.channel, *kind);
+                vfx::State vs;
+                vs.kind = *kind;
+                vs.fl = fl.state.empty() ? vfx::defaultState (*kind) : fl.state;
+                node.channel.pluginState = vfx::writeState (vs);
+                if (! fl.label.empty())
+                    node.channel.name = fl.label;
+                node.channel.mixerTrack = 0;
+                node.channel.volume = 1.0f;
+                node.channel.pan = 0.0f;
+                if ((options.report != nullptr))
+                    ++options.report->converted["Patcher: " + fl.plugin];
+            }
+            else if (fl.generator)
             {
                 node.generator = true;
                 flp::Project mini;
@@ -2214,11 +2243,17 @@ Song importFlp (const flp::Project& input, const FlpImportOptions& options)
                 }
                 else
                 {
-                    // a node's MIDI output: a MIDI Out's (round 162); other plugins' MIDI outputs are not passed yet
+                    // a node's MIDI output: a MIDI Out's (round 162), a VFX node's voice output N (FL's pin N, 1…;
+                    // round 164b); other plugins' MIDI outputs are not passed yet
                     const auto& source = doc.nodes[(std::size_t) w.from];
-                    if (! source.generator || source.channel.instrument != InstrumentKind::midiOut)
+                    if (! source.generator)
+                        continue;
+                    if (source.channel.instrument == InstrumentKind::vfx)
+                        w.fromPort = std::max (0, src->index - 1);
+                    else if (source.channel.instrument == InstrumentKind::midiOut)
+                        w.fromPort = 0;
+                    else
                         continue;
-                    w.fromPort = 0;
                 }
                 if (w.to == patchToHost) // "MIDI port N": the notes go to the plugins on that MIDI port
                 {

+ 100 - 0
src/core/Instruments.cpp

@@ -1,4 +1,5 @@
 #include "core/Instruments.h"
+#include "core/Vfx.h"
 #include "core/Scheduler.h"
 
 #include "core/DirectWave.h"
@@ -230,6 +231,7 @@ private:
             case InstrumentKind::plugin:
             case InstrumentKind::controller:
             case InstrumentKind::midiOut:
+            case InstrumentKind::vfx:
             case InstrumentKind::patcher:
             case InstrumentKind::sakura:
             case InstrumentKind::drumpad:
@@ -683,6 +685,7 @@ struct SynthVoice
     std::array<LfoState, lfoTargets> lfo {};
     float lfoGain = 1.0f, lfoGainStep = 0.0f; // volume LFO, ramped between ticks
     float basePan = 0.0f;                     // note pan (the pan LFO adds to it)
+    float cents = 0.0f;                       // the note's fine pitch (a VFX may move it while it sounds)
     SvfCoefficients filter; // this voice's (only with a cutoff envelope)
     double pitchMul = 1.0;
     float fmLevel = 1.0f;   // FM index envelope (1 -> fmSustain)
@@ -818,6 +821,7 @@ public:
                 v.stage = 0;
                 v.age = 0;
                 const auto target = midiToHz (key) / sampleRate * std::pow (2.0, nextCents / 1200.0);
+                v.cents = nextCents;
                 glide (v, v.phaseDelta, target);
                 lastPhaseDelta = target;
                 for (auto& m : v.mod)
@@ -850,6 +854,7 @@ public:
         target->key = key;
         target->velocity = velocity;
         const auto delta = midiToHz (key) / sampleRate * std::pow (2.0, nextCents / 1200.0);
+        target->cents = nextCents;
         glide (*target, lastPhaseDelta, delta); // with porta, starts from the previous note's pitch
         lastPhaseDelta = delta;
         voicePan (nextPan, target->panL, target->panR);
@@ -870,6 +875,29 @@ public:
         nextPorta = porta;
     }
 
+    // a VFX changes a sounding note (round 164b): its fine pitch, pan or volume
+    void voiceProperty (int key, int prop, float value) noexcept override
+    {
+        if (! std::isfinite (value))
+            return;
+        for (auto& v : voices)
+            if (v.active && ! v.releasing && v.key == key)
+            {
+                if (prop == (int) vfx::Prop::pitch && v.phaseDelta > 0.0)
+                {
+                    v.phaseDelta *= std::exp2 ((double) (value - v.cents) / 1200.0);
+                    v.cents = value;
+                }
+                else if (prop == (int) vfx::Prop::pan)
+                {
+                    v.basePan = std::clamp (value, -1.0f, 1.0f);
+                    voicePan (v.basePan, v.panL, v.panR);
+                }
+                else if (prop == (int) vfx::Prop::velocity)
+                    v.velocity = std::clamp (value, 0.0f, 1.0f);
+            }
+    }
+
     void slideTo (int key, float cents, float samples) noexcept override
     {
         const auto target = midiToHz (key) / sampleRate * std::pow (2.0, cents / 1200.0);
@@ -1397,6 +1425,7 @@ struct SamplerVoice
     std::array<LfoState, lfoTargets> lfo {};
     float lfoGain = 1.0f, lfoGainStep = 0.0f;
     float basePan = 0.0f;
+    float cents = 0.0f; // the note's fine pitch (a VFX may move it while it sounds)
     const SampleData* data = nullptr; // this voice's sample (the chosen zone, in multi-sample)
     float zoneGain = 1.0f;
     double loopStart = 0.0, loopEnd = 0.0; // loopEnd > loopStart: the voice jumps back to the loop start
@@ -1737,6 +1766,7 @@ public:
         }
         voicePan (clipMode ? 0.0f : nextPan, target->panL, target->panR);
         target->basePan = clipMode ? 0.0f : nextPan;
+        target->cents = clipMode ? 0.0f : nextCents;
 
         for (std::size_t i = 0; i < lfoTargets; ++i)
             if (lfos[i].active && ! clipMode)
@@ -1905,6 +1935,30 @@ public:
         bendMul = clipMode || ! std::isfinite (semitones) ? 1.0 : std::exp2 ((double) std::clamp (semitones, -48.0f, 48.0f) / 12.0);
     }
 
+    // a VFX changes a sounding note (round 164b): its fine pitch, pan or volume
+    void voiceProperty (int key, int prop, float value) noexcept override
+    {
+        if (! std::isfinite (value))
+            return;
+        for (auto& v : voices)
+            if (v.active && v.stage != 3 && v.key == key)
+            {
+                if (prop == (int) vfx::Prop::pitch)
+                {
+                    const auto ratio = std::exp2 ((double) (value - v.cents) / 1200.0);
+                    v.rate *= ratio;
+                    v.cents = value;
+                }
+                else if (prop == (int) vfx::Prop::pan)
+                {
+                    v.basePan = v.notePan = std::clamp (value, -1.0f, 1.0f);
+                    voicePan (v.basePan, v.panL, v.panR);
+                }
+                else if (prop == (int) vfx::Prop::velocity)
+                    v.velocity = std::clamp (value, 0.0f, 1.0f);
+            }
+    }
+
     void setNextNoteExpression (float pan, float cents, bool porta) noexcept override
     {
         nextPan = pan;
@@ -2816,6 +2870,50 @@ public:
     void render (float*, float*, int, float, float) noexcept override {}
     bool idle() const noexcept override { return true; }
 };
+
+// A VFX note processor in the Channel Rack or a Patcher (round 164b): no sound; the renderer / the graph run its
+// processor on the notes and send what it plays to the instruments on its outputs.
+class VfxInstrument final : public Instrument
+{
+public:
+    void prepare (double sampleRate) noexcept override
+    {
+        rate = sampleRate;
+        if (processor != nullptr)
+            processor->prepare (sampleRate);
+    }
+    void noteOn (int, float) noexcept override {}
+    void noteOff (int) noexcept override {}
+    void allNotesOff() noexcept override {}
+    void render (float*, float*, int, float, float) noexcept override {}
+    bool idle() const noexcept override { return true; }
+    vfx::Processor* noteProcessor() noexcept override { return processor.get(); }
+    // (UI thread: the first call builds the processor before the instrument reaches the audio thread; later ones only
+    // hand the new settings over)
+    void configure (const ChannelDef& channel, double) noexcept override
+    {
+        const auto state = vfx::readState (channel.pluginState);
+        if (! state)
+            return;
+        if (processor == nullptr || processor->kind() != state->kind)
+        {
+            if (processor == nullptr)
+            {
+                processor = vfx::makeProcessor (state->kind, state->fl);
+                processor->prepare (rate);
+            }
+            return;
+        }
+        if (state->fl != lastState)
+            processor->configure (state->fl);
+        lastState = state->fl;
+    }
+
+private:
+    std::unique_ptr<vfx::Processor> processor;
+    std::vector<std::uint8_t> lastState;
+    double rate = 44100.0;
+};
 } // namespace
 
 float samplerGain (float db) noexcept
@@ -2831,6 +2929,8 @@ std::unique_ptr<Instrument> makeInstrument (InstrumentKind kind, std::shared_ptr
         return std::make_unique<ControllerInstrument>();
     if (kind == InstrumentKind::midiOut)
         return std::make_unique<MidiOutInstrument>();
+    if (kind == InstrumentKind::vfx)
+        return std::make_unique<VfxInstrument>();
 
     if (kind == InstrumentKind::sampler || kind == InstrumentKind::audioClip)
         return std::make_unique<SamplerInstrument> (std::move (sample), kind == InstrumentKind::audioClip);

+ 13 - 0
src/core/Instruments.h

@@ -15,6 +15,10 @@
 
 namespace lynx
 {
+namespace vfx
+{
+class Processor;
+}
 class Instrument
 {
 public:
@@ -96,6 +100,15 @@ public:
     virtual int auxOutputCount() const noexcept { return 0; }
     virtual int auxOutputTrack (int /*k*/) const noexcept { return -1; }
     virtual const float* auxOutputData (int /*k*/, int /*side*/) const noexcept { return nullptr; }
+    // A VFX channel / node (round 164b, core/Vfx.h): its note processor (null for every other instrument)
+    virtual vfx::Processor* noteProcessor() noexcept { return nullptr; }
+    // The next note's colour group (0…15, FL's note colours; called right before noteOn): a Patcher passes it to its
+    // VFX nodes (VFX Color Mapper, VFX Envelope). Ignored by the others.
+    virtual void setNextNoteColour (int /*colour*/) noexcept {}
+    // A property of the sounding voices of `key` changes while they sound (VFX Envelope, round 164b): `prop` is a
+    // vfx::Prop (0 velocity 0..1 — the voice's volume relative to its note-on velocity is value / velocity at
+    // note-on —, 1 pitch in cents from the key, 2 pan −1..1, 3 Mod X, 4 Mod Y). Ignored if unsupported.
+    virtual void voiceProperty (int /*key*/, int /*prop*/, float /*value*/) noexcept {}
 };
 
 // Audio of an already-decoded sample (loaded off the audio thread). Short samples

+ 295 - 34
src/core/Patcher.cpp

@@ -40,6 +40,9 @@ bool sameEffectSetup (const EffectSlot& a, const EffectSlot& b)
 
 bool sameInstrumentSetup (const ChannelDef& a, const ChannelDef& b)
 {
+    // a VFX node takes new settings while it runs (its held voices end as they started): only its kind is structure
+    if (a.instrument == InstrumentKind::vfx || b.instrument == InstrumentKind::vfx)
+        return a.instrument == b.instrument && vfx::kindOf (a) == vfx::kindOf (b);
     if (a.instrument != b.instrument || a.samplePath != b.samplePath || a.zones != b.zones || a.modelParams != b.modelParams
         || a.pluginState != b.pluginState || a.plugin.id != b.plugin.id || ! (a.plugin == b.plugin) || a.controllerState != b.controllerState)
         return false;
@@ -93,6 +96,13 @@ NodePorts nodePorts (const PatchNode& node)
         if (node.channel.instrument == InstrumentKind::controller || node.channel.instrument == InstrumentKind::midiOut)
             p.audioOuts = 0; // (no sound of their own)
         p.midiOut = node.channel.instrument == InstrumentKind::midiOut;
+        p.midiOuts = p.midiOut ? 1 : 0;
+        if (const auto kind = vfx::kindOf (node.channel)) // a VFX node: voices in, voices out (round 164b)
+        {
+            p.audioOuts = 0;
+            p.midiOut = true;
+            p.midiOuts = vfx::outputCount (*kind);
+        }
         if (node.channel.instrument == InstrumentKind::patcher)
             p.audioOuts = 1 + (int) node.channel.patcher.outputTracks.size();
         return p;
@@ -156,6 +166,8 @@ struct Graph::Node
     std::shared_ptr<Effect> effect;
     std::shared_ptr<Instrument> instrument;
     bool plugin = false; // values reach it through setParameter (control cables), not the params array
+    vfx::Processor* vfx = nullptr;                    // a VFX node's processor (owned by its instrument)
+    std::vector<std::vector<MidiTarget>> vfxTargets;  // [voice output] what it reaches
 
     struct Head
     {
@@ -186,6 +198,17 @@ struct Graph::ControlWire
     int docIndex = 0;
 };
 
+struct Graph::VfxQueue
+{
+    vfx::EventList in, out; // the voices that reached the node in this piece; what it sends
+};
+
+struct Graph::NoteOut
+{
+    int node = 0, midiChannel = -1;
+    vfx::Event event;
+};
+
 struct Graph::Values
 {
     struct NodeValues
@@ -350,31 +373,53 @@ Graph::Graph (const PatcherDoc& doc, double sampleRate, const Factories& factori
     }
     highestAux = std::max (highestAux, (int) doc.outputTracks.size());
 
-    // MIDI (round 162): what each "From LYNX" pin reaches, through MIDI Out nodes (they set the MIDI channel)
+    // MIDI (round 162): what each "From LYNX" pin reaches, through MIDI Out nodes (they set the MIDI channel); VFX
+    // nodes (round 164b) take the voices into their processors and send theirs on from their voice outputs
     pinTargets.assign ((std::size_t) patchMidiPortPin (patchMidiPorts), {});
     for (int pin = 0; pin < (int) pinTargets.size(); ++pin)
+        pinTargets[(std::size_t) pin] = midiTargetsOf (doc, patchFromHost, pin);
+    vfxQueues.resize ((std::size_t) count);
+    for (int i = 0; i < count; ++i)
+    {
+        auto& node = *nodes[(std::size_t) i];
+        if (node.instrument == nullptr || (node.vfx = node.instrument->noteProcessor()) == nullptr)
+            continue;
+        node.vfx->prepare (rate);
+        const auto kind = node.vfx->kind();
+        for (int k = 0; k < vfx::outputCount (kind); ++k)
+            node.vfxTargets.push_back (midiTargetsOf (doc, i, k));
+        vfxQueues[(std::size_t) i] = std::make_unique<VfxQueue>();
+        hasVfx = true;
+    }
+    if (hasVfx)
     {
-        auto& targets = pinTargets[(std::size_t) pin];
-        std::vector<char> seen ((std::size_t) count, 0);
-        // (source, its pin, the channel set on the way)
-        std::vector<std::tuple<int, int, int>> todo { { patchFromHost, pin, -1 } };
-        while (! todo.empty())
+        // sources first (Kahn over the VFX → VFX links); a loop runs in index order (its voices wait a piece)
+        std::vector<int> pendingInputs ((std::size_t) count, 0);
+        for (int i = 0; i < count; ++i)
+            for (const auto& targets : nodes[(std::size_t) i]->vfxTargets)
+                for (const auto& t : targets)
+                    if (t.vfx && t.node != i)
+                        ++pendingInputs[(std::size_t) t.node];
+        std::vector<char> placed ((std::size_t) count, 0);
+        for (bool progress = true; progress;)
         {
-            const auto [from, fromPin, channel] = todo.back();
-            todo.pop_back();
-            for (const auto& w : doc.wires)
-            {
-                if (w.kind != PatchWire::Kind::midi || ! w.enabled || w.from != from || w.fromPort != fromPin || w.to < 0 || w.to >= count
-                    || seen[(std::size_t) w.to])
-                    continue;
-                seen[(std::size_t) w.to] = 1;
-                const auto& target = doc.nodes[(std::size_t) w.to];
-                if (target.generator && target.channel.instrument == InstrumentKind::midiOut)
-                    todo.emplace_back (w.to, 0, midictl::parseMidiOut (target.channel.pluginState).channel);
-                else if (target.generator)
-                    targets.push_back ({ w.to, channel });
-            }
+            progress = false;
+            for (int i = 0; i < count; ++i)
+                if (! placed[(std::size_t) i] && nodes[(std::size_t) i]->vfx != nullptr && pendingInputs[(std::size_t) i] == 0)
+                {
+                    placed[(std::size_t) i] = 1;
+                    vfxOrder.push_back (i);
+                    progress = true;
+                    for (const auto& targets : nodes[(std::size_t) i]->vfxTargets)
+                        for (const auto& t : targets)
+                            if (t.vfx && t.node != i)
+                                --pendingInputs[(std::size_t) t.node];
+                }
         }
+        for (int i = 0; i < count; ++i)
+            if (! placed[(std::size_t) i] && nodes[(std::size_t) i]->vfx != nullptr)
+                vfxOrder.push_back (i);
+        noteOuts.reserve (vfx::EventList::capacity);
     }
 
     published = doc.published;
@@ -548,25 +593,28 @@ void Graph::reset() noexcept
     }
 }
 
-void Graph::setSongPosition (double ticks) noexcept
+void Graph::setSongPosition (double position) noexcept
 {
+    ticks = position;
+    playing = hostTimeline().playing.load (std::memory_order_relaxed);
     for (auto& n : nodes)
     {
         if (n->effect != nullptr)
-            n->effect->setSongPosition (ticks);
+            n->effect->setSongPosition (position);
         if (n->instrument != nullptr)
-            n->instrument->setSongPosition (ticks);
+            n->instrument->setSongPosition (position);
         for (auto& h : n->heads)
             if (h.effect != nullptr)
-                h.effect->setSongPosition (ticks);
+                h.effect->setSongPosition (position);
     }
 }
 
-void Graph::setPlaying (bool playing) noexcept
+void Graph::setPlaying (bool on) noexcept
 {
+    playing = on;
     for (auto& n : nodes)
         if (n->effect != nullptr)
-            n->effect->setPlaying (playing);
+            n->effect->setPlaying (on);
 }
 
 void Graph::setHeldNotes (const NoteMask* channels, int count) noexcept
@@ -581,11 +629,63 @@ void Graph::noteOff (int key) noexcept { deliver (0, false, key, 0.0f, -1); }
 void Graph::noteOnMidi (int key, float velocity, int midiChannel) noexcept { deliver (0, true, key, velocity, midiChannel); }
 void Graph::noteOffMidi (int key, int midiChannel) noexcept { deliver (0, false, key, 0.0f, midiChannel); }
 
+std::vector<Graph::MidiTarget> Graph::midiTargetsOf (const PatcherDoc& doc, int from, int pin) const
+{
+    std::vector<MidiTarget> targets;
+    const auto count = (int) doc.nodes.size();
+    std::vector<char> seen ((std::size_t) count, 0);
+    // (source, its pin, the channel set on the way)
+    std::vector<std::tuple<int, int, int>> todo { { from, pin, -1 } };
+    while (! todo.empty())
+    {
+        const auto [source, sourcePin, channel] = todo.back();
+        todo.pop_back();
+        for (const auto& w : doc.wires)
+        {
+            if (w.kind != PatchWire::Kind::midi || ! w.enabled || w.from != source || w.fromPort != sourcePin || w.to < 0 || w.to >= count
+                || seen[(std::size_t) w.to])
+                continue;
+            seen[(std::size_t) w.to] = 1;
+            const auto& target = doc.nodes[(std::size_t) w.to];
+            if (! target.generator)
+                continue;
+            if (target.channel.instrument == InstrumentKind::midiOut)
+                todo.emplace_back (w.to, 0, midictl::parseMidiOut (target.channel.pluginState).channel);
+            else
+                targets.push_back ({ w.to, channel, target.channel.instrument == InstrumentKind::vfx });
+        }
+    }
+    return targets;
+}
+
 void Graph::deliver (int pin, bool on, int key, float velocity, int midiChannel) noexcept
 {
     if (pin < 0 || pin >= (int) pinTargets.size())
         return;
     for (const auto& t : pinTargets[(std::size_t) pin])
+    {
+        if (t.vfx)
+        {
+            // into the VFX node's processor at the next piece's start, with the note's properties
+            if (auto& q = vfxQueues[(std::size_t) t.node])
+            {
+                vfx::Event e;
+                e.type = on ? vfx::Event::Type::on : vfx::Event::Type::off;
+                e.voice.key = key;
+                e.voice.velocity = velocity;
+                e.voice.pan = nextVoice.pan;
+                e.voice.cents = nextVoice.cents;
+                e.voice.modX = nextVoice.modX;
+                e.voice.modY = nextVoice.modY;
+                e.voice.release = nextVoice.release;
+                e.voice.porta = nextVoice.porta;
+                const auto channel = t.midiChannel >= 0 ? t.midiChannel : midiChannel;
+                e.voice.colour = channel >= 0 ? (channel & 15) : nextVoice.colour;
+                e.id = vfx::inputId (key, e.voice.colour);
+                q->in.add (e);
+            }
+            continue;
+        }
         if (auto& i = nodes[(std::size_t) t.node]->instrument)
         {
             const auto channel = t.midiChannel >= 0 ? t.midiChannel : midiChannel;
@@ -594,6 +694,11 @@ void Graph::deliver (int pin, bool on, int key, float velocity, int midiChannel)
             else
                 on ? i->noteOnMidi (key, velocity, channel) : i->noteOffMidi (key, channel);
         }
+    }
+    if (! on)
+        nextVoice.release = 0.5f;
+    else
+        nextVoice = {};
 }
 
 void Graph::noteOnPort (int port, int key, float velocity, int midiChannel) noexcept
@@ -638,6 +743,15 @@ bool Graph::takesMidiPort (int port) const noexcept
 
 void Graph::allNotesOff() noexcept
 {
+    // the VFX nodes' voices end (their instruments stop below anyway); their queues empty
+    for (const auto i : vfxOrder)
+    {
+        auto& q = *vfxQueues[(std::size_t) i];
+        q.in.clear();
+        q.out.clear();
+        nodes[(std::size_t) i]->vfx->releaseAll (q.out);
+        q.out.clear();
+    }
     for (auto& n : nodes)
         if (n->instrument != nullptr)
             n->instrument->allNotesOff();
@@ -650,8 +764,20 @@ void Graph::slideTo (int key, float cents, float samples) noexcept
             i->slideTo (key, cents, samples);
 }
 
+void Graph::setNextNoteModulation (float modX, float modY) noexcept
+{
+    nextVoice.modX = modX;
+    nextVoice.modY = modY;
+}
+
+void Graph::setNextNoteRelease (float velocity) noexcept { nextVoice.release = velocity; }
+void Graph::setNextNoteColour (int colour) noexcept { nextVoice.colour = colour & 15; }
+
 void Graph::setNextNoteExpression (float pan, float cents, bool porta) noexcept
 {
+    nextVoice.pan = pan;
+    nextVoice.cents = cents;
+    nextVoice.porta = porta;
     for (const auto t : noteTargets)
         if (auto& i = nodes[(std::size_t) t]->instrument)
             i->setNextNoteExpression (pan, cents, porta);
@@ -664,7 +790,10 @@ bool Graph::hasInstruments() const noexcept
 
 bool Graph::instrumentsIdle() const noexcept
 {
-    return std::all_of (nodes.begin(), nodes.end(), [] (const auto& n) { return n->instrument == nullptr || n->instrument->idle(); });
+    // (a VFX node that holds voices or plays on its own — a sequencer — keeps the graph running)
+    return std::all_of (nodes.begin(), nodes.end(), [] (const auto& n) {
+        return (n->instrument == nullptr || n->instrument->idle()) && (n->vfx == nullptr || ! n->vfx->busy());
+    });
 }
 
 float Graph::controlOutput (int) const noexcept { return 0.0f; }
@@ -748,14 +877,128 @@ void Graph::processPiece (const float* inL, const float* inR, const float* scL,
             values.nodes[(std::size_t) c.to].params[(std::size_t) c.param] = v;
     }
 
+    if (! hasVfx)
+    {
+        renderNodes (inL, inR, scL, scR, outL, outR, 0, n, bpm);
+        return;
+    }
+    // VFX nodes: what they play lands at its sample; the piece is rendered in parts between those samples
+    runVfx (n, bpm);
+    std::size_t next = 0;
+    for (int position = 0; position < n;)
+    {
+        while (next < noteOuts.size() && noteOuts[next].event.offset <= position)
+            playNoteOut (noteOuts[next++]);
+        const auto end = next < noteOuts.size() ? std::min (n, noteOuts[next].event.offset) : n;
+        if (end > position)
+            renderNodes (inL + position, inR + position, scL != nullptr ? scL + position : nullptr, scR != nullptr ? scR + position : nullptr,
+                         outL + position, outR + position, position, end - position, bpm);
+        position = end;
+    }
+    while (next < noteOuts.size())
+        playNoteOut (noteOuts[next++]);
+}
+
+void Graph::runVfx (int n, double bpm) noexcept
+{
+    noteOuts.clear();
+    vfx::Transport t;
+    t.sampleRate = rate;
+    t.bpm = bpm;
+    t.ticks = ticks;
+    t.playing = playing;
+    for (const auto i : vfxOrder)
+    {
+        auto& q = *vfxQueues[(std::size_t) i];
+        q.in.sortByOffset();
+        q.out.clear();
+        nodes[(std::size_t) i]->vfx->process (&q.in[0], q.in.size(), n, t, q.out);
+        q.in.clear();
+        for (int k = 0; k < q.out.size(); ++k)
+            routeVfxOutput (i, q.out[k]);
+        q.out.clear();
+    }
+    // (stable insertion sort in place: std::stable_sort may allocate on the audio thread)
+    for (std::size_t i = 1; i < noteOuts.size(); ++i)
+    {
+        const auto o = noteOuts[i];
+        auto j = i;
+        for (; j > 0 && o.event.offset < noteOuts[j - 1].event.offset; --j)
+            noteOuts[j] = noteOuts[j - 1];
+        noteOuts[j] = o;
+    }
+    ticks += (double) n * bpm * (double) ppq / (60.0 * rate);
+}
+
+void Graph::routeVfxOutput (int node, const vfx::Event& e) noexcept
+{
+    const auto& targets = nodes[(std::size_t) node]->vfxTargets;
+    if (e.output < 0 || e.output >= (int) targets.size())
+        return;
+    for (const auto& t : targets[(std::size_t) e.output])
+    {
+        if (t.vfx)
+        {
+            if (auto& q = vfxQueues[(std::size_t) t.node])
+            {
+                auto in = e;
+                in.output = 0;
+                in.id = (node + 1) * (1 << 20) + (e.id & ((1 << 20) - 1)); // (ids of different sources never meet)
+                if (t.midiChannel >= 0)
+                    in.voice.colour = t.midiChannel & 15;
+                q->in.add (in);
+            }
+        }
+        else if (noteOuts.size() < noteOuts.capacity())
+            noteOuts.push_back ({ t.node, t.midiChannel, e });
+    }
+}
+
+void Graph::playNoteOut (const NoteOut& o) noexcept
+{
+    auto& i = nodes[(std::size_t) o.node]->instrument;
+    if (i == nullptr)
+        return;
+    const auto& e = o.event;
+    const auto& v = e.voice;
+    const auto channel = o.midiChannel >= 0 ? o.midiChannel : v.colour;
+    switch (e.type)
+    {
+        case vfx::Event::Type::on:
+            i->setNextNoteExpression (v.pan, v.cents, v.porta);
+            i->setNextNoteModulation (v.modX, v.modY);
+            i->setNextNoteColour (v.colour);
+            if (channel > 0)
+                i->noteOnMidi (v.key, v.velocity, channel);
+            else
+                i->noteOn (v.key, v.velocity);
+            break;
+        case vfx::Event::Type::off:
+            i->setNextNoteRelease (v.release);
+            if (channel > 0)
+                i->noteOffMidi (v.key, channel);
+            else
+                i->noteOff (v.key);
+            break;
+        case vfx::Event::Type::prop:
+            i->voiceProperty (v.key, (int) e.prop, e.value);
+            break;
+    }
+}
+
+void Graph::renderNodes (const float* inL, const float* inR, const float* scL, const float* scR, float* outL, float* outR, int start, int n,
+                         double bpm) noexcept
+{
+    // (inL…outR point at this part of the piece; the nodes' buffers are indexed from `start`)
+    auto& values = *active;
     auto sourceOf = [&] (const AudioWire& w, int side) -> const float* {
         if (w.from == patchFromHost)
         {
             if (w.fromBuffer == 1)
-                return (side == 0 ? scL : scR) != nullptr ? (side == 0 ? scL : scR) : zeros.data();
+                return (side == 0 ? scL : scR) != nullptr ? (side == 0 ? scL : scR) : zeros.data() + start;
             return side == 0 ? inL : inR;
         }
-        return nodes[(std::size_t) w.from]->out[(std::size_t) w.fromBuffer][(std::size_t) side].data();
+        return nodes[(std::size_t) w.from]->out[(std::size_t) w.fromBuffer][(std::size_t) side].data() + start;
     };
     auto gather = [&] (const std::vector<int>& list, float* l, float* r) {
         std::fill (l, l + n, 0.0f);
@@ -791,8 +1034,8 @@ void Graph::processPiece (const float* inL, const float* inR, const float* scL,
     {
         auto& node = *nodes[(std::size_t) i];
         auto& v = values.nodes[(std::size_t) i];
-        auto* oL = node.out[0][0].data();
-        auto* oR = node.out[0][1].data();
+        auto* oL = node.out[0][0].data() + start;
+        auto* oR = node.out[0][1].data() + start;
 
         if (node.generator)
         {
@@ -823,8 +1066,8 @@ void Graph::processPiece (const float* inL, const float* inR, const float* scL,
         }
         for (std::size_t h = 0; h < node.heads.size(); ++h)
         {
-            auto* hL = node.out[1 + h][0].data();
-            auto* hR = node.out[1 + h][1].data();
+            auto* hL = node.out[1 + h][0].data() + start;
+            auto* hR = node.out[1 + h][1].data() + start;
             std::copy (inBufL, inBufL + n, hL);
             std::copy (inBufR, inBufR + n, hR);
             if (node.heads[h].effect != nullptr)
@@ -844,7 +1087,7 @@ void Graph::processPiece (const float* inL, const float* inR, const float* scL,
     std::copy (inBufL, inBufL + n, outL);
     std::copy (inBufR, inBufR + n, outR);
     for (std::size_t bus = 1; bus < outputs.size(); ++bus)
-        gather (outputs[bus], aux[bus - 1][0].data(), aux[bus - 1][1].data());
+        gather (outputs[bus], aux[bus - 1][0].data() + start, aux[bus - 1][1].data() + start);
 }
 
 // ---------------------------------------------------------------------------------------------------------------
@@ -937,6 +1180,9 @@ public:
     void noteOffPort (int port, int key, int midiChannel) noexcept override { graph.noteOffPort (port, key, midiChannel); }
     void slideTo (int key, float cents, float samples) noexcept override { graph.slideTo (key, cents, samples); }
     void setNextNoteExpression (float pan, float cents, bool porta) noexcept override { graph.setNextNoteExpression (pan, cents, porta); }
+    void setNextNoteModulation (float modX, float modY) noexcept override { graph.setNextNoteModulation (modX, modY); }
+    void setNextNoteRelease (float velocity) noexcept override { graph.setNextNoteRelease (velocity); }
+    void setNextNoteColour (int colour) noexcept override { graph.setNextNoteColour (colour); }
     void setSongPosition (double ticks) noexcept override { graph.setSongPosition (ticks); }
     void setParameter (int index, float value) noexcept override { graph.setPublished (index, value); }
     int latencySamples() const noexcept override { return graph.latencySamples(); }
@@ -1199,6 +1445,21 @@ std::vector<int> shownToMidiPorts (const PatcherDoc& doc)
     return ports;
 }
 
+int shownMidiOutputs (const PatcherDoc& doc, int node)
+{
+    if (node < 0 || node >= (int) doc.nodes.size())
+        return 0;
+    const auto ports = nodePorts (doc.nodes[(std::size_t) node]);
+    const auto kind = vfx::kindOf (doc.nodes[(std::size_t) node].channel);
+    if (! kind)
+        return ports.midiOuts;
+    int highest = -1;
+    for (const auto& w : doc.wires)
+        if (w.kind == PatchWire::Kind::midi && w.from == node)
+            highest = std::max (highest, w.fromPort);
+    return std::clamp (std::max (vfx::outputsShown (*kind), highest + 2), 1, ports.midiOuts);
+}
+
 bool fromNotesShown (const PatcherDoc& doc, bool generator)
 {
     if (std::any_of (doc.wires.begin(), doc.wires.end(),

+ 32 - 0
src/core/Patcher.h

@@ -23,6 +23,7 @@
 #include "core/Effects.h"
 #include "core/Instruments.h"
 #include "core/Song.h"
+#include "core/Vfx.h"
 
 namespace lynx::patcher
 {
@@ -47,7 +48,10 @@ struct NodePorts
     int audioIns = 1, audioOuts = 1, controlOuts = 0;
     bool midiIn = false;
     bool midiOut = false; // a MIDI Out node: its notes leave on its MIDI output pin (round 162)
+    int midiOuts = 0;     // MIDI output pins (a MIDI Out: 1; a VFX node: its voice outputs, round 164b)
 };
+// The voice outputs a VFX node shows (FL activates the first few; LYNX shows one free pin past the last cabled one)
+int shownMidiOutputs (const PatcherDoc& doc, int node);
 NodePorts nodePorts (const PatchNode& node);
 
 // MIDI through the I/O nodes (round 162, FL's "MIDI port N" pins).
@@ -109,6 +113,10 @@ public:
     void allNotesOff() noexcept;
     void slideTo (int key, float cents, float samples) noexcept;
     void setNextNoteExpression (float pan, float cents, bool porta) noexcept;
+    // the next note's other properties, for the VFX nodes (round 164b)
+    void setNextNoteModulation (float modX, float modY) noexcept;
+    void setNextNoteRelease (float velocity) noexcept;
+    void setNextNoteColour (int colour) noexcept;
     bool hasInstruments() const noexcept;
     bool instrumentsIdle() const noexcept;
 
@@ -149,9 +157,33 @@ private:
     struct MidiTarget
     {
         int node = 0, midiChannel = -1; // −1 = the incoming channel (a MIDI Out node on the way sets its own)
+        bool vfx = false;               // a VFX node: the voice goes into its processor
     };
+    // what a node's MIDI output pin `pin` (or a "From LYNX" pin) reaches, through MIDI Out nodes
+    std::vector<MidiTarget> midiTargetsOf (const PatcherDoc& doc, int from, int pin) const;
     std::vector<std::vector<MidiTarget>> pinTargets; // ["From LYNX" pin: 0 Notes, 1 + port] the instruments it reaches
     void deliver (int pin, bool on, int key, float velocity, int midiChannel) noexcept;
+
+    // VFX nodes (round 164b): their processors run at the start of each piece on the voices that reached them, and
+    // what they send out plays the instruments on their outputs at the exact sample (the piece is split there)
+    struct VfxQueue;
+    struct NoteOut;
+    std::vector<int> vfxOrder;                // VFX nodes, sources before the nodes they feed
+    std::vector<std::unique_ptr<VfxQueue>> vfxQueues; // [node] (null: not a VFX node)
+    std::vector<NoteOut> noteOuts;            // what the VFX nodes play in the current piece (capacity reserved)
+    bool hasVfx = false;
+    struct PendingVoice
+    {
+        float pan = 0.0f, cents = 0.0f, modX = 0.5f, modY = 0.5f, release = 0.5f;
+        int colour = 0;
+        bool porta = false;
+    } nextVoice;
+    double ticks = 0.0;
+    bool playing = false;
+    void runVfx (int n, double bpm) noexcept;
+    void routeVfxOutput (int node, const vfx::Event& e) noexcept;
+    void playNoteOut (const NoteOut& o) noexcept;
+    void renderNodes (const float* inL, const float* inR, const float* scL, const float* scR, float* outL, float* outR, int start, int n, double bpm) noexcept;
     std::vector<PatchParam> published;
     std::vector<float> publishedValues; // built-in targets: the latest automation value (NaN = none), applied each block
     std::vector<std::vector<int>> outputs; // [bus of "To LYNX"] its cables

+ 113 - 6
src/core/RackRenderer.cpp

@@ -1,5 +1,6 @@
 #include "core/RackRenderer.h"
 #include "core/HardwareInsert.h"
+#include "core/Vfx.h"
 #include "core/FacetEq.h"
 #include "core/MidiControls.h"
 #include "core/Patcher.h"
@@ -610,6 +611,8 @@ void RackState::buildMidiRoutes()
     midiTargets.assign (count, {});
     midiSources.assign (count, {});
     midiOutChannel.assign (count, -1);
+    vfxChannels.clear();
+    vfxPort.assign (count, -1);
     hasMidiRoutes = false;
     midiOutTargets.assign (count, {});
     hasMidiOutputs = false;
@@ -700,6 +703,17 @@ void RackState::buildMidiRoutes()
                 send (c, r.port, std::max (0, r.midiChannel), 0);
             continue;
         }
+        if (song.channels[c].instrument == InstrumentKind::vfx) // a VFX channel: output k on port + k (round 164b)
+        {
+            if (const auto vs = vfx::readState (song.channels[c].pluginState))
+            {
+                vfxChannels.push_back ((int) c);
+                vfxPort[c] = vs->port;
+                for (int k = 0; k < vfx::outputCount (vs->kind) && vs->port + k < patchMidiPorts; ++k)
+                    send (c, vs->port + k, 0, 0);
+            }
+            continue;
+        }
         if (song.channels[c].instrument != InstrumentKind::midiOut)
             continue;
         const auto settings = midictl::parseMidiOut (song.channels[c].pluginState);
@@ -1264,7 +1278,7 @@ void RackRenderer::applyPluginParams (const RackState& state, int firstSlot) noe
 void RackRenderer::deliverToEffects (const RackState& state, const NoteEvent& e) noexcept
 {
     if (e.channel < 0 || (std::size_t) e.channel >= state.effectMidiRoutes.size()
-        || (e.type != NoteEvent::Type::on && e.type != NoteEvent::Type::off))
+        || (e.type != NoteEvent::Type::on && e.type != NoteEvent::Type::off) || e.port == -2)
         return;
     if (e.type == NoteEvent::Type::on && state.song.channels[(std::size_t) e.channel].muted)
         return;
@@ -1272,6 +1286,8 @@ void RackRenderer::deliverToEffects (const RackState& state, const NoteEvent& e)
     {
         if ((std::size_t) route.track >= state.effects.size() || (std::size_t) route.slot >= state.effects[(std::size_t) route.track].size())
             continue;
+        if (e.port >= 0 && route.port != e.port)
+            continue;
         if (auto* graph = patcher::graphOf (state.effects[(std::size_t) route.track][(std::size_t) route.slot].get()))
         {
             if (e.type == NoteEvent::Type::on)
@@ -1391,6 +1407,8 @@ void RackRenderer::renderChannel (const RackState& state, int i, int n) noexcept
             // a note of a MIDI Out channel on this plugin's MIDI input port, with that MIDI Out's MIDI channel
             if (sources == nullptr || ! routed (e.channel) || (e.type != NoteEvent::Type::on && e.type != NoteEvent::Type::off))
                 continue;
+            if (e.port == -2) // (a VFX channel's own note: its processor's output goes out instead)
+                continue;
             if (e.sampleOffset > position)
             {
                 instrument.render (l + position, r + position, e.sampleOffset - position, gl, gr);
@@ -1399,15 +1417,29 @@ void RackRenderer::renderChannel (const RackState& state, int i, int n) noexcept
             // (each route from that channel: its port and MIDI channel, round 162)
             for (const auto& route : state.midiRoutesIn[(std::size_t) i])
             {
-                if (route.other != e.channel)
+                if (route.other != e.channel || (e.port >= 0 && route.port != e.port))
                     continue;
+                // (a VFX channel's voice keeps its colour as the MIDI channel)
+                const auto midiChannel = e.port >= 0 ? (int) e.colour : route.midiChannel;
                 if (e.type == NoteEvent::Type::on)
                 {
                     if (! c.muted && ! state.song.channels[(std::size_t) e.channel].muted)
-                        instrument.noteOnPort (route.port, e.key, e.velocity, route.midiChannel);
+                    {
+                        if (e.port >= 0)
+                        {
+                            instrument.setNextNoteExpression (e.pan, e.cents, e.porta);
+                            instrument.setNextNoteModulation (e.modX, e.modY);
+                            instrument.setNextNoteColour (e.colour);
+                        }
+                        instrument.noteOnPort (route.port, e.key, e.velocity, midiChannel);
+                    }
                 }
                 else
-                    instrument.noteOffPort (route.port, e.key, route.midiChannel);
+                {
+                    if (e.port >= 0)
+                        instrument.setNextNoteRelease (e.release);
+                    instrument.noteOffPort (route.port, e.key, midiChannel);
+                }
             }
             continue;
         }
@@ -1440,6 +1472,7 @@ void RackRenderer::renderChannel (const RackState& state, int i, int n) noexcept
                                                           : std::pair<float, float> { e.modX, e.modY };
                     instrument.setNextNoteModulation (modX, modY);
                 }
+                instrument.setNextNoteColour (e.colour);
 
                 if (e.fadeIn > 0.0f || e.fadeOut > 0.0f)
                     instrument.setNextClipFades (e.clipElapsed, e.clipRemaining, e.fadeIn, e.fadeOut);
@@ -1912,7 +1945,8 @@ void RackRenderer::process (const RackState* state,
             const auto bit = std::uint64_t { 1 } << (e.key & 63);
             const auto inRange = e.key >= 0 && e.key < 128;
             // played on a MIDI Out channel: the plugins on its port get the note with its MIDI channel
-            if (state->hasMidiRoutes && (std::size_t) e.channel < state->midiRoutesOut.size())
+            if (state->hasMidiRoutes && (std::size_t) e.channel < state->midiRoutesOut.size()
+                && ((std::size_t) e.channel >= state->vfxPort.size() || state->vfxPort[(std::size_t) e.channel] < 0))
                 for (const auto& route : state->midiRoutesOut[(std::size_t) e.channel])
                     if (route.other < (int) state->instruments.size() && state->instruments[(std::size_t) route.other] != nullptr)
                     {
@@ -2102,7 +2136,76 @@ bool RackRenderer::routesLiveNotes (const RackState& state, int channel) const n
     const auto& misc = state.song.channels[c].misc;
     return (c < state.arpeggiators.size() && state.arpeggiators[c] != nullptr) || (c < state.echoes.size() && state.echoes[c] != nullptr)
            || misc.key.pan != 0.0f || misc.velocity.pan != 0.0f
-           || (misc.addToKey && misc.rootNote != 60 && state.song.channels[c].instrument != InstrumentKind::sampler);
+           || (misc.addToKey && misc.rootNote != 60 && state.song.channels[c].instrument != InstrumentKind::sampler)
+           || (c < state.vfxPort.size() && state.vfxPort[c] >= 0); // (a VFX channel's processor takes them in the chunk)
+}
+
+void RackRenderer::runVfxChannels (const RackState& state, bool playing, int numSamples) noexcept
+{
+    vfx::Transport transport;
+    transport.sampleRate = sampleRate;
+    transport.bpm = chunkTps * sampleRate * 60.0 / (double) ppq; // (the tempo at this chunk)
+    transport.ticks = chunkStartTick; // (stopped: the live clock, as the arpeggiator)
+    transport.playing = playing;
+    for (const auto c : state.vfxChannels)
+    {
+        if ((std::size_t) c >= state.instruments.size() || state.instruments[(std::size_t) c] == nullptr)
+            continue;
+        auto* processor = state.instruments[(std::size_t) c]->noteProcessor();
+        if (processor == nullptr)
+            continue;
+        vfxIn->clear();
+        vfxOut->clear();
+        const auto count = events.size();
+        for (int k = 0; k < count; ++k)
+        {
+            auto& e = events.at (k);
+            if (e.channel != c || e.port != -1)
+                continue;
+            if (e.type == NoteEvent::Type::on || e.type == NoteEvent::Type::off)
+            {
+                vfx::Event in;
+                in.type = e.type == NoteEvent::Type::on ? vfx::Event::Type::on : vfx::Event::Type::off;
+                in.offset = e.sampleOffset;
+                in.voice.key = e.key;
+                in.voice.velocity = e.velocity;
+                in.voice.pan = e.pan;
+                in.voice.cents = e.cents;
+                in.voice.modX = e.modX;
+                in.voice.modY = e.modY;
+                in.voice.release = e.release;
+                in.voice.colour = e.colour & 15;
+                in.voice.porta = e.porta;
+                in.id = vfx::inputId (e.key, in.voice.colour);
+                vfxIn->add (in);
+            }
+            e.port = -2; // (taken by the processor)
+        }
+        processor->process (vfxIn->size() > 0 ? &(*vfxIn)[0] : nullptr, vfxIn->size(), numSamples, transport, *vfxOut);
+        const auto port = state.vfxPort[(std::size_t) c];
+        for (int k = 0; k < vfxOut->size(); ++k)
+        {
+            const auto& o = (*vfxOut)[k];
+            if (o.type == vfx::Event::Type::prop || port + o.output >= patchMidiPorts)
+                continue; // (voice properties over time reach the instruments inside a Patcher only)
+            NoteEvent e;
+            e.type = o.type == vfx::Event::Type::on ? NoteEvent::Type::on : NoteEvent::Type::off;
+            e.channel = c;
+            e.sampleOffset = std::clamp (o.offset, 0, std::max (0, numSamples - 1));
+            e.key = o.voice.key;
+            e.velocity = o.voice.velocity;
+            e.pan = o.voice.pan;
+            e.cents = o.voice.cents;
+            e.modX = o.voice.modX;
+            e.modY = o.voice.modY;
+            e.release = o.voice.release;
+            e.colour = (std::int8_t) (o.voice.colour & 15);
+            e.porta = o.voice.porta;
+            e.port = (std::int16_t) (port + o.output);
+            events.add (e);
+        }
+    }
+    events.sortByOffset();
 }
 
 void RackRenderer::processChunk (const RackState& state, bool playing, double startTick, int numSamples,
@@ -2189,6 +2292,10 @@ void RackRenderer::processChunk (const RackState& state, bool playing, double st
         events.sortByOffset();
     }
 
+    // VFX channels (round 164b): their processors turn their notes into what they send on their ports
+    if (! state.vfxChannels.empty())
+        runVfxChannels (state, playing, numSamples);
+
     // cut groups: each note of a channel "cuts" the channels linked to it, at the same sample
     if (state.hasCutGroups)
     {

+ 7 - 0
src/core/RackRenderer.h

@@ -24,6 +24,7 @@
 #include "core/Meters.h"
 #include "core/Pdc.h"
 #include "core/Scheduler.h"
+#include "core/Vfx.h"
 #include "core/Song.h"
 
 namespace lynx
@@ -157,6 +158,9 @@ struct RackState
     // FL's wrapper "Output port" (round 149): [plugin channel] → the plugin channels whose input port is its output port
     std::vector<std::vector<int>> midiOutTargets;
     bool hasMidiOutputs = false;
+    // VFX channels (round 164b): their notes go through their processor; output k goes out on MIDI port vfxPort + k
+    std::vector<int> vfxChannels;
+    std::vector<int> vfxPort; // [channel] (−1 = not a VFX channel)
     void buildMidiRoutes();
 
     // Loads (or fetches from cache) a file's audio; nullptr on failure.
@@ -344,6 +348,9 @@ private:
     // live-played notes of channels with an arpeggiator, echo delay or key / velocity tracking go through the
     // channel's note path like the scheduled ones (FL, round 149); while stopped the arpeggiator runs on its own clock
     std::array<NoteEvent, 256> liveRouted {};
+    // the VFX channels' processors run on the chunk's events before the channels render (round 164b)
+    void runVfxChannels (const RackState& state, bool playing, int numSamples) noexcept;
+    std::unique_ptr<vfx::EventList> vfxIn = std::make_unique<vfx::EventList>(), vfxOut = std::make_unique<vfx::EventList>();
     int liveRoutedCount = 0;
     double liveTick = 0.0;
     bool routesLiveNotes (const RackState& state, int channel) const noexcept;

+ 2 - 0
src/core/Scheduler.cpp

@@ -137,6 +137,7 @@ void schedulePatternLoop (const Pattern& pattern,
         on.modX = note.modX;
         on.modY = note.modY;
         on.release = note.release;
+        on.colour = (std::int8_t) (note.colour & 15);
         const auto timing = noteTiming (note, swing, channelOf (channels, note.channel));
         const auto start = timing.start;
 
@@ -306,6 +307,7 @@ void scheduleSong (const Song& song, double startTick, int numSamples, double tp
             e.modX = note.modX;
             e.modY = note.modY;
             e.release = note.release;
+            e.colour = (std::int8_t) (note.colour & 15);
 
             if (note.slide)
             {

+ 5 - 0
src/core/Scheduler.h

@@ -37,6 +37,10 @@ struct NoteEvent
     float clipElapsed = 0.0f, clipRemaining = 0.0f, fadeIn = 0.0f, fadeOut = 0.0f;
     // the note's Mod X / Y (0..1, 0.5 = none) and, on its "off", its release velocity (0..1) — REA round 151
     float modX = 0.5f, modY = 0.5f, release = 0.5f;
+    std::int8_t colour = 0; // the note's colour group 0…15 (FL's note colours: VFX Color Mapper, round 164b)
+    // A VFX channel (round 164b): −1 = an ordinary note; −2 = one its processor takes (it goes nowhere else); N ≥ 0 =
+    // what the processor sent on MIDI port N (only the routes on that port take it)
+    std::int16_t port = -1;
 };
 
 // Fixed-capacity buffer. Events beyond capacity are dropped
@@ -53,6 +57,7 @@ public:
     int size() const noexcept { return count; }
     int droppedCount() const noexcept { return dropped; }
     const NoteEvent& operator[] (int i) const noexcept { return events[(std::size_t) i]; }
+    NoteEvent& at (int i) noexcept { return events[(std::size_t) i]; }
     const NoteEvent* begin() const noexcept { return events.data(); }
     const NoteEvent* end() const noexcept { return events.data() + count; }
 

+ 2 - 1
src/core/Song.h

@@ -79,7 +79,8 @@ enum class InstrumentKind : std::uint8_t
     midiOut,    // FL's MIDI Out (REA_rodada16 §1, REA_rodada133 §4): no sound; its notes and MIDI controls go to the plugins whose
                 // MIDI input port is its port (PluginRef::midiInPort). FL's state (channel @4, port @24) in pluginState
     patcher,    // FL's Patcher as a generator (REA_rodada141): a graph of instruments and effects in ChannelDef::patcher
-    soundfont   // LYNX Soundfont (REA_rodada158, core/SoundFont.h): the .sf2 / .sf3 in samplePath, settings in modelParams
+    soundfont,  // LYNX Soundfont (REA_rodada158, core/SoundFont.h): the .sf2 / .sf3 in samplePath, settings in modelParams
+    vfx         // FL's VFX note processors (round 164b, core/Vfx.h): kind, output port and FL's state in pluginState; no sound
 };
 
 // External plugin: format identifier (the app knows how to find the file) + saved state.

+ 1783 - 0
src/core/Vfx.cpp

@@ -0,0 +1,1783 @@
+#include "core/Vfx.h"
+
+#include <algorithm>
+#include <atomic>
+#include <cmath>
+#include <cstring>
+#include <functional>
+
+#include "core/FlSynths.h"
+#include "core/Song.h"
+#include "core/VfxDetail.h"
+#include "flp/Flp.h"
+
+namespace lynx::vfx
+{
+using detail::Handoff;
+using detail::Reader;
+using detail::put;
+
+namespace
+{
+constexpr std::uint32_t lynxMagic = 0x5846564c; // "LVFX"
+} // namespace
+
+int inputId (int key, int colour) noexcept { return (colour & 15) * 128 + (key & 127); }
+
+// ---------------------------------------------------------------------------------------------------------------
+
+const char* flName (Kind kind) noexcept
+{
+    switch (kind)
+    {
+        case Kind::keyMapper: return "VFX Key Mapper";
+        case Kind::colorMapper: return "VFX Color Mapper";
+        case Kind::envelope: return "VFX Envelope";
+        case Kind::keyboardSplitter: return "VFX Keyboard Splitter";
+        case Kind::levelScaler: return "VFX Level Scaler";
+        case Kind::sequencer: return "VFX Sequencer";
+        case Kind::script: return "VFX Script";
+    }
+    return "VFX";
+}
+
+std::optional<Kind> kindOfFlName (std::string_view name) noexcept
+{
+    auto same = [] (std::string_view a, std::string_view b) {
+        return a.size() == b.size() && std::equal (a.begin(), a.end(), b.begin(), [] (char x, char y) {
+                   return std::tolower ((unsigned char) x) == std::tolower ((unsigned char) y);
+               });
+    };
+    for (const auto k : allKinds)
+        if (same (name, flName (k)))
+            return k;
+    return std::nullopt;
+}
+
+void EventList::sortByOffset() noexcept
+{
+    // stable insertion sort in place (std::stable_sort may allocate; the events arrive nearly in order); an "off"
+    // goes before an "on" on the same sample
+    const auto before = [] (const Event& a, const Event& b) {
+        if (a.offset != b.offset)
+            return a.offset < b.offset;
+        return a.type == Event::Type::off && b.type != Event::Type::off;
+    };
+    for (int i = 1; i < count; ++i)
+    {
+        const auto e = events[(std::size_t) i];
+        auto j = i;
+        for (; j > 0 && before (e, events[(std::size_t) j - 1]); --j)
+            events[(std::size_t) j] = events[(std::size_t) j - 1];
+        events[(std::size_t) j] = e;
+    }
+}
+
+void EventList::removeFirst (int n) noexcept
+{
+    n = std::clamp (n, 0, count);
+    std::move (events.begin() + n, events.begin() + count, events.begin());
+    count -= n;
+}
+
+// ---------------------------------------------------------------------------------------------------------------
+// VFX Key Mapper
+
+KeyMapperSettings defaultKeyMapper()
+{
+    KeyMapperSettings s;
+    for (int i = 0; i < 12; ++i)
+        s.rows[(std::size_t) i] = { i };
+    return s;
+}
+
+std::optional<KeyMapperSettings> parseKeyMapper (const std::vector<std::uint8_t>& fl)
+{
+    Reader r { fl.data(), fl.size() };
+    KeyMapperSettings s;
+    s.version = r.i32();
+    if (r.failed || s.version < 1 || s.version > 16)
+        return std::nullopt;
+    s.enabled = r.i32() != 0;
+    s.baseKey = r.i32();
+    s.offset = r.i32();
+    s.multimode = r.i32();
+    s.slide = r.i32();
+    for (auto& row : s.rows)
+    {
+        const auto n = r.i32();
+        if (r.failed || n < 0 || n > 128)
+            return std::nullopt;
+        row.clear();
+        for (int k = 0; k < n; ++k)
+            row.push_back (r.get<std::int16_t>());
+    }
+    if (r.failed)
+        return std::nullopt;
+    s.extra.assign (fl.begin() + (std::ptrdiff_t) r.pos, fl.end());
+    return s;
+}
+
+std::vector<std::uint8_t> writeKeyMapper (const KeyMapperSettings& s)
+{
+    std::vector<std::uint8_t> out;
+    put<std::int32_t> (out, s.version);
+    put<std::int32_t> (out, s.enabled ? 1 : 0);
+    put<std::int32_t> (out, s.baseKey);
+    put<std::int32_t> (out, s.offset);
+    put<std::int32_t> (out, s.multimode);
+    put<std::int32_t> (out, s.slide);
+    for (const auto& row : s.rows)
+    {
+        put<std::int32_t> (out, (std::int32_t) row.size());
+        for (const auto v : row)
+            put<std::int16_t> (out, (std::int16_t) v);
+    }
+    out.insert (out.end(), s.extra.begin(), s.extra.end());
+    return out;
+}
+
+// ---------------------------------------------------------------------------------------------------------------
+// VFX Color Mapper
+
+ColorMapperSettings defaultColorMapper()
+{
+    ColorMapperSettings s;
+    for (int i = 0; i < 16; ++i)
+        s.port[(std::size_t) i] = s.colour[(std::size_t) i] = i;
+    return s;
+}
+
+std::optional<ColorMapperSettings> parseColorMapper (const std::vector<std::uint8_t>& fl)
+{
+    Reader r { fl.data(), fl.size() };
+    ColorMapperSettings s;
+    s.header = r.u32();
+    for (auto& p : s.port)
+        p = std::clamp (r.i32(), 0, 15);
+    for (auto& c : s.colour)
+        c = std::clamp (r.i32(), 0, 15);
+    if (r.failed)
+        return std::nullopt;
+    return s;
+}
+
+std::vector<std::uint8_t> writeColorMapper (const ColorMapperSettings& s)
+{
+    std::vector<std::uint8_t> out;
+    put<std::uint32_t> (out, s.header);
+    for (const auto p : s.port)
+        put<std::int32_t> (out, p);
+    for (const auto c : s.colour)
+        put<std::int32_t> (out, c);
+    return out;
+}
+
+// ---------------------------------------------------------------------------------------------------------------
+// VFX Level Scaler (REA_rodada164b §Level Scaler)
+
+bool LevelScalerSettings::identity (int tab) const noexcept
+{
+    return at (tab, multiply) == 8192 && at (tab, offset) == 0 && at (tab, tension) == 0 && at (tab, humanize) == 0;
+}
+
+void resetLevelScalerTab (LevelScalerSettings& s, int tab)
+{
+    // the editor's Reset: bipolar properties are centred
+    s.at (tab, LevelScalerSettings::center) = tab >= LevelScalerSettings::finePitch ? 4096 : 0;
+    s.at (tab, LevelScalerSettings::multiply) = 8192;
+    s.at (tab, LevelScalerSettings::offset) = 0;
+    s.at (tab, LevelScalerSettings::tension) = 0;
+    s.at (tab, LevelScalerSettings::humanize) = 0;
+    s.at (tab, LevelScalerSettings::humanizeMode) = 1;
+}
+
+LevelScalerSettings defaultLevelScaler()
+{
+    LevelScalerSettings s;
+    for (int t = 0; t < LevelScalerSettings::tabCount; ++t)
+        resetLevelScalerTab (s, t);
+    return s;
+}
+
+std::optional<LevelScalerSettings> parseLevelScaler (const std::vector<std::uint8_t>& fl)
+{
+    Reader r { fl.data(), fl.size() };
+    auto s = defaultLevelScaler();
+    s.version = r.u32();
+    if (r.failed)
+        return std::nullopt;
+    if (s.version >= 2)
+        return defaultLevelScaler(); // (FL ignores a state it does not know)
+    // chunks: id, 64-bit size, data (unknown ids skipped)
+    while (r.left() >= 12)
+    {
+        const auto id = r.u32();
+        const auto size = r.get<std::uint64_t>();
+        if (size > r.left())
+            return std::nullopt;
+        const auto end = r.pos + (std::size_t) size;
+        if (id == 0x3ea && size >= 1)
+            s.selectedTab = std::clamp ((int) r.get<std::uint8_t>(), 0, 5);
+        else if (id == 0x3e9 && size >= 144)
+        {
+            static constexpr std::array<std::pair<int, int>, 6> range { { { 0, 8192 }, { -16384, 16384 }, { -8192, 8192 }, { -8192, 8192 }, { 0, 16384 }, { 0, 2 } } };
+            for (int i = 0; i < 36; ++i)
+                s.p[(std::size_t) i] = std::clamp (r.i32(), range[(std::size_t) (i % 6)].first, range[(std::size_t) (i % 6)].second);
+        }
+        r.pos = end;
+    }
+    if (r.failed)
+        return std::nullopt;
+    return s;
+}
+
+std::vector<std::uint8_t> writeLevelScaler (const LevelScalerSettings& s)
+{
+    std::vector<std::uint8_t> out;
+    put<std::uint32_t> (out, 1);
+    put<std::uint32_t> (out, 0x3ea);
+    put<std::uint64_t> (out, 1);
+    put<std::uint8_t> (out, (std::uint8_t) std::clamp (s.selectedTab, 0, 5));
+    put<std::uint32_t> (out, 0x3e9);
+    put<std::uint64_t> (out, 144);
+    for (const auto v : s.p)
+        put<std::int32_t> (out, v);
+    return out;
+}
+
+double levelScale (const LevelScalerSettings& s, int tab, double x, double lo, double hi, double random) noexcept
+{
+    using L = LevelScalerSettings;
+    if (s.identity (tab) || ! (hi > lo))
+        return x;
+    const auto c = s.at (tab, L::center) / 8192.0;
+    const auto scale = 1.0 / std::max (c, 1.0 - c);
+    const auto tension = s.at (tab, L::tension);
+    const auto g = std::pow (8193.0, std::abs (tension) / 8192.0) - 1.0;
+    const auto mul = s.at (tab, L::multiply) / (8192.0 * scale);
+    const auto off = s.at (tab, L::offset) / 8192.0 + c;
+    const auto u = (x - lo) / (hi - lo);
+    const auto d = u - c;
+    const auto m = std::min (1.0, std::abs (d) * scale);
+    auto shape = m;
+    if (tension > 0 && g > 0.0)
+        shape = 1.0 - (std::pow (g + 1.0, 1.0 - m) - 1.0) / g;
+    else if (tension < 0 && g > 0.0)
+        shape = (std::pow (g + 1.0, m) - 1.0) / g;
+    const auto y = std::clamp ((d < 0.0 ? -shape : shape) * mul + off, 0.0, 1.0);
+    auto out = std::clamp (lo + y * (hi - lo), lo, hi);
+    if (const auto h = s.at (tab, L::humanize) / 16384.0; h > 0.0)
+    {
+        const auto mode = s.at (tab, L::humanizeMode);
+        const auto a = mode == 2 ? out : out - (out - lo) * h;
+        const auto b = mode == 0 ? out : out + (hi - out) * h;
+        out = a + std::clamp (random, 0.0, 1.0) * (b - a);
+    }
+    return out;
+}
+
+// ---------------------------------------------------------------------------------------------------------------
+// FL's mapping curves and VFX Keyboard Splitter (REA_rodada164b §Keyboard Splitter)
+
+MapCurve MapCurve::flat (double level)
+{
+    MapCurve m;
+    m.points.push_back ({ 0.0, level });
+    m.points.push_back ({ 1.0, level });
+    return m;
+}
+
+double MapCurve::at (double x) const noexcept
+{
+    if (points.empty())
+        return 0.0;
+    if (x <= points.front().x)
+        return points.front().y;
+    for (std::size_t i = 1; i < points.size(); ++i)
+        if (x < points[i].x)
+        {
+            const auto& a = points[i - 1];
+            const auto& b = points[i];
+            if (b.curve == 2) // hold: the previous level up to this point
+                return a.y;
+            auto f = b.x > a.x ? (x - a.x) / (b.x - a.x) : 1.0;
+            if (b.tension != 0.0f) // (the automation clips' bend, FL's sign)
+                f = std::pow (f, std::pow (2.0, (double) -b.tension * 3.0));
+            return a.y + (b.y - a.y) * f;
+        }
+    return points.back().y;
+}
+
+bool MapCurve::isFlat (double level) const noexcept
+{
+    return std::all_of (points.begin(), points.end(), [level] (const Point& p) { return std::abs (p.y - level) < 1e-9; });
+}
+
+namespace
+{
+bool readMap (Reader& r, MapCurve& m)
+{
+    r.i32(); // kind (3)
+    const auto version = r.i32();
+    const auto n = r.i32();
+    if (r.failed || n < 0 || n > 4096 || version < 2 || version > 3)
+        return false;
+    m.points.clear();
+    double x = 0.0;
+    for (int k = 0; k < n; ++k)
+    {
+        MapCurve::Point p;
+        const auto dx = r.get<double>();
+        x += std::isfinite (dx) ? dx : 0.0;
+        p.x = x;
+        p.y = r.get<double>();
+        if (! std::isfinite (p.y))
+            p.y = 0.0;
+        p.tension = r.get<float>();
+        if (! std::isfinite (p.tension))
+            p.tension = 0.0f;
+        p.curve = r.get<std::uint8_t>();
+        p.b13 = r.get<std::uint8_t>();
+        p.b14 = r.get<std::uint8_t>();
+        p.b15 = r.get<std::uint8_t>();
+        m.points.push_back (p);
+    }
+    for (auto& f : m.footer)
+        f = r.i32();
+    return ! r.failed;
+}
+
+void writeMap (std::vector<std::uint8_t>& out, const MapCurve& m, int kind = 3)
+{
+    put<std::int32_t> (out, kind);
+    put<std::int32_t> (out, 3);
+    put<std::int32_t> (out, (std::int32_t) m.points.size());
+    double x = 0.0;
+    for (const auto& p : m.points)
+    {
+        put<double> (out, p.x - x);
+        x = p.x;
+        put<double> (out, p.y);
+        put<float> (out, p.tension);
+        put<std::uint8_t> (out, p.curve);
+        put<std::uint8_t> (out, p.b13);
+        put<std::uint8_t> (out, p.b14);
+        put<std::uint8_t> (out, p.b15); // (FL's shape flag: 2 straight, 1 / 0xff bent up / down)
+    }
+    for (const auto f : m.footer)
+        put<std::int32_t> (out, f);
+}
+} // namespace
+
+KeyboardSplitterSettings defaultKeyboardSplitter()
+{
+    KeyboardSplitterSettings s;
+    s.zones[0].keyboard = MapCurve::flat (1.0); // zone 1: the whole keyboard
+    return s;
+}
+
+std::optional<KeyboardSplitterSettings> parseKeyboardSplitter (const std::vector<std::uint8_t>& fl)
+{
+    Reader r { fl.data(), fl.size() };
+    KeyboardSplitterSettings s;
+    s.header = r.u32();
+    if (r.failed || s.header >= 0x100004 || (s.header & 0xfffff) == 0)
+        return std::nullopt;
+    if ((s.header >> 20) != 0)
+        s.page = std::clamp ((int) r.get<std::uint8_t>(), 0, 1);
+    for (auto& z : s.zones)
+    {
+        if (! readMap (r, z.keyboard) || ! readMap (r, z.velocity))
+            return std::nullopt;
+        z.transpose = std::clamp (r.i32(), -48, 48);
+        z.absolute = r.get<std::uint8_t>() != 0;
+        z.random = r.get<std::uint8_t>() != 0;
+        // name: u8 length (255: a u32 follows), UTF-16 characters
+        std::uint32_t length = r.get<std::uint8_t>();
+        if (length == 255)
+            length = r.u32();
+        if (r.failed || length > 4096 || length * 2 > r.left())
+            return std::nullopt;
+        std::u16string name;
+        for (std::uint32_t k = 0; k < length; ++k)
+            name.push_back ((char16_t) r.get<std::uint16_t>());
+        z.name.clear();
+        for (std::size_t k = 0; k < name.size(); ++k)
+        {
+            std::uint32_t c = name[k];
+            if (c >= 0xd800 && c < 0xdc00 && k + 1 < name.size())
+                c = 0x10000 + ((c - 0xd800) << 10) + ((std::uint32_t) name[++k] - 0xdc00);
+            if (c < 0x80)
+                z.name.push_back ((char) c);
+            else if (c < 0x800)
+                z.name += { (char) (0xc0 | (c >> 6)), (char) (0x80 | (c & 0x3f)) };
+            else if (c < 0x10000)
+                z.name += { (char) (0xe0 | (c >> 12)), (char) (0x80 | ((c >> 6) & 0x3f)), (char) (0x80 | (c & 0x3f)) };
+            else
+                z.name += { (char) (0xf0 | (c >> 18)), (char) (0x80 | ((c >> 12) & 0x3f)), (char) (0x80 | ((c >> 6) & 0x3f)), (char) (0x80 | (c & 0x3f)) };
+        }
+    }
+    if (r.failed)
+        return std::nullopt;
+    return s;
+}
+
+std::vector<std::uint8_t> writeKeyboardSplitter (const KeyboardSplitterSettings& s)
+{
+    std::vector<std::uint8_t> out;
+    put<std::uint32_t> (out, 0x100003);
+    put<std::uint8_t> (out, (std::uint8_t) std::clamp (s.page, 0, 1));
+    for (const auto& z : s.zones)
+    {
+        writeMap (out, z.keyboard);
+        writeMap (out, z.velocity);
+        put<std::int32_t> (out, z.transpose);
+        put<std::uint8_t> (out, z.absolute ? 1 : 0);
+        put<std::uint8_t> (out, z.random ? 1 : 0);
+        std::u16string name;
+        for (std::size_t k = 0; k < z.name.size();)
+        {
+            const auto b = (std::uint8_t) z.name[k];
+            std::uint32_t c = b;
+            int more = b >= 0xf0 ? 3 : b >= 0xe0 ? 2 : b >= 0xc0 ? 1 : 0;
+            c = more == 3 ? b & 0x07 : more == 2 ? b & 0x0f : more == 1 ? b & 0x1f : b;
+            ++k;
+            for (; more > 0 && k < z.name.size(); --more, ++k)
+                c = (c << 6) | ((std::uint8_t) z.name[k] & 0x3f);
+            if (c >= 0x10000)
+            {
+                c -= 0x10000;
+                name.push_back ((char16_t) (0xd800 + (c >> 10)));
+                name.push_back ((char16_t) (0xdc00 + (c & 0x3ff)));
+            }
+            else
+                name.push_back ((char16_t) c);
+        }
+        if (name.size() < 255)
+            put<std::uint8_t> (out, (std::uint8_t) name.size());
+        else
+        {
+            put<std::uint8_t> (out, 255);
+            put<std::uint32_t> (out, (std::uint32_t) name.size());
+        }
+        for (const auto c : name)
+            put<std::uint16_t> (out, (std::uint16_t) c);
+    }
+    return out;
+}
+
+double splitterGain (double m) noexcept
+{
+    return m >= 1.0 ? 1.0 : (std::pow (11.0, m) - 1.0) / 10.0;
+}
+
+// ---------------------------------------------------------------------------------------------------------------
+// VFX Envelope (REA_rodada164b §Envelope)
+
+namespace
+{
+MapCurve curveOf (std::initializer_list<std::tuple<double, double, float>> points, std::array<std::int32_t, 5> footer)
+{
+    MapCurve m;
+    for (const auto& [x, y, t] : points)
+        m.points.push_back ({ x, y, t });
+    m.footer = footer;
+    return m;
+}
+} // namespace
+
+EnvelopeSettings defaultEnvelope()
+{
+    EnvelopeSettings s;
+    for (int g = 0; g < 16; ++g)
+    {
+        auto& a = s.articulators[(std::size_t) g];
+        for (int t = 0; t < EnvelopeSettings::targetCount; ++t)
+        {
+            auto& p = a.parts[(std::size_t) t];
+            p.lfoAmp = curveOf ({ { 0.0, 0.5, 0.0f }, { 1.0, 0.5, 0.0f }, { 1.25, 1.0, 0.0f }, { 2.25, 0.5, 0.0f } }, { 0, 0, -1, -1, -1 });
+            if (t == EnvelopeSettings::velocity)
+            {
+                p.base = 0.0f;
+                // a volume envelope: attack, a peak, sustain at half (= the note's own level), release
+                p.envelope = curveOf ({ { 0.0, 0.0, 0.0f }, { 0.75, 1.0, 0.2f }, { 2.25, 0.5, 0.2f }, { 2.5, 0.0, 0.2f } },
+                                      { 0, g == 0 ? -1 : 0, 1, -1, 2 });
+            }
+            else
+            {
+                p.base = 0.5f;
+                p.env = t == EnvelopeSettings::pitch ? 0.25f : 1.0f;
+                p.envelope = curveOf ({ { 0.0, 0.5, 0.0f }, { 0.25, 0.5, 0.0f } }, { 1, -1, -1, -1, -1 }); // (on, neutral)
+            }
+        }
+    }
+    return s;
+}
+
+namespace
+{
+bool readPart (Reader& r, EnvelopeSettings::Part& p)
+{
+    p.version = r.i32();
+    p.base = r.get<float>();
+    p.env = r.get<float>();
+    p.lfo = r.get<float>();
+    if (! readMap (r, p.envelope))
+        return false;
+    for (auto& k : p.adsr)
+        k = r.i32();
+    if (! readMap (r, p.lfoAmp))
+        return false;
+    p.speed = r.i32();
+    p.tension = r.i32();
+    p.skew = r.i32();
+    p.pulseWidth = r.i32();
+    p.phase = p.version >= 3 ? r.i32() : 0;
+    for (auto* f : { &p.base, &p.env, &p.lfo })
+        if (! std::isfinite (*f))
+            *f = 0.0f;
+    return ! r.failed;
+}
+
+void writePart (std::vector<std::uint8_t>& out, const EnvelopeSettings::Part& p)
+{
+    put<std::int32_t> (out, 3);
+    put<float> (out, p.base);
+    put<float> (out, p.env);
+    put<float> (out, p.lfo);
+    writeMap (out, p.envelope, 1);
+    for (const auto k : p.adsr)
+        put<std::int32_t> (out, k);
+    writeMap (out, p.lfoAmp, 2);
+    for (const auto v : { p.speed, p.tension, p.skew, p.pulseWidth, p.phase })
+        put<std::int32_t> (out, v);
+}
+
+void writeChunk (std::vector<std::uint8_t>& out, std::int32_t id, const std::vector<std::uint8_t>& data)
+{
+    put<std::int32_t> (out, id);
+    put<std::int64_t> (out, (std::int64_t) data.size());
+    out.insert (out.end(), data.begin(), data.end());
+}
+} // namespace
+
+std::optional<EnvelopeSettings> parseEnvelope (const std::vector<std::uint8_t>& fl)
+{
+    Reader r { fl.data(), fl.size() };
+    auto s = defaultEnvelope();
+    s.header = r.u32();
+    if (r.failed || s.header >= 0x10004)
+        return std::nullopt;
+    std::vector<std::int32_t> params;
+    int group = 0, target = 0;
+    while (r.left() >= 12)
+    {
+        const auto id = r.i32();
+        const auto size = r.get<std::int64_t>();
+        if (size < 0 || (std::uint64_t) size > r.left())
+            return std::nullopt;
+        const auto end = r.pos + (std::size_t) size;
+        Reader c { fl.data(), end, r.pos };
+        switch (id)
+        {
+            case 1003:
+                s.enabled = c.i32() != 0;
+                s.shownArticulator = std::clamp (c.i32(), 0, 15);
+                s.shownTarget = std::clamp (c.i32(), 0, 4);
+                s.shownPart = std::clamp (c.i32(), 0, 1);
+                break;
+            case 1008:
+                params.clear();
+                while (c.left() >= 4)
+                    params.push_back (c.i32());
+                break;
+            case 1007:
+                for (auto& t : s.toggles)
+                    t = c.left() >= 4 ? c.i32() : 0;
+                break;
+            case 1004:
+            {
+                group = std::clamp (c.i32(), 0, 15);
+                auto& a = s.articulators[(std::size_t) group];
+                a.colour = std::clamp (c.i32(), 0, 15);
+                a.low = std::clamp (c.i32(), 0, 132);
+                a.high = std::clamp (c.i32(), 0, 132);
+                break;
+            }
+            case 1005:
+                group = std::clamp (c.i32(), 0, 15);
+                target = std::clamp (c.i32(), 0, 4);
+                break;
+            case 1006:
+                if (! readPart (c, s.articulators[(std::size_t) group].parts[(std::size_t) target]))
+                    return std::nullopt;
+                break;
+            default: break;
+        }
+        r.pos = end;
+    }
+    if (r.failed)
+        return std::nullopt;
+    // the parameter values set the base / envelope / LFO levels (FL pushes them after loading)
+    if (params.size() >= 880)
+        for (int g = 0; g < 16; ++g)
+            for (int t = 0; t < 5; ++t)
+            {
+                auto& p = s.articulators[(std::size_t) g].parts[(std::size_t) t];
+                const auto at = (std::size_t) ((g * 5 + t) * 11);
+                p.base = std::clamp (params[at + 8], 0, 256) / 256.0f;
+                p.env = std::clamp (params[at + 9], -256, 256) / 256.0f;
+                p.lfo = std::clamp (params[at + 10], -256, 256) / 256.0f;
+            }
+    return s;
+}
+
+std::vector<std::uint8_t> writeEnvelope (const EnvelopeSettings& s)
+{
+    std::vector<std::uint8_t> out, chunk;
+    put<std::uint32_t> (out, 0x10003);
+    for (const auto v : { s.enabled ? 1 : 0, s.shownArticulator, s.shownTarget, s.shownPart })
+        put<std::int32_t> (chunk, v);
+    writeChunk (out, 1003, chunk);
+    chunk.clear();
+    for (const auto& a : s.articulators)
+        for (const auto& p : a.parts)
+            for (const auto v : { p.adsr[0], p.adsr[1], p.adsr[2], p.adsr[3], p.speed, p.tension, p.skew, p.pulseWidth,
+                                  (std::int32_t) std::lround (p.base * 256.0f), (std::int32_t) std::lround (p.env * 256.0f),
+                                  (std::int32_t) std::lround (p.lfo * 256.0f) })
+                put<std::int32_t> (chunk, v);
+    writeChunk (out, 1008, chunk);
+    chunk.clear();
+    for (const auto t : s.toggles)
+        put<std::int32_t> (chunk, t);
+    writeChunk (out, 1007, chunk);
+    for (int g = 0; g < 16; ++g)
+    {
+        const auto& a = s.articulators[(std::size_t) g];
+        chunk.clear();
+        for (const auto v : { g, a.colour, a.low, a.high })
+            put<std::int32_t> (chunk, v);
+        writeChunk (out, 1004, chunk);
+        for (int t = 0; t < 5; ++t)
+        {
+            chunk.clear();
+            for (const auto v : { g, t, 0 })
+                put<std::int32_t> (chunk, v);
+            writeChunk (out, 1005, chunk);
+            chunk.clear();
+            writePart (chunk, a.parts[(std::size_t) t]);
+            writeChunk (out, 1006, chunk);
+        }
+    }
+    return out;
+}
+
+// ---------------------------------------------------------------------------------------------------------------
+// Presets
+
+std::vector<Preset> builtInPresets (Kind kind)
+{
+    std::vector<Preset> out;
+    if (kind == Kind::keyMapper)
+    {
+        // scales: each key plays the nearest scale note at or below it (as FL's scale presets do)
+        struct Scale
+        {
+            const char* name;
+            std::vector<int> notes;
+        };
+        const std::vector<Scale> scales {
+            { "Major", { 0, 2, 4, 5, 7, 9, 11 } },
+            { "Natural minor", { 0, 2, 3, 5, 7, 8, 10 } },
+            { "Harmonic minor", { 0, 2, 3, 5, 7, 8, 11 } },
+            { "Melodic minor", { 0, 2, 3, 5, 7, 9, 11 } },
+            { "Dorian", { 0, 2, 3, 5, 7, 9, 10 } },
+            { "Phrygian", { 0, 1, 3, 5, 7, 8, 10 } },
+            { "Lydian", { 0, 2, 4, 6, 7, 9, 11 } },
+            { "Mixolydian", { 0, 2, 4, 5, 7, 9, 10 } },
+            { "Locrian", { 0, 1, 3, 5, 6, 8, 10 } },
+            { "Major pentatonic", { 0, 2, 4, 7, 9 } },
+            { "Minor pentatonic", { 0, 3, 5, 7, 10 } },
+            { "Blues", { 0, 3, 5, 6, 7, 10 } },
+            { "Whole tone", { 0, 2, 4, 6, 8, 10 } },
+            { "Diminished", { 0, 2, 3, 5, 6, 8, 9, 11 } },
+        };
+        for (const auto& scale : scales)
+        {
+            auto s = defaultKeyMapper();
+            for (int pc = 0; pc < 12; ++pc)
+            {
+                int below = 0;
+                for (const auto n : scale.notes)
+                    if (n <= pc)
+                        below = n;
+                s.rows[(std::size_t) pc] = { below };
+            }
+            out.push_back ({ "Scales", scale.name, writeKeyMapper (s) });
+        }
+        auto shifted = [&] (const char* name, std::vector<int> intervals) {
+            auto s = defaultKeyMapper();
+            for (int pc = 0; pc < 12; ++pc)
+            {
+                s.rows[(std::size_t) pc].clear();
+                for (const auto i : intervals)
+                    s.rows[(std::size_t) pc].push_back (pc + i);
+            }
+            out.push_back ({ "Harmony", name, writeKeyMapper (s) });
+        };
+        shifted ("Octave up", { 0, 12 });
+        shifted ("Octave down", { -12, 0 });
+        shifted ("Fifth up", { 0, 7 });
+        shifted ("Fifth down", { -5, 0 });
+        shifted ("Power chord", { 0, 7, 12 });
+        shifted ("Major triad", { 0, 4, 7 });
+        shifted ("Minor triad", { 0, 3, 7 });
+        auto inverted = defaultKeyMapper();
+        for (int pc = 0; pc < 12; ++pc)
+            inverted.rows[(std::size_t) pc] = { 11 - pc };
+        out.push_back ({ "Special", "Inverted", writeKeyMapper (inverted) });
+    }
+    if (kind == Kind::levelScaler)
+    {
+        using L = LevelScalerSettings;
+        auto make = [&] (const char* folder, const char* name, std::function<void (L&)> f) {
+            auto s = defaultLevelScaler();
+            f (s);
+            out.push_back ({ folder, name, writeLevelScaler (s) });
+        };
+        make ("Velocity", "Humanize (subtle)", [] (L& s) { s.at (L::velocity, L::humanize) = 2400; });
+        make ("Velocity", "Humanize (strong)", [] (L& s) { s.at (L::velocity, L::humanize) = 6000; });
+        make ("Velocity", "Softer", [] (L& s) { s.at (L::velocity, L::multiply) = 6144; });
+        make ("Velocity", "Compress", [] (L& s) {
+            s.at (L::velocity, L::center) = 6400;
+            s.at (L::velocity, L::multiply) = 4096;
+        });
+        make ("Velocity", "Expand", [] (L& s) {
+            s.at (L::velocity, L::center) = 6400;
+            s.at (L::velocity, L::multiply) = 12288;
+        });
+        make ("Velocity", "Fixed", [] (L& s) {
+            s.at (L::velocity, L::multiply) = 0;
+            s.at (L::velocity, L::offset) = 6400;
+        });
+        make ("Velocity", "Inverted", [] (L& s) {
+            s.at (L::velocity, L::center) = 4096;
+            s.at (L::velocity, L::multiply) = -8192;
+        });
+        make ("Other", "Random pan", [] (L& s) { s.at (L::pan, L::humanize) = 8192; });
+        make ("Other", "Detune (random fine pitch)", [] (L& s) { s.at (L::finePitch, L::humanize) = 300; });
+        make ("Other", "Short releases", [] (L& s) { s.at (L::release, L::offset) = -4096; });
+    }
+    return out;
+}
+
+std::optional<std::vector<std::uint8_t>> stateFromFlPreset (const std::vector<std::uint8_t>& bytes, Kind kind)
+{
+    try
+    {
+        const auto project = flp::parseProject (bytes, true);
+        if (project.channels.empty() || kindOfFlName (project.channels.front().pluginName) != kind)
+            return std::nullopt;
+        return project.channels.front().pluginState;
+    }
+    catch (const flp::Error&)
+    {
+        return std::nullopt;
+    }
+}
+
+// ---------------------------------------------------------------------------------------------------------------
+// VFX Script
+
+namespace
+{
+// the INI's lines (CRLF or LF) with their section
+template <typename F>
+void scriptLines (const std::string& text, F&& f)
+{
+    std::string section;
+    std::size_t at = 0;
+    while (at <= text.size())
+    {
+        auto end = text.find ('\n', at);
+        if (end == std::string::npos)
+            end = text.size();
+        auto from = at, to = end; // (the line without its BOM / CR)
+        if (to > from && text[to - 1] == '\r')
+            --to;
+        if (from == 0 && text.rfind ("\xEF\xBB\xBF", 0) == 0)
+            from = std::min<std::size_t> (3, to);
+        const auto line = text.substr (from, to - from);
+        if (line.size() >= 2 && line.front() == '[' && line.back() == ']')
+            section = line.substr (1, line.size() - 2);
+        else if (! f (section, line, from, to))
+            return;
+        if (end == text.size())
+            break;
+        at = end + 1;
+    }
+}
+} // namespace
+
+std::string ScriptSettings::source() const
+{
+    std::string out;
+    scriptLines (text, [&] (const std::string& section, const std::string& line, std::size_t, std::size_t) {
+        if (section != "Script" || line.rfind ("Source=", 0) != 0)
+            return true;
+        auto s = line.substr (7);
+        for (std::size_t k = 0; (k = s.find ("<linebreak>", k)) != std::string::npos;)
+            s.replace (k, 11, "\n");
+        out = s;
+        return false;
+    });
+    return out;
+}
+
+void ScriptSettings::setSource (const std::string& source)
+{
+    std::string flat;
+    for (std::size_t i = 0; i < source.size(); ++i)
+    {
+        if (source[i] == '\r')
+            continue;
+        if (source[i] == '\n')
+            flat += "<linebreak>";
+        else
+            flat += source[i];
+    }
+    bool done = false;
+    scriptLines (text, [&] (const std::string& section, const std::string& line, std::size_t from, std::size_t to) {
+        if (section != "Script" || line.rfind ("Source=", 0) != 0)
+            return true;
+        text.replace (from, to - from, "Source=" + flat);
+        done = true;
+        return false;
+    });
+    if (! done)
+        text = "\xEF\xBB\xBF[Script]\r\nSource=" + flat + "\r\n" + (text.rfind ("\xEF\xBB\xBF", 0) == 0 ? text.substr (3) : text);
+}
+
+std::vector<std::pair<std::string, std::string>> ScriptSettings::parameters() const
+{
+    std::vector<std::pair<std::string, std::string>> out;
+    scriptLines (text, [&] (const std::string& section, const std::string& line, std::size_t, std::size_t) {
+        if (section == "Parameters")
+            if (const auto eq = line.find ('='); eq != std::string::npos)
+                out.emplace_back (line.substr (0, eq), line.substr (eq + 1));
+        return true;
+    });
+    return out;
+}
+
+bool ScriptSettings::hasSurface() const { return text.find ("\r\n[Surface]") != std::string::npos || text.find ("\n[Surface]") != std::string::npos; }
+
+ScriptSettings defaultScript()
+{
+    ScriptSettings s;
+    s.text = "\xEF\xBB\xBF[Script]\r\nSource=import flvfx as vfx\r\n";
+    return s;
+}
+
+std::optional<ScriptSettings> parseScript (const std::vector<std::uint8_t>& fl)
+{
+    Reader r { fl.data(), fl.size() };
+    const auto n = r.u32();
+    if (r.failed || n != r.left())
+        return std::nullopt;
+    ScriptSettings s;
+    s.text.assign ((const char*) fl.data() + 4, n);
+    return s;
+}
+
+std::vector<std::uint8_t> writeScript (const ScriptSettings& s)
+{
+    std::vector<std::uint8_t> out;
+    put<std::uint32_t> (out, (std::uint32_t) s.text.size());
+    out.insert (out.end(), s.text.begin(), s.text.end());
+    return out;
+}
+
+// ---------------------------------------------------------------------------------------------------------------
+
+std::vector<std::uint8_t> defaultState (Kind kind)
+{
+    switch (kind)
+    {
+        case Kind::keyMapper: return writeKeyMapper (defaultKeyMapper());
+        case Kind::colorMapper: return writeColorMapper (defaultColorMapper());
+        case Kind::levelScaler: return writeLevelScaler (defaultLevelScaler());
+        case Kind::keyboardSplitter: return writeKeyboardSplitter (defaultKeyboardSplitter());
+        case Kind::envelope: return writeEnvelope (defaultEnvelope());
+        case Kind::sequencer: return writeSequencer (defaultSequencer());
+        case Kind::script: return writeScript (defaultScript());
+    }
+    return {};
+}
+
+int outputCount (Kind kind) noexcept
+{
+    return kind == Kind::colorMapper || kind == Kind::keyboardSplitter ? 16 : 1;
+}
+
+int outputsShown (Kind kind) noexcept
+{
+    return kind == Kind::colorMapper || kind == Kind::keyboardSplitter ? 4 : 1;
+}
+
+std::string outputName (Kind kind, int output)
+{
+    if (kind == Kind::colorMapper)
+        return "Voice " + std::to_string (output + 1);
+    if (kind == Kind::keyboardSplitter)
+        return "Zone " + std::to_string (output + 1);
+    return "Voice output";
+}
+
+std::optional<State> readState (const std::vector<std::uint8_t>& pluginState)
+{
+    Reader r { pluginState.data(), pluginState.size() };
+    if (r.u32() != lynxMagic)
+        return std::nullopt;
+    const auto kind = r.u32();
+    const auto port = r.i32();
+    r.u32(); // (reserved)
+    if (r.failed || kind >= (std::uint32_t) kindCount)
+        return std::nullopt;
+    State s;
+    s.kind = (Kind) kind;
+    s.port = std::clamp (port, 0, 255);
+    s.fl.assign (pluginState.begin() + (std::ptrdiff_t) r.pos, pluginState.end());
+    return s;
+}
+
+std::vector<std::uint8_t> writeState (const State& state)
+{
+    std::vector<std::uint8_t> out;
+    put<std::uint32_t> (out, lynxMagic);
+    put<std::uint32_t> (out, (std::uint32_t) state.kind);
+    put<std::int32_t> (out, state.port);
+    put<std::uint32_t> (out, 0);
+    out.insert (out.end(), state.fl.begin(), state.fl.end());
+    return out;
+}
+
+void makeChannel (ChannelDef& channel, Kind kind)
+{
+    channel.instrument = InstrumentKind::vfx;
+    channel.name = flName (kind);
+    State s;
+    s.kind = kind;
+    s.fl = defaultState (kind);
+    channel.pluginState = writeState (s);
+}
+
+std::optional<Kind> kindOf (const ChannelDef& channel)
+{
+    if (channel.instrument != InstrumentKind::vfx)
+        return std::nullopt;
+    if (auto s = readState (channel.pluginState))
+        return s->kind;
+    return std::nullopt;
+}
+
+// ---------------------------------------------------------------------------------------------------------------
+// Processors
+
+namespace
+{
+// What every processor keeps: the voices it sent out for each input voice, so an input's "off" ends exactly them
+// (even after the settings changed) and releaseAll ends everything.
+struct VoiceTable
+{
+    struct Entry
+    {
+        int input = -1;  // input id
+        int id = 0;      // output voice id
+        int output = 0;
+        Voice voice;
+        float slide = 0.0f; // Key Mapper's pitch slide: cents still to go (0 = none)
+    };
+    std::array<Entry, 512> entries {};
+    int count = 0;
+    int nextId = 1;
+
+    int add (int input, int output, const Voice& v) noexcept
+    {
+        if (count >= (int) entries.size())
+            return -1;
+        auto& e = entries[(std::size_t) count++];
+        e.input = input;
+        e.output = output;
+        e.voice = v;
+        e.slide = 0.0f;
+        e.id = nextId++;
+        if (nextId > 1 << 30)
+            nextId = 1;
+        return e.id;
+    }
+    // sends the "off" of every voice of `input` (all with input < 0)
+    void release (int input, int offset, float releaseVelocity, EventList& out) noexcept
+    {
+        int kept = 0;
+        for (int i = 0; i < count; ++i)
+        {
+            auto& e = entries[(std::size_t) i];
+            if (input >= 0 && e.input != input)
+            {
+                entries[(std::size_t) kept++] = e;
+                continue;
+            }
+            Event off;
+            off.type = Event::Type::off;
+            off.offset = offset;
+            off.output = e.output;
+            off.id = e.id;
+            off.voice = e.voice;
+            off.voice.release = releaseVelocity;
+            out.add (off);
+        }
+        count = kept;
+    }
+};
+
+Event onEvent (int offset, int output, int id, const Voice& v) noexcept
+{
+    Event e;
+    e.type = Event::Type::on;
+    e.offset = offset;
+    e.output = output;
+    e.id = id;
+    e.voice = v;
+    return e;
+}
+
+// A processor whose settings are FL's parsed state
+template <typename Settings>
+class Base : public Processor
+{
+public:
+    explicit Base (Settings initial) : settings (std::move (initial)) {}
+
+    void releaseAll (EventList& out) noexcept override { voices.release (-1, 0, 0.5f, out); }
+    bool busy() const noexcept override { return voices.count > 0; }
+
+protected:
+    const Settings& current() noexcept
+    {
+        settings.take();
+        return settings.get();
+    }
+    void publish (Settings s) { settings.publish (std::move (s)); }
+
+    VoiceTable voices;
+
+private:
+    Handoff<Settings> settings;
+};
+
+// Notes pass unchanged (a plugin whose behaviour LYNX does not reproduce yet keeps the notes flowing)
+class ThroughProcessor final : public Processor
+{
+public:
+    explicit ThroughProcessor (Kind k) : which (k) {}
+    Kind kind() const noexcept override { return which; }
+    void releaseAll (EventList& out) noexcept override { voices.release (-1, 0, 0.5f, out); }
+    void process (const Event* in, int count, int, const Transport&, EventList& out) noexcept override
+    {
+        for (int i = 0; i < count; ++i)
+        {
+            const auto& e = in[i];
+            if (e.type == Event::Type::on)
+            {
+                if (const auto id = voices.add (e.id, 0, e.voice); id >= 0)
+                    out.add (onEvent (e.offset, 0, id, e.voice));
+            }
+            else if (e.type == Event::Type::off)
+                voices.release (e.id, e.offset, e.voice.release, out);
+        }
+    }
+    bool configure (const std::vector<std::uint8_t>&) override { return true; }
+
+private:
+    Kind which;
+    VoiceTable voices;
+};
+
+class KeyMapper final : public Base<KeyMapperSettings>
+{
+public:
+    explicit KeyMapper (KeyMapperSettings s) : Base (std::move (s)) {}
+    Kind kind() const noexcept override { return Kind::keyMapper; }
+    bool configure (const std::vector<std::uint8_t>& fl) override
+    {
+        auto s = parseKeyMapper (fl);
+        if (! s)
+            return false;
+        publish (std::move (*s));
+        return true;
+    }
+
+    void process (const Event* in, int count, int n, const Transport& transport, EventList& out) noexcept override
+    {
+        const auto& s = current();
+        // the slides under way move on (FL: the voice's pitch covers 99 % of the way in `slide` / 192 beats)
+        if (s.slide > 0)
+        {
+            const auto beats = (double) n * transport.bpm / (60.0 * std::max (1.0, transport.sampleRate));
+            const auto keep = (float) std::pow (0.01, beats * 192.0 / (double) s.slide);
+            for (int i = 0; i < voices.count; ++i)
+                slideStep (voices.entries[(std::size_t) i], keep, out);
+        }
+        else
+            for (int i = 0; i < voices.count; ++i)
+                slideStep (voices.entries[(std::size_t) i], 0.0f, out);
+
+        for (int i = 0; i < count; ++i)
+        {
+            const auto& e = in[i];
+            if (e.type == Event::Type::off)
+            {
+                voices.release (e.id, e.offset, e.voice.release, out);
+                continue;
+            }
+            if (e.type != Event::Type::on)
+                continue;
+            if (! s.enabled)
+            {
+                send (e, e.voice, 0, out);
+                continue;
+            }
+            // FL: the row of the input's pitch class counted from the base key; its values are semitones from the start
+            // of that octave (on the base key); the offset transposes what comes out
+            const auto k = std::max (0, e.voice.key - s.baseKey + 12);
+            const auto rowIndex = k % 12;
+            const auto octaveStart = e.voice.key - rowIndex;
+            const auto& row = s.rows[(std::size_t) rowIndex];
+            const auto size = (int) row.size();
+            if (size == 0)
+                continue; // (the note is muted)
+            auto play = [&] (int value, float gain) {
+                auto v = e.voice;
+                v.key = octaveStart + value + s.offset;
+                if (v.key < 0 || v.key > 127)
+                    return;
+                v.velocity *= gain;
+                // with a pitch slide the new note starts at the played pitch and glides to its own
+                const auto slide = s.slide > 0 ? (float) (e.voice.key - v.key) * 100.0f : 0.0f;
+                send (e, v, slide, out);
+            };
+            switch (s.multimode)
+            {
+                case 1: // all, gain-compensated (1 / sqrt n)
+                    for (const auto value : row)
+                        play (value, 1.0f / std::sqrt ((float) size));
+                    break;
+                case 2: // one of them at random
+                    play (row[(std::size_t) (nextRandom() % (std::uint32_t) size)], 1.0f);
+                    break;
+                case 3: // the next one in the row's order (the first first)
+                {
+                    auto& c = cycle[(std::size_t) rowIndex];
+                    const auto at = ((c % size) + size) % size;
+                    c = at + 1;
+                    play (row[(std::size_t) at], 1.0f);
+                    break;
+                }
+                case 4: // backwards (the last first)
+                {
+                    auto& c = cycle[(std::size_t) rowIndex];
+                    c = (((c + size - 1) % size) + size) % size;
+                    play (row[(std::size_t) c], 1.0f);
+                    break;
+                }
+                default:
+                    for (const auto value : row)
+                        play (value, 1.0f);
+                    break;
+            }
+        }
+    }
+
+    void releaseAll (EventList& out) noexcept override
+    {
+        voices.release (-1, 0, 0.5f, out);
+        cycle.fill (0); // (FL: a flush starts the cycles again)
+    }
+
+private:
+    void send (const Event& input, Voice v, float slide, EventList& out) noexcept
+    {
+        const auto cents = v.cents;
+        v.cents += slide;
+        if (const auto id = voices.add (input.id, 0, v); id >= 0)
+        {
+            out.add (onEvent (input.offset, 0, id, v));
+            auto& entry = voices.entries[(std::size_t) voices.count - 1];
+            entry.slide = slide;
+            entry.voice.cents = cents;
+        }
+    }
+    // one block of a voice's slide: `keep` of the way left stays (a prop event with its pitch)
+    static void slideStep (VoiceTable::Entry& e, float keep, EventList& out) noexcept
+    {
+        if (e.slide == 0.0f)
+            return;
+        e.slide *= keep;
+        if (std::abs (e.slide) < 0.5f)
+            e.slide = 0.0f;
+        Event p;
+        p.type = Event::Type::prop;
+        p.output = e.output;
+        p.id = e.id;
+        p.voice = e.voice;
+        p.prop = Prop::pitch;
+        p.value = e.voice.cents + e.slide;
+        out.add (p);
+    }
+    std::uint32_t nextRandom() noexcept
+    {
+        seed ^= seed << 13;
+        seed ^= seed >> 17;
+        seed ^= seed << 5;
+        return seed;
+    }
+    std::array<int, 12> cycle {};
+    std::uint32_t seed = 0x9e3779b9u;
+};
+
+class ColorMapper final : public Base<ColorMapperSettings>
+{
+public:
+    explicit ColorMapper (ColorMapperSettings s) : Base (std::move (s)) {}
+    Kind kind() const noexcept override { return Kind::colorMapper; }
+    bool configure (const std::vector<std::uint8_t>& fl) override
+    {
+        auto s = parseColorMapper (fl);
+        if (! s)
+            return false;
+        publish (*s);
+        return true;
+    }
+    void process (const Event* in, int count, int, const Transport&, EventList& out) noexcept override
+    {
+        const auto& s = current();
+        for (int i = 0; i < count; ++i)
+        {
+            const auto& e = in[i];
+            if (e.type == Event::Type::off)
+            {
+                voices.release (e.id, e.offset, e.voice.release, out);
+                continue;
+            }
+            if (e.type != Event::Type::on)
+                continue;
+            const auto c = e.voice.colour & 15;
+            auto v = e.voice;
+            v.colour = s.colour[(std::size_t) c];
+            const auto port = s.port[(std::size_t) c];
+            if (const auto id = voices.add (e.id, port, v); id >= 0)
+                out.add (onEvent (e.offset, port, id, v));
+        }
+    }
+};
+} // namespace
+
+namespace
+{
+// One voice in, one voice out, its velocity, fine pitch, pan, Mod X / Y and release velocity through the curves.
+// (FL re-evaluates the curves every tick from the parent's live levels; LYNX applies them when the note starts and
+// to its release velocity when it ends: the voices' levels do not change on their way here.)
+class LevelScaler final : public Base<LevelScalerSettings>
+{
+public:
+    explicit LevelScaler (LevelScalerSettings s) : Base (std::move (s)) {}
+    Kind kind() const noexcept override { return Kind::levelScaler; }
+    bool configure (const std::vector<std::uint8_t>& fl) override
+    {
+        auto s = parseLevelScaler (fl);
+        if (! s)
+            return false;
+        publish (std::move (*s));
+        return true;
+    }
+    void process (const Event* in, int count, int, const Transport&, EventList& out) noexcept override
+    {
+        using L = LevelScalerSettings;
+        const auto& s = current();
+        for (int i = 0; i < count; ++i)
+        {
+            const auto& e = in[i];
+            if (e.type == Event::Type::on)
+            {
+                auto v = e.voice;
+                // (FL's order: pan, Mod X, Mod Y, fine pitch, velocity; each with its own random, fixed for the note)
+                v.pan = (float) levelScale (s, L::pan, v.pan, -1.0, 1.0, random());
+                v.modX = (float) (levelScale (s, L::modX, v.modX * 2.0 - 1.0, -1.0, 1.0, random()) * 0.5 + 0.5);
+                v.modY = (float) (levelScale (s, L::modY, v.modY * 2.0 - 1.0, -1.0, 1.0, random()) * 0.5 + 0.5);
+                v.cents = (float) (levelScale (s, L::finePitch, v.cents / 1200.0, -1.0, 1.0, random()) * 1200.0);
+                v.velocity = (float) levelScale (s, L::velocity, v.velocity, 0.0, 1.0, random());
+                if (const auto id = voices.add (e.id, 0, v); id >= 0)
+                    out.add (onEvent (e.offset, 0, id, v));
+            }
+            else if (e.type == Event::Type::off)
+                voices.release (e.id, e.offset, (float) levelScale (s, L::release, e.voice.release, 0.0, 1.0, random()), out);
+        }
+    }
+
+private:
+    double random() noexcept
+    {
+        seed ^= seed << 13;
+        seed ^= seed >> 17;
+        seed ^= seed << 5;
+        return (double) (seed >> 8) / 16777216.0;
+    }
+    std::uint32_t seed = 0x2545f491u;
+};
+} // namespace
+
+namespace
+{
+// Each note on every zone whose keyboard × velocity level is above zero, on that zone's output (FL: the level
+// scales the note's volume, or replaces it with Absolute; Random zones play one of them, picked by their keyboard
+// level). LYNX works in velocities: vol = (11^(1.28 v) − 1) / 10 both ways.
+class KeyboardSplitter final : public Base<KeyboardSplitterSettings>
+{
+public:
+    explicit KeyboardSplitter (KeyboardSplitterSettings s) : Base (std::move (s)) {}
+    Kind kind() const noexcept override { return Kind::keyboardSplitter; }
+    bool configure (const std::vector<std::uint8_t>& fl) override
+    {
+        auto s = parseKeyboardSplitter (fl);
+        if (! s)
+            return false;
+        publish (std::move (*s));
+        return true;
+    }
+    void process (const Event* in, int count, int, const Transport&, EventList& out) noexcept override
+    {
+        const auto& s = current();
+        for (int i = 0; i < count; ++i)
+        {
+            const auto& e = in[i];
+            if (e.type == Event::Type::off)
+            {
+                voices.release (e.id, e.offset, e.voice.release, out);
+                continue;
+            }
+            if (e.type != Event::Type::on)
+                continue;
+            const auto x = ((double) e.voice.key + e.voice.cents / 100.0) / 132.0;
+            const auto velocity = std::min (1.0, (double) e.voice.velocity);
+            std::array<double, 16> w {};
+            bool anyRandom = false;
+            for (int z = 0; z < 16; ++z)
+            {
+                const auto& zone = s.zones[(std::size_t) z];
+                if (! zone.active())
+                    continue;
+                w[(std::size_t) z] = splitterGain (zone.keyboard.at (x));
+                anyRandom = anyRandom || zone.random;
+            }
+            if (anyRandom) // one weighted pick among the random zones, which then plays at full level
+            {
+                double total = 0.0;
+                for (int z = 0; z < 16; ++z)
+                    if (s.zones[(std::size_t) z].random && s.zones[(std::size_t) z].active())
+                        total += w[(std::size_t) z];
+                const auto r = random() * total;
+                int chosen = -1;
+                double acc = 0.0;
+                for (int z = 0; z < 16; ++z)
+                    if (s.zones[(std::size_t) z].random && s.zones[(std::size_t) z].active() && w[(std::size_t) z] > 0.0)
+                    {
+                        if (acc <= r)
+                            chosen = z;
+                        acc += w[(std::size_t) z];
+                        w[(std::size_t) z] = 0.0;
+                    }
+                if (chosen >= 0) // (FL then falls back on zone 1; LYNX plays no random zone)
+                    w[(std::size_t) chosen] = 1.0;
+            }
+            const auto volumeIn = velocityToVolume (velocity);
+            for (int z = 0; z < 16; ++z)
+            {
+                const auto& zone = s.zones[(std::size_t) z];
+                if (w[(std::size_t) z] <= 0.0)
+                    continue;
+                const auto level = w[(std::size_t) z] * splitterGain (zone.velocity.at (velocity));
+                if (level <= 1e-5)
+                    continue;
+                auto v = e.voice;
+                v.velocity = (float) volumeToVelocity (zone.absolute ? level : volumeIn * level);
+                v.key = e.voice.key + zone.transpose;
+                if (v.key < 0 || v.key > 127)
+                    continue;
+                if (const auto id = voices.add (e.id, z, v); id >= 0)
+                    out.add (onEvent (e.offset, z, id, v));
+            }
+        }
+    }
+
+private:
+    static double velocityToVolume (double v) noexcept { return (std::pow (11.0, 1.28 * v) - 1.0) / 10.0; }
+    static double volumeToVelocity (double vol) noexcept { return std::clamp (std::log (10.0 * vol + 1.0) / std::log (11.0) / 1.28, 0.0, 1.0); }
+    double random() noexcept
+    {
+        seed ^= seed << 13;
+        seed ^= seed >> 17;
+        seed ^= seed << 5;
+        return (double) (seed >> 8) / 16777216.0;
+    }
+    std::uint32_t seed = 0x12bd6aau;
+};
+} // namespace
+
+namespace
+{
+// An FL curve as the Envelope Controller's (core/FlSynths.h): accumulated points, LYNX's tension sign on the segment
+// starting at a point, a hold as a step
+void toArticulator (const MapCurve& m, ControllerArticulator& a)
+{
+    a.count = 0;
+    a.sustain = -1;
+    a.decayPoint = -1;
+    const auto sustain = m.footer[4], decay = m.footer[2];
+    for (std::size_t i = 0; i < m.points.size() && a.count < (int) a.time.size(); ++i)
+    {
+        const auto& p = m.points[i];
+        if (i > 0)
+        {
+            if (p.curve == 2 && p.x > m.points[i - 1].x && a.count + 1 < (int) a.time.size())
+            {
+                a.time[(std::size_t) a.count] = (float) p.x;
+                a.level[(std::size_t) a.count] = a.level[(std::size_t) a.count - 1];
+                a.tension[(std::size_t) a.count] = 0.0f;
+                ++a.count;
+            }
+            else if (p.curve <= 1)
+                a.tension[(std::size_t) a.count - 1] = std::clamp (-p.tension, -1.0f, 1.0f);
+        }
+        if ((int) i == sustain)
+            a.sustain = a.count;
+        if ((int) i == decay)
+            a.decayPoint = a.count;
+        a.time[(std::size_t) a.count] = (float) p.x;
+        a.level[(std::size_t) a.count] = (float) std::clamp (p.y, 0.0, 1.0);
+        a.tension[(std::size_t) a.count] = 0.0f;
+        ++a.count;
+    }
+}
+
+// What the audio thread evaluates: per articulator and target the envelope, the LFO amplitude and the LFO wave
+struct EnvelopeRuntime
+{
+    struct Part
+    {
+        bool envOn = false, lfoOn = false, envTempo = false, lfoTempo = false;
+        float base = 0.5f, env = 0.0f, lfo = 0.0f, offset = 0.5f;
+        ControllerArticulator envelope, amplitude, wave; // (levels 0…1 with base 0: their curves' values)
+        double rate = 1.0, startPhase = 0.0;            // LFO: cycles per unit, phase at the trigger
+    };
+    struct Articulator
+    {
+        int colour = 0, low = 0, high = 132;
+        std::array<Part, 5> parts;
+    };
+    bool enabled = true;
+    std::array<Articulator, 16> articulators;
+
+    // (big: on the heap, never on a stack)
+    static std::unique_ptr<EnvelopeRuntime> from (const EnvelopeSettings& s)
+    {
+        auto made = std::make_unique<EnvelopeRuntime>();
+        auto& rt = *made;
+        rt.enabled = s.enabled;
+        for (int g = 0; g < 16; ++g)
+        {
+            const auto& a = s.articulators[(std::size_t) g];
+            auto& r = rt.articulators[(std::size_t) g];
+            r.colour = a.colour;
+            r.low = a.low;
+            r.high = a.high;
+            for (int t = 0; t < 5; ++t)
+            {
+                const auto& p = a.parts[(std::size_t) t];
+                auto& q = r.parts[(std::size_t) t];
+                q.envOn = p.envOn() && ! p.envelope.points.empty();
+                q.lfoOn = p.lfoOn();
+                q.envTempo = (p.envelope.footer[0] & 1) != 0;
+                q.lfoTempo = (p.lfoAmp.footer[0] & 1) != 0;
+                q.base = p.base;
+                q.env = p.env;
+                q.lfo = p.lfo;
+                q.offset = t == EnvelopeSettings::velocity ? 0.0f : 0.5f;
+                toArticulator (p.envelope, q.envelope);
+                q.envelope.adsr = p.adsr;
+                q.envelope = controllerWithKnobs (q.envelope);
+                for (auto* c : { &q.envelope, &q.amplitude })
+                {
+                    c->base = 0.0f;
+                    c->envLevel = 1.0f;
+                    c->bipolar = false;
+                    c->envOn = true;
+                }
+                toArticulator (p.lfoAmp, q.amplitude);
+                q.wave.lfoSpeed = p.speed;
+                q.wave.lfoTension = p.tension;
+                q.wave.lfoSkew = p.skew;
+                q.wave.lfoPulseWidth = p.pulseWidth;
+                q.wave.lfoPhase = p.phase;
+                q.rate = controllerLfoRate (q.wave);
+                q.startPhase = controllerLfoStartPhase (q.wave);
+            }
+        }
+        return made;
+    }
+};
+
+// One note in, the same note out, its volume, fine pitch, pan and Mod X / Y moved by the envelopes and LFOs of every
+// articulator whose note colour and key range it matches (FL re-applies them each tick; LYNX each block).
+class Envelope final : public Processor
+{
+public:
+    explicit Envelope (const EnvelopeSettings& s) : settings (EnvelopeRuntime::from (s)) {}
+    Kind kind() const noexcept override { return Kind::envelope; }
+    bool configure (const std::vector<std::uint8_t>& fl) override
+    {
+        auto s = parseEnvelope (fl);
+        if (! s)
+            return false;
+        settings.publish (EnvelopeRuntime::from (*s));
+        return true;
+    }
+    bool busy() const noexcept override { return count > 0; }
+
+    void releaseAll (EventList& out) noexcept override
+    {
+        for (int i = 0; i < count; ++i)
+            if (! voices[(std::size_t) i].released)
+                out.add (offEvent (voices[(std::size_t) i], 0));
+        count = 0;
+    }
+
+    void process (const Event* in, int n, int samples, const Transport& transport, EventList& out) noexcept override
+    {
+        settings.take();
+        const auto& rt = settings.get();
+        const auto seconds = samples / std::max (1.0, transport.sampleRate);
+        const auto beats = seconds * transport.bpm / 60.0;
+        // the voices sounding move on (and send what changed)
+        for (int i = 0; i < count; ++i)
+        {
+            auto& v = voices[(std::size_t) i];
+            v.seconds += seconds;
+            v.beats += beats;
+            if (v.released)
+            {
+                v.releaseSeconds += seconds;
+                v.releaseBeats += beats;
+            }
+            apply (rt, v, 0, &out);
+        }
+        // the finished ones go (their output was released and their envelopes have ended, or 30 s after the release)
+        int kept = 0;
+        for (int i = 0; i < count; ++i)
+        {
+            const auto& v = voices[(std::size_t) i];
+            if (v.released && (v.releaseSeconds > 30.0 || finished (rt, v)))
+                continue;
+            voices[(std::size_t) kept++] = v;
+        }
+        count = kept;
+
+        for (int i = 0; i < n; ++i)
+        {
+            const auto& e = in[i];
+            if (e.type == Event::Type::on)
+            {
+                Voice v;
+                v.input = e.id;
+                v.id = nextId++;
+                if (nextId > 1 << 30)
+                    nextId = 1;
+                v.source = e.voice;
+                v.sent = e.voice;
+                for (int g = 0; g < 16; ++g)
+                {
+                    const auto& a = rt.articulators[(std::size_t) g];
+                    const auto key = e.voice.key + 1;
+                    if (a.colour == e.voice.colour && key >= a.low && key <= a.high)
+                        v.matched |= (std::uint16_t) (1u << g);
+                }
+                Voice playing = v;
+                apply (rt, playing, e.offset, nullptr);
+                out.add (onEvent (e.offset, 0, playing.id, playing.sent));
+                if (count < (int) voices.size())
+                    voices[(std::size_t) count++] = playing;
+            }
+            else if (e.type == Event::Type::off)
+                for (int k = 0; k < count; ++k)
+                {
+                    auto& v = voices[(std::size_t) k];
+                    if (v.input == e.id && ! v.released)
+                    {
+                        v.released = true;
+                        v.source.release = e.voice.release;
+                        out.add (offEvent (v, e.offset));
+                    }
+                }
+        }
+    }
+
+private:
+    struct Voice
+    {
+        int input = -1, id = 0;
+        Voice() = default;
+        vfx::Voice source, sent;
+        std::uint16_t matched = 0;
+        bool released = false;
+        double seconds = 0.0, beats = 0.0, releaseSeconds = 0.0, releaseBeats = 0.0;
+    };
+
+    static Event offEvent (const Voice& v, int offset) noexcept
+    {
+        Event e;
+        e.type = Event::Type::off;
+        e.offset = offset;
+        e.id = v.id;
+        e.voice = v.sent;
+        e.voice.release = v.source.release;
+        return e;
+    }
+
+    // the voice's levels now (FL's per-voice apply); with `out`, prop events for what changed
+    static void apply (const EnvelopeRuntime& rt, Voice& v, int offset, EventList* out) noexcept
+    {
+        auto now = v.source;
+        if (rt.enabled && v.matched != 0)
+        {
+            const auto sourceVolume = (std::pow (11.0, 1.28 * (double) v.source.velocity) - 1.0) / 10.0;
+            auto volume = sourceVolume;
+            double cents = v.source.cents, pan = v.source.pan, modX = v.source.modX * 2.0 - 1.0, modY = v.source.modY * 2.0 - 1.0;
+            for (int g = 15; g >= 0; --g) // (FL: the last articulator first)
+            {
+                if ((v.matched & (1u << g)) == 0)
+                    continue;
+                for (int t = 4; t >= 0; --t)
+                {
+                    const auto& p = rt.articulators[(std::size_t) g].parts[(std::size_t) t];
+                    if (! p.envOn && ! p.lfoOn)
+                        continue;
+                    const auto envTime = p.envTempo ? v.beats : v.seconds;
+                    const auto envRelease = ! v.released ? -1.0 : p.envTempo ? v.releaseBeats : v.releaseSeconds;
+                    const auto e = p.envOn ? controllerValue (p.envelope, envTime, envRelease) - p.offset : 0.0f;
+                    double l = 0.0;
+                    if (p.lfoOn)
+                    {
+                        const auto lfoTime = p.lfoTempo ? v.beats : v.seconds;
+                        const auto lfoRelease = ! v.released ? -1.0 : p.lfoTempo ? v.releaseBeats : v.releaseSeconds;
+                        const auto amp = controllerValue (p.amplitude, lfoTime, lfoRelease) - 0.5;
+                        l = amp * controllerLfoWave (p.wave, p.startPhase + p.rate * lfoTime);
+                    }
+                    if (t == EnvelopeSettings::velocity)
+                    {
+                        double m = p.base;
+                        if (p.envOn)
+                            m = p.env >= 0.0f ? p.base + 2.0 * p.env * e : (1.0 - p.base) + 2.0 * std::abs (p.env) * (1.0 - e);
+                        if (p.lfoOn)
+                            m *= 2.0 * p.lfo * l;
+                        volume = std::clamp (volume * m, 0.0, 4.0);
+                        continue;
+                    }
+                    auto d = (double) p.base - 0.5;
+                    if (p.envOn)
+                        d += 2.0 * p.env * e;
+                    if (p.lfoOn)
+                        d += 2.0 * p.lfo * l;
+                    if (t == EnvelopeSettings::pitch)
+                        cents += d * 4800.0;
+                    else if (t == EnvelopeSettings::pan)
+                        pan = std::clamp (pan + d, -1.0, 1.0);
+                    else if (t == EnvelopeSettings::modX)
+                        modX = std::clamp (modX + d, -2.0, 2.0);
+                    else
+                        modY = std::clamp (modY + d, -2.0, 2.0);
+                }
+            }
+            if (volume != sourceVolume)
+                now.velocity = (float) std::clamp (std::log (10.0 * volume + 1.0) / std::log (11.0) / 1.28, 0.0, 1.0);
+            now.cents = (float) std::clamp (cents, -v.source.key * 100.0, 12000.0 - v.source.key * 100.0); // (FL: Init.Pitch 0…12000)
+            now.pan = (float) pan;
+            now.modX = (float) std::clamp (modX * 0.5 + 0.5, 0.0, 1.0);
+            now.modY = (float) std::clamp (modY * 0.5 + 0.5, 0.0, 1.0);
+        }
+        if (out != nullptr)
+        {
+            auto send = [&] (Prop prop, float before, float after) {
+                if (std::abs (after - before) < 1e-4f)
+                    return;
+                Event p;
+                p.type = Event::Type::prop;
+                p.offset = offset;
+                p.id = v.id;
+                p.voice = v.sent;
+                p.prop = prop;
+                p.value = after;
+                out->add (p);
+            };
+            send (Prop::velocity, v.sent.velocity, now.velocity);
+            send (Prop::pitch, v.sent.cents, now.cents);
+            send (Prop::pan, v.sent.pan, now.pan);
+            send (Prop::modX, v.sent.modX, now.modX);
+            send (Prop::modY, v.sent.modY, now.modY);
+        }
+        now.key = v.source.key;
+        v.sent = now;
+    }
+
+    static bool finished (const EnvelopeRuntime& rt, const Voice& v) noexcept
+    {
+        if (! rt.enabled || v.matched == 0)
+            return true;
+        for (int g = 0; g < 16; ++g)
+            if ((v.matched & (1u << g)) != 0)
+                for (const auto& p : rt.articulators[(std::size_t) g].parts)
+                {
+                    if (p.envOn && ! controllerVoiceFinished (p.envelope, p.envTempo ? v.beats : v.seconds, p.envTempo ? v.releaseBeats : v.releaseSeconds))
+                        return false;
+                    if (p.lfoOn && ! controllerVoiceFinished (p.amplitude, p.lfoTempo ? v.beats : v.seconds, p.lfoTempo ? v.releaseBeats : v.releaseSeconds))
+                        return false;
+                }
+        return true;
+    }
+
+    Handoff<EnvelopeRuntime> settings;
+    std::array<Voice, 256> voices {};
+    int count = 0, nextId = 1;
+};
+} // namespace
+
+std::unique_ptr<Processor> makeProcessor (Kind kind, const std::vector<std::uint8_t>& fl)
+{
+    switch (kind)
+    {
+        case Kind::keyMapper:
+            return std::make_unique<KeyMapper> (parseKeyMapper (fl).value_or (defaultKeyMapper()));
+        case Kind::colorMapper:
+            return std::make_unique<ColorMapper> (parseColorMapper (fl).value_or (defaultColorMapper()));
+        case Kind::levelScaler:
+            return std::make_unique<LevelScaler> (parseLevelScaler (fl).value_or (defaultLevelScaler()));
+        case Kind::keyboardSplitter:
+            return std::make_unique<KeyboardSplitter> (parseKeyboardSplitter (fl).value_or (defaultKeyboardSplitter()));
+        case Kind::envelope:
+            return std::make_unique<Envelope> (parseEnvelope (fl).value_or (defaultEnvelope()));
+        case Kind::sequencer: return makeSequencer (fl);
+        default: break;
+    }
+    return std::make_unique<ThroughProcessor> (kind);
+}
+} // namespace lynx::vfx

+ 378 - 0
src/core/Vfx.h

@@ -0,0 +1,378 @@
+#pragma once
+
+// FL Studio's VFX plugins (round 164b, docs/analise/REA_rodada164b.md): note-level processors that sit between the
+// notes of a Patcher ("From LYNX" events) or of a channel and the instruments they play. Each one takes voices
+// (note on / off with FL's voice properties: velocity, pan, fine pitch, Mod X / Y, release, note colour) and sends
+// voices out on one or more outputs, possibly changing them over time (VFX Envelope) or making new ones on the
+// beat (VFX Sequencer).
+//
+// LYNX keeps each plugin's settings in FL's own state format (the .fst / .flp 0xD5 record), so FL's presets and
+// projects load as they are; ChannelDef::pluginState holds a small LYNX header (kind, channel output port) and then
+// that state. Behaviour rebuilt from FL's plugins (REA, clean-room: our own code).
+
+#include <array>
+#include <cstdint>
+#include <memory>
+#include <optional>
+#include <string>
+#include <string_view>
+#include <vector>
+
+namespace lynx
+{
+struct ChannelDef;
+
+namespace vfx
+{
+enum class Kind : std::uint8_t
+{
+    keyMapper,
+    colorMapper,
+    envelope,
+    keyboardSplitter,
+    levelScaler,
+    sequencer,
+    script
+};
+constexpr int kindCount = 7;
+constexpr std::array<Kind, kindCount> allKinds { Kind::colorMapper, Kind::envelope,    Kind::keyMapper, Kind::keyboardSplitter,
+                                                 Kind::levelScaler, Kind::script, Kind::sequencer };
+
+// FL's plugin name ("VFX Key Mapper"), which LYNX shows too
+const char* flName (Kind kind) noexcept;
+std::optional<Kind> kindOfFlName (std::string_view name) noexcept;
+
+// ---------------------------------------------------------------------------------------------------------------
+// Voices and events
+
+// FL's voice properties (the note's own, as the Piano roll / the channel give them)
+struct Voice
+{
+    int key = 60;            // 0…127 (MIDI; 60 = C4, FL's C5)
+    float velocity = 100.0f / 128.0f; // 0..1
+    float pan = 0.0f;        // −1..1
+    float cents = 0.0f;      // fine pitch, cents
+    float modX = 0.5f, modY = 0.5f; // 0..1, 0.5 = none
+    float release = 0.5f;    // release velocity 0..1
+    int colour = 0;          // note colour group 0…15 (= MIDI channel)
+    bool porta = false;
+};
+
+// A voice property a processor changes while the voice sounds (VFX Envelope)
+enum class Prop : std::uint8_t
+{
+    velocity, // 0..1 (the voice's volume)
+    pitch,    // cents from the voice's own key
+    pan,      // −1..1
+    modX,     // 0..1
+    modY      // 0..1
+};
+
+struct Event
+{
+    enum class Type : std::uint8_t { on, off, prop };
+    Type type = Type::on;
+    int offset = 0; // sample within the block
+    int output = 0; // output port 0… (inputs: 0)
+    int id = 0;     // voice id: an off / prop names the on it belongs to (inputs: the host's key + colour)
+    Voice voice;    // on: the whole voice; off / prop: key and colour
+    Prop prop = Prop::velocity;
+    float value = 0.0f;
+};
+
+// The id of a host voice (an input event's id): its key and colour
+int inputId (int key, int colour) noexcept;
+
+// Fixed-capacity event list (never allocates on the audio thread; extra events are dropped)
+class EventList
+{
+public:
+    static constexpr int capacity = 1024;
+    void clear() noexcept { count = 0; }
+    void add (const Event& e) noexcept
+    {
+        if (count < capacity)
+            events[(std::size_t) count++] = e;
+    }
+    int size() const noexcept { return count; }
+    Event& operator[] (int i) noexcept { return events[(std::size_t) i]; }
+    const Event& operator[] (int i) const noexcept { return events[(std::size_t) i]; }
+    void sortByOffset() noexcept; // stable
+    void removeFirst (int n) noexcept;
+
+private:
+    std::array<Event, capacity> events {};
+    int count = 0;
+};
+
+struct Transport
+{
+    double sampleRate = 44100.0;
+    double bpm = 140.0;
+    double ticks = 0.0; // song position (LYNX ticks, 960 per quarter) at the block's start
+    bool playing = false;
+};
+
+// ---------------------------------------------------------------------------------------------------------------
+// Settings (FL's state, parsed)
+
+struct KeyMapperSettings
+{
+    int version = 2;
+    bool enabled = true;
+    int baseKey = 0;     // labels only (0 = C)
+    int offset = 0;      // transposition of the input, −12…12
+    int multimode = 0;   // 0 all, 1 all (gain-compensated), 2 random, 3 cycle up, 4 cycle down
+    int slide = 0;       // pitch slide steps (0 = none)
+    // [input pitch class] output notes, relative to the input octave's C (row i → i = no change)
+    std::array<std::vector<int>, 12> rows;
+    std::vector<std::uint8_t> extra; // fields of newer versions LYNX keeps as they are
+    bool operator== (const KeyMapperSettings&) const = default;
+};
+KeyMapperSettings defaultKeyMapper();
+std::optional<KeyMapperSettings> parseKeyMapper (const std::vector<std::uint8_t>& fl);
+std::vector<std::uint8_t> writeKeyMapper (const KeyMapperSettings& s);
+
+struct ColorMapperSettings
+{
+    std::uint32_t header = 0;
+    std::array<int, 16> port {};   // [note colour] the voice output 0…15 it goes to
+    std::array<int, 16> colour {}; // [note colour] the colour it leaves with
+    bool operator== (const ColorMapperSettings&) const = default;
+};
+ColorMapperSettings defaultColorMapper();
+std::optional<ColorMapperSettings> parseColorMapper (const std::vector<std::uint8_t>& fl);
+std::vector<std::uint8_t> writeColorMapper (const ColorMapperSettings& s);
+
+// VFX Level Scaler: per voice property (tab) a transfer curve: Center, Multiply, Offset, Tension, Humanize (+ mode)
+struct LevelScalerSettings
+{
+    enum Tab { velocity, release, finePitch, pan, modX, modY, tabCount };
+    enum Field { center, multiply, offset, tension, humanize, humanizeMode, fieldCount };
+    std::uint32_t version = 1;
+    int selectedTab = 0;                 // (the editor's)
+    std::array<std::int32_t, 36> p {};   // p[6 · tab + field], FL's units (Center 0…8192, Multiply ±16384 = ×±2, …)
+    int& at (int tab, int field) noexcept { return p[(std::size_t) (tab * 6 + field)]; }
+    int at (int tab, int field) const noexcept { return p[(std::size_t) (tab * 6 + field)]; }
+    bool identity (int tab) const noexcept; // (passes the value untouched)
+    bool operator== (const LevelScalerSettings&) const = default;
+};
+LevelScalerSettings defaultLevelScaler();
+void resetLevelScalerTab (LevelScalerSettings& s, int tab);
+std::optional<LevelScalerSettings> parseLevelScaler (const std::vector<std::uint8_t>& fl);
+std::vector<std::uint8_t> writeLevelScaler (const LevelScalerSettings& s);
+// The curve: x in lo…hi → out in lo…hi; `random` 0…1 places it in the humanize range (FL's T(tab, x, lo, hi, rnd))
+double levelScale (const LevelScalerSettings& s, int tab, double x, double lo, double hi, double random) noexcept;
+
+// FL's mapping curve (TMMap): points at x 0…1 with a level 0…1; a point's tension bends the segment that ends at it,
+// curve type 2 holds the previous level up to it (a step). Kept as FL stores them, so the file writes back as read.
+struct MapCurve
+{
+    struct Point
+    {
+        double x = 0.0, y = 0.0; // x absolute (FL stores the distance from the previous point)
+        float tension = 0.0f;
+        std::uint8_t curve = 0, b13 = 0, b14 = 0, b15 = 2;
+        bool operator== (const Point&) const = default;
+    };
+    std::vector<Point> points;
+    std::array<std::int32_t, 5> footer { 0, -1, -1, -1, -1 };
+    bool operator== (const MapCurve&) const = default;
+    static MapCurve flat (double level);
+    double at (double x) const noexcept;       // the level at x (the ends hold outside)
+    bool isFlat (double level) const noexcept; // every point at that level
+};
+
+// VFX Keyboard Splitter: 16 zones, each a keyboard map (x = key / 132) and a velocity map; a note plays on every
+// zone whose level is above zero, on that zone's output
+struct KeyboardSplitterSettings
+{
+    struct Zone
+    {
+        MapCurve keyboard = MapCurve::flat (0.0), velocity = MapCurve::flat (1.0);
+        int transpose = 0; // semitones −48…48
+        bool absolute = false, random = false;
+        std::string name;  // empty: "Zone N"
+        bool operator== (const Zone&) const = default;
+        bool active() const noexcept { return ! (keyboard.isFlat (0.0) && velocity.isFlat (1.0)); }
+    };
+    std::uint32_t header = 0x100003;
+    int page = 0; // (the editor's: 0 keyboard, 1 velocity)
+    std::array<Zone, 16> zones;
+    bool operator== (const KeyboardSplitterSettings&) const = default;
+};
+KeyboardSplitterSettings defaultKeyboardSplitter();
+std::optional<KeyboardSplitterSettings> parseKeyboardSplitter (const std::vector<std::uint8_t>& fl);
+std::vector<std::uint8_t> writeKeyboardSplitter (const KeyboardSplitterSettings& s);
+// FL's map level → volume gain: (11^m − 1) / 10; volume ↔ velocity: vol = (11^(1.28 v) − 1) / 10
+double splitterGain (double mapLevel) noexcept;
+
+// VFX Envelope: 16 articulators, each for one note colour and key range, with five targets (velocity, pitch, pan,
+// Mod X, Mod Y), each an envelope and an LFO as in FL's Envelope Controller
+struct EnvelopeSettings
+{
+    enum Target { velocity, pitch, pan, modX, modY, targetCount };
+    struct Part
+    {
+        int version = 3;
+        float base = 0.5f, env = 1.0f, lfo = 1.0f;   // base 0…1, amounts −1…1
+        MapCurve envelope;                          // footer: flags (bit 0 tempo), enabled, decay, loop, sustain
+        std::array<std::int32_t, 4> adsr { 128, 128, 0, 128 };
+        MapCurve lfoAmp;                            // the LFO's amplitude over time (footer as above)
+        std::int32_t speed = 40898, tension = 0, skew = 0, pulseWidth = 0, phase = 0;
+        bool envOn() const noexcept { return envelope.footer[1] != 0; }
+        bool lfoOn() const noexcept { return lfoAmp.footer[1] != 0; }
+        bool operator== (const Part&) const = default;
+    };
+    struct Articulator
+    {
+        int colour = 0, low = 0, high = 132; // key range: note + 1 (FL)
+        std::array<Part, targetCount> parts;
+        bool operator== (const Articulator&) const = default;
+    };
+    std::uint32_t header = 0x10003;
+    bool enabled = true;
+    int shownArticulator = 0, shownTarget = 0, shownPart = 0; // (the editor's)
+    std::array<std::int32_t, 4> toggles {};
+    std::array<Articulator, 16> articulators;
+    bool operator== (const EnvelopeSettings&) const = default;
+};
+EnvelopeSettings defaultEnvelope();
+std::optional<EnvelopeSettings> parseEnvelope (const std::vector<std::uint8_t>& fl);
+std::vector<std::uint8_t> writeEnvelope (const EnvelopeSettings& s);
+
+// VFX Sequencer (FL's port of BlueARP): a bank of 128 step programs (six lanes of 64 steps each) and the
+// parameters that turn held notes into arpeggios / sequences. Kept as FL stores it, so a bank writes back as read.
+struct SequencerSettings
+{
+    enum Lane { scaleStep, octave, stepType, keySelect, velocity, gateStep, laneCount };
+    enum StepType { off, normal, rest, tie, chord, random };
+    struct Program
+    {
+        std::vector<std::int8_t> params;                         // FL param 39 + i (prgp), 42 or 43 bytes
+        std::array<std::uint8_t, 48> name {};                    // NUL-padded Latin-1
+        std::array<std::array<std::int8_t, 64>, laneCount> lanes {};
+        std::vector<std::vector<std::uint8_t>> extra;            // unknown chunks (tag, size, data) kept as they are
+        std::string nameText() const;
+        void setName (const std::string& n);
+        bool operator== (const Program&) const = default;
+    };
+    struct Chain
+    {
+        std::vector<std::uint8_t> head { 0, 0xff, 0xff, 0xff, 0xff }; // chnp (meaning unknown)
+        std::array<std::int8_t, 8> slots { -1, -1, -1, -1, -1, -1, -1, -1 };
+        std::array<std::uint8_t, 48> name {};
+        bool operator== (const Chain&) const = default;
+    };
+    std::uint32_t version = 2, engineVersion = 1;
+    std::vector<std::int8_t> fixp;   // FL params 0…19
+    std::vector<std::int8_t> fpgp;   // the program-level params that are global (FL param 39 + i)
+    std::vector<Chain> chains;
+    std::vector<Program> programs;
+    std::vector<std::vector<std::uint8_t>> extra;                // unknown bank chunks
+    std::vector<std::uint8_t> gui { 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0 }; // record 2 (the editor's combos)
+    std::vector<std::uint8_t> options;                           // record 3 (absent in FL's default state)
+    bool operator== (const SequencerSettings&) const = default;
+
+    // FL's parameter numbers
+    enum Param
+    {
+        midiIn = 1, arpMode = 5, currentProgram = 8, steps = 40, gate = 41, sync = 42, latch = 43, missingKeys = 44,
+        inputLow = 45, inputHigh = 46, outputLow = 47, outputHigh = 48, order = 49, fixedKey = 50, transposeOctaves = 51,
+        inputQuantize = 52, transposeSemitones = 53, swing = 55, restartOn = 56, forceKey = 57, forceScale = 58,
+        forceMode = 59, pageLock = 60, page = 61, patternShift = 62, inputWrapLow = 63, inputWrapHigh = 64, polyOctave = 65,
+        polyKeys = 66, missingOctave = 67, gateLaneMode = 69, randomVelocity = 70, randomGate = 71, randomStart = 72,
+        smartBend = 80, programMode = 81, inputRangeMode = 16, velocityMode = 17, selectedLayer = 68
+    };
+    // A parameter's value as the plugin uses it (FL's lookup: per program or global); 0 when it does not exist
+    int get (int param) const noexcept;
+    void set (int param, int value);
+    static bool perProgram (int param) noexcept;
+    static int minimum (int param) noexcept;
+    static int maximum (int param) noexcept;
+    int program() const noexcept; // the current program 0…
+    Program& current();
+    const Program& current() const;
+};
+SequencerSettings defaultSequencer();
+std::optional<SequencerSettings> parseSequencer (const std::vector<std::uint8_t>& fl);
+std::vector<std::uint8_t> writeSequencer (const SequencerSettings& s);
+// Rotates all six lanes of the current program by `delta` steps (FL's Pattern shift)
+void shiftPattern (SequencerSettings& s, int delta);
+
+// VFX Script: FL's Python note scripts. The state is an INI text (UTF-8 with a BOM, CRLF): [Script] Source= (the
+// source on one line, line breaks as "<linebreak>"), [Parameters] (the script's controls by name), [Surface].
+// LYNX keeps it as it is; it does not run Python, so the notes pass through.
+struct ScriptSettings
+{
+    std::string text;
+    std::string source() const;                 // line breaks restored ("\n")
+    void setSource (const std::string& source); // (keeps every other line)
+    std::vector<std::pair<std::string, std::string>> parameters() const;
+    bool hasSurface() const;
+    bool operator== (const ScriptSettings&) const = default;
+};
+ScriptSettings defaultScript();
+std::optional<ScriptSettings> parseScript (const std::vector<std::uint8_t>& fl);
+std::vector<std::uint8_t> writeScript (const ScriptSettings& s);
+
+// ---------------------------------------------------------------------------------------------------------------
+// Presets
+
+// LYNX's own presets of a kind (scales, chords… built from music theory, so they exist without FL Studio)
+struct Preset
+{
+    std::string folder, name;
+    std::vector<std::uint8_t> fl;
+};
+std::vector<Preset> builtInPresets (Kind kind);
+// The state in an FL preset file (.fst: the plugin's name and its 0xD5 record) when it is one of `kind`
+std::optional<std::vector<std::uint8_t>> stateFromFlPreset (const std::vector<std::uint8_t>& fileBytes, Kind kind);
+
+// ---------------------------------------------------------------------------------------------------------------
+// A VFX node / channel
+
+// The default state of a new plugin of that kind (FL's "Default" preset)
+std::vector<std::uint8_t> defaultState (Kind kind);
+// How many voice outputs it has (FL's Patcher pins 1…N) and how many FL shows by default
+int outputCount (Kind kind) noexcept;
+int outputsShown (Kind kind) noexcept;
+std::string outputName (Kind kind, int output);
+
+// LYNX's channel / node state: "LVFX", the kind, the channel's output MIDI port (a VFX channel in the Channel Rack
+// sends output k on MIDI port `port + k`), then FL's state.
+struct State
+{
+    Kind kind = Kind::keyMapper;
+    int port = 0;
+    std::vector<std::uint8_t> fl;
+};
+std::optional<State> readState (const std::vector<std::uint8_t>& pluginState);
+std::vector<std::uint8_t> writeState (const State& state);
+// A channel / node of that kind with its default settings
+void makeChannel (ChannelDef& channel, Kind kind);
+std::optional<Kind> kindOf (const ChannelDef& channel);
+
+// The processor. Audio thread: process() never allocates. UI thread: configure() hands new settings over.
+class Processor
+{
+public:
+    virtual ~Processor() = default;
+    virtual Kind kind() const noexcept = 0;
+    virtual void prepare (double sampleRate) noexcept { rate = sampleRate; }
+    // the held voices end (each sent out as an "off")
+    virtual void releaseAll (EventList& out) noexcept = 0;
+    // One block of n samples: the input events (sorted by offset) in, the output events out (any order).
+    virtual void process (const Event* in, int count, int n, const Transport& transport, EventList& out) noexcept = 0;
+    // It holds voices or plays on its own (a sequencer): the host keeps running it while no note arrives
+    virtual bool busy() const noexcept { return false; }
+    // New FL state (UI thread); taken at the next block. False if it does not parse.
+    virtual bool configure (const std::vector<std::uint8_t>& flState) = 0;
+
+protected:
+    double rate = 44100.0;
+};
+std::unique_ptr<Processor> makeProcessor (Kind kind, const std::vector<std::uint8_t>& flState);
+std::unique_ptr<Processor> makeSequencer (const std::vector<std::uint8_t>& flState); // (VfxSequencer.cpp)
+} // namespace vfx
+} // namespace lynx

+ 90 - 0
src/core/VfxDetail.h

@@ -0,0 +1,90 @@
+#pragma once
+
+// Internals shared by the VFX sources (Vfx.cpp, VfxSequencer.cpp): byte reading / writing and the lock-free
+// settings hand-over to the audio thread.
+
+#include <algorithm>
+#include <atomic>
+#include <cstdint>
+#include <cstring>
+#include <memory>
+#include <vector>
+
+namespace lynx::vfx::detail
+{
+
+struct Reader
+{
+    const std::uint8_t* data;
+    std::size_t size, pos = 0;
+    bool failed = false;
+
+    template <typename T>
+    T get() noexcept
+    {
+        T v {};
+        if (failed || sizeof (T) > size - pos)
+        {
+            failed = true;
+            return v;
+        }
+        std::memcpy (&v, data + pos, sizeof (T));
+        pos += sizeof (T);
+        return v;
+    }
+    std::int32_t i32() noexcept { return get<std::int32_t>(); }
+    std::uint32_t u32() noexcept { return get<std::uint32_t>(); }
+    std::size_t left() const noexcept { return failed ? 0 : size - pos; }
+};
+
+template <typename T>
+void put (std::vector<std::uint8_t>& out, T v)
+{
+    const auto* p = reinterpret_cast<const std::uint8_t*> (&v);
+    out.insert (out.end(), p, p + sizeof (T));
+}
+
+// Settings handed from the UI thread to the audio thread without locks or allocation on the audio side (the
+// Patcher graph's pattern): the UI publishes a new object, the audio thread swaps it in and parks the old one, the
+// UI frees it on its next call.
+template <typename T>
+class Handoff
+{
+public:
+    explicit Handoff (T initial) : active (std::make_unique<T> (std::move (initial))) {}
+    explicit Handoff (std::unique_ptr<T> initial) : active (std::move (initial)) {}
+    ~Handoff()
+    {
+        delete pending.exchange (nullptr);
+        delete retired.exchange (nullptr);
+    }
+    void publish (T value)
+    {
+        delete retired.exchange (nullptr);
+        delete pending.exchange (new T (std::move (value)));
+    }
+    void publish (std::unique_ptr<T> value)
+    {
+        delete retired.exchange (nullptr);
+        delete pending.exchange (value.release());
+    }
+    // audio thread: true when new settings arrived
+    bool take() noexcept
+    {
+        auto* incoming = pending.exchange (nullptr);
+        if (incoming == nullptr)
+            return false;
+        auto* old = active.release();
+        active.reset (incoming);
+        delete retired.exchange (old); // (normally null: the UI frees it on its next call)
+        return true;
+    }
+    const T& get() const noexcept { return *active; }
+
+private:
+    std::unique_ptr<T> active;
+    std::atomic<T*> pending { nullptr };
+    std::atomic<T*> retired { nullptr };
+};
+
+} // namespace lynx::vfx::detail

+ 1451 - 0
src/core/VfxSequencer.cpp

@@ -0,0 +1,1451 @@
+// VFX Sequencer (round 164b, docs/analise/REA_rodada164b.md §Sequencer): FL's port of BlueARP — a bank of step
+// programs that turn held notes into arpeggios and sequences. The state is FL's (so FL's bank and projects load and
+// write back as they are); the engine follows the behaviour measured in FL's plugin (REA, clean-room: our own code).
+
+#include <algorithm>
+#include <cmath>
+#include <cstring>
+
+#include "core/Vfx.h"
+#include "core/VfxDetail.h"
+
+namespace lynx::vfx
+{
+using detail::Handoff;
+using detail::put;
+using detail::Reader;
+using S = SequencerSettings;
+
+namespace
+{
+// ---------------------------------------------------------------------------------------------------------------
+// Parameters
+
+struct ParamInfo
+{
+    int min, max, def;
+    bool perProgram;
+};
+
+// FL param 39 + i (the program-level block)
+constexpr ParamInfo programParams[43] = {
+    { 0, 127, 17, false },  // 0 PatchVerProg
+    { 0, 64, 16, true },    // 1 Steps
+    { 1, 125, 90, true },   // 2 Gate %
+    { 0, 12, 4, true },     // 3 Sync
+    { 0, 1, 0, false },     // 4 Latch
+    { 0, 4, 0, true },      // 5 Missing key substitution
+    { 0, 127, 0, false },   // 6 Input range low
+    { 0, 127, 127, false }, // 7 Input range high
+    { 0, 127, 0, false },   // 8 Output wrap low
+    { 0, 127, 127, false }, // 9 Output wrap high
+    { 0, 7, 0, true },      // 10 Order algorithm
+    { 0, 127, 64, true },   // 11 Fixed key
+    { -3, 3, 0, true },     // 12 Transpose octaves
+    { 0, 8, 1, false },     // 13 Input quantize
+    { -12, 12, 0, false },  // 14 Transpose semitones
+    { 0, 1, 0, false },     // 15 Page scroll
+    { -50, 50, 0, true },   // 16 Swing
+    { 0, 3, 0, false },     // 17 Restart on
+    { 0, 13, 0, true },     // 18 Force scale: key
+    { 0, 14, 0, true },     // 19 Force scale: scale
+    { 0, 1, 0, true },      // 20 Force scale: mode
+    { 0, 1, 0, false },     // 21 Page lock
+    { 0, 3, 0, false },     // 22 Page selected
+    { -8, 8, 0, false },    // 23 Pattern shift
+    { 0, 127, 0, false },   // 24 Input wrap low
+    { 0, 127, 127, false }, // 25 Input wrap high
+    { 0, 1, 0, true },      // 26 Polyphonic octave
+    { 0, 1, 0, true },      // 27 Polyphonic key select
+    { 0, 2, 0, true },      // 28 Missing key octave
+    { 0, 4, 0, false },     // 29 Selected layer
+    { 0, 1, 0, true },      // 30 Gate lane mode
+    { 0, 100, 0, true },    // 31 Randomize velocity
+    { 0, 100, 0, true },    // 32 Randomize gate
+    { 0, 100, 0, true },    // 33 Randomize start
+    { 0, 1, 0, false },     // 34 Latch mode
+    { 0, 1, 1, false },     // 35 Filter: pitch bend
+    { 0, 1, 1, false },     // 36 Filter: mod wheel
+    { 0, 1, 1, false },     // 37 Filter: aftertouch
+    { 0, 1, 0, false },     // 38 Filter: other CC
+    { 0, 3, 3, false },     // 39 Filter: sustain
+    { 0, 1, 0, false },     // 40 Sustain polarity
+    { -7, 7, 0, true },     // 41 Smart bend
+    { 0, 1, 0, true },      // 42 Program mode
+};
+
+// FL params 0…19
+constexpr ParamInfo globalParams[20] = {
+    { 0, 127, 17, false }, { -1, 15, -1, false }, { 0, 15, 0, false }, { 0, 5, 0, false },  { 0, 13, 0, false },
+    { 0, 6, 1, false },    { 0, 0, 0, false },    { 0, 120, 120, false }, { 0, 127, 3, false }, { 0, 5, 3, false },
+    { 1, 16, 8, false },   { -1, 15, -1, false }, { 0, 8, 5, false },  { 0, 1, 1, false },   { 0, 3, 0, false },
+    { 0, 2, 0, false },    { 0, 1, 0, false },    { 0, 2, 0, false },  { 0, 2, 0, false },   { 0, 1, 0, false },
+};
+
+const ParamInfo* info (int param) noexcept
+{
+    if (param >= 0 && param < 20)
+        return &globalParams[param];
+    if (param >= 39 && param < 39 + 43)
+        return &programParams[param - 39];
+    return nullptr;
+}
+
+// step length in beats per Sync index (1/64 … 3/8)
+constexpr double syncBeats[13] = { 0.0625, 1.0 / 12.0, 0.125, 1.0 / 6.0, 0.25, 1.0 / 3.0, 0.5, 2.0 / 3.0, 1.0, 0.1875, 0.375, 0.75, 1.5 };
+// input quantize grid in beats (index 2 "1/12" is 0.75 in FL's plugin; kept)
+constexpr double quantizeBeats[9] = { 0.0, 0.25, 0.75, 0.5, 2.0 / 3.0, 1.0, 2.0, 4.0, 8.0 };
+
+std::vector<std::uint8_t> chunk (const char* tag, const std::vector<std::uint8_t>& data)
+{
+    std::vector<std::uint8_t> out (tag, tag + 4);
+    put<std::uint32_t> (out, (std::uint32_t) data.size());
+    out.insert (out.end(), data.begin(), data.end());
+    return out;
+}
+
+template <typename T>
+std::vector<std::uint8_t> bytes (const T& c)
+{
+    std::vector<std::uint8_t> out (c.size());
+    std::memcpy (out.data(), c.data(), c.size());
+    return out;
+}
+
+std::array<std::uint8_t, 48> nameBytes (const std::string& s)
+{
+    std::array<std::uint8_t, 48> out {};
+    std::memcpy (out.data(), s.data(), std::min<std::size_t> (s.size(), 47));
+    return out;
+}
+
+void appendChunk (std::vector<std::uint8_t>& out, const std::vector<std::uint8_t>& c) { out.insert (out.end(), c.begin(), c.end()); }
+} // namespace
+
+std::string S::Program::nameText() const
+{
+    std::string s;
+    for (const auto c : name)
+    {
+        if (c == 0)
+            break;
+        s += (char) c;
+    }
+    return s;
+}
+
+void S::Program::setName (const std::string& n) { name = nameBytes (n); }
+
+bool S::perProgram (int param) noexcept
+{
+    const auto* i = info (param);
+    return i != nullptr && i->perProgram;
+}
+
+int S::minimum (int param) noexcept
+{
+    if (param >= 0x80 && param < 0x200)
+    {
+        static constexpr int lo[6] = { -12, 0, 0, 0, 0, -3 };
+        return lo[(param - 0x80) / 64];
+    }
+    const auto* i = info (param);
+    return i != nullptr ? i->min : 0;
+}
+
+int S::maximum (int param) noexcept
+{
+    if (param >= 0x80 && param < 0x200)
+    {
+        static constexpr int hi[6] = { 12, 127, 5, 127, 127, 16 };
+        return hi[(param - 0x80) / 64];
+    }
+    const auto* i = info (param);
+    return i != nullptr ? i->max : 0;
+}
+
+int S::program() const noexcept
+{
+    const auto p = fixp.size() > 8 ? (int) fixp[8] : 0;
+    return programs.empty() ? 0 : std::clamp (p, 0, (int) programs.size() - 1);
+}
+
+S::Program& S::current() { return programs[(std::size_t) program()]; }
+const S::Program& S::current() const { return programs[(std::size_t) program()]; }
+
+int S::get (int param) const noexcept
+{
+    if (param >= 0x80 && param < 0x200)
+    {
+        if (programs.empty())
+            return 0;
+        return current().lanes[(std::size_t) ((param - 0x80) / 64)][(std::size_t) ((param - 0x80) % 64)];
+    }
+    const auto* i = info (param);
+    if (i == nullptr)
+        return 0;
+    if (param < 20)
+        return (std::size_t) param < fixp.size() ? std::clamp ((int) fixp[(std::size_t) param], i->min, i->max) : i->def;
+    const auto k = (std::size_t) (param - 39);
+    if (i->perProgram)
+    {
+        if (programs.empty())
+            return i->def;
+        const auto& p = current().params;
+        return k < p.size() ? std::clamp ((int) p[k], i->min, i->max) : i->def;
+    }
+    return k < fpgp.size() ? std::clamp ((int) fpgp[k], i->min, i->max) : i->def;
+}
+
+void S::set (int param, int value)
+{
+    value = std::clamp (value, minimum (param), maximum (param));
+    if (param >= 0x80 && param < 0x200)
+    {
+        if (! programs.empty())
+            current().lanes[(std::size_t) ((param - 0x80) / 64)][(std::size_t) ((param - 0x80) % 64)] = (std::int8_t) value;
+        return;
+    }
+    const auto* i = info (param);
+    if (i == nullptr)
+        return;
+    auto store = [&] (std::vector<std::int8_t>& v, std::size_t k, int def) {
+        if (v.size() <= k)
+            v.resize (k + 1, (std::int8_t) def);
+        v[k] = (std::int8_t) value;
+    };
+    if (param < 20)
+        store (fixp, (std::size_t) param, i->def);
+    else if (i->perProgram)
+    {
+        if (! programs.empty())
+            store (current().params, (std::size_t) (param - 39), i->def);
+    }
+    else
+        store (fpgp, (std::size_t) (param - 39), i->def);
+}
+
+void shiftPattern (SequencerSettings& s, int delta)
+{
+    if (s.programs.empty())
+        return;
+    const auto steps = std::clamp (s.get (S::steps), 1, 64);
+    auto& p = s.current();
+    for (auto& lane : p.lanes)
+    {
+        auto old = lane;
+        for (int i = 0; i < steps; ++i)
+            lane[(std::size_t) ((((i + delta) % steps) + steps) % steps)] = old[(std::size_t) i];
+    }
+}
+
+// ---------------------------------------------------------------------------------------------------------------
+// LYNX's own bank (a fresh plugin without FL Studio's factory bank): a few programs written for LYNX
+
+SequencerSettings defaultSequencer()
+{
+    S s;
+    s.fixp = { 17, -1, 0, 0, 0, 1, 0, 120, 2, 3, 8, -1, 5, 1, 0, 0, 0, 0, 0, 0 };
+    s.fpgp = { 17, 16, 90, 4, 0, 0, 0, 127, 0, 127, 0, 64, 0, 1, 0, 0, 0, 0, 0, 0, 0,
+               0,  0,  0,  0, 127, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 3, 0, 0 };
+    for (int c = 0; c < 16; ++c)
+    {
+        S::Chain chain;
+        chain.name = nameBytes ("Chain " + std::string (c < 9 ? "0" : "") + std::to_string (c + 1));
+        s.chains.push_back (chain);
+    }
+    S::Program blank;
+    blank.params = s.fpgp;
+    for (auto& v : blank.lanes[S::octave]) v = 0x08;
+    for (auto& v : blank.lanes[S::stepType]) v = S::normal;
+    for (auto& v : blank.lanes[S::keySelect]) v = 0x04;
+    for (auto& v : blank.lanes[S::velocity]) v = 96;
+    blank.setName ("Initial");
+    s.programs.assign (128, blank);
+
+    auto make = [&] (int index, const std::string& name, auto&& fill) {
+        auto p = blank;
+        p.setName (name);
+        fill (p);
+        s.programs[(std::size_t) index] = p;
+    };
+    auto param = [] (S::Program& p, int flParam, int v) { p.params[(std::size_t) (flParam - 39)] = (std::int8_t) v; };
+    auto keys = [] (S::Program& p, std::initializer_list<int> slots) { // 1…5 = N1…N5, 0 = Fixed, -1 = Root
+        int i = 0;
+        for (int step = 0; step < 64; ++step)
+        {
+            const auto k = *(slots.begin() + (i++ % (int) slots.size()));
+            p.lanes[S::keySelect][(std::size_t) step] = (std::int8_t) (k == 0 ? 1 : k < 0 ? 2 : 1 << (k + 1));
+        }
+    };
+    make (1, "Thru", [&] (S::Program& p) { param (p, S::steps, 0); });
+    make (2, "Up 4 keys", [&] (S::Program& p) {
+        param (p, S::gate, 50);
+        param (p, S::missingKeys, 3);
+        keys (p, { 1, 2, 3, 4 });
+    });
+    make (3, "Down 4 keys", [&] (S::Program& p) {
+        param (p, S::gate, 50);
+        param (p, S::missingKeys, 2);
+        keys (p, { 4, 3, 2, 1 });
+    });
+    make (4, "Up and down 3 keys", [&] (S::Program& p) {
+        param (p, S::gate, 60);
+        param (p, S::missingKeys, 3);
+        keys (p, { 1, 2, 3, 2 });
+    });
+    make (5, "Up 2 octaves", [&] (S::Program& p) {
+        param (p, S::steps, 12);
+        param (p, S::gate, 60);
+        param (p, S::missingKeys, 1);
+        keys (p, { 1, 2, 3 });
+        for (int i = 3; i < 6; ++i)
+            p.lanes[S::octave][(std::size_t) i] = p.lanes[S::octave][(std::size_t) (i + 6)] = 0x10;
+    });
+    make (6, "Chord stabs", [&] (S::Program& p) {
+        param (p, S::gate, 40);
+        const int pattern[16] = { 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0 };
+        for (int i = 0; i < 64; ++i)
+            p.lanes[S::stepType][(std::size_t) i] = (std::int8_t) (pattern[i % 16] ? S::chord : S::off);
+    });
+    make (7, "Gated chords", [&] (S::Program& p) {
+        param (p, S::gate, 70);
+        const int pattern[16] = { 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1 };
+        for (int i = 0; i < 64; ++i)
+            p.lanes[S::stepType][(std::size_t) i] = (std::int8_t) (pattern[i % 16] ? S::chord : S::off);
+    });
+    make (8, "Random notes", [&] (S::Program& p) {
+        param (p, S::gate, 50);
+        for (auto& v : p.lanes[S::stepType]) v = S::random;
+    });
+    make (9, "Octave bass", [&] (S::Program& p) {
+        param (p, S::gate, 40);
+        for (int i = 0; i < 64; ++i)
+        {
+            p.lanes[S::octave][(std::size_t) i] = (std::int8_t) (i % 2 == 0 ? 0x08 : 0x10);
+            p.lanes[S::velocity][(std::size_t) i] = (std::int8_t) (i % 4 == 0 ? 120 : 90);
+        }
+    });
+    make (10, "A minor run", [&] (S::Program& p) {
+        param (p, S::gate, 70);
+        param (p, S::forceKey, 2 + 9);
+        param (p, S::forceScale, 3);
+        const int run[16] = { 0, 1, 2, 3, 4, 5, 6, 7, 6, 5, 4, 3, 2, 1, 0, -1 };
+        for (int i = 0; i < 64; ++i)
+            p.lanes[S::scaleStep][(std::size_t) i] = (std::int8_t) run[i % 16];
+    });
+    make (11, "Scale of the chord", [&] (S::Program& p) {
+        param (p, S::gate, 70);
+        param (p, S::forceKey, 1);
+        param (p, S::forceScale, 1);
+        keys (p, { -1 });
+        const int run[16] = { 0, 2, 4, 7, 4, 2, 0, -1, 0, 2, 4, 5, 7, 5, 4, 2 };
+        for (int i = 0; i < 64; ++i)
+            p.lanes[S::scaleStep][(std::size_t) i] = (std::int8_t) run[i % 16];
+    });
+    make (12, "Accents", [&] (S::Program& p) {
+        param (p, S::gate, 55);
+        param (p, S::missingKeys, 1);
+        keys (p, { 1, 2, 3, 4 });
+        const int vel[4] = { 127, 64, 96, 64 };
+        for (int i = 0; i < 64; ++i)
+            p.lanes[S::velocity][(std::size_t) i] = (std::int8_t) vel[i % 4];
+    });
+    make (13, "Legato ties", [&] (S::Program& p) {
+        param (p, S::gate, 90);
+        param (p, S::missingKeys, 1);
+        keys (p, { 1, 2, 3, 2 });
+        for (int i = 0; i < 64; ++i)
+            if (i % 4 == 1)
+                p.lanes[S::stepType][(std::size_t) i] = S::tie;
+            else if (i % 8 == 7)
+                p.lanes[S::stepType][(std::size_t) i] = S::rest;
+    });
+    make (14, "Triplets up", [&] (S::Program& p) {
+        param (p, S::steps, 12);
+        param (p, S::sync, 5);
+        param (p, S::gate, 60);
+        param (p, S::missingKeys, 1);
+        keys (p, { 1, 2, 3 });
+    });
+    make (15, "Swing eighths", [&] (S::Program& p) {
+        param (p, S::steps, 8);
+        param (p, S::sync, 6);
+        param (p, S::gate, 50);
+        param (p, S::swing, 30);
+        param (p, S::missingKeys, 1);
+        keys (p, { 1, 3, 2, 3 });
+    });
+    return s;
+}
+
+// ---------------------------------------------------------------------------------------------------------------
+// FL's state
+
+std::optional<SequencerSettings> parseSequencer (const std::vector<std::uint8_t>& fl)
+{
+    Reader r { fl.data(), fl.size() };
+    S s;
+    s.version = r.u32();
+    if (r.failed || s.version != 2)
+        return std::nullopt;
+    s.gui.clear();
+    bool bank = false;
+    while (r.left() >= 12)
+    {
+        const auto id = r.u32();
+        const auto size = r.get<std::uint64_t>();
+        if (r.failed || size > r.left())
+            return std::nullopt;
+        const auto* data = fl.data() + r.pos;
+        r.pos += (std::size_t) size;
+        if (id == 2)
+            s.gui.assign (data, data + size);
+        else if (id == 3)
+            s.options.assign (data, data + size);
+        else if (id == 1)
+        {
+            Reader e { data, (std::size_t) size };
+            s.engineVersion = e.u32();
+            char tag[4];
+            if (e.left() < 8)
+                return std::nullopt;
+            std::memcpy (tag, data + e.pos, 4);
+            e.pos += 4;
+            const auto bankSize = e.u32();
+            if (e.failed || std::memcmp (tag, "bbnk", 4) != 0 || bankSize > e.left())
+                return std::nullopt;
+            // the bank's chunks
+            auto walk = [&] (std::size_t from, std::size_t to, auto&& onChunk) {
+                auto p = from;
+                while (p + 8 <= to)
+                {
+                    std::uint32_t n = 0;
+                    std::memcpy (&n, data + p + 4, 4);
+                    if (n > to - p - 8)
+                        return false;
+                    onChunk (data + p, data + p + 8, (std::size_t) n);
+                    p += 8 + n;
+                }
+                return p == to;
+            };
+            bool ok = true;
+            ok = walk (e.pos, e.pos + bankSize, [&] (const std::uint8_t* head, const std::uint8_t* body, std::size_t n) {
+                const std::string_view t ((const char*) head, 4);
+                if (t == "fixp")
+                    s.fixp.assign ((const std::int8_t*) body, (const std::int8_t*) body + n);
+                else if (t == "fpgp")
+                    s.fpgp.assign ((const std::int8_t*) body, (const std::int8_t*) body + n);
+                else if (t == "chnp")
+                {
+                    s.chains.emplace_back();
+                    s.chains.back().head.assign (body, body + n);
+                }
+                else if (t == "chns" && ! s.chains.empty())
+                    std::memcpy (s.chains.back().slots.data(), body, std::min<std::size_t> (n, 8));
+                else if (t == "chnn" && ! s.chains.empty())
+                    std::memcpy (s.chains.back().name.data(), body, std::min<std::size_t> (n, 48));
+                else if (t == "prog")
+                {
+                    S::Program p;
+                    const auto from = (std::size_t) (body - data);
+                    ok = ok && walk (from, from + n, [&] (const std::uint8_t* h, const std::uint8_t* b, std::size_t m) {
+                        const std::string_view u ((const char*) h, 4);
+                        if (u == "prgp")
+                            p.params.assign ((const std::int8_t*) b, (const std::int8_t*) b + m);
+                        else if (u == "pgnm")
+                            std::memcpy (p.name.data(), b, std::min<std::size_t> (m, 48));
+                        else if (u.substr (0, 3) == "stp" && u[3] >= '0' && u[3] <= '5' && m == 64)
+                            std::memcpy (p.lanes[(std::size_t) (u[3] - '0')].data(), b, 64);
+                        else
+                            p.extra.emplace_back (h, b + m);
+                    });
+                    s.programs.push_back (std::move (p));
+                }
+                else
+                    s.extra.emplace_back (head, body + n);
+            });
+            if (! ok)
+                return std::nullopt;
+            bank = true;
+        }
+    }
+    if (! bank || s.programs.empty() || s.fixp.size() < 20)
+        return std::nullopt;
+    return s;
+}
+
+std::vector<std::uint8_t> writeSequencer (const SequencerSettings& s)
+{
+    std::vector<std::uint8_t> bank;
+    std::vector<std::uint8_t> fixp (s.fixp.size()), fpgp (s.fpgp.size());
+    std::memcpy (fixp.data(), s.fixp.data(), fixp.size());
+    std::memcpy (fpgp.data(), s.fpgp.data(), fpgp.size());
+    appendChunk (bank, chunk ("fixp", fixp));
+    appendChunk (bank, chunk ("fpgp", fpgp));
+    for (const auto& c : s.chains)
+    {
+        appendChunk (bank, chunk ("chnp", c.head));
+        appendChunk (bank, chunk ("chns", bytes (c.slots)));
+        appendChunk (bank, chunk ("chnn", bytes (c.name)));
+    }
+    for (const auto& p : s.programs)
+    {
+        std::vector<std::uint8_t> prog;
+        std::vector<std::uint8_t> params (p.params.size());
+        std::memcpy (params.data(), p.params.data(), params.size());
+        appendChunk (prog, chunk ("prgp", params));
+        appendChunk (prog, chunk ("pgnm", bytes (p.name)));
+        for (int l = 0; l < S::laneCount; ++l)
+        {
+            const char tag[5] = { 's', 't', 'p', (char) ('0' + l), 0 };
+            appendChunk (prog, chunk (tag, bytes (p.lanes[(std::size_t) l])));
+        }
+        for (const auto& x : p.extra)
+            appendChunk (prog, x);
+        appendChunk (bank, chunk ("prog", prog));
+    }
+    for (const auto& x : s.extra)
+        appendChunk (bank, x);
+
+    std::vector<std::uint8_t> engine;
+    put<std::uint32_t> (engine, s.engineVersion);
+    appendChunk (engine, chunk ("bbnk", bank));
+
+    std::vector<std::uint8_t> out;
+    put<std::uint32_t> (out, s.version);
+    auto record = [&] (std::uint32_t id, const std::vector<std::uint8_t>& data) {
+        put<std::uint32_t> (out, id);
+        put<std::uint64_t> (out, (std::uint64_t) data.size());
+        out.insert (out.end(), data.begin(), data.end());
+    };
+    record (1, engine);
+    if (! s.gui.empty())
+        record (2, s.gui);
+    if (! s.options.empty())
+        record (3, s.options);
+    return out;
+}
+
+// ---------------------------------------------------------------------------------------------------------------
+// The engine
+
+namespace
+{
+struct Chord
+{
+    std::uint16_t mask;
+    bool inversion;
+    int rootOffset, score;
+    std::array<int, 2> completion;
+    std::array<std::int8_t, 7> scale;
+    int scaleCount;
+};
+
+constexpr std::uint16_t m (std::initializer_list<int> intervals)
+{
+    std::uint16_t v = 0;
+    for (const auto i : intervals)
+        v = (std::uint16_t) (v | (1u << i));
+    return v;
+}
+
+// chord masks, whether found on a note that is not the lowest, root offset, score, completion notes (order
+// "chord normalized"), and the scale each one implies (Force scale "detect")
+const Chord chords[38] = {
+    { m ({ 0, 7 }), false, 0, 20, { 0, 0 }, { 0, 0, 0, 0, 7, 7, 7 }, 7 },
+    { m ({ 0, 5 }), false, 0, 20, { 0, 0 }, { 0, 0, 0, 5, 5, 5, 5 }, 7 },
+    { m ({ 0, 4 }), false, 0, 20, { 7, 0 }, { 0, 2, 4, 5, 7, 7, 9 }, 7 },
+    { m ({ 0, 3 }), false, 0, 20, { 7, 0 }, { 0, 2, 3, 5, 7, 8, 10 }, 7 },
+    { m ({ 0, 4, 7 }), true, 0, 30, { 0, 0 }, { 0, 2, 4, 5, 7, 7, 9 }, 7 },
+    { m ({ 0, 3, 7 }), true, 0, 30, { 0, 0 }, { 0, 2, 3, 5, 7, 8, 10 }, 7 },
+    { m ({ 0, 5, 7 }), false, 0, 30, { 0, 0 }, { 0, 5, 5, 5, 7, 7, 7 }, 7 },
+    { m ({ 0, 2, 7 }), false, 0, 30, { 0, 0 }, { 0, 2, 2, 2, 7, 7, 7 }, 7 },
+    { m ({ 0, 3, 6 }), true, 0, 30, { 0, 0 }, { 0, 2, 3, 5, 6, 6, 6 }, 7 },
+    { m ({ 0, 4, 6 }), true, 0, 30, { 0, 0 }, { 0, 2, 4, 6, 7, 7, 7 }, 7 },
+    { m ({ 0, 4, 8 }), false, 0, 30, { 0, 0 }, { 0, 2, 5, 8, 9, 9, 11 }, 7 },
+    { m ({ 0, 2, 4 }), true, 0, 30, { 7, 0 }, { 0, 2, 2, 4, 4, 7, 7 }, 7 },
+    { m ({ 0, 2, 3 }), true, 0, 30, { 0, 0 }, { 0, 2, 2, 3, 3, 5, 7 }, 7 },
+    { m ({ 0, 4, 11 }), true, 0, 30, { 7, 0 }, { 0, 2, 4, 5, 7, 9, 11 }, 7 },
+    { m ({ 0, 3, 10 }), true, 0, 30, { 7, 0 }, { 0, 2, 3, 5, 7, 8, 10 }, 7 },
+    { m ({ 0, 4, 10 }), true, 0, 30, { 7, 0 }, { 0, 2, 4, 5, 7, 9, 10 }, 7 },
+    { m ({ 0, 4, 7, 11 }), true, 0, 40, { 0, 0 }, { 0, 2, 4, 5, 7, 9, 11 }, 7 },
+    { m ({ 0, 4, 7, 9 }), false, 0, 40, { 0, 0 }, { 0, 2, 4, 5, 7, 9, 11 }, 7 },
+    { m ({ 0, 4, 7, 10 }), true, 0, 40, { 0, 0 }, { 0, 2, 4, 5, 7, 9, 10 }, 7 },
+    { m ({ 0, 2, 4, 7 }), true, 0, 40, { 0, 0 }, { 0, 2, 4, 5, 7, 9, 11 }, 7 },
+    { m ({ 0, 2, 3, 7 }), true, 0, 40, { 0, 0 }, { 0, 2, 3, 5, 7, 8, 10 }, 7 },
+    { m ({ 0, 5, 7, 10 }), false, 0, 40, { 0, 0 }, { 0, 0, 5, 5, 7, 7, 10 }, 7 },
+    { m ({ 0, 2, 7, 10 }), false, 0, 40, { 0, 0 }, { 0, 2, 5, 5, 7, 7, 10 }, 7 },
+    { m ({ 0, 2, 4, 9 }), false, 2, 40, { 0, 0 }, { 0, 2, 5, 5, 7, 7, 10 }, 7 },
+    { m ({ 0, 4, 5, 11 }), false, 0, 40, { 7, 9 }, { 0, 2, 4, 5, 7, 9, 11 }, 7 },
+    { m ({ 0, 2, 3, 10 }), true, 0, 40, { 7, 0 }, { 0, 2, 3, 5, 7, 8, 10 }, 7 },
+    { m ({ 0, 3, 7, 9 }), true, 0, 40, { 0, 0 }, { 0, 2, 3, 5, 7, 8, 10 }, 7 },
+    { m ({ 0, 3, 7, 10 }), true, 0, 40, { 0, 0 }, { 0, 2, 3, 5, 7, 8, 10 }, 7 },
+    { m ({ 0, 3, 7, 11 }), true, 0, 40, { 0, 0 }, { 0, 2, 3, 5, 7, 8, 11 }, 7 },
+    { m ({ 0, 3, 6, 7 }), true, 0, 40, { 0, 0 }, { 0, 2, 3, 6, 7, 8, 10 }, 7 },
+    { m ({ 0, 3, 6, 9 }), false, 0, 40, { 0, 0 }, { 0, 2, 3, 6, 7, 10, 0 }, 6 },
+    { m ({ 0, 4, 6, 9 }), false, 0, 40, { 0, 0 }, { 0, 2, 4, 5, 6, 9, 0 }, 6 },
+    { m ({ 0, 4, 8, 9 }), false, 0, 40, { 0, 0 }, { 0, 2, 4, 5, 7, 9, 0 }, 6 },
+    { m ({ 0, 2, 4, 7, 11 }), true, 0, 50, { 0, 0 }, { 0, 2, 4, 5, 7, 9, 11 }, 7 },
+    { m ({ 0, 4, 5, 7, 11 }), true, 0, 50, { 0, 0 }, { 0, 2, 4, 5, 7, 9, 11 }, 7 },
+    { m ({ 0, 2, 3, 7, 10 }), true, 0, 50, { 0, 0 }, { 0, 2, 3, 5, 7, 8, 10 }, 7 },
+    { m ({ 0, 3, 5, 7, 10 }), true, 0, 50, { 0, 0 }, { 0, 2, 3, 5, 7, 8, 10 }, 7 },
+    { m ({ 0, 4, 5, 7, 9, 11 }), true, 0, 60, { 0, 0 }, { 0, 2, 4, 5, 7, 9, 11 }, 7 },
+};
+
+struct Scale
+{
+    std::array<std::int8_t, 7> degrees;
+    int count;
+};
+// Force scale 2…14
+const Scale scales[13] = {
+    { { 0, 2, 4, 5, 7, 9, 11 }, 7 }, { { 0, 2, 3, 5, 7, 8, 10 }, 7 }, { { 0, 2, 3, 5, 7, 8, 11 }, 7 },
+    { { 0, 2, 3, 5, 7, 9, 11 }, 7 }, { { 0, 2, 4, 7, 9 }, 5 },          { { 0, 3, 5, 7, 10 }, 5 },
+    { { 0, 2, 5, 7, 10 }, 5 },       { { 0, 3, 5, 6, 7, 10 }, 6 },      { { 0, 2, 3, 5, 7, 9, 10 }, 7 },
+    { { 0, 1, 3, 5, 7, 8, 10 }, 7 }, { { 0, 2, 4, 6, 7, 9, 11 }, 7 },   { { 0, 2, 4, 5, 7, 9, 10 }, 7 },
+    { { 0, 1, 3, 5, 6, 8, 10 }, 7 },
+};
+
+// The current program with every value resolved (built on the UI thread)
+struct Runtime
+{
+    int midiIn = -1, arpMode = 1, steps = 16, gate = 90, sync = 4, latch = 0, missing = 0, inLow = 0, inHigh = 127,
+        outLow = 0, outHigh = 127, order = 0, fixedKey = 64, transposeOctaves = 0, inputQuantize = 1, transposeSemitones = 0,
+        swing = 0, restartOn = 0, forceKey = 0, forceScale = 0, forceMode = 0, pageLock = 0, page = 0, wrapLow = 0,
+        wrapHigh = 127, polyOctave = 0, polyKeys = 0, missingOctave = 0, gateLaneMode = 0, randomVelocity = 0,
+        randomGate = 0, randomStart = 0, smartBend = 0, programMode = 0, inputRangeMode = 0, velocityMode = 0;
+    std::array<std::array<std::int8_t, 64>, 6> lanes {};
+};
+
+Runtime resolve (const S& s)
+{
+    Runtime r;
+    r.midiIn = s.get (S::midiIn);
+    r.arpMode = s.get (S::arpMode);
+    r.steps = s.get (S::steps);
+    r.gate = s.get (S::gate);
+    r.sync = s.get (S::sync);
+    r.latch = s.get (S::latch);
+    r.missing = s.get (S::missingKeys);
+    r.inLow = s.get (S::inputLow);
+    r.inHigh = s.get (S::inputHigh);
+    r.outLow = s.get (S::outputLow);
+    r.outHigh = s.get (S::outputHigh);
+    r.order = s.get (S::order);
+    r.fixedKey = s.get (S::fixedKey);
+    r.transposeOctaves = s.get (S::transposeOctaves);
+    r.inputQuantize = s.get (S::inputQuantize);
+    r.transposeSemitones = s.get (S::transposeSemitones);
+    r.swing = s.get (S::swing);
+    r.restartOn = s.get (S::restartOn);
+    r.forceKey = s.get (S::forceKey);
+    r.forceScale = s.get (S::forceScale);
+    r.forceMode = s.get (S::forceMode);
+    r.pageLock = s.get (S::pageLock);
+    r.page = s.get (S::page);
+    r.wrapLow = s.get (S::inputWrapLow);
+    r.wrapHigh = s.get (S::inputWrapHigh);
+    r.polyOctave = s.get (S::polyOctave);
+    r.polyKeys = s.get (S::polyKeys);
+    r.missingOctave = s.get (S::missingOctave);
+    r.gateLaneMode = s.get (S::gateLaneMode);
+    r.randomVelocity = s.get (S::randomVelocity);
+    r.randomGate = s.get (S::randomGate);
+    r.randomStart = s.get (S::randomStart);
+    r.smartBend = s.get (S::smartBend);
+    r.programMode = s.get (S::programMode);
+    r.inputRangeMode = s.get (S::inputRangeMode);
+    r.velocityMode = s.get (S::velocityMode);
+    if (! s.programs.empty())
+        r.lanes = s.current().lanes;
+    return r;
+}
+
+// FL's "MIDI velocity" here is the voice volume × 100 (velocity 100/128 = 100)
+int midiVelocity (float velocity) noexcept
+{
+    const auto volume = (std::pow (11.0, 1.28 * (double) velocity) - 1.0) / 10.0;
+    return (int) std::clamp (volume * 100.0 + 1e-9, 0.0, 127.0);
+}
+
+float voiceVelocity (int midi) noexcept
+{
+    const auto volume = std::max (0, midi) / 100.0;
+    return (float) std::clamp (std::log (10.0 * volume + 1.0) / std::log (11.0) / 1.28, 0.0, 1.0);
+}
+
+class Sequencer final : public Processor
+{
+public:
+    explicit Sequencer (const S& s) : settings (resolve (s)) {}
+
+    Kind kind() const noexcept override { return Kind::sequencer; }
+
+    bool configure (const std::vector<std::uint8_t>& fl) override
+    {
+        const auto s = parseSequencer (fl);
+        if (! s)
+            return false;
+        settings.publish (resolve (*s));
+        return true;
+    }
+
+    bool busy() const noexcept override { return heldCount > 0 || arpCount > 0 || soundingCount > 0 || thruCount > 0 || freeRun != 0; }
+
+    void releaseAll (EventList& out) noexcept override
+    {
+        killAll (0, out);
+        heldCount = arpCount = keyCount = 0;
+        freeRun = 0;
+        lastStep = -1;
+    }
+
+    void process (const Event* in, int count, int n, const Transport& t, EventList& out) noexcept override
+    {
+        if (settings.take())
+        {
+            const auto& r = settings.get();
+            if (r.arpMode != lastArpMode && lastArpMode >= 0)
+            {
+                killAll (0, out);
+                lastStep = -1;
+            }
+            keysDirty = arpCount > 0;
+        }
+        const auto& r = settings.get();
+        lastArpMode = r.arpMode;
+        sampleRate = t.sampleRate > 0.0 ? t.sampleRate : 44100.0;
+        const auto bpm = std::max (1.0, t.bpm);
+        const auto beatsPerSample = bpm / 60.0 / sampleRate;
+        stepSamples = sampleRate * 60.0 / bpm * syncBeats[std::clamp (r.sync, 0, 12)];
+
+        // transport start / stop
+        const auto songBeats = t.ticks / 960.0;
+        if (t.playing && ! wasPlaying)
+        {
+            anchored = false;
+            restartOffset = 0.0;
+            if (r.restartOn == 3)
+            {
+                restartOffset = quantizeUp (songBeats, r);
+                anchored = true;
+            }
+            freeRun = 0;
+            lastStep = -1;
+        }
+        else if (! t.playing && wasPlaying)
+        {
+            killAll (0, out);
+            heldCount = arpCount = keyCount = 0;
+            chordIndex = -1;
+            freeRun = 0;
+            lastStep = -1;
+        }
+        else if (t.playing && songBeats < lastSongBeats - 1e-6 && r.restartOn != 0) // (a loop jumped back)
+            restartOffset = std::min (restartOffset, songBeats);
+        wasPlaying = t.playing;
+
+        if (count == 0 && ! busy())
+        {
+            lastSongBeats = songBeats + n * beatsPerSample;
+            return;
+        }
+
+        int next = 0;
+        for (int s = 0; s < n; ++s)
+        {
+            while (next < count && in[next].offset <= s)
+                input (in[next++], s, songBeats + s * beatsPerSample, t.playing, r, out);
+
+            const auto playingArp = mode (r) == Mode::arp;
+            if (playingArp && arpCount > 0 && (t.playing || freeRun != 0))
+            {
+                const auto pos = t.playing ? songBeats + s * beatsPerSample : freeBeats;
+                const auto rel = t.playing ? pos - (r.restartOn == 0 ? 0.0 : restartOffset) : pos;
+                if (rel >= -1e-9)
+                {
+                    const auto step = stepIndex (std::max (0.0, rel), r);
+                    if (step != lastStep || regenerate)
+                    {
+                        const auto grid = quantizeBeats[std::clamp (r.inputQuantize, 0, 8)];
+                        const auto cell = grid > 0.0 ? (long long) std::floor (rel / grid + 1e-9) : -1;
+                        if (keysDirty && (grid <= 0.0 || cell != lastCell || keyCount == 0))
+                        {
+                            buildKeys (r);
+                            keysDirty = false;
+                        }
+                        lastCell = cell;
+                        if (step != lastStep || regenerate)
+                            generate (step, s, r, out);
+                        lastStep = step;
+                        regenerate = false;
+                    }
+                }
+            }
+            schedule (s, out);
+            if (! t.playing && freeRun != 0)
+            {
+                freeBeats += beatsPerSample;
+                if (freeRun == 2 && --tailSamples <= 0)
+                {
+                    freeRun = 0;
+                    freeBeats = 0.0;
+                    lastStep = -1;
+                }
+            }
+        }
+        while (next < count)
+            input (in[next++], std::max (0, n - 1), songBeats + n * beatsPerSample, t.playing, r, out);
+        lastSongBeats = songBeats + n * beatsPerSample;
+    }
+
+private:
+    enum class Mode { off, arp, thru };
+    struct Key
+    {
+        int note = 0, velocity = 96, order = 0;
+    };
+    struct Sounding
+    {
+        int note = 0, velocity = 0, id = 0;
+        double startDelay = 0.0, gate = 0.0;
+        bool started = false;
+    };
+    struct Thru
+    {
+        int input = 0, id = 0, note = 0;
+    };
+
+    Mode mode (const Runtime& r) const noexcept
+    {
+        switch (r.arpMode)
+        {
+            case 0: return Mode::off;
+            case 2: return Mode::thru;
+            case 3: case 4: case 5: case 6:
+            {
+                const auto threshold = r.arpMode <= 4 ? 2 : 3;
+                if (heldCount >= threshold)
+                    return r.steps < 2 ? Mode::thru : Mode::arp;
+                return r.arpMode == 4 || r.arpMode == 6 ? Mode::thru : Mode::off;
+            }
+            default: return r.steps < 2 ? Mode::thru : Mode::arp;
+        }
+    }
+
+    double quantizeUp (double beats, const Runtime& r) const noexcept
+    {
+        const auto grid = quantizeBeats[std::clamp (r.inputQuantize, 0, 8)];
+        return grid > 0.0 ? std::ceil (beats / grid - 1e-9) * grid : beats;
+    }
+
+    int stepIndex (double rel, const Runtime& r) const noexcept
+    {
+        const auto steps = std::max (1, r.steps);
+        const auto stepBeats = syncBeats[std::clamp (r.sync, 0, 12)];
+        const auto perBeat = 1.0 / stepBeats;
+        auto x = rel * perBeat;
+        if (r.sync > 7) // (FL's plugin wraps the long syncs this way)
+        {
+            const auto span = std::floor (steps * perBeat) * perBeat;
+            if (span > 0.0)
+                x = std::fmod (x, span);
+        }
+        if (r.swing != 0)
+        {
+            const auto k = std::floor (x / 2.0);
+            const auto f = x - 2.0 * k;
+            const auto threshold = r.swing >= 0 ? 1.0 : 0.0; // (FL: (s + 100) div 100)
+            if (f >= threshold)
+                x = 2.0 * k + 2.0 - (100.0 / (100.0 - r.swing)) * (2.0 - f);
+            else
+                x = 2.0 * k + (100.0 / (100.0 + r.swing)) * f;
+        }
+        auto step = (long long) std::floor (x + 1e-9);
+        if (r.pageLock != 0)
+            return std::min (steps - 1, r.page * 16 + (int) (step % 16));
+        return (int) (step % steps);
+    }
+
+    // --- input ------------------------------------------------------------------------------------------------
+
+    void input (const Event& e, int offset, double songBeats, bool playing, const Runtime& r, EventList& out) noexcept
+    {
+        const auto key = std::clamp (e.voice.key, 0, 127);
+        if (e.type == Event::Type::off)
+        {
+            for (int i = 0; i < thruCount; ++i)
+                if (thru[(std::size_t) i].input == e.id)
+                {
+                    off (thru[(std::size_t) i].id, thru[(std::size_t) i].note, offset, out);
+                    thru[(std::size_t) i] = thru[(std::size_t) --thruCount];
+                    break;
+                }
+            const auto before = mode (r);
+            removeKey (held, heldCount, key);
+            if (r.latch == 0)
+            {
+                removeKey (arp, arpCount, key);
+                keysDirty = true;
+            }
+            if (mode (r) != before)
+                modeChanged (offset, out);
+            if (heldCount == 0 && arpCount == 0)
+            {
+                anchoredByKey = false;
+                if (! playing && freeRun == 1)
+                {
+                    if (r.restartOn == 1)
+                    {
+                        freeRun = 0;
+                        freeBeats = 0.0;
+                        lastStep = -1;
+                    }
+                    else
+                    {
+                        freeRun = 2;
+                        tailSamples = (long long) sampleRate;
+                    }
+                }
+                keyCount = 0;
+                if (r.restartOn == 1 || r.restartOn == 2)
+                    lastStep = -1;
+            }
+            return;
+        }
+        if (e.type != Event::Type::on)
+            return;
+        const auto inRange = key >= r.inLow && key <= r.inHigh;
+        const auto velocity = midiVelocity (e.voice.velocity);
+        if (! inRange && r.inputRangeMode == 0)
+            return;
+        if (! inRange || r.arpMode == 2)
+        {
+            if (r.arpMode != 0)
+                thruNote (e, key, offset, r, out);
+            return;
+        }
+        const auto before = mode (r);
+        if (r.latch != 0 && heldCount == 0) // (a new chord replaces the latched one)
+            arpCount = 0;
+        const auto wasEmpty = arpCount == 0;
+        addKey (held, heldCount, key, velocity);
+        addKey (arp, arpCount, key, velocity);
+        keysDirty = true;
+        const auto now = mode (r);
+        if (now != before)
+            modeChanged (offset, out);
+        if (now == Mode::thru)
+        {
+            thruNote (e, key, offset, r, out);
+            return;
+        }
+        if (now != Mode::arp)
+            return;
+        if (! playing)
+        {
+            if (freeRun != 2)
+            {
+                freeBeats = 0.0;
+                lastStep = -1;
+            }
+            freeRun = 1;
+        }
+        else if (wasEmpty && ((r.restartOn == 1) || (r.restartOn == 2 && ! anchored)))
+        {
+            restartOffset = quantizeUp (songBeats, r);
+            anchored = true;
+            anchoredByKey = true;
+            lastStep = -1;
+        }
+        if (wasEmpty)
+        {
+            buildKeys (r);
+            keysDirty = false;
+            regenerate = true;
+        }
+    }
+
+    void addKey (std::array<Key, 16>& list, int& count, int note, int velocity) noexcept
+    {
+        removeKey (list, count, note);
+        if (count >= 16)
+            return;
+        list[(std::size_t) count++] = { note, velocity, ++arrivals };
+    }
+    static void removeKey (std::array<Key, 16>& list, int& count, int note) noexcept
+    {
+        for (int i = 0; i < count; ++i)
+            if (list[(std::size_t) i].note == note)
+            {
+                for (int j = i + 1; j < count; ++j)
+                    list[(std::size_t) (j - 1)] = list[(std::size_t) j];
+                --count;
+                return;
+            }
+    }
+    void modeChanged (int offset, EventList& out) noexcept
+    {
+        killAll (offset, out);
+        lastStep = -1;
+        regenerate = true;
+    }
+
+    void thruNote (const Event& e, int key, int offset, const Runtime& r, EventList& out) noexcept
+    {
+        if (thruCount >= (int) thru.size())
+            return;
+        const auto note = pitch (key, 0, false, r);
+        Voice v;
+        v.key = note;
+        v.velocity = e.voice.velocity;
+        const auto id = newId();
+        out.add (onEvent (offset, id, v));
+        thru[(std::size_t) thruCount++] = { e.id, id, note };
+    }
+
+    // --- the key list (FL: rebuilt on the input-quantize grid) ---------------------------------------------------
+
+    void buildKeys (const Runtime& r) noexcept
+    {
+        // pitch-sorted copy for chord detection
+        std::array<Key, 16> sorted = arp;
+        const auto n = arpCount;
+        for (int i = 1; i < n; ++i)
+        {
+            const auto k = sorted[(std::size_t) i];
+            auto j = i;
+            for (; j > 0 && sorted[(std::size_t) (j - 1)].note > k.note; --j)
+                sorted[(std::size_t) j] = sorted[(std::size_t) (j - 1)];
+            sorted[(std::size_t) j] = k;
+        }
+        detectChord (sorted, n);
+
+        keyCount = 0;
+        auto push = [&] (int note, int velocity) {
+            if (keyCount < 16)
+                keys[(std::size_t) keyCount++] = { std::clamp (note, 0, 127), velocity, 0 };
+        };
+        if (r.programMode == 1)
+        {
+            const auto* scale = activeScale (r);
+            push (r.fixedKey, 96);
+            if (scale != nullptr && scale->count > 5)
+                for (const auto d : { 2, 4, 5 })
+                    push (r.fixedKey + scale->degrees[(std::size_t) d], 96);
+            else
+            {
+                push (r.fixedKey + 5, 96);
+                push (r.fixedKey + 7, 96);
+            }
+        }
+        else if (r.order == 6 && chordIndex >= 0 && n > 0)
+        {
+            const auto& c = chords[chordIndex];
+            int v = 0;
+            for (int i = 0; i < 12; ++i)
+                if (c.mask & (1u << i))
+                    push (root + i, sorted[(std::size_t) (v++ % n)].velocity);
+            for (const auto x : c.completion)
+                if (x != 0)
+                    push (root + x, sorted[(std::size_t) (v++ % n)].velocity);
+        }
+        else if (r.order == 7 && chordIndex >= 0)
+        {
+            const auto& c = chords[chordIndex];
+            for (int i = 0; i < n; ++i)
+            {
+                const auto rel = ((sorted[(std::size_t) i].note - root) % 12 + 12) % 12;
+                if (c.mask & (1u << rel))
+                    push (root + rel, sorted[(std::size_t) i].velocity);
+            }
+        }
+        else
+        {
+            std::array<Key, 16> list = r.order == 0 || r.order == 1 || r.order >= 6 ? sorted : arp;
+            if (r.order == 4 || r.order == 5) // by velocity (ties keep their order)
+                for (int i = 1; i < n; ++i)
+                {
+                    const auto k = list[(std::size_t) i];
+                    auto j = i;
+                    for (; j > 0 && list[(std::size_t) (j - 1)].velocity > k.velocity; --j)
+                        list[(std::size_t) j] = list[(std::size_t) (j - 1)];
+                    list[(std::size_t) j] = k;
+                }
+            const auto reverse = r.order == 1 || r.order == 3 || r.order == 5;
+            for (int i = 0; i < n; ++i)
+            {
+                const auto& k = list[(std::size_t) (reverse ? n - 1 - i : i)];
+                push (k.note, k.velocity);
+            }
+        }
+        // input range wrap
+        for (int i = 0; i < keyCount; ++i)
+        {
+            auto& k = keys[(std::size_t) i].note;
+            while (k < r.wrapLow && k + 12 <= 127)
+                k += 12;
+            while (k > r.wrapHigh && k - 12 >= 0)
+                k -= 12;
+            k = std::clamp (k, std::min (r.wrapLow, r.wrapHigh), std::max (r.wrapLow, r.wrapHigh));
+        }
+        realKeys = keyCount;
+        // the missing keys N1…N5
+        filled = 0;
+        if (keyCount > 0 && keyCount < 5 && r.missing != 0)
+        {
+            const auto octave = r.missingOctave == 1 ? -12 : r.missingOctave == 2 ? 12 : 0;
+            for (int i = keyCount; i < 5; ++i)
+            {
+                Key k;
+                switch (r.missing)
+                {
+                    case 1: k = keys[(std::size_t) (i % realKeys)]; break;
+                    case 2: k = keys[0]; break;
+                    case 3: k = keys[(std::size_t) (realKeys - 1)]; break;
+                    default: k = { r.fixedKey, 96, 0 }; break;
+                }
+                k.note = std::clamp (k.note + octave, 0, 127);
+                keys[(std::size_t) i] = k;
+            }
+            filled = 5 - keyCount;
+        }
+    }
+
+    void detectChord (const std::array<Key, 16>& sorted, int n) noexcept
+    {
+        chordIndex = -1;
+        root = n > 0 ? sorted[0].note : 60;
+        int best = 0;
+        for (int b = 0; b < n; ++b)
+        {
+            const auto candidate = sorted[(std::size_t) b].note;
+            std::uint16_t mask = 0;
+            for (int i = 0; i < n; ++i)
+                mask = (std::uint16_t) (mask | (1u << (((sorted[(std::size_t) i].note - candidate) % 12 + 12) % 12)));
+            for (int c = 0; c < 38; ++c)
+            {
+                const auto& entry = chords[c];
+                if ((b == 0 || entry.inversion) && (entry.mask & ~mask) == 0 && entry.score > best)
+                {
+                    best = entry.score;
+                    chordIndex = c;
+                    root = candidate + entry.rootOffset;
+                }
+            }
+        }
+        if (chordIndex >= 0)
+            detectedScale = { chords[chordIndex].scale, chords[chordIndex].scaleCount };
+    }
+
+    const Scale* activeScale (const Runtime& r) const noexcept
+    {
+        if (r.forceScale == 1 && chordIndex >= 0)
+            return &detectedScale;
+        if (r.forceScale >= 2 && r.forceScale <= 14)
+            return &scales[r.forceScale - 2];
+        return nullptr;
+    }
+
+    // FL's pitch pipeline: scale forcing (snap down, move by scale steps), transpose, the output range
+    int pitch (int note, int scaleStep, bool force, const Runtime& r) const noexcept
+    {
+        auto key = r.forceKey - 2;
+        if (key == -1)
+            key = ((root % 12) + 12) % 12;
+        if (key == -2 && r.forceScale > 0 && keyCount > 0)
+            key = keys[0].note % 12;
+        const auto* scale = activeScale (r);
+        if (r.forceMode == 1 && scaleStep == 0)
+            force = false;
+        int n;
+        if (! force || scale == nullptr || key < 0)
+            n = note + scaleStep;
+        else
+        {
+            const auto rr = note - key + 12;
+            const auto octave = (int) std::floor (rr / 12.0) - 1;
+            const auto pc = ((rr % 12) + 12) % 12;
+            int d = 0;
+            for (int i = 0; i < scale->count; ++i)
+                if (scale->degrees[(std::size_t) i] <= pc)
+                    d = i;
+            d += scaleStep;
+            const auto carry = (int) std::floor ((double) d / scale->count);
+            d -= carry * scale->count;
+            n = std::clamp (scale->degrees[(std::size_t) d] + key + (octave + carry) * 12, 0, 127);
+        }
+        n += r.transposeSemitones + 12 * r.transposeOctaves;
+        if (n < r.outLow)
+        {
+            n += 12 * (int) std::ceil ((r.outLow - n) / 12.0);
+            if (n > r.outHigh)
+                n = r.outLow;
+        }
+        if (n > r.outHigh)
+        {
+            n -= 12 * (int) std::ceil ((n - r.outHigh) / 12.0);
+            if (n < r.outLow)
+                n = r.outHigh;
+        }
+        return std::clamp (n, 0, 127);
+    }
+
+    // --- one step ------------------------------------------------------------------------------------------------
+
+    int rand15() noexcept
+    {
+        seed ^= seed << 13;
+        seed ^= seed >> 17;
+        seed ^= seed << 5;
+        return (int) (seed & 0x7fff);
+    }
+
+    void generate (int step, int offset, const Runtime& r, EventList& out) noexcept
+    {
+        if (keyCount == 0 && r.programMode == 0)
+            return;
+        const auto s = (std::size_t) std::clamp (step, 0, 63);
+        const auto type = (int) r.lanes[S::stepType][s];
+        if (type == S::off || type == S::rest)
+            return;
+        struct Note
+        {
+            int note, velocity;
+        };
+        std::array<Note, 32> notes {};
+        int count = 0;
+        auto add = [&] (int note, int velocity) {
+            if (count < (int) notes.size())
+                notes[(std::size_t) count++] = { note, velocity };
+        };
+        if (type == S::chord)
+            for (int i = 0; i < realKeys; ++i)
+                add (keys[(std::size_t) i].note, keys[(std::size_t) i].velocity);
+        else if (type == S::random)
+        {
+            int pick = 0;
+            if (realKeys == 2)
+            {
+                pick = rand15() % 2;
+                if (pick == lastRandom && ++randomRepeats >= 3)
+                    pick = 1 - pick;
+                if (pick != lastRandom)
+                    randomRepeats = 0;
+            }
+            else if (realKeys > 2)
+            {
+                pick = rand15() % (realKeys - 1);
+                if (pick >= lastRandom && lastRandom >= 0)
+                    ++pick;
+            }
+            lastRandom = pick;
+            if (realKeys > 0)
+                add (keys[(std::size_t) pick].note, keys[(std::size_t) pick].velocity);
+        }
+        else
+        {
+            const auto select = (int) (std::uint8_t) r.lanes[S::keySelect][s];
+            const auto first = keyCount > 0 ? keys[0].velocity : 96;
+            for (int bit = 0; bit < 7; ++bit)
+            {
+                if ((select & (1 << bit)) == 0)
+                    continue;
+                if (bit == 0)
+                    add (r.fixedKey, 96);
+                else if (bit == 1)
+                    add (root, first);
+                else if (bit - 2 < keyCount + filled && bit - 2 < 5)
+                    add (keys[(std::size_t) (bit - 2)].note, keys[(std::size_t) (bit - 2)].velocity);
+            }
+        }
+        if (count == 0)
+            return;
+        // octaves (bit k = octave k − 3)
+        const auto octaves = (int) (std::uint8_t) r.lanes[S::octave][s];
+        if (r.polyOctave == 0)
+        {
+            int shift = 0;
+            for (int k = 0; k < 7; ++k)
+                if (octaves & (1 << k))
+                    shift += 12 * (k - 3);
+            for (int i = 0; i < count; ++i)
+                notes[(std::size_t) i].note += shift;
+        }
+        else
+        {
+            bool firstBit = true;
+            const auto base = notes[0];
+            for (int k = 0; k < 7; ++k)
+            {
+                if ((octaves & (1 << k)) == 0)
+                    continue;
+                if (firstBit)
+                {
+                    for (int i = 0; i < count; ++i)
+                        notes[(std::size_t) i].note += 12 * (k - 3);
+                    firstBit = false;
+                }
+                else
+                    add (base.note + 12 * (k - 3), base.velocity);
+            }
+        }
+        auto scaleStep = (int) r.lanes[S::scaleStep][s] + r.smartBend;
+        // gate (in steps)
+        auto gatePercent = (double) r.gate;
+        if (r.gateLaneMode == 0)
+            gatePercent = std::min (std::floor (std::pow (2.0, (double) r.lanes[S::gateStep][s]) * gatePercent + 0.5), r.steps * 100.0 - 1.0);
+        auto gate = gatePercent / 100.0;
+        if (r.randomGate > 0)
+            gate += r.randomGate * (rand15() - 16383) / 100.0 / 32767.0;
+        gate = std::max (0.01, gate);
+        // the following rests lengthen it; a tie makes it overlap the next note (legato)
+        for (int k = 1; k < r.steps; ++k)
+        {
+            const auto t = (int) r.lanes[S::stepType][(std::size_t) ((step + k) % std::max (1, r.steps))];
+            if (t == S::rest)
+            {
+                gate += 1.0;
+                continue;
+            }
+            if (t == S::tie && gate < 1.25)
+                gate = 1.25;
+            break;
+        }
+        double delay = 0.0;
+        if (r.randomStart > 0 && r.smartBend == 0)
+            delay = rand15() / 32767.0 * stepSamples * r.randomStart / 200.0;
+        for (int i = 0; i < count; ++i)
+        {
+            const auto note = pitch (notes[(std::size_t) i].note, scaleStep, true, r);
+            int velocity = r.lanes[S::velocity][s];
+            if (r.velocityMode == 1)
+                velocity = notes[(std::size_t) i].velocity;
+            else if (r.velocityMode == 2)
+                velocity = std::clamp (notes[(std::size_t) i].velocity + velocity - 96, 0, 127);
+            if (r.randomVelocity > 0)
+                velocity = std::clamp ((int) std::lround (velocity + r.randomVelocity * ((rand15() - 16383.5) / 32767.0) * 1.27), 0, 127);
+            start (note, velocity, offset, delay, gate * stepSamples, out);
+        }
+    }
+
+    void start (int note, int velocity, int offset, double delay, double gateSamples, EventList& out) noexcept
+    {
+        for (int i = 0; i < soundingCount; ++i)
+        {
+            auto& e = sounding[(std::size_t) i];
+            if (e.note != note)
+                continue;
+            if (e.started) // (the same pitch: retriggered)
+                off (e.id, e.note, offset, out);
+            e = { note, velocity, newId(), delay, gateSamples, false };
+            if (delay <= 0.0)
+                begin (e, offset, out);
+            return;
+        }
+        if (soundingCount >= (int) sounding.size())
+            return;
+        auto& e = sounding[(std::size_t) soundingCount++];
+        e = { note, velocity, newId(), delay, gateSamples, false };
+        if (delay <= 0.0)
+            begin (e, offset, out);
+    }
+
+    void begin (Sounding& e, int offset, EventList& out) noexcept
+    {
+        Voice v;
+        v.key = e.note;
+        v.velocity = voiceVelocity (e.velocity);
+        out.add (onEvent (offset, e.id, v));
+        e.started = true;
+    }
+
+    // one sample of the sounding notes: delayed starts, gate countdowns
+    void schedule (int offset, EventList& out) noexcept
+    {
+        for (int i = 0; i < soundingCount;)
+        {
+            auto& e = sounding[(std::size_t) i];
+            if (! e.started)
+            {
+                e.startDelay -= 1.0;
+                if (e.startDelay <= 0.0)
+                    begin (e, offset, out);
+                ++i;
+                continue;
+            }
+            e.gate -= 1.0;
+            if (e.gate < 0.01)
+            {
+                off (e.id, e.note, offset, out);
+                sounding[(std::size_t) i] = sounding[(std::size_t) --soundingCount];
+                continue;
+            }
+            ++i;
+        }
+    }
+
+    void killAll (int offset, EventList& out) noexcept
+    {
+        for (int i = 0; i < soundingCount; ++i)
+            if (sounding[(std::size_t) i].started)
+                off (sounding[(std::size_t) i].id, sounding[(std::size_t) i].note, offset, out);
+        soundingCount = 0;
+        for (int i = 0; i < thruCount; ++i)
+            off (thru[(std::size_t) i].id, thru[(std::size_t) i].note, offset, out);
+        thruCount = 0;
+    }
+
+    int newId() noexcept
+    {
+        const auto id = nextId++;
+        if (nextId > 1 << 30)
+            nextId = 1;
+        return id;
+    }
+
+    static Event onEvent (int offset, int id, const Voice& v) noexcept
+    {
+        Event e;
+        e.type = Event::Type::on;
+        e.offset = offset;
+        e.id = id;
+        e.voice = v;
+        return e;
+    }
+
+    static void off (int id, int note, int offset, EventList& out) noexcept
+    {
+        Event e;
+        e.type = Event::Type::off;
+        e.offset = offset;
+        e.id = id;
+        e.voice.key = note;
+        out.add (e);
+    }
+
+    Handoff<Runtime> settings;
+    std::array<Key, 16> held {}, arp {}, keys {};
+    int heldCount = 0, arpCount = 0, keyCount = 0, realKeys = 0, filled = 0;
+    int chordIndex = -1, root = 60;
+    std::array<Sounding, 16> sounding {};
+    int soundingCount = 0;
+    std::array<Thru, 64> thru {};
+    int thruCount = 0;
+    int nextId = 1, lastStep = -1, lastArpMode = -1, lastRandom = -1, randomRepeats = 0;
+    long long lastCell = -1, tailSamples = 0;
+    bool keysDirty = false, regenerate = false, wasPlaying = false, anchored = false, anchoredByKey = false;
+    int freeRun = 0; // 0 off, 1 running, 2 the second after the last key
+    double freeBeats = 0.0, restartOffset = 0.0, lastSongBeats = 0.0, stepSamples = 1.0, sampleRate = 44100.0;
+    std::uint32_t seed = 0x2545f491u;
+    int arrivals = 0;
+    Scale detectedScale {};
+};
+} // namespace
+
+std::unique_ptr<Processor> makeSequencer (const std::vector<std::uint8_t>& fl)
+{
+    return std::make_unique<Sequencer> (parseSequencer (fl).value_or (defaultSequencer()));
+}
+} // namespace lynx::vfx

+ 2 - 1
src/engine/ProjectFile.cpp

@@ -115,6 +115,7 @@ const char* instrumentId (InstrumentKind k)
         case InstrumentKind::midiOut: return "midiOut";
         case InstrumentKind::patcher: return "patcher";
         case InstrumentKind::soundfont: return "soundfont";
+        case InstrumentKind::vfx: return "vfx";
     }
     return "synth";
 }
@@ -129,7 +130,7 @@ InstrumentKind instrumentFromId (const juce::String& id)
                     InstrumentKind::fruitkick, InstrumentKind::bassdrum, InstrumentKind::toxic,
                     InstrumentKind::threeosc, InstrumentKind::autogun, InstrumentKind::transistorbass,
                     InstrumentKind::simsynth, InstrumentKind::wasp, InstrumentKind::plucked, InstrumentKind::beepmap, InstrumentKind::sawer, InstrumentKind::flkeys,
-                    InstrumentKind::granulizer, InstrumentKind::drumaxx, InstrumentKind::slayer, InstrumentKind::fruitydance, InstrumentKind::directwave, InstrumentKind::midiOut, InstrumentKind::patcher, InstrumentKind::soundfont })
+                    InstrumentKind::granulizer, InstrumentKind::drumaxx, InstrumentKind::slayer, InstrumentKind::fruitydance, InstrumentKind::directwave, InstrumentKind::midiOut, InstrumentKind::patcher, InstrumentKind::soundfont, InstrumentKind::vfx })
         if (id == instrumentId (k))
             return k;
 

+ 10 - 1
src/ui/BrowserComponent.cpp

@@ -8,6 +8,7 @@
 #include "core/SearchQuery.h"
 #include "core/SearchService.h"
 #include "core/ValueMath.h"
+#include "core/Vfx.h"
 #include "platform/Paths.h"
 
 #include <mutex>
@@ -428,6 +429,14 @@ public:
                 if (natives::available (e, fl))
                     generatorEntry (*flGens, flEngineName (e), tr ("built-in FL engine"), Icon::keyboard,
                                     [kind = e.kind] { return std::optional<ChannelDef> (natives::makeChannel (kind, flStudioAccess())); });
+            // FL's VFX note processors (round 164b): channels with no sound, they play other channels / Patcher nodes
+            auto vfxGens = folder (gens.get(), tr ("VFX (note effects)"), Icon::folder);
+            for (const auto kind : vfx::allKinds)
+                generatorEntry (*vfxGens, vfx::flName (kind), tr ("built-in"), Icon::keyboard, [kind] {
+                    ChannelDef c;
+                    vfx::makeChannel (c, kind);
+                    return std::optional<ChannelDef> (c);
+                });
             auto installed = folder (gens.get(), tr ("Installed"), Icon::folder);
             for (const auto& t : types)
                 if (t.isInstrument)
@@ -440,7 +449,7 @@ public:
                                         c.plugin.name = name;
                                         return std::optional<ChannelDef> (c);
                                     });
-            for (auto* f : { &lynxGens, &flGens, &installed })
+            for (auto* f : { &lynxGens, &flGens, &vfxGens, &installed })
                 if (! (*f)->children.empty())
                     gens->children.push_back (std::move (*f));
             root->children.push_back (std::move (gens));

+ 18 - 1
src/ui/ChannelRackComponent.cpp

@@ -25,6 +25,7 @@
 #include "ui/AudioEditor.h"
 #include "core/RackOps.h"
 #include "core/SoundFont.h"
+#include "core/Vfx.h"
 #include "ui/SoundFontEditor.h"
 
 namespace lynx
@@ -79,6 +80,7 @@ juce::String instrumentName (InstrumentKind k)
         case InstrumentKind::midiOut: return "MIDI Out";
         case InstrumentKind::patcher: return "Patcher";
         case InstrumentKind::soundfont: return "LYNX Soundfont";
+        case InstrumentKind::vfx: return "VFX";
     }
     return "?";
 }
@@ -2110,6 +2112,18 @@ void ChannelRackComponent::addInstrumentItems (juce::PopupMenu& menu, int insert
         });
         menu.addSubMenu (tr ("FL engines"), engines);
     }
+    // FL's VFX note processors (round 164b): no sound of their own, their outputs go out on MIDI ports
+    {
+        juce::PopupMenu vfxMenu;
+        for (const auto kind : vfx::allKinds)
+            vfxMenu.addItem (vfx::flName (kind), [this, add, kind] {
+                ChannelDef c;
+                vfx::makeChannel (c, kind);
+                const auto added = add (c);
+                openChannelSettings (engine, added);
+            });
+        menu.addSubMenu (tr ("VFX (note effects)"), vfxMenu);
+    }
     // FL's Patcher as a generator (REA_rodada141): an empty graph, its editor opens
     menu.addItem (tr ("Patcher"), [this, add] {
         ChannelDef c;
@@ -2137,7 +2151,10 @@ void ChannelRackComponent::addInstrumentItems (juce::PopupMenu& menu, int insert
         const auto added = add (c);
         openPluginWindow (added); // the plugin opens when added
         openEditorRow = added;
-    }, this);
+    }, this, [this, add] (ChannelDef c) {
+        const auto added = add (c);
+        openChannelSettings (engine, added);
+    });
     menu.addSubMenu (tr ("Plugin (VST/VST3/CLAP)"), plugins);
 }
 

+ 4 - 0
src/ui/ChannelSettings.cpp

@@ -42,6 +42,7 @@
 #include "ui/Theme.h"
 #include "ui/WaveformView.h"
 #include "ui/SoundFontEditor.h"
+#include "ui/VfxEditors.h"
 
 namespace lynx
 {
@@ -3265,6 +3266,7 @@ bool hasChannelSettings (InstrumentKind kind) noexcept
         case InstrumentKind::fruitydance:
         case InstrumentKind::sytrus:
         case InstrumentKind::soundfont:
+        case InstrumentKind::vfx:
             return true;
         default:
             return false;
@@ -3311,6 +3313,8 @@ std::unique_ptr<juce::Component> makeChannelSettingsPanel (AudioEngine& engine,
         return makeMidiOutEditor (engine, channel);
     if (engine.getSong().channels[(std::size_t) channel].instrument == InstrumentKind::soundfont)
         return makeSoundFontEditor (engine, channel);
+    if (engine.getSong().channels[(std::size_t) channel].instrument == InstrumentKind::vfx)
+        return makeVfxEditor (engine, channel);
     if (const auto kind = engine.getSong().channels[(std::size_t) channel].instrument;
         kind == InstrumentKind::sakura || kind == InstrumentKind::drumpad || kind == InstrumentKind::boobass
                  || kind == InstrumentKind::drumsynth || kind == InstrumentKind::harmless || kind == InstrumentKind::harmor

+ 520 - 65
src/ui/I18nData.h

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

+ 41 - 5
src/ui/PatcherEditor.cpp

@@ -11,6 +11,7 @@
 #include "core/NativeEngines.h"
 #include "core/SoundFont.h"
 #include "core/Patcher.h"
+#include "core/Vfx.h"
 #include "engine/PluginHost.h"
 #include "ui/I18n.h"
 #include "ui/MixerComponent.h"
@@ -20,6 +21,7 @@
 #include "ui/PluginWindow.h"
 #include "ui/Theme.h"
 #include "ui/ToolWindow.h"
+#include "ui/VfxEditors.h"
 
 namespace lynx
 {
@@ -817,8 +819,20 @@ private:
         };
         if (ports.midiIn)
             add (false, PatchWire::Kind::midi, 0, tr ("Notes"));
-        if (ports.midiOut) // a MIDI Out node's notes (round 162)
-            add (true, PatchWire::Kind::midi, 0, tr ("MIDI out"));
+        if (ports.midiOut) // a MIDI Out node's notes (round 162); a VFX node's voice outputs (round 164b)
+        {
+            const auto kind = vfx::kindOf (node.channel);
+            const auto shown = kind ? patcher::shownMidiOutputs (d, n) : 1;
+            std::optional<vfx::KeyboardSplitterSettings> zones; // (the Keyboard Splitter's outputs carry the zones' names)
+            if (kind == vfx::Kind::keyboardSplitter)
+                if (const auto st = vfx::readState (node.channel.pluginState))
+                    zones = vfx::parseKeyboardSplitter (st->fl);
+            for (int o = 0; o < shown; ++o)
+                add (true, PatchWire::Kind::midi, o,
+                     zones && o < 16 && ! zones->zones[(std::size_t) o].name.empty() ? juce::String::fromUTF8 (zones->zones[(std::size_t) o].name.c_str())
+                     : kind ? juce::String (vfx::outputName (*kind, o))
+                            : tr ("MIDI out"));
+        }
         for (int i = 0; i < ports.audioIns; ++i)
             add (false, PatchWire::Kind::audio, i, i == 0 ? tr ("In") : tr ("Side-chain"));
         const auto splitter = ! node.generator && node.effect.kind == EffectKind::frequencySplitter && node.busHeads.empty();
@@ -881,7 +895,8 @@ private:
         else
         {
             const auto ports = patcher::nodePorts (d.nodes[(std::size_t) n]);
-            rows = std::max ({ 1, ports.audioIns + (ports.midiIn ? 1 : 0), ports.audioOuts + ports.controlOuts + (ports.midiOut ? 1 : 0) });
+            const auto midiOuts = ! ports.midiOut ? 0 : vfx::kindOf (d.nodes[(std::size_t) n].channel) ? patcher::shownMidiOutputs (d, n) : 1;
+            rows = std::max ({ 1, ports.audioIns + (ports.midiIn ? 1 : 0), ports.audioOuts + ports.controlOuts + midiOuts });
         }
         return { at.x, at.y, nodeWidth, headerHeight + (float) rows * pinSpacing + 4.0f };
     }
@@ -1239,6 +1254,14 @@ public:
                                                                    addNode (n, at);
                                                                } });
 
+        // FL's VFX note processors (round 164b): FL files them under Effects / Patcher
+        for (const auto kind : vfx::allKinds)
+            effects[tr ("Patcher")].push_back ({ vfx::flName (kind), true, [addChannel, kind] {
+                                                   ChannelDef c;
+                                                   vfx::makeChannel (c, kind);
+                                                   addChannel (c);
+                                               } });
+
         juce::PopupMenu pluginEffects, pluginInstruments;
         addPluginItems (pluginEffects, engine, false, [this, at] (PluginRef ref) {
             PatchNode n;
@@ -1253,7 +1276,7 @@ public:
             n.channel.name = ref.name;
             n.channel.plugin = ref;
             addNode (n, at);
-        }, this);
+        }, this, addChannel);
 
         juce::PopupMenu add;
         float rows = 0.0f; // (a section header is a bit taller than an item)
@@ -1330,6 +1353,14 @@ private:
     void pickPlugin (bool instruments, juce::Point<float> at)
     {
         juce::Component::SafePointer<PatcherEditor> safe (this);
+        auto builtIn = [safe, at] (ChannelDef c) {
+            if (safe == nullptr)
+                return;
+            PatchNode n;
+            n.generator = true;
+            n.channel = std::move (c);
+            safe->addNode (n, at);
+        };
         showPluginPicker (engine, instruments, [safe, instruments, at] (PluginRef ref) {
             if (safe == nullptr)
                 return;
@@ -1347,7 +1378,7 @@ private:
                 n.effect.plugin = ref;
             }
             safe->addNode (n, at);
-        });
+        }, builtIn);
     }
 
     void chooseSampleNode (juce::Point<float> at)
@@ -1736,6 +1767,11 @@ private:
             openToolWindow (makeMidiOutEditor (engine, locate), title + " - " + tr ("Patcher"), target.key() + "-node-" + juce::String (n));
             return;
         }
+        if (node.generator && node.channel.instrument == InstrumentKind::vfx)
+        {
+            openToolWindow (makeVfxEditor (engine, locate, -1), title + " - " + tr ("Patcher"), target.key() + "-node-" + juce::String (n));
+            return;
+        }
         if (node.generator && node.channel.instrument == InstrumentKind::controller && ! parseKeyboardController (node.channel.controllerState))
         {
             openToolWindow (makeEnvelopeControllerEditor (engine, locate), title + " - " + tr ("Patcher"), target.key() + "-node-" + juce::String (n));

+ 22 - 4
src/ui/PluginPicker.cpp

@@ -1,6 +1,7 @@
 #include "ui/PluginPicker.h"
 
 #include "core/PluginCatalog.h"
+#include "core/Vfx.h"
 #include "ui/I18n.h"
 #include "ui/PluginManager.h"
 #include "ui/TextCache.h"
@@ -33,12 +34,15 @@ class PluginPicker final : public juce::Component,
                            private juce::KeyListener
 {
 public:
-    PluginPicker (AudioEngine& e, bool instruments, std::function<void (PluginRef)> chosen)
-        : engine (e), onChosen (std::move (chosen))
+    PluginPicker (AudioEngine& e, bool instruments, std::function<void (PluginRef)> chosen, std::function<void (ChannelDef)> builtIn)
+        : engine (e), onChosen (std::move (chosen)), onBuiltIn (std::move (builtIn))
     {
         for (const auto& type : engine.getPluginHost().getKnownPlugins().getTypes())
             entries.push_back ({ type.createIdentifierString().toStdString(), type.name.toStdString(), type.manufacturerName.toStdString(),
                                  type.pluginFormatName.toStdString(), type.category.toStdString(), type.isInstrument });
+        if (onBuiltIn) // FL's VFX note effects, built in (round 164b)
+            for (const auto kind : vfx::allKinds)
+                entries.push_back ({ builtInPrefix + std::to_string ((int) kind), vfx::flName (kind), "LYNX", "Built-in", "Note effect", true });
 
         for (auto* b : { &instrumentsTab, &effectsTab })
         {
@@ -357,6 +361,17 @@ private:
         if (row < 0 || row >= (int) shown.size() || ! onChosen)
             return;
         const auto& e = entries[(std::size_t) shown[(std::size_t) row]];
+        if (e.id.rfind (builtInPrefix, 0) == 0)
+        {
+            ChannelDef c;
+            vfx::makeChannel (c, (vfx::Kind) std::stoi (e.id.substr (builtInPrefix.size())));
+            auto chosen = std::move (onBuiltIn);
+            onChosen = nullptr;
+            closeToolWindowOf (*this);
+            if (chosen)
+                chosen (std::move (c));
+            return;
+        }
         PluginRef ref;
         ref.id = e.id;
         ref.name = e.name;
@@ -397,6 +412,8 @@ private:
 
     AudioEngine& engine;
     std::function<void (PluginRef)> onChosen;
+    std::function<void (ChannelDef)> onBuiltIn;
+    inline static const std::string builtInPrefix = "lynx:vfx:";
     std::vector<plugincatalog::Entry> entries;
     std::vector<int> shown;
     std::vector<Group> groupRows;
@@ -411,8 +428,9 @@ private:
 };
 } // namespace
 
-void showPluginPicker (AudioEngine& engine, bool instruments, std::function<void (PluginRef)> onChosen)
+void showPluginPicker (AudioEngine& engine, bool instruments, std::function<void (PluginRef)> onChosen, std::function<void (ChannelDef)> onBuiltIn)
 {
-    openToolWindow (std::make_unique<PluginPicker> (engine, instruments, std::move (onChosen)), tr ("Plugin picker"), "pluginpicker");
+    openToolWindow (std::make_unique<PluginPicker> (engine, instruments, std::move (onChosen), instruments ? std::move (onBuiltIn) : nullptr),
+                    tr ("Plugin picker"), "pluginpicker");
 }
 } // namespace lynx

+ 4 - 1
src/ui/PluginPicker.h

@@ -14,5 +14,8 @@ namespace lynx
 // favourite star (click it), name, vendor, format and category; typing filters (every word must match). Double-click
 // or Enter adds the highlighted plugin; "Manage plugins..." opens the Plugin manager, "Scan" looks for new ones.
 // One picker at a time (a tool window); `onChosen` runs once, then the picker closes.
-void showPluginPicker (AudioEngine& engine, bool instruments, std::function<void (PluginRef)> onChosen);
+// `onBuiltIn` (instruments only): LYNX's built-in note effects (FL's VFX, round 164b) are listed too, as "LYNX"
+// entries; choosing one hands over a new channel of it.
+void showPluginPicker (AudioEngine& engine, bool instruments, std::function<void (PluginRef)> onChosen,
+                       std::function<void (ChannelDef)> onBuiltIn = nullptr);
 } // namespace lynx

+ 15 - 7
src/ui/PluginWindow.cpp

@@ -776,7 +776,8 @@ juce::PopupMenu pluginProcessingMenu (AudioEngine& engine, const PluginRef& curr
     return menu;
 }
 
-void addPluginItems (juce::PopupMenu& menu, AudioEngine& engine, bool instruments, std::function<void (PluginRef)> onChosen, juce::Component* owner)
+void addPluginItems (juce::PopupMenu& menu, AudioEngine& engine, bool instruments, std::function<void (PluginRef)> onChosen, juce::Component* owner,
+                     std::function<void (ChannelDef)> onBuiltIn)
 {
     // FL's way (round 151): the favourites right here, every other plugin in the picker ("More plugins...", FL's
     // list of every generator / effect with its categories, search and favourite stars). The old menu listed all
@@ -801,15 +802,22 @@ void addPluginItems (juce::PopupMenu& menu, AudioEngine& engine, bool instrument
     if (menu.getNumItems() > 0)
         menu.addSeparator();
 
-    if (kind == 0)
+    if (kind == 0 && ! onBuiltIn)
         menu.addItem (tr ("(no plugins found; use \"Scan for plugins\")"), false, false, [] {});
     else
         menu.addItem (instruments ? tr ("More plugins... ({0} instruments)", { juce::String (kind) }) : tr ("More plugins... ({0} effects)", { juce::String (kind) }),
-                      [&engine, instruments, onChosen, safe = juce::Component::SafePointer<juce::Component> (owner), hasOwner = owner != nullptr] {
-                          showPluginPicker (engine, instruments, [onChosen, safe, hasOwner] (PluginRef ref) {
-                              if (! hasOwner || safe != nullptr)
-                                  onChosen (ref);
-                          });
+                      [&engine, instruments, onChosen, onBuiltIn, safe = juce::Component::SafePointer<juce::Component> (owner), hasOwner = owner != nullptr] {
+                          showPluginPicker (
+                              engine, instruments,
+                              [onChosen, safe, hasOwner] (PluginRef ref) {
+                                  if (! hasOwner || safe != nullptr)
+                                      onChosen (ref);
+                              },
+                              ! onBuiltIn ? std::function<void (ChannelDef)>()
+                                          : [onBuiltIn, safe, hasOwner] (ChannelDef c) {
+                                                if (! hasOwner || safe != nullptr)
+                                                    onBuiltIn (std::move (c));
+                                            });
                       });
 
     menu.addSeparator();

+ 2 - 1
src/ui/PluginWindow.h

@@ -49,6 +49,7 @@ juce::PopupMenu pluginProcessingMenu (AudioEngine& engine, const PluginRef& curr
 // Menus of known plugins (instruments or effects): the favourites, then "More plugins..." (the plugin picker) and
 // the scan. `onChosen` receives the reference; from the picker (a window of its own, chosen later) it is only
 // called while `owner` (the component whose menu this is) still exists.
+// `onBuiltIn`: the picker lists LYNX's built-in note effects too (core/Vfx.h) and hands a new channel of one over.
 void addPluginItems (juce::PopupMenu& menu, AudioEngine& engine, bool instruments, std::function<void (PluginRef)> onChosen,
-                     juce::Component* owner = nullptr);
+                     juce::Component* owner = nullptr, std::function<void (ChannelDef)> onBuiltIn = nullptr);
 } // namespace lynx

+ 2345 - 0
src/ui/VfxEditors.cpp

@@ -0,0 +1,2345 @@
+#include "ui/VfxEditors.h"
+
+#include <algorithm>
+#include <array>
+
+#include "core/Vfx.h"
+#include "engine/Text.h"
+#include "ui/I18n.h"
+#include "ui/Theme.h"
+#include "ui/ToolWindow.h"
+#include "ui/ValueControl.h"
+
+namespace lynx
+{
+namespace
+{
+juce::String keyName (int key)
+{
+    return juce::MidiMessage::getMidiNoteName (std::clamp (key, 0, 127), true, true, 4);
+}
+
+juce::String pitchClassName (int pc)
+{
+    static const char* names[] = { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" };
+    return names[((pc % 12) + 12) % 12];
+}
+
+// A small knob with LYNX's control contract (drag, Ctrl = fine, wheel, Alt / middle-click / double-click reset,
+// right-click: type a value / reset)
+class Knob final : public juce::Component
+{
+public:
+    Knob (ui::ValueSpec s, std::function<double()> get, std::function<void (double)> set)
+        : spec (std::move (s)), getter (std::move (get)), setter (std::move (set))
+    {
+        setRepaintsOnMouseActivity (true);
+        ui::setHint (*this, spec.name, true, false);
+    }
+
+    void paint (juce::Graphics& g) override
+    {
+        const auto value = getter();
+        if (box) // (a value box: the caption above, the value in a field; dragged like the knob)
+        {
+            auto area = getLocalBounds().toFloat();
+            g.setColour (theme::colour::textSecondary);
+            g.setFont (theme::font (theme::type::caption));
+            g.drawText (caption, area.removeFromTop (15.0f), juce::Justification::centredLeft);
+            g.setColour (isMouseOverOrDragging() ? theme::colour::bg5 : theme::colour::bg4);
+            g.fillRoundedRectangle (area, 3.0f);
+            g.setColour (theme::colour::textPrimary);
+            g.setFont (theme::font (theme::type::small));
+            g.drawText (spec.text (value), area, juce::Justification::centred);
+            return;
+        }
+        const auto v = juce::jlimit (0.0, 1.0, (value - spec.minimum) / juce::jmax (1e-9, spec.maximum - spec.minimum));
+        auto area = getLocalBounds().toFloat();
+        const auto label = area.removeFromBottom (14.0f);
+        const auto valueArea = area.removeFromBottom (13.0f);
+        const auto size = juce::jmin (area.getWidth(), area.getHeight()) - 4.0f;
+        const auto box = juce::Rectangle<float> (size, size).withCentre (area.getCentre());
+        constexpr float sweep = juce::MathConstants<float>::pi * 1.5f;
+        g.setColour (theme::colour::bg4);
+        g.fillEllipse (box.reduced (4.0f));
+        juce::Path track, arc;
+        const auto radius = size * 0.5f - 1.5f;
+        track.addCentredArc (box.getCentreX(), box.getCentreY(), radius, radius, 0.0f, -sweep * 0.5f, sweep * 0.5f, true);
+        g.setColour (theme::colour::knobTrack);
+        g.strokePath (track, juce::PathStrokeType (3.0f));
+        // bipolar knobs light from the centre
+        const auto bipolar = spec.minimum < 0.0 && spec.maximum > 0.0;
+        const auto from = bipolar ? 0.5 : 0.0;
+        arc.addCentredArc (box.getCentreX(), box.getCentreY(), radius, radius, 0.0f, -sweep * 0.5f + sweep * (float) std::min (from, v),
+                           -sweep * 0.5f + sweep * (float) std::max (from, v), true);
+        g.setColour (isMouseOverOrDragging() ? theme::colour::accent : theme::colour::knobArc);
+        g.strokePath (arc, juce::PathStrokeType (3.0f));
+        const auto angle = -sweep * 0.5f + sweep * (float) v;
+        const auto tip = box.getCentre() + juce::Point<float> (std::sin (angle), -std::cos (angle)) * (radius - 5.0f);
+        g.drawLine (box.getCentreX(), box.getCentreY(), tip.x, tip.y, 2.0f);
+        g.setColour (theme::colour::textPrimary);
+        g.setFont (theme::font (theme::type::caption));
+        g.drawText (spec.text (value), valueArea, juce::Justification::centred);
+        g.setColour (theme::colour::textSecondary);
+        g.drawText (caption, label, juce::Justification::centred);
+    }
+
+    void mouseDown (const juce::MouseEvent& e) override
+    {
+        if (e.mods.isPopupMenu())
+        {
+            ui::showValueMenu (*this, nullptr, spec, getter(), [this] (double v) { change (v); });
+            return;
+        }
+        if (ui::isResetClick (e))
+        {
+            change (spec.defaultValue);
+            return;
+        }
+        drag.begin (e, getter());
+    }
+    void mouseDrag (const juce::MouseEvent& e) override
+    {
+        if (drag.isActive())
+            change (drag.update (e, spec));
+    }
+    void mouseUp (const juce::MouseEvent&) override { drag.end(); }
+    void mouseDoubleClick (const juce::MouseEvent&) override { change (spec.defaultValue); }
+    void mouseWheelMove (const juce::MouseEvent& e, const juce::MouseWheelDetails& w) override
+    {
+        if (const auto v = ui::wheelValue (getter(), e, w, spec))
+            change (*v);
+    }
+
+    juce::String caption;
+    bool box = false;
+
+private:
+    void change (double v)
+    {
+        v = juce::jlimit (spec.minimum, spec.maximum, v);
+        if (spec.interval > 0.0)
+            v = spec.minimum + std::round ((v - spec.minimum) / spec.interval) * spec.interval;
+        setter (v);
+        repaint();
+    }
+
+    ui::ValueSpec spec;
+    std::function<double()> getter;
+    std::function<void (double)> setter;
+    ui::ValueDrag drag;
+};
+
+ui::ValueSpec intSpec (const juce::String& name, int lo, int hi, int def, std::function<juce::String (double)> text = nullptr)
+{
+    ui::ValueSpec s;
+    s.name = name;
+    s.minimum = lo;
+    s.maximum = hi;
+    s.defaultValue = def;
+    s.interval = 1.0;
+    s.pixelsForRange = std::clamp ((double) (hi - lo) * 6.0, 120.0, 300.0);
+    if (text)
+    {
+        s.toText = text;
+        s.fromText = ui::inverseOf (text, lo, hi);
+    }
+    else
+        s.toText = [] (double v) { return juce::String ((int) std::lround (v)); };
+    return s;
+}
+
+// What every body gets: the plugin's FL state and a way to change it
+class Body : public juce::Component
+{
+public:
+    using Edit = std::function<void (std::vector<std::uint8_t>&)>;
+    std::function<void (Edit)> edit;
+    virtual void refresh (const std::vector<std::uint8_t>& fl) = 0;
+    virtual int preferredHeight() const { return 300; }
+    virtual int preferredWidth() const { return 700; }
+};
+
+// ---------------------------------------------------------------------------------------------------------------
+// VFX Key Mapper: inputs (one octave) down, outputs across; the controls above
+
+class KeyMapperBody final : public Body
+{
+public:
+    static constexpr int lowest = -12, columns = 36; // outputs: an octave below the row's octave to an octave above (FL's range)
+
+    KeyMapperBody()
+    {
+        enable.setButtonText (tr ("Enable"));
+        enable.onClick = [this] { change ([on = enable.getToggleState()] (vfx::KeyMapperSettings& s) { s.enabled = on; }); };
+        addAndMakeVisible (enable);
+        for (const auto& [id, text] : std::vector<std::pair<int, juce::String>> {
+                 { 1, tr ("All") }, { 2, tr ("All (gain-compensated)") }, { 3, tr ("Random") }, { 4, tr ("Cycle up") }, { 5, tr ("Cycle down") } })
+            multimode.addItem (text, id);
+        multimode.onChange = [this] { change ([m = multimode.getSelectedId() - 1] (vfx::KeyMapperSettings& s) { s.multimode = std::max (0, m); }); };
+        ui::setHint (multimode, tr ("Multimode: how an input mapped to several notes plays them"));
+        addAndMakeVisible (multimode);
+        multimodeLabel.setText (tr ("Multimode"), juce::dontSendNotification);
+        multimodeLabel.setFont (theme::font (theme::type::small));
+        addAndMakeVisible (multimodeLabel);
+
+        offset.caption = tr ("Offset");
+        baseKey.caption = tr ("Base key");
+        slide.caption = tr ("Pitch slide");
+        addAndMakeVisible (offset);
+        addAndMakeVisible (baseKey);
+        addAndMakeVisible (slide);
+    }
+
+    void refresh (const std::vector<std::uint8_t>& fl) override
+    {
+        settings = vfx::parseKeyMapper (fl).value_or (vfx::defaultKeyMapper());
+        enable.setToggleState (settings.enabled, juce::dontSendNotification);
+        multimode.setSelectedId (std::clamp (settings.multimode, 0, 4) + 1, juce::dontSendNotification);
+        repaint();
+        offset.repaint();
+        baseKey.repaint();
+        slide.repaint();
+    }
+
+    int preferredHeight() const override { return 64 + 12 * 22 + 30; }
+    int preferredWidth() const override { return 64 + columns * 15 + 16; }
+
+    void resized() override
+    {
+        auto top = getLocalBounds().reduced (8, 4).removeFromTop (60);
+        enable.setBounds (top.removeFromLeft (90).withSizeKeepingCentre (90, 24));
+        top.removeFromLeft (8);
+        offset.setBounds (top.removeFromLeft (64));
+        baseKey.setBounds (top.removeFromLeft (64));
+        slide.setBounds (top.removeFromLeft (64));
+        top.removeFromLeft (16);
+        auto mm = top.removeFromLeft (200);
+        multimodeLabel.setBounds (mm.removeFromTop (22));
+        multimode.setBounds (mm.removeFromTop (24));
+    }
+
+    void paint (juce::Graphics& g) override
+    {
+        const auto grid = gridArea();
+        g.setColour (theme::colour::bg0);
+        g.fillRect (grid);
+        const auto cw = grid.getWidth() / (float) columns, rh = grid.getHeight() / 12.0f;
+        // output columns: the octaves and the black keys, labelled every C
+        for (int c = 0; c < columns; ++c)
+        {
+            const auto value = lowest + c;
+            const auto pc = ((value % 12) + 12) % 12;
+            const auto black = pc == 1 || pc == 3 || pc == 6 || pc == 8 || pc == 10;
+            const juce::Rectangle<float> col (grid.getX() + (float) c * cw, grid.getY(), cw, grid.getHeight());
+            if (value >= 0 && value < 12) // the row's own octave, brighter (as FL draws it)
+            {
+                g.setColour (theme::colour::bg2);
+                g.fillRect (col);
+            }
+            if (black)
+            {
+                g.setColour (theme::colour::bg0.withAlpha (0.55f));
+                g.fillRect (col);
+            }
+            g.setColour (pc == 0 ? theme::colour::borderStrong : theme::colour::border);
+            g.drawVerticalLine ((int) col.getX(), grid.getY(), grid.getBottom());
+            if (pc == 0)
+            {
+                g.setColour (theme::colour::textSecondary);
+                g.setFont (theme::font (theme::type::caption));
+                const auto octave = value / 12;
+                const auto name = pitchClassName (settings.baseKey);
+                g.drawText (octave == 0 ? name : (octave > 0 ? name + " +" + juce::String (octave) : name + " " + juce::String (octave)),
+                            juce::Rectangle<float> (col.getX() + 2.0f, grid.getBottom() + 2.0f, 40.0f, 14.0f), juce::Justification::centredLeft);
+            }
+        }
+        // input rows (top = B, bottom = C, as a keyboard on its side)
+        for (int r = 0; r < 12; ++r)
+        {
+            const auto pc = 11 - r;
+            const juce::Rectangle<float> row (grid.getX(), grid.getY() + (float) r * rh, grid.getWidth(), rh);
+            g.setColour (theme::colour::border);
+            g.drawHorizontalLine ((int) row.getY(), grid.getX(), grid.getRight());
+            const auto black = pc == 1 || pc == 3 || pc == 6 || pc == 8 || pc == 10;
+            const juce::Rectangle<float> label (4.0f, row.getY(), grid.getX() - 8.0f, rh);
+            g.setColour (black ? theme::colour::bg4 : theme::colour::bg6);
+            g.fillRoundedRectangle (label.reduced (1.0f, 1.5f), 2.0f);
+            g.setColour (theme::colour::textPrimary);
+            g.setFont (theme::font (theme::type::small));
+            g.drawText (pitchClassName (pc + settings.baseKey), label.reduced (6.0f, 0.0f), juce::Justification::centredLeft);
+            // the unchanged note (a faint diagonal)
+            g.setColour (theme::colour::bg5.withAlpha (0.55f));
+            g.fillRect (cell (pc, pc).reduced (cw * 0.35f, rh * 0.35f));
+            for (const auto value : settings.rows[(std::size_t) pc])
+            {
+                const auto c = cell (pc, value);
+                if (c.isEmpty())
+                    continue;
+                g.setColour (settings.enabled ? theme::colour::accent : theme::colour::textDisabled);
+                g.fillRoundedRectangle (c.reduced (1.5f), 2.5f);
+            }
+        }
+        g.setColour (theme::colour::borderStrong);
+        g.drawRect (grid);
+        if (hover.has_value())
+        {
+            g.setColour (theme::colour::textPrimary.withAlpha (0.5f));
+            g.drawRect (cell (hover->first, hover->second), 1.0f);
+        }
+    }
+
+    void mouseMove (const juce::MouseEvent& e) override
+    {
+        auto now = cellAt (e.position);
+        if (now != hover)
+        {
+            hover = now;
+            if (hover)
+                ui::setHint (*this, tr ("{0} plays {1} - left-click: add / remove, right-click: only this note, middle-click or Alt+click: reset the row",
+                                        { pitchClassName (hover->first + settings.baseKey), outputName (hover->first, hover->second) }));
+            repaint();
+        }
+    }
+    void mouseExit (const juce::MouseEvent&) override
+    {
+        hover.reset();
+        repaint();
+    }
+
+    void mouseDown (const juce::MouseEvent& e) override
+    {
+        if (const auto grid = gridArea(); e.position.x < grid.getX() && e.position.y >= grid.getY() && e.position.y < grid.getBottom())
+        {
+            // a click on a row's label: back to the note itself
+            const auto pc = 11 - std::clamp ((int) ((e.position.y - grid.getY()) / (grid.getHeight() / 12.0f)), 0, 11);
+            change ([pc] (vfx::KeyMapperSettings& s) { s.rows[(std::size_t) pc] = { pc }; });
+            return;
+        }
+        const auto at = cellAt (e.position);
+        if (! at)
+            return;
+        const auto [pc, value] = *at;
+        if (e.mods.isMiddleButtonDown() || e.mods.isAltDown())
+            change ([pc] (vfx::KeyMapperSettings& s) { s.rows[(std::size_t) pc] = { pc }; });
+        else if (e.mods.isPopupMenu())
+            change ([pc, value] (vfx::KeyMapperSettings& s) { s.rows[(std::size_t) pc] = { value }; });
+        else
+            change ([pc, value] (vfx::KeyMapperSettings& s) {
+                auto& row = s.rows[(std::size_t) pc];
+                if (auto it = std::find (row.begin(), row.end(), value); it != row.end())
+                    row.erase (it);
+                else
+                    row.push_back (value); // (FL keeps the order: Cycle and Random follow it)
+            });
+    }
+
+private:
+    juce::Rectangle<float> gridArea() const
+    {
+        return getLocalBounds().toFloat().withTrimmedTop (68.0f).withTrimmedLeft (56.0f).withTrimmedRight (8.0f).withTrimmedBottom (20.0f);
+    }
+    juce::Rectangle<float> cell (int pc, int value) const
+    {
+        const auto grid = gridArea();
+        const auto c = value - lowest;
+        if (c < 0 || c >= columns)
+            return {};
+        const auto cw = grid.getWidth() / (float) columns, rh = grid.getHeight() / 12.0f;
+        return { grid.getX() + (float) c * cw, grid.getY() + (float) (11 - pc) * rh, cw, rh };
+    }
+    std::optional<std::pair<int, int>> cellAt (juce::Point<float> p) const
+    {
+        const auto grid = gridArea();
+        if (! grid.contains (p))
+            return std::nullopt;
+        const auto c = (int) ((p.x - grid.getX()) / (grid.getWidth() / (float) columns));
+        const auto r = (int) ((p.y - grid.getY()) / (grid.getHeight() / 12.0f));
+        return std::make_pair (11 - std::clamp (r, 0, 11), lowest + std::clamp (c, 0, columns - 1));
+    }
+    juce::String outputName (int pc, int value) const
+    {
+        const auto shift = value - pc;
+        return pitchClassName (value + settings.baseKey) + " (" + (shift > 0 ? "+" : "") + juce::String (shift) + ")";
+    }
+
+    void change (std::function<void (vfx::KeyMapperSettings&)> f)
+    {
+        if (edit)
+            edit ([f] (std::vector<std::uint8_t>& fl) {
+                auto s = vfx::parseKeyMapper (fl).value_or (vfx::defaultKeyMapper());
+                f (s);
+                fl = vfx::writeKeyMapper (s);
+            });
+    }
+
+    vfx::KeyMapperSettings settings = vfx::defaultKeyMapper();
+    juce::ToggleButton enable;
+    juce::ComboBox multimode;
+    juce::Label multimodeLabel;
+    Knob offset { intSpec (tr ("Offset (transpose)"), -12, 12, 0, [] (double v) { return (v > 0 ? "+" : "") + juce::String ((int) std::lround (v)); }),
+                  [this] { return (double) settings.offset; },
+                  [this] (double v) { change ([v] (vfx::KeyMapperSettings& s) { s.offset = (int) std::lround (v); }); } };
+    Knob baseKey { intSpec (tr ("Base key: the note the rows and their octaves start on"), 0, 11, 0, [] (double v) { return pitchClassName ((int) std::lround (v)); }),
+                   [this] { return (double) settings.baseKey; },
+                   [this] (double v) { change ([v] (vfx::KeyMapperSettings& s) { s.baseKey = (int) std::lround (v); }); } };
+    Knob slide { intSpec (tr ("Pitch slide: the new notes start at the played pitch and glide to their own (in steps)"), 0, 192, 0,
+                          [] (double v) { const auto u = (int) std::lround (v); return juce::String (u / 48) + ":" + juce::String (u % 48).paddedLeft ('0', 2); }),
+                 [this] { return (double) settings.slide; },
+                 [this] (double v) { change ([v] (vfx::KeyMapperSettings& s) { s.slide = (int) std::lround (v); }); } };
+    std::optional<std::pair<int, int>> hover;
+};
+
+// ---------------------------------------------------------------------------------------------------------------
+// VFX Color Mapper: per note colour, the voice output it goes to and the colour it leaves with
+
+class ColorMapperBody final : public Body
+{
+public:
+    ColorMapperBody()
+    {
+        for (int c = 0; c < 16; ++c)
+        {
+            auto& port = ports[(std::size_t) c];
+            auto& colour = colours[(std::size_t) c];
+            for (int k = 0; k < 16; ++k)
+            {
+                port.addItem (tr ("Voice {0}", { juce::String (k + 1) }), k + 1);
+                colour.addItem (tr ("Colour {0}", { juce::String (k + 1) }), k + 1);
+            }
+            port.onChange = [this, c] { change ([c, v = ports[(std::size_t) c].getSelectedId() - 1] (vfx::ColorMapperSettings& s) { s.port[(std::size_t) c] = std::max (0, v); }); };
+            colour.onChange = [this, c] { change ([c, v = colours[(std::size_t) c].getSelectedId() - 1] (vfx::ColorMapperSettings& s) { s.colour[(std::size_t) c] = std::max (0, v); }); };
+            ui::setHint (port, tr ("The voice output the notes of colour {0} go to", { juce::String (c + 1) }));
+            ui::setHint (colour, tr ("The colour the notes of colour {0} leave with", { juce::String (c + 1) }));
+            addAndMakeVisible (port);
+            addAndMakeVisible (colour);
+        }
+    }
+
+    void refresh (const std::vector<std::uint8_t>& fl) override
+    {
+        settings = vfx::parseColorMapper (fl).value_or (vfx::defaultColorMapper());
+        for (int c = 0; c < 16; ++c)
+        {
+            ports[(std::size_t) c].setSelectedId (settings.port[(std::size_t) c] + 1, juce::dontSendNotification);
+            colours[(std::size_t) c].setSelectedId (settings.colour[(std::size_t) c] + 1, juce::dontSendNotification);
+        }
+        repaint();
+    }
+
+    int preferredHeight() const override { return 28 + 8 * 28 + 8; }
+
+    void resized() override
+    {
+        auto area = getLocalBounds().reduced (10, 4).withTrimmedTop (24);
+        const auto half = area.getWidth() / 2;
+        for (int c = 0; c < 16; ++c)
+        {
+            auto column = c < 8 ? area.withWidth (half - 10) : area.withTrimmedLeft (half + 10);
+            auto row = column.withHeight (26).translated (0, (c % 8) * 28);
+            row.removeFromLeft (70);
+            ports[(std::size_t) c].setBounds (row.removeFromLeft ((row.getWidth() - 8) / 2));
+            row.removeFromLeft (8);
+            colours[(std::size_t) c].setBounds (row);
+        }
+    }
+
+    void paint (juce::Graphics& g) override
+    {
+        auto area = getLocalBounds().reduced (10, 4);
+        const auto half = area.getWidth() / 2;
+        g.setFont (theme::font (theme::type::caption));
+        g.setColour (theme::colour::textSecondary);
+        for (const auto x : { area.getX(), area.getX() + half + 10 })
+        {
+            const auto w = half - 10 - 70;
+            g.drawText (theme::caps (tr ("Note colour")), x, area.getY(), 70, 18, juce::Justification::centredLeft);
+            g.drawText (theme::caps (tr ("Voice output")), x + 70, area.getY(), (w - 8) / 2, 18, juce::Justification::centredLeft);
+            g.drawText (theme::caps (tr ("Colour")), x + 70 + (w - 8) / 2 + 8, area.getY(), (w - 8) / 2, 18, juce::Justification::centredLeft);
+        }
+        area.removeFromTop (24);
+        for (int c = 0; c < 16; ++c)
+        {
+            auto column = c < 8 ? area.withWidth (half - 10) : area.withTrimmedLeft (half + 10);
+            auto row = column.withHeight (26).translated (0, (c % 8) * 28).removeFromLeft (64).toFloat();
+            g.setColour (theme::noteGroupHue (c));
+            g.fillRoundedRectangle (row.removeFromLeft (26.0f).reduced (3.0f), 3.0f);
+            g.setColour (theme::colour::textPrimary);
+            g.setFont (theme::font (theme::type::small));
+            g.drawText (juce::String (c + 1), row.reduced (4.0f, 0.0f), juce::Justification::centredLeft);
+        }
+    }
+
+private:
+    void change (std::function<void (vfx::ColorMapperSettings&)> f)
+    {
+        if (edit)
+            edit ([f] (std::vector<std::uint8_t>& fl) {
+                auto s = vfx::parseColorMapper (fl).value_or (vfx::defaultColorMapper());
+                f (s);
+                fl = vfx::writeColorMapper (s);
+            });
+    }
+
+    vfx::ColorMapperSettings settings = vfx::defaultColorMapper();
+    std::array<juce::ComboBox, 16> ports, colours;
+};
+
+// ---------------------------------------------------------------------------------------------------------------
+// VFX Level Scaler: a tab per voice property, its curve's controls on the left, the curve on the right
+
+class LevelScalerBody final : public Body
+{
+public:
+    using L = vfx::LevelScalerSettings;
+
+    LevelScalerBody()
+    {
+        static const char* names[] = { TR_NOOP ("Velocity"), TR_NOOP ("Release"), TR_NOOP ("Fine pitch"), TR_NOOP ("Pan"), TR_NOOP ("Mod X"), TR_NOOP ("Mod Y") };
+        for (int t = 0; t < L::tabCount; ++t)
+        {
+            auto& b = tabs[(std::size_t) t];
+            b.setButtonText (tr (names[t]));
+            b.setClickingTogglesState (false);
+            b.setColour (juce::TextButton::buttonOnColourId, theme::colour::accentMuted);
+            b.onClick = [this, t] { change ([t] (L& st) { st.selectedTab = t; }); };
+            addAndMakeVisible (b);
+        }
+        auto knob = [this] (Knob& k, const juce::String& caption) {
+            k.caption = caption;
+            addAndMakeVisible (k);
+        };
+        knob (center, tr ("Center"));
+        knob (multiply, tr ("Multiply"));
+        knob (offset, tr ("Offset"));
+        knob (tension, tr ("Tension"));
+        knob (humanize, tr ("Humanize"));
+        mode.addItem (tr ("Subtract"), 1);
+        mode.addItem (tr ("Spread"), 2);
+        mode.addItem (tr ("Add"), 3);
+        mode.onChange = [this] { set (L::humanizeMode, mode.getSelectedId() - 1); };
+        ui::setHint (mode, tr ("Humanize mode: the random part goes below the value, around it or above it"));
+        addAndMakeVisible (mode);
+        reset.setButtonText (tr ("Reset"));
+        ui::setHint (reset, tr ("Reset all controls of this property"));
+        reset.onClick = [this] { change ([] (L& st) { vfx::resetLevelScalerTab (st, st.selectedTab); }); };
+        addAndMakeVisible (reset);
+    }
+
+    void refresh (const std::vector<std::uint8_t>& fl) override
+    {
+        settings = vfx::parseLevelScaler (fl).value_or (vfx::defaultLevelScaler());
+        for (int t = 0; t < L::tabCount; ++t)
+            tabs[(std::size_t) t].setToggleState (t == settings.selectedTab, juce::dontSendNotification);
+        mode.setSelectedId (std::clamp (settings.at (settings.selectedTab, L::humanizeMode), 0, 2) + 1, juce::dontSendNotification);
+        for (auto* k : { &center, &multiply, &offset, &tension, &humanize })
+            k->repaint();
+        repaint();
+    }
+
+    int preferredHeight() const override { return 360; }
+    int preferredWidth() const override { return 700; }
+
+    void resized() override
+    {
+        auto area = getLocalBounds().reduced (12, 6);
+        auto top = area.removeFromTop (28);
+        for (auto& b : tabs)
+            b.setBounds (top.removeFromLeft (92).reduced (2, 0));
+        area.removeFromTop (8);
+        auto left = area.removeFromLeft (230);
+        auto row1 = left.removeFromTop (92);
+        for (auto* k : { &center, &multiply, &offset })
+            k->setBounds (row1.removeFromLeft (76));
+        auto row2 = left.removeFromTop (92);
+        for (auto* k : { &tension, &humanize })
+            k->setBounds (row2.removeFromLeft (76));
+        auto side = row2.reduced (2, 14);
+        mode.setBounds (side.removeFromTop (26));
+        left.removeFromTop (8);
+        reset.setBounds (left.removeFromTop (26).withWidth (100));
+        graph = area.reduced (10, 0).toFloat();
+    }
+
+    void paint (juce::Graphics& g) override
+    {
+        if (graph.isEmpty())
+            return;
+        const auto tab = settings.selectedTab;
+        const auto bipolar = tab >= L::finePitch;
+        const auto lo = bipolar ? -1.0 : 0.0, hi = 1.0;
+        g.setColour (theme::colour::bg0);
+        g.fillRoundedRectangle (graph, 4.0f);
+        g.setColour (theme::colour::border);
+        for (int k = 1; k < 8; ++k)
+        {
+            g.drawVerticalLine ((int) (graph.getX() + graph.getWidth() * (float) k / 8.0f), graph.getY(), graph.getBottom());
+            g.drawHorizontalLine ((int) (graph.getY() + graph.getHeight() * (float) k / 8.0f), graph.getX(), graph.getRight());
+        }
+        g.setColour (theme::colour::textDisabled);
+        g.setFont (theme::font (theme::type::title, true));
+        g.drawText (tabs[(std::size_t) tab].getButtonText(), graph.reduced (12.0f, 8.0f), juce::Justification::topLeft);
+        auto point = [&] (double u, double y) {
+            return juce::Point<float> (graph.getX() + (float) u * graph.getWidth(), graph.getBottom() - (float) ((y - lo) / (hi - lo)) * graph.getHeight());
+        };
+        g.setColour (theme::colour::borderStrong);
+        g.drawLine (juce::Line<float> (point (0.0, lo), point (1.0, hi)), 1.0f);
+        juce::Path curve, upper, lower;
+        constexpr int steps = 160;
+        for (int k = 0; k <= steps; ++k)
+        {
+            const auto u = (double) k / steps;
+            const auto x = lo + u * (hi - lo);
+            const auto p = point (u, vfx::levelScale (settings, tab, x, lo, hi, 0.5));
+            const auto a = point (u, vfx::levelScale (settings, tab, x, lo, hi, 0.0));
+            const auto b = point (u, vfx::levelScale (settings, tab, x, lo, hi, 1.0));
+            if (k == 0)
+            {
+                curve.startNewSubPath (p);
+                lower.startNewSubPath (a);
+                upper.startNewSubPath (b);
+            }
+            else
+            {
+                curve.lineTo (p);
+                lower.lineTo (a);
+                upper.lineTo (b);
+            }
+        }
+        if (settings.at (tab, L::humanize) > 0)
+        {
+            juce::Path band (upper);
+            for (int k = steps; k >= 0; --k)
+            {
+                const auto u = (double) k / steps;
+                band.lineTo (point (u, vfx::levelScale (settings, tab, lo + u * (hi - lo), lo, hi, 0.0)));
+            }
+            band.closeSubPath();
+            g.setColour (theme::colour::accent.withAlpha (0.16f));
+            g.fillPath (band);
+            g.setColour (theme::colour::accent.withAlpha (0.45f));
+            g.strokePath (upper, juce::PathStrokeType (1.0f));
+            g.strokePath (lower, juce::PathStrokeType (1.0f));
+        }
+        g.setColour (theme::colour::accent);
+        g.strokePath (curve, juce::PathStrokeType (2.2f));
+        g.setColour (theme::colour::borderStrong);
+        g.drawRoundedRectangle (graph, 4.0f, 1.0f);
+        g.setColour (theme::colour::textSecondary);
+        g.setFont (theme::font (theme::type::caption));
+        g.drawText (tr ("in"), graph.withTrimmedTop (graph.getHeight() - 16.0f).reduced (6.0f, 0.0f), juce::Justification::centredRight);
+        g.drawText (tr ("out"), graph.reduced (6.0f, 4.0f).withHeight (14.0f), juce::Justification::centredRight);
+    }
+
+private:
+    void change (std::function<void (L&)> f)
+    {
+        if (edit)
+            edit ([f] (std::vector<std::uint8_t>& fl) {
+                auto s = vfx::parseLevelScaler (fl).value_or (vfx::defaultLevelScaler());
+                f (s);
+                fl = vfx::writeLevelScaler (s);
+            });
+    }
+    void set (int field, double v)
+    {
+        change ([field, v] (L& st) { st.at (st.selectedTab, field) = (int) std::lround (v); });
+    }
+    double get (int field) const { return settings.at (settings.selectedTab, field); }
+    static juce::String percent (double v) { return juce::String (v * 100.0, 0) + "%"; }
+
+    L settings = vfx::defaultLevelScaler();
+    std::array<juce::TextButton, L::tabCount> tabs;
+    Knob center { intSpec (tr ("Center: the input level the curve turns around"), 0, 8192, 0, [] (double v) { return percent (v / 8192.0); }),
+                  [this] { return get (L::center); }, [this] (double v) { set (L::center, v); } };
+    Knob multiply { intSpec (tr ("Multiply: the slope around the center (negative inverts)"), -16384, 16384, 8192,
+                             [] (double v) { return juce::String::charToString (0xd7) + juce::String (v / 8192.0, 2); }),
+                    [this] { return get (L::multiply); }, [this] (double v) { set (L::multiply, v); } };
+    Knob offset { intSpec (tr ("Offset: moves every value up or down"), -8192, 8192, 0,
+                           [] (double v) { return (v > 0 ? "+" : "") + percent (v / 8192.0); }),
+                  [this] { return get (L::offset); }, [this] (double v) { set (L::offset, v); } };
+    Knob tension { intSpec (tr ("Tension: bends the curve (positive rises fast, negative starts slow)"), -8192, 8192, 0,
+                            [] (double v) { return (v > 0 ? "+" : "") + percent (v / 8192.0); }),
+                   [this] { return get (L::tension); }, [this] (double v) { set (L::tension, v); } };
+    Knob humanize { intSpec (tr ("Humanize: a random amount for each note"), 0, 16384, 0, [] (double v) { return percent (v / 16384.0); }),
+                    [this] { return get (L::humanize); }, [this] (double v) { set (L::humanize, v); } };
+    juce::ComboBox mode;
+    juce::TextButton reset;
+    juce::Rectangle<float> graph;
+};
+
+// ---------------------------------------------------------------------------------------------------------------
+// An FL mapping / envelope curve, edited with the mouse: drag a point, double-click to add one, right-click a point to
+// remove it, drag a segment up or down to bend it; Alt+click a segment straightens it
+
+class CurveEditor final : public juce::Component
+{
+public:
+    std::function<void (const vfx::MapCurve&)> onChange;
+    std::function<void (juce::Graphics&, juce::Rectangle<float>, double xMax)> drawGrid; // under the curves
+    std::vector<std::pair<vfx::MapCurve, juce::Colour>> behind;                          // other curves, faint
+    double fixedXMax = 0.0;  // > 0: the x range (maps: 1); else it follows the curve (envelopes)
+    bool bipolar = false;    // a centre line
+    int sustainPoint = -1, loopPoint = -1;
+    juce::Colour colour = theme::colour::accent;
+    float marker = -1.0f;    // a vertical line (x), e.g. the last note
+
+    void setCurve (const vfx::MapCurve& c)
+    {
+        if (dragging < 0 && bending < 0)
+            curve = c;
+        repaint();
+    }
+
+    void paint (juce::Graphics& g) override
+    {
+        const auto area = plot();
+        g.setColour (theme::colour::bg0);
+        g.fillRoundedRectangle (area, 4.0f);
+        const auto xMax = range();
+        if (drawGrid)
+            drawGrid (g, area, xMax);
+        if (bipolar)
+        {
+            g.setColour (theme::colour::borderStrong);
+            g.drawHorizontalLine ((int) area.getCentreY(), area.getX(), area.getRight());
+        }
+        for (const auto& [c, col] : behind)
+            stroke (g, c, col.withAlpha (0.35f), 1.2f, false);
+        stroke (g, curve, colour, 2.2f, true);
+        for (int i = 0; i < (int) curve.points.size(); ++i)
+        {
+            const auto p = toScreen (curve.points[(std::size_t) i]);
+            const auto r = i == hover || i == dragging ? 5.5f : 4.0f;
+            g.setColour (theme::colour::bg0);
+            g.fillEllipse (juce::Rectangle<float> (r * 2.0f + 2.0f, r * 2.0f + 2.0f).withCentre (p));
+            g.setColour (i == sustainPoint ? theme::colour::warning : colour);
+            g.fillEllipse (juce::Rectangle<float> (r * 2.0f, r * 2.0f).withCentre (p));
+        }
+        if (sustainPoint >= 0 && sustainPoint < (int) curve.points.size())
+        {
+            const auto x = toScreen (curve.points[(std::size_t) sustainPoint]).x;
+            g.setColour (theme::colour::warning.withAlpha (0.6f));
+            g.drawVerticalLine ((int) x, area.getY(), area.getBottom());
+            g.setFont (theme::font (theme::type::caption));
+            g.drawText (tr ("sustain"), juce::Rectangle<float> (x + 3.0f, area.getY() + 2.0f, 60.0f, 14.0f), juce::Justification::centredLeft);
+        }
+        if (marker >= 0.0f && marker <= xMax)
+        {
+            g.setColour (theme::colour::textPrimary.withAlpha (0.7f));
+            const auto x = area.getX() + (float) (marker / xMax) * area.getWidth();
+            g.drawVerticalLine ((int) x, area.getY(), area.getBottom());
+        }
+        g.setColour (theme::colour::borderStrong);
+        g.drawRoundedRectangle (area, 4.0f, 1.0f);
+    }
+
+    void mouseMove (const juce::MouseEvent& e) override
+    {
+        const auto h = pointAt (e.position);
+        if (h != hover)
+        {
+            hover = h;
+            repaint();
+        }
+    }
+    void mouseExit (const juce::MouseEvent&) override
+    {
+        hover = -1;
+        repaint();
+    }
+
+    void mouseDown (const juce::MouseEvent& e) override
+    {
+        const auto at = pointAt (e.position);
+        if (e.mods.isPopupMenu())
+        {
+            if (at > 0 && at < (int) curve.points.size() - 1 && curve.points.size() > 2)
+            {
+                curve.points.erase (curve.points.begin() + at);
+                hover = -1;
+                commit();
+            }
+            return;
+        }
+        if (at >= 0)
+        {
+            dragging = at;
+            return;
+        }
+        const auto seg = segmentAt (e.position.x);
+        if (seg > 0 && e.mods.isAltDown())
+        {
+            curve.points[(std::size_t) seg].tension = 0.0f;
+            curve.points[(std::size_t) seg].b15 = 2;
+            commit();
+            return;
+        }
+        if (seg > 0)
+        {
+            bending = seg;
+            bendStart = curve.points[(std::size_t) seg].tension;
+        }
+    }
+
+    void mouseDrag (const juce::MouseEvent& e) override
+    {
+        const auto area = plot();
+        if (dragging >= 0)
+        {
+            auto& p = curve.points[(std::size_t) dragging];
+            const auto xMax = range();
+            auto x = (double) ((e.position.x - area.getX()) / area.getWidth()) * xMax;
+            const auto lo = dragging == 0 ? 0.0 : curve.points[(std::size_t) dragging - 1].x;
+            const auto hi = dragging + 1 < (int) curve.points.size() ? curve.points[(std::size_t) dragging + 1].x : (fixedXMax > 0.0 ? fixedXMax : 1.0e4);
+            p.x = dragging == 0 ? 0.0 : std::clamp (x, lo, hi);
+            p.y = std::clamp ((double) ((area.getBottom() - e.position.y) / area.getHeight()), 0.0, 1.0);
+            if (e.mods.isShiftDown()) // (snap the level to 1/8)
+                p.y = std::round (p.y * 8.0) / 8.0;
+            commit();
+        }
+        else if (bending > 0)
+        {
+            auto& p = curve.points[(std::size_t) bending];
+            const auto rising = p.y >= curve.points[(std::size_t) bending - 1].y;
+            const auto dy = (float) -e.getDistanceFromDragStartY() / 120.0f;
+            p.tension = std::clamp (bendStart + (rising ? -dy : dy), -1.0f, 1.0f);
+            p.b15 = p.tension == 0.0f ? 2 : p.tension > 0.0f ? 1 : 0xff;
+            commit();
+        }
+    }
+    void mouseUp (const juce::MouseEvent&) override
+    {
+        dragging = bending = -1;
+    }
+    void mouseDoubleClick (const juce::MouseEvent& e) override
+    {
+        if (pointAt (e.position) >= 0)
+            return;
+        const auto area = plot();
+        const auto x = (double) ((e.position.x - area.getX()) / area.getWidth()) * range();
+        const auto y = std::clamp ((double) ((area.getBottom() - e.position.y) / area.getHeight()), 0.0, 1.0);
+        auto at = curve.points.begin();
+        while (at != curve.points.end() && at->x <= x)
+            ++at;
+        if (at == curve.points.begin())
+            return;
+        curve.points.insert (at, vfx::MapCurve::Point { x, y });
+        commit();
+    }
+
+private:
+    juce::Rectangle<float> plot() const { return getLocalBounds().toFloat().reduced (2.0f, 2.0f); }
+    double range() const
+    {
+        if (fixedXMax > 0.0)
+            return fixedXMax;
+        const auto last = curve.points.empty() ? 1.0 : curve.points.back().x;
+        return std::max (1.0, std::ceil (last * 1.25 * 4.0) / 4.0);
+    }
+    juce::Point<float> toScreen (const vfx::MapCurve::Point& p) const
+    {
+        const auto area = plot();
+        return { area.getX() + (float) (p.x / range()) * area.getWidth(), area.getBottom() - (float) p.y * area.getHeight() };
+    }
+    int pointAt (juce::Point<float> at) const
+    {
+        for (int i = (int) curve.points.size() - 1; i >= 0; --i)
+            if (toScreen (curve.points[(std::size_t) i]).getDistanceFrom (at) < 8.0f)
+                return i;
+        return -1;
+    }
+    int segmentAt (float sx) const
+    {
+        for (int i = 1; i < (int) curve.points.size(); ++i)
+            if (sx >= toScreen (curve.points[(std::size_t) i - 1]).x && sx < toScreen (curve.points[(std::size_t) i]).x)
+                return i;
+        return -1;
+    }
+    void stroke (juce::Graphics& g, const vfx::MapCurve& c, juce::Colour col, float width, bool fill) const
+    {
+        if (c.points.empty())
+            return;
+        const auto area = plot();
+        const auto xMax = range();
+        juce::Path path;
+        const auto steps = (int) area.getWidth() / 2;
+        for (int k = 0; k <= steps; ++k)
+        {
+            const auto x = xMax * k / steps;
+            const juce::Point<float> p (area.getX() + area.getWidth() * (float) k / (float) steps, area.getBottom() - (float) c.at (x) * area.getHeight());
+            if (k == 0)
+                path.startNewSubPath (p);
+            else
+                path.lineTo (p);
+        }
+        if (fill)
+        {
+            juce::Path under (path);
+            under.lineTo (area.getBottomRight());
+            under.lineTo (area.getBottomLeft());
+            under.closeSubPath();
+            g.setColour (col.withAlpha (0.12f));
+            g.fillPath (under);
+        }
+        g.setColour (col);
+        g.strokePath (path, juce::PathStrokeType (width));
+    }
+    void commit()
+    {
+        repaint();
+        if (onChange)
+            onChange (curve);
+    }
+
+    vfx::MapCurve curve;
+    int hover = -1, dragging = -1, bending = -1;
+    float bendStart = 0.0f;
+};
+
+// ---------------------------------------------------------------------------------------------------------------
+// VFX Keyboard Splitter: the zones, a page per map (keyboard, velocity), the current zone's map over the others
+
+juce::Colour zoneColour (int z)
+{
+    return juce::Colour::fromHSV (std::fmod ((float) z * 2.5f / 16.0f, 1.0f), 0.62f, 0.95f, 1.0f);
+}
+
+class KeyboardSplitterBody final : public Body
+{
+public:
+    using S = vfx::KeyboardSplitterSettings;
+
+    KeyboardSplitterBody()
+    {
+        for (int z = 0; z < 16; ++z)
+        {
+            auto& b = zoneButtons[(std::size_t) z];
+            b.setButtonText (juce::String (z + 1));
+            b.setClickingTogglesState (false);
+            b.onClick = [this, z] {
+                zone = z;
+                refreshControls();
+            };
+            addAndMakeVisible (b);
+        }
+        for (int p = 0; p < 2; ++p)
+        {
+            auto& b = pages[(std::size_t) p];
+            b.setButtonText (p == 0 ? tr ("Keyboard") : tr ("Velocity"));
+            b.setClickingTogglesState (false);
+            b.setColour (juce::TextButton::buttonOnColourId, theme::colour::accentMuted);
+            b.onClick = [this, p] { change ([p] (S& st) { st.page = p; }); };
+            addAndMakeVisible (b);
+        }
+        name.setTextToShowWhenEmpty (tr ("Zone {0}", { "1" }), theme::colour::textDisabled);
+        name.onReturnKey = name.onFocusLost = [this] {
+            change ([z = zone, text = name.getText().trim().toStdString()] (S& st) { st.zones[(std::size_t) z].name = text; });
+        };
+        ui::setHint (name, tr ("The zone's name (its output's name in the Patcher)"));
+        addAndMakeVisible (name);
+        flag.onClick = [this] {
+            change ([z = zone, on = flag.getToggleState()] (S& st) {
+                auto& zn = st.zones[(std::size_t) z];
+                (st.page == 0 ? zn.random : zn.absolute) = on;
+            });
+        };
+        addAndMakeVisible (flag);
+        transpose.caption = tr ("Transpose");
+        addAndMakeVisible (transpose);
+        for (auto [label, make] : std::initializer_list<std::pair<const char*, int>> { { TR_NOOP ("Whole keyboard"), 0 }, { TR_NOOP ("Clear"), 1 } })
+        {
+            auto* b = make == 0 ? &whole : &clear;
+            b->setButtonText (tr (label));
+            b->onClick = [this, make = make] {
+                change ([z = zone, make] (S& st) {
+                    auto& curve = st.page == 0 ? st.zones[(std::size_t) z].keyboard : st.zones[(std::size_t) z].velocity;
+                    curve = vfx::MapCurve::flat (make == 0 ? 1.0 : (st.page == 0 ? 0.0 : 1.0));
+                });
+            };
+            addAndMakeVisible (b);
+        }
+        ui::setHint (whole, tr ("The whole range at full level"));
+        ui::setHint (clear, tr ("Back to the map's default (the zone is off when both maps are)"));
+        editor.fixedXMax = 1.0;
+        editor.onChange = [this] (const vfx::MapCurve& c) {
+            change ([z = zone, c] (S& st) { (st.page == 0 ? st.zones[(std::size_t) z].keyboard : st.zones[(std::size_t) z].velocity) = c; });
+        };
+        editor.drawGrid = [this] (juce::Graphics& g, juce::Rectangle<float> area, double) {
+            g.setFont (theme::font (theme::type::caption));
+            if (settings.page == 0) // octaves: C0 … C10 (x = key / 132)
+                for (int key = 0; key <= 132; key += 12)
+                {
+                    const auto x = area.getX() + area.getWidth() * (float) key / 132.0f;
+                    g.setColour (theme::colour::border);
+                    g.drawVerticalLine ((int) x, area.getY(), area.getBottom());
+                    g.setColour (theme::colour::textSecondary);
+                    if (key < 132)
+                        g.drawText ("C" + juce::String (key / 12), juce::Rectangle<float> (x + 3.0f, area.getBottom() - 16.0f, 40.0f, 14.0f), juce::Justification::centredLeft);
+                }
+            else
+                for (int q = 1; q < 4; ++q)
+                {
+                    g.setColour (theme::colour::border);
+                    g.drawVerticalLine ((int) (area.getX() + area.getWidth() * (float) q / 4.0f), area.getY(), area.getBottom());
+                }
+            for (int q = 1; q < 4; ++q)
+            {
+                g.setColour (theme::colour::border.withAlpha (0.5f));
+                g.drawHorizontalLine ((int) (area.getY() + area.getHeight() * (float) q / 4.0f), area.getX(), area.getRight());
+            }
+        };
+        addAndMakeVisible (editor);
+    }
+
+    void refresh (const std::vector<std::uint8_t>& fl) override
+    {
+        settings = vfx::parseKeyboardSplitter (fl).value_or (vfx::defaultKeyboardSplitter());
+        refreshControls();
+    }
+
+    int preferredHeight() const override { return 400; }
+    int preferredWidth() const override { return 860; }
+
+    void resized() override
+    {
+        auto area = getLocalBounds().reduced (12, 6);
+        auto top = area.removeFromTop (30);
+        for (auto& b : zoneButtons)
+            b.setBounds (top.removeFromLeft (30).reduced (1, 0));
+        top.removeFromLeft (12);
+        name.setBounds (top.removeFromLeft (150).reduced (0, 2));
+        top.removeFromLeft (12);
+        for (auto& b : pages)
+            b.setBounds (top.removeFromLeft (84).reduced (1, 0));
+        area.removeFromTop (6);
+        auto row = area.removeFromTop (64);
+        transpose.setBounds (row.removeFromLeft (70));
+        row.removeFromLeft (10);
+        flag.setBounds (row.removeFromLeft (220).withSizeKeepingCentre (220, 24));
+        clear.setBounds (row.removeFromRight (90).withSizeKeepingCentre (90, 26));
+        row.removeFromRight (6);
+        whole.setBounds (row.removeFromRight (130).withSizeKeepingCentre (130, 26));
+        area.removeFromTop (6);
+        editor.setBounds (area);
+    }
+
+private:
+    void refreshControls()
+    {
+        const auto& z = settings.zones[(std::size_t) zone];
+        for (int k = 0; k < 16; ++k)
+        {
+            auto& b = zoneButtons[(std::size_t) k];
+            const auto active = settings.zones[(std::size_t) k].active();
+            b.setColour (juce::TextButton::buttonColourId, active ? zoneColour (k).withAlpha (0.55f) : theme::colour::bg3);
+            b.setColour (juce::TextButton::buttonOnColourId, zoneColour (k));
+            b.setColour (juce::TextButton::textColourOffId, active ? theme::colour::textPrimary : theme::colour::textDisabled);
+            b.setToggleState (k == zone, juce::dontSendNotification);
+        }
+        for (int p = 0; p < 2; ++p)
+            pages[(std::size_t) p].setToggleState (p == settings.page, juce::dontSendNotification);
+        if (! name.hasKeyboardFocus (true))
+            name.setText (juce::String::fromUTF8 (z.name.c_str()), juce::dontSendNotification);
+        name.setTextToShowWhenEmpty (tr ("Zone {0}", { juce::String (zone + 1) }), theme::colour::textDisabled);
+        const auto keyboard = settings.page == 0;
+        flag.setButtonText (keyboard ? tr ("Random (the map is a probability)") : tr ("Absolute (the map sets the volume)"));
+        ui::setHint (flag, keyboard ? tr ("Random: each note goes to one of the random zones, picked by their keyboard maps")
+                                    : tr ("Absolute: the velocity map gives the volume instead of scaling the note's"));
+        flag.setToggleState (keyboard ? z.random : z.absolute, juce::dontSendNotification);
+        transpose.setVisible (keyboard);
+        editor.colour = zoneColour (zone);
+        editor.behind.clear();
+        for (int k = 0; k < 16; ++k)
+            if (k != zone && settings.zones[(std::size_t) k].active())
+                editor.behind.emplace_back (keyboard ? settings.zones[(std::size_t) k].keyboard : settings.zones[(std::size_t) k].velocity, zoneColour (k));
+        editor.setCurve (keyboard ? z.keyboard : z.velocity);
+        transpose.repaint();
+        repaint();
+    }
+
+    void change (std::function<void (S&)> f)
+    {
+        if (edit)
+            edit ([f] (std::vector<std::uint8_t>& fl) {
+                auto s = vfx::parseKeyboardSplitter (fl).value_or (vfx::defaultKeyboardSplitter());
+                f (s);
+                fl = vfx::writeKeyboardSplitter (s);
+            });
+    }
+
+    S settings = vfx::defaultKeyboardSplitter();
+    int zone = 0;
+    std::array<juce::TextButton, 16> zoneButtons;
+    std::array<juce::TextButton, 2> pages;
+    juce::TextEditor name;
+    juce::ToggleButton flag;
+    juce::TextButton whole, clear;
+    Knob transpose { intSpec (tr ("Transpose (semitones)"), -48, 48, 0, [] (double v) { return (v > 0 ? "+" : "") + juce::String ((int) std::lround (v)); }),
+                     [this] { return (double) settings.zones[(std::size_t) zone].transpose; },
+                     [this] (double v) { change ([z = zone, v] (S& st) { st.zones[(std::size_t) z].transpose = (int) std::lround (v); }); } };
+    CurveEditor editor;
+};
+
+// ---------------------------------------------------------------------------------------------------------------
+// VFX Envelope: 16 articulators (each for a note colour and key range), 5 targets, an envelope and an LFO each
+
+class EnvelopeBody final : public Body
+{
+public:
+    using E = vfx::EnvelopeSettings;
+
+    EnvelopeBody()
+    {
+        for (int g = 0; g < 16; ++g)
+        {
+            auto& b = articulatorButtons[(std::size_t) g];
+            b.setButtonText (juce::String (g + 1));
+            b.setClickingTogglesState (false);
+            b.setColour (juce::TextButton::buttonOnColourId, theme::colour::accent);
+            b.onClick = [this, g] { change ([g] (E& st) { st.shownArticulator = g; }); };
+            ui::setHint (b, tr ("Articulator {0}", { juce::String (g + 1) }));
+            addAndMakeVisible (b);
+        }
+        static const char* targetNames[] = { TR_NOOP ("Velocity"), TR_NOOP ("Pitch"), TR_NOOP ("Pan"), TR_NOOP ("Mod X"), TR_NOOP ("Mod Y") };
+        for (int t = 0; t < 5; ++t)
+        {
+            auto& b = targets[(std::size_t) t];
+            b.setButtonText (tr (targetNames[t]));
+            b.setClickingTogglesState (false);
+            b.setColour (juce::TextButton::buttonOnColourId, theme::colour::accentMuted);
+            b.onClick = [this, t] { change ([t] (E& st) { st.shownTarget = t; }); };
+            addAndMakeVisible (b);
+        }
+        for (int p = 0; p < 2; ++p)
+        {
+            auto& b = partTabs[(std::size_t) p];
+            b.setButtonText (p == 0 ? tr ("Envelope") : tr ("LFO"));
+            b.setClickingTogglesState (false);
+            b.setColour (juce::TextButton::buttonOnColourId, theme::colour::accentMuted);
+            b.onClick = [this, p] { change ([p] (E& st) { st.shownPart = p; }); };
+            addAndMakeVisible (b);
+        }
+        for (int c = 0; c < 16; ++c)
+            colour.addItem (tr ("Colour {0}", { juce::String (c + 1) }), c + 1);
+        colour.onChange = [this] { changeArticulator ([c = colour.getSelectedId() - 1] (E::Articulator& a) { a.colour = std::max (0, c); }); };
+        ui::setHint (colour, tr ("The note colour this articulator works on (the MIDI channel)"));
+        addAndMakeVisible (colour);
+        enable.setButtonText (tr ("Enable"));
+        enable.onClick = [this] { change ([on = enable.getToggleState()] (E& st) { st.enabled = on; }); };
+        ui::setHint (enable, tr ("Off: the notes pass unchanged"));
+        addAndMakeVisible (enable);
+        partOn.onClick = [this] {
+            changePart ([lfo = settings.shownPart == 1, on = partOn.getToggleState()] (E::Part& p) { (lfo ? p.lfoAmp : p.envelope).footer[1] = on ? -1 : 0; });
+        };
+        addAndMakeVisible (partOn);
+        tempo.setButtonText (tr ("Tempo"));
+        tempo.onClick = [this] {
+            changePart ([lfo = settings.shownPart == 1, on = tempo.getToggleState()] (E::Part& p) {
+                auto& f = (lfo ? p.lfoAmp : p.envelope).footer[0];
+                f = on ? (f | 1) : (f & ~1);
+            });
+        };
+        ui::setHint (tempo, tr ("Tempo: the time in beats (else in seconds)"));
+        addAndMakeVisible (tempo);
+        for (auto* k : { &low, &high, &base, &envLevel, &lfoLevel, &attack, &decay, &sustain, &release, &speed, &lfoTension, &skew, &pulseWidth })
+            addAndMakeVisible (k);
+        low.caption = tr ("Low");
+        high.caption = tr ("High");
+        base.caption = tr ("Base");
+        envLevel.caption = tr ("Env");
+        lfoLevel.caption = tr ("LFO");
+        attack.caption = tr ("Attack");
+        decay.caption = tr ("Decay");
+        sustain.caption = tr ("Sustain");
+        release.caption = tr ("Release");
+        speed.caption = tr ("Speed");
+        lfoTension.caption = tr ("Tension");
+        skew.caption = tr ("Skew");
+        pulseWidth.caption = tr ("Pulse width");
+        editor.onChange = [this] (const vfx::MapCurve& c) {
+            changePart ([lfo = settings.shownPart == 1, c] (E::Part& p) {
+                auto& curve = lfo ? p.lfoAmp : p.envelope;
+                const auto footer = curve.footer;
+                curve = c;
+                curve.footer = footer;
+                // the sustain / decay / loop points stay inside the curve
+                for (const auto k : { 2, 3, 4 })
+                    if (curve.footer[(std::size_t) k] >= (int) curve.points.size())
+                        curve.footer[(std::size_t) k] = (int) curve.points.size() - 1;
+            });
+        };
+        addAndMakeVisible (editor);
+    }
+
+    void refresh (const std::vector<std::uint8_t>& fl) override
+    {
+        settings = vfx::parseEnvelope (fl).value_or (vfx::defaultEnvelope());
+        const auto& a = articulator();
+        const auto& p = part();
+        for (int g = 0; g < 16; ++g)
+        {
+            const auto& ag = settings.articulators[(std::size_t) g];
+            const auto used = std::any_of (ag.parts.begin(), ag.parts.end(), [] (const E::Part& q) { return q.lfoOn() || (q.envOn() && ! neutral (q)); });
+            articulatorButtons[(std::size_t) g].setColour (juce::TextButton::textColourOffId, used ? theme::colour::textPrimary : theme::colour::textDisabled);
+            articulatorButtons[(std::size_t) g].setToggleState (g == settings.shownArticulator, juce::dontSendNotification);
+        }
+        for (int t = 0; t < 5; ++t)
+        {
+            const auto& q = a.parts[(std::size_t) t];
+            targets[(std::size_t) t].setToggleState (t == settings.shownTarget, juce::dontSendNotification);
+            targets[(std::size_t) t].setColour (juce::TextButton::textColourOffId,
+                                                q.lfoOn() || (q.envOn() && ! neutral (q)) ? theme::colour::accent : theme::colour::textPrimary);
+        }
+        for (int k = 0; k < 2; ++k)
+            partTabs[(std::size_t) k].setToggleState (k == settings.shownPart, juce::dontSendNotification);
+        colour.setSelectedId (a.colour + 1, juce::dontSendNotification);
+        enable.setToggleState (settings.enabled, juce::dontSendNotification);
+        const auto lfo = settings.shownPart == 1;
+        const auto& curve = lfo ? p.lfoAmp : p.envelope;
+        partOn.setButtonText (lfo ? tr ("LFO on") : tr ("Envelope on"));
+        partOn.setToggleState (lfo ? p.lfoOn() : p.envOn(), juce::dontSendNotification);
+        tempo.setToggleState ((curve.footer[0] & 1) != 0, juce::dontSendNotification);
+        for (auto* k : { &attack, &decay, &sustain, &release })
+            k->setVisible (! lfo);
+        for (auto* k : { &speed, &lfoTension, &skew, &pulseWidth })
+            k->setVisible (lfo);
+        editor.bipolar = lfo || settings.shownTarget != E::velocity;
+        editor.sustainPoint = curve.footer[4];
+        editor.setCurve (curve);
+        for (auto* c : getChildren())
+            if (dynamic_cast<Knob*> (c) != nullptr)
+                c->repaint();
+        repaint();
+    }
+
+    int preferredHeight() const override { return 470; }
+    int preferredWidth() const override { return 860; }
+
+    void resized() override
+    {
+        auto area = getLocalBounds().reduced (12, 6);
+        auto top = area.removeFromTop (30);
+        for (auto& b : articulatorButtons)
+            b.setBounds (top.removeFromLeft (28).reduced (1, 0));
+        top.removeFromLeft (14);
+        for (auto& b : targets)
+            b.setBounds (top.removeFromLeft (72).reduced (1, 0));
+        enable.setBounds (top.removeFromRight (90));
+        area.removeFromTop (8);
+        auto row = area.removeFromTop (70);
+        auto left = row.removeFromLeft (130);
+        colour.setBounds (left.removeFromTop (26));
+        for (auto* k : { &low, &high })
+            k->setBounds (row.removeFromLeft (62));
+        row.removeFromLeft (14);
+        for (auto* k : { &base, &envLevel, &lfoLevel })
+            k->setBounds (row.removeFromLeft (62));
+        area.removeFromTop (8);
+        auto parts = area.removeFromTop (28);
+        for (auto& b : partTabs)
+            b.setBounds (parts.removeFromLeft (100).reduced (1, 0));
+        parts.removeFromLeft (14);
+        partOn.setBounds (parts.removeFromLeft (140));
+        tempo.setBounds (parts.removeFromLeft (90));
+        area.removeFromTop (6);
+        auto knobs = area.removeFromBottom (70);
+        for (auto* k : { &attack, &decay, &sustain, &release })
+            k->setBounds (knobs.withWidth (62).translated ((int) (k == &attack ? 0 : k == &decay ? 1 : k == &sustain ? 2 : 3) * 66, 0));
+        for (auto* k : { &speed, &lfoTension, &skew, &pulseWidth })
+            k->setBounds (knobs.withWidth (62).translated ((int) (k == &speed ? 0 : k == &lfoTension ? 1 : k == &skew ? 2 : 3) * 66, 0));
+        area.removeFromBottom (22); // (the help line)
+        editor.setBounds (area);
+    }
+
+    void paint (juce::Graphics& g) override
+    {
+        g.setColour (theme::colour::textSecondary);
+        g.setFont (theme::font (theme::type::caption));
+        const auto& p = part();
+        const auto lfo = settings.shownPart == 1;
+        const auto unit = ((lfo ? p.lfoAmp : p.envelope).footer[0] & 1) != 0 ? tr ("beats") : tr ("seconds");
+        g.drawText (tr ("Time in {0}. Drag a point, double-click to add one, right-click to remove it, drag a segment to bend it.", { unit }),
+                    editor.getBounds().translated (0, editor.getHeight() + 2).withHeight (14), juce::Justification::centredLeft);
+    }
+
+private:
+    static bool neutral (const E::Part& p)
+    {
+        return std::all_of (p.envelope.points.begin(), p.envelope.points.end(), [] (const vfx::MapCurve::Point& q) { return std::abs (q.y - 0.5) < 1e-6; })
+               && std::abs (p.base - 0.5f) < 1e-6f;
+    }
+    const E::Articulator& articulator() const { return settings.articulators[(std::size_t) settings.shownArticulator]; }
+    const E::Part& part() const { return articulator().parts[(std::size_t) settings.shownTarget]; }
+
+    void change (std::function<void (E&)> f)
+    {
+        if (edit)
+            edit ([f] (std::vector<std::uint8_t>& fl) {
+                auto s = vfx::parseEnvelope (fl).value_or (vfx::defaultEnvelope());
+                f (s);
+                fl = vfx::writeEnvelope (s);
+            });
+    }
+    void changeArticulator (std::function<void (E::Articulator&)> f)
+    {
+        change ([f] (E& st) { f (st.articulators[(std::size_t) st.shownArticulator]); });
+    }
+    void changePart (std::function<void (E::Part&)> f)
+    {
+        change ([f] (E& st) { f (st.articulators[(std::size_t) st.shownArticulator].parts[(std::size_t) st.shownTarget]); });
+    }
+    Knob partKnob (const juce::String& hint, int lo, int hi, int def, std::function<int& (E::Part&)> field, std::function<juce::String (double)> text = nullptr)
+    {
+        return Knob (intSpec (hint, lo, hi, def, std::move (text)),
+                     [this, field] { auto p = part(); return (double) field (p); },
+                     [this, field] (double v) { changePart ([field, v] (E::Part& p) { field (p) = (int) std::lround (v); }); });
+    }
+    Knob levelKnob (const juce::String& hint, int lo, int hi, int def, float E::Part::*field)
+    {
+        return Knob (intSpec (hint, lo, hi, def, [lo] (double v) { return lo < 0 ? juce::String (v / 2.56, 0) + "%" : juce::String (v / 2.56, 0) + "%"; }),
+                     [this, field] { return (double) std::lround (part().*field * 256.0f); },
+                     [this, field] (double v) { changePart ([field, v] (E::Part& p) { p.*field = (float) (v / 256.0); }); });
+    }
+    static juce::String keyText (double v)
+    {
+        const auto k = (int) std::lround (v) - 1; // (FL stores the key + 1)
+        return k < 0 ? juce::String ("-") : pitchClassName (k % 12) + juce::String (k / 12 - 1); // (LYNX's names: 60 = C4)
+    }
+
+    E settings = vfx::defaultEnvelope();
+    std::array<juce::TextButton, 16> articulatorButtons;
+    std::array<juce::TextButton, 5> targets;
+    std::array<juce::TextButton, 2> partTabs;
+    juce::ComboBox colour;
+    juce::ToggleButton enable, partOn, tempo;
+    Knob low { intSpec (tr ("Low key: the lowest note this articulator works on"), 0, 132, 0, keyText),
+               [this] { return (double) articulator().low; },
+               [this] (double v) { changeArticulator ([v] (E::Articulator& a) { a.low = (int) std::lround (v); a.high = std::max (a.high, a.low); }); } };
+    Knob high { intSpec (tr ("High key: the highest note this articulator works on"), 0, 132, 132, keyText),
+                [this] { return (double) articulator().high; },
+                [this] (double v) { changeArticulator ([v] (E::Articulator& a) { a.high = (int) std::lround (v); a.low = std::min (a.low, a.high); }); } };
+    Knob base = levelKnob (tr ("Base level"), 0, 256, 128, &E::Part::base);
+    Knob envLevel = levelKnob (tr ("Envelope level"), -256, 256, 256, &E::Part::env);
+    Knob lfoLevel = levelKnob (tr ("LFO level"), -256, 256, 256, &E::Part::lfo);
+    Knob attack = partKnob (tr ("Attack: scales the time up to the decay point"), 0, 256, 128, [] (E::Part& p) -> int& { return p.adsr[0]; });
+    Knob decay = partKnob (tr ("Decay: scales the time up to the sustain point"), 0, 256, 128, [] (E::Part& p) -> int& { return p.adsr[1]; });
+    Knob sustain = partKnob (tr ("Sustain: raises or lowers the sustain level"), -256, 256, 0, [] (E::Part& p) -> int& { return p.adsr[2]; });
+    Knob release = partKnob (tr ("Release: scales the time after the sustain point"), 0, 256, 128, [] (E::Part& p) -> int& { return p.adsr[3]; });
+    Knob speed = partKnob (tr ("LFO speed"), 0, 65536, 40898, [] (E::Part& p) -> int& { return p.speed; }, [] (double v) {
+        const auto rate = (std::pow (10001.0, v / 65536.0) - 1.0) / 625.0;
+        return juce::String (rate, rate < 1.0 ? 2 : 1);
+    });
+    Knob lfoTension = partKnob (tr ("LFO tension"), -128, 128, 0, [] (E::Part& p) -> int& { return p.tension; });
+    Knob skew = partKnob (tr ("LFO skew"), -128, 128, 0, [] (E::Part& p) -> int& { return p.skew; });
+    Knob pulseWidth = partKnob (tr ("LFO pulse width"), -128, 128, 0, [] (E::Part& p) -> int& { return p.pulseWidth; });
+    CurveEditor editor;
+};
+
+// ---------------------------------------------------------------------------------------------------------------
+// VFX Sequencer (FL's layout, LYNX's look): the sequence on top, a big grid that edits the chosen lane, the six lanes
+// below (click one to edit it), the parameters on the right; 16 steps per page
+
+class SequencerBody final : public Body
+{
+public:
+    using S = vfx::SequencerSettings;
+    enum Layer { noteSelect, velocity, octave, gate, stepType, scaleStep, layerCount };
+
+    SequencerBody()
+    {
+        program.onClick = [this] { showProgramMenu(); };
+        ui::setHint (program, tr ("The sequence (program) of the bank that plays; the bank keeps 128"));
+        addAndMakeVisible (program);
+        for (auto* b : { &prevProgram, &nextProgram, &dice, &shiftLeft, &shiftRight })
+        {
+            b->setWantsKeyboardFocus (false);
+            addAndMakeVisible (b);
+        }
+        prevProgram.onClick = [this] { stepProgram (-1); };
+        nextProgram.onClick = [this] { stepProgram (1); };
+        dice.onClick = [this] {
+            // a random sequence of those that differ from the first (the bank's empty slots are copies of it)
+            std::vector<int> candidates;
+            for (int p = 1; p < (int) settings.programs.size(); ++p)
+                if (settings.programs[(std::size_t) p].lanes != settings.programs[0].lanes || settings.programs[(std::size_t) p].params != settings.programs[0].params)
+                    candidates.push_back (p);
+            if (! candidates.empty())
+                change ([n = candidates[(std::size_t) juce::Random::getSystemRandom().nextInt ((int) candidates.size())]] (S& s) { s.set (S::currentProgram, n); });
+        };
+        ui::setHint (dice, tr ("A random sequence"));
+        shiftLeft.onClick = [this] { change ([] (S& s) { vfx::shiftPattern (s, -1); }); };
+        shiftRight.onClick = [this] { change ([] (S& s) { vfx::shiftPattern (s, 1); }); };
+        ui::setHint (shiftLeft, tr ("Shift the pattern one step earlier"));
+        ui::setHint (shiftRight, tr ("Shift the pattern one step later"));
+        for (int p = 0; p < 4; ++p)
+        {
+            auto& b = pages[(std::size_t) p];
+            b.setButtonText (juce::String (p + 1));
+            b.setClickingTogglesState (false);
+            b.setColour (juce::TextButton::buttonOnColourId, theme::colour::accentMuted);
+            b.onClick = [this, p] { change ([p] (S& s) { s.set (S::page, p); }); };
+            ui::setHint (b, tr ("Steps {0} to {1}", { juce::String (p * 16 + 1), juce::String (p * 16 + 16) }));
+            addAndMakeVisible (b);
+        }
+        toggle (pageLock, tr ("Page lock"), S::pageLock, tr ("Plays only the page shown"));
+        toggle (latch, tr ("Latch"), S::latch, tr ("Latch: the notes keep playing after the keys are released, until a new chord"));
+        toggle (polyKeys, tr ("Poly"), S::polyKeys, tr ("Several keys per step (else one)"));
+        toggle (polyOctave, tr ("Poly"), S::polyOctave, tr ("Several octaves per step (else one)"));
+        toggle (gateLaneMode, tr ("Chan."), S::gateLaneMode, tr ("The gate lane sets each step's output channel instead of its length"));
+
+        combo (arpMode, tr ("Mode"), S::arpMode, { tr ("Off"), tr ("On"), tr ("Thru"), tr ("On from 2 keys, else off"), tr ("On from 2 keys, else thru"),
+                                                    tr ("On from 3 keys, else off"), tr ("On from 3 keys, else thru") });
+        combo (programMode, tr ("Input"), S::programMode, { tr ("The held keys"), tr ("The fixed key") });
+        combo (order, tr ("Order"), S::order, { tr ("By pitch"), tr ("By pitch, descending"), tr ("As played"), tr ("As played, reversed"),
+                                                 tr ("By velocity"), tr ("By velocity, descending"), tr ("Chord, normalized"), tr ("Chord, as played") });
+        combo (missing, tr ("Missing keys"), S::missingKeys, { tr ("Not played"), tr ("Cyclic"), tr ("First key"), tr ("Last key"), tr ("Fixed key") });
+        combo (missingOctave, tr ("Missing octave"), S::missingOctave, { tr ("Same"), "-1", "+1" });
+        combo (quantize, tr ("Input quantize"), S::inputQuantize, { tr ("None"), "1/16", "1/12", "1/8", "1/6", "1/4", "1/2", tr ("1 bar"), tr ("2 bars") });
+        combo (sync, tr ("Step"), S::sync, { "1/64", "1/48", "1/32", "1/24", "1/16", "1/12", "1/8", "1/6", "1/4", "3/64", "3/32", "3/16", "3/8" });
+        combo (restart, tr ("Restart on"), S::restartOn, { tr ("Beat"), tr ("Key"), tr ("First key"), tr ("Play") });
+        combo (velocityMode, tr ("Velocity"), S::velocityMode, { tr ("From the lane"), tr ("From the keys"), tr ("Keys + lane") });
+        juce::StringArray keysList { tr ("Off"), tr ("Detect") };
+        for (int k = 0; k < 12; ++k)
+            keysList.add (pitchClassName (k));
+        combo (forceKey, tr ("Scale key"), S::forceKey, keysList);
+        combo (forceScale, tr ("Scale"), S::forceScale, { tr ("Chromatic"), tr ("Detect"), tr ("Major"), tr ("Minor"), tr ("Harmonic minor"), tr ("Melodic minor"),
+                                                          tr ("Pentatonic major"), tr ("Pentatonic minor"), tr ("Pentatonic neutral"), tr ("Blues"),
+                                                          tr ("Dorian"), tr ("Phrygian"), tr ("Lydian"), tr ("Mixolydian"), tr ("Locrian") });
+        combo (forceMode, tr ("Scale mode"), S::forceMode, { tr ("All notes"), tr ("Scale steps only") });
+        ui::setHint (arpMode, tr ("Mode: Thru passes the notes (transposed); the auto modes play only while enough keys are held"));
+        ui::setHint (order, tr ("Order: how the held keys are numbered N1, N2…"));
+        ui::setHint (missing, tr ("What the steps of a key that is not held play"));
+        ui::setHint (restart, tr ("Where the sequence starts: on the song's beats, at each new key, at the first key, at play"));
+        ui::setHint (forceKey, tr ("Scale key: Detect takes the held chord's root"));
+        ui::setHint (forceScale, tr ("Scale: the notes snap to it and the scale-step lane moves along it"));
+        ui::setHint (quantize, tr ("Input quantize: chord changes wait for this grid"));
+
+        auto percent = [] (double v) { return juce::String ((int) v) + " %"; };
+        auto key = [] (double v) { return keyName ((int) v); };
+        auto signedValue = [] (double v) { return v > 0 ? "+" + juce::String ((int) v) : juce::String ((int) v); };
+        box (steps, tr ("Steps"), S::steps);
+        box (gatePercent, tr ("Gate"), S::gate, percent);
+        box (swing, tr ("Swing"), S::swing, signedValue);
+        box (fixedKey, tr ("Fixed key"), S::fixedKey, key);
+        box (smartBend, tr ("Smart bend"), S::smartBend, signedValue);
+        box (transpose, tr ("Transpose"), S::transposeSemitones, signedValue);
+        box (octaves, tr ("Octave"), S::transposeOctaves, signedValue);
+        box (randomVelocity, tr ("Rand. vel."), S::randomVelocity, percent);
+        box (randomGate, tr ("Rand. gate"), S::randomGate, percent);
+        box (randomStart, tr ("Rand. start"), S::randomStart, percent);
+        box (outLow, tr ("Out low"), S::outputLow, key);
+        box (outHigh, tr ("Out high"), S::outputHigh, key);
+
+        static const char* laneNames[] = { TR_NOOP ("Note select"), TR_NOOP ("Velocity"), TR_NOOP ("Octave"), TR_NOOP ("Gate"), TR_NOOP ("Step type"), TR_NOOP ("Scale step") };
+        for (int l = 0; l < layerCount; ++l)
+        {
+            auto& b = laneButtons[(std::size_t) l];
+            b.setButtonText (tr (laneNames[l]));
+            b.setClickingTogglesState (false);
+            b.setColour (juce::TextButton::buttonOnColourId, theme::colour::accentMuted);
+            b.onClick = [this, l] { showLayer (l); };
+            ui::setHint (b, tr ("Edit this lane in the grid above"));
+            addAndMakeVisible (b);
+        }
+        grid.owner = this;
+        addAndMakeVisible (grid);
+        for (int l = 0; l < layerCount; ++l)
+        {
+            auto& r = rows[(std::size_t) l];
+            r.owner = this;
+            r.layer = l;
+            addAndMakeVisible (r);
+        }
+    }
+
+    void refresh (const std::vector<std::uint8_t>& fl) override
+    {
+        settings = vfx::parseSequencer (fl).value_or (vfx::defaultSequencer());
+        program.setButtonText (juce::String (settings.program()).paddedLeft ('0', 3) + ". " + juce::String (settings.current().nameText()));
+        for (int k = 0; k < 4; ++k)
+            pages[(std::size_t) k].setToggleState (k == settings.get (S::page), juce::dontSendNotification);
+        for (int k = 0; k < layerCount; ++k)
+            laneButtons[(std::size_t) k].setToggleState (k == shown, juce::dontSendNotification);
+        for (auto& [b, param] : toggles)
+            b->setToggleState (settings.get (param) != 0, juce::dontSendNotification);
+        for (auto& [c, param] : combos)
+            c->setSelectedItemIndex (settings.get (param) - S::minimum (param), juce::dontSendNotification);
+        for (auto& b : boxes)
+            b->repaint();
+        grid.repaint();
+        for (auto& r : rows)
+            r.repaint();
+        repaint();
+    }
+
+    int preferredWidth() const override { return 1080; }
+    int preferredHeight() const override { return 470; }
+
+    void resized() override
+    {
+        auto area = getLocalBounds().reduced (12, 4);
+        auto right = area.removeFromRight (336);
+        area.removeFromRight (14);
+
+        auto top = area.removeFromTop (28);
+        prevProgram.setBounds (top.removeFromLeft (24));
+        program.setBounds (top.removeFromLeft (250));
+        nextProgram.setBounds (top.removeFromLeft (24));
+        top.removeFromLeft (4);
+        dice.setBounds (top.removeFromLeft (28));
+        top.removeFromLeft (10);
+        latch.setBounds (top.removeFromLeft (70));
+        shiftRight.setBounds (top.removeFromRight (28));
+        shiftLeft.setBounds (top.removeFromRight (28));
+        top.removeFromRight (8);
+        pageLock.setBounds (top.removeFromRight (96));
+        for (int k = 3; k >= 0; --k)
+            pages[(std::size_t) k].setBounds (top.removeFromRight (28).reduced (1, 0));
+        area.removeFromTop (8);
+
+        auto lanes = area.removeFromBottom (layerCount * 24);
+        for (int l = 0; l < layerCount; ++l)
+        {
+            auto row = lanes.removeFromTop (24).reduced (0, 1);
+            auto label = row.removeFromLeft (Grid::labelWidth).withTrimmedRight (4);
+            laneButtons[(std::size_t) l].setBounds (label.removeFromLeft (74));
+            if (l == noteSelect)
+                polyKeys.setBounds (label.reduced (2, 0));
+            if (l == octave)
+                polyOctave.setBounds (label.reduced (2, 0));
+            if (l == gate)
+                gateLaneMode.setBounds (label.reduced (2, 0));
+            rows[(std::size_t) l].setBounds (row);
+        }
+        area.removeFromBottom (8);
+        grid.setBounds (area);
+
+        // the parameters: four sections, three controls a row
+        int y = right.getY();
+        auto section = [&] (int index, std::initializer_list<juce::Component*> items) {
+            sectionTops[(std::size_t) index] = y;
+            y += 20;
+            int column = 0;
+            for (auto* c : items)
+            {
+                const auto x = right.getX() + column * 112;
+                c->setBounds (x + 2, y + 15, 106, 22);
+                if (dynamic_cast<Knob*> (c) != nullptr)
+                    c->setBounds (x + 2, y, 106, 37);
+                if (++column == 3)
+                {
+                    column = 0;
+                    y += 40;
+                }
+            }
+            if (column != 0)
+                y += 40;
+            y += 4;
+        };
+        section (0, { &arpMode, &programMode, &velocityMode });
+        section (1, { &order, &missing, &missingOctave, &quantize, smartBend.get(), fixedKey.get() });
+        section (2, { steps.get(), &sync, gatePercent.get(), swing.get(), &restart, &forceMode, &forceKey, &forceScale });
+        section (3, { transpose.get(), octaves.get(), randomVelocity.get(), randomGate.get(), randomStart.get(), outLow.get(), outHigh.get() });
+        sectionTops[4] = y;
+    }
+
+    void paint (juce::Graphics& g) override
+    {
+        static const char* titles[] = { TR_NOOP ("Mode"), TR_NOOP ("Input"), TR_NOOP ("Arpeggiator"), TR_NOOP ("Output") };
+        const auto x = getLocalBounds().reduced (12, 4).getRight() - 336;
+        for (int k = 0; k < 4; ++k)
+        {
+            const auto y = sectionTops[(std::size_t) k];
+            g.setColour (theme::colour::bg3);
+            g.fillRoundedRectangle (juce::Rectangle<float> ((float) x - 6.0f, (float) y, 342.0f, (float) (sectionTops[(std::size_t) k + 1] - y - 4)), 4.0f);
+            g.setColour (theme::colour::accent);
+            g.setFont (theme::font (theme::type::caption, true));
+            g.drawText (theme::caps (tr (titles[k])), x, y + 2, 200, 16, juce::Justification::centredLeft);
+        }
+        g.setFont (theme::font (theme::type::caption));
+        g.setColour (theme::colour::textSecondary);
+        for (auto& [c, param] : combos)
+            g.drawText (c->getName(), c->getBounds().translated (0, -15).withHeight (14), juce::Justification::centredLeft);
+    }
+
+    // lane values as text and colour (the big grid's labels and the lane rows)
+    juce::String text (int layer, int step) const
+    {
+        const auto& p = settings.current();
+        const auto v = (int) p.lanes[(std::size_t) laneOf (layer)][(std::size_t) step];
+        switch (layer)
+        {
+            case noteSelect:
+            {
+                static const char* names[] = { "F", "R", "N1", "N2", "N3", "N4", "N5" };
+                juce::String s;
+                for (int bit = 0; bit < 7; ++bit)
+                    if (v & (1 << bit))
+                        s << (s.isEmpty() ? "" : "+") << names[bit];
+                return s.isEmpty() ? "-" : s;
+            }
+            case octave:
+            {
+                juce::String s;
+                for (int bit = 0; bit < 7; ++bit)
+                    if (v & (1 << bit))
+                        s << (s.isEmpty() ? "" : ",") << (bit == 3 ? juce::String ("-") : bit > 3 ? "+" + juce::String (bit - 3) : juce::String (bit - 3));
+                return s.isEmpty() ? juce::String ("x") : s;
+            }
+            case gate:
+            {
+                if (settings.get (S::gateLaneMode) != 0)
+                    return v == 0 ? juce::String ("-") : juce::String (v);
+                static const char* names[] = { "1/8", "1/4", "1/2", "-", "2x", "4x", "8x", "16x", "32x" };
+                return names[juce::jlimit (0, 8, v + 3)];
+            }
+            case stepType:
+            {
+                static const char* names[] = { "Off", "Nrm", "Rst", "Tie", "Chr", "Rnd" };
+                return names[juce::jlimit (0, 5, v)];
+            }
+            case scaleStep: return v == 0 ? juce::String ("-") : (v > 0 ? "+" : "") + juce::String (v);
+            default: return juce::String (v);
+        }
+    }
+
+    static juce::Colour laneColour (int layer)
+    {
+        static const juce::uint32 colours[] = { 0xffe5383b, 0xff59c27a, 0xffe8894a, 0xff4cb8d8, 0xff3fbf86, 0xffd9b443 };
+        return juce::Colour (colours[juce::jlimit (0, 5, layer)]);
+    }
+
+    static int laneOf (int layer)
+    {
+        static const int lanes[] = { S::keySelect, S::velocity, S::octave, S::gateStep, S::stepType, S::scaleStep };
+        return lanes[juce::jlimit (0, 5, layer)];
+    }
+
+    int firstStep() const { return settings.get (S::page) * 16; }
+
+    // the big grid: rows for the bit / choice lanes, bars for velocity, scale step and channels
+    struct Grid final : juce::Component
+    {
+        SequencerBody* owner = nullptr;
+        static constexpr int labelWidth = 140;
+
+        int layer() const { return owner->shown; }
+        bool bars() const
+        {
+            return layer() == velocity || layer() == scaleStep || (layer() == gate && owner->settings.get (S::gateLaneMode) != 0);
+        }
+        int rows() const
+        {
+            switch (layer())
+            {
+                case noteSelect: case octave: return 7;
+                case gate: return 9;
+                case stepType: return 6;
+                default: return 0;
+            }
+        }
+        juce::String rowName (int row) const
+        {
+            switch (layer())
+            {
+                case noteSelect:
+                {
+                    static const char* names[] = { "N5", "N4", "N3", "N2", "N1", TR_NOOP ("Root"), TR_NOOP ("Fixed") };
+                    return row >= 5 ? tr (names[row]) : names[row];
+                }
+                case octave: return row == 3 ? "0" : (row < 3 ? "+" : "") + juce::String (3 - row);
+                case gate:
+                {
+                    static const char* names[] = { "32x", "16x", "8x", "4x", "2x", "1x", "1/2", "1/4", "1/8" };
+                    return names[row];
+                }
+                case stepType:
+                {
+                    static const char* names[] = { TR_NOOP ("Random"), TR_NOOP ("Chord"), TR_NOOP ("Tie"), TR_NOOP ("Rest"), TR_NOOP ("Note"), TR_NOOP ("Off") };
+                    return tr (names[row]);
+                }
+                default: return {};
+            }
+        }
+        // row ↔ value: the bit lanes have a bit per row (top = highest), the others a value per row
+        bool rowSet (int value, int row) const
+        {
+            if (layer() == noteSelect || layer() == octave)
+                return (value & (1 << (6 - row))) != 0;
+            return value == (layer() == gate ? 5 - row : 5 - row);
+        }
+        int barMin() const { return layer() == scaleStep ? (owner->settings.get (14) == 2 || owner->settings.get (14) == 0 ? -12 : 0) : 0; }
+        int barMax() const { return layer() == scaleStep ? 12 : layer() == gate ? 16 : 127; }
+
+        juce::Rectangle<int> cells() const { return getLocalBounds().withTrimmedLeft (labelWidth).withTrimmedBottom (18); }
+        int stepAt (int x) const
+        {
+            const auto c = cells();
+            return owner->firstStep() + juce::jlimit (0, 15, (x - c.getX()) * 16 / std::max (1, c.getWidth()));
+        }
+        int rowAt (int y) const
+        {
+            const auto c = cells();
+            return juce::jlimit (0, rows() - 1, (y - c.getY()) * rows() / std::max (1, c.getHeight()));
+        }
+
+        void paint (juce::Graphics& g) override
+        {
+            const auto& s = owner->settings;
+            const auto c = cells();
+            const auto steps = s.get (S::steps);
+            const auto lane = laneOf (layer());
+            const auto colour = laneColour (layer());
+            const auto w = c.getWidth() / 16.0f;
+            g.setColour (theme::colour::bg0);
+            g.fillRoundedRectangle (c.toFloat().expanded (2.0f), 3.0f);
+            g.setFont (theme::font (theme::type::caption));
+            for (int k = 0; k < 16; ++k)
+            {
+                const auto step = owner->firstStep() + k;
+                const auto x = c.getX() + k * w;
+                const auto used = step < steps;
+                const auto value = (int) s.current().lanes[(std::size_t) lane][(std::size_t) step];
+                const auto type = (int) s.current().lanes[S::stepType][(std::size_t) step];
+                const auto silent = type == S::off || type == S::rest;
+                g.setColour (k % 4 == 0 ? theme::colour::textPrimary : theme::colour::textSecondary);
+                g.drawText (juce::String (step + 1), juce::Rectangle<float> (x, (float) c.getBottom() + 3.0f, w, 14.0f), juce::Justification::centred);
+                const auto alpha = used ? 1.0f : 0.35f;
+                if (! bars())
+                {
+                    const auto h = c.getHeight() / (float) rows();
+                    for (int r = 0; r < rows(); ++r)
+                    {
+                        const auto cell = juce::Rectangle<float> (x, c.getY() + r * h, w, h).reduced (1.0f);
+                        g.setColour ((k / 4 % 2 == 0 ? theme::colour::bg4 : theme::colour::bg3).withMultipliedAlpha (alpha));
+                        g.fillRect (cell);
+                        if (rowSet (value, r))
+                        {
+                            g.setColour (colour.withMultipliedAlpha (alpha * (layer() == noteSelect && (silent || type == S::chord || type == S::random) ? 0.4f : 1.0f)));
+                            g.fillRect (cell);
+                            g.setColour (juce::Colours::white.withAlpha (alpha));
+                            const auto label = layer() == noteSelect ? rowName (r) : owner->text (noteSelect, step);
+                            if (cell.getWidth() > 24.0f)
+                                g.drawText (label, cell, juce::Justification::centred);
+                        }
+                    }
+                }
+                else
+                {
+                    const auto lo = barMin(), hi = barMax();
+                    const auto zero = lo < 0 ? c.getY() + c.getHeight() * (float) hi / (float) (hi - lo) : (float) c.getBottom();
+                    const auto y = c.getY() + c.getHeight() * (float) (hi - juce::jlimit (lo, hi, value)) / (float) (hi - lo);
+                    const auto column = juce::Rectangle<float> (x, (float) c.getY(), w, (float) c.getHeight()).reduced (1.0f, 0.0f);
+                    g.setColour ((k / 4 % 2 == 0 ? theme::colour::bg4 : theme::colour::bg3).withMultipliedAlpha (alpha * 0.6f));
+                    g.fillRect (column);
+                    auto bar = juce::Rectangle<float>::leftTopRightBottom (column.getX(), std::min (y, zero), column.getRight(), std::max (y, zero));
+                    g.setColour (colour.withMultipliedAlpha (alpha * (silent ? 0.4f : 1.0f)));
+                    g.fillRect (bar.getHeight() < 2.0f ? bar.withHeight (2.0f).withY (zero - 1.0f) : bar);
+                    g.setColour (juce::Colours::white.withAlpha (alpha));
+                    g.drawText (owner->text (layer(), step), column.withHeight (16.0f).withY (std::min (y, zero) - (std::min (y, zero) > c.getY() + 16 ? 16.0f : 0.0f)),
+                                juce::Justification::centred);
+                }
+            }
+            // row labels / scale
+            g.setColour (theme::colour::textSecondary);
+            if (! bars())
+            {
+                const auto h = c.getHeight() / (float) rows();
+                for (int r = 0; r < rows(); ++r)
+                    g.drawText (rowName (r), juce::Rectangle<float> (0.0f, c.getY() + r * h, labelWidth - 8.0f, h), juce::Justification::centredRight);
+            }
+            else
+                for (const auto v : { barMax(), (barMin() + barMax()) / 2, barMin() })
+                {
+                    const auto y = c.getY() + c.getHeight() * (float) (barMax() - v) / (float) (barMax() - barMin());
+                    g.drawText (juce::String (v), juce::Rectangle<float> (0.0f, y - 7.0f, labelWidth - 8.0f, 14.0f), juce::Justification::centredRight);
+                }
+        }
+
+        void mouseDown (const juce::MouseEvent& e) override
+        {
+            lastStep = -1;
+            if (! bars())
+            {
+                const auto step = stepAt (e.x);
+                const auto row = rowAt (e.y);
+                const auto value = (int) owner->settings.current().lanes[(std::size_t) laneOf (layer())][(std::size_t) step];
+                painting = ! rowSet (value, row); // (a poly lane: the click toggles that row, a drag paints the same)
+                paintRow = row;
+            }
+            mouseDrag (e);
+        }
+
+        void mouseDrag (const juce::MouseEvent& e) override
+        {
+            const auto step = stepAt (e.x);
+            const auto lane = laneOf (layer());
+            const auto right = e.mods.isPopupMenu();
+            if (! bars())
+            {
+                if (step == lastStep)
+                    return;
+                lastStep = step;
+                const auto l = layer();
+                const auto row = paintRow;
+                const auto set = painting;
+                const auto poly = (l == noteSelect && owner->settings.get (S::polyKeys) != 0) || (l == octave && owner->settings.get (S::polyOctave) != 0);
+                owner->change ([=] (S& s) {
+                    auto& v = s.current().lanes[(std::size_t) lane][(std::size_t) step];
+                    if (l == noteSelect || l == octave)
+                    {
+                        const auto bit = 6 - row;
+                        if (right)
+                            v = (std::int8_t) (l == octave ? 0x08 : 0); // (right-click: no key / octave 0)
+                        else if (poly)
+                            v = (std::int8_t) (set ? (v | (1 << bit)) : (v & ~(1 << bit)));
+                        else
+                            v = (std::int8_t) (1 << bit);
+                    }
+                    else
+                        v = (std::int8_t) (right ? (l == stepType ? S::normal : 0) : 5 - row);
+                });
+                return;
+            }
+            const auto c = cells();
+            const auto lo = barMin(), hi = barMax();
+            const auto value = right ? (layer() == velocity ? 96 : 0)
+                                     : juce::jlimit (lo, hi, (int) std::lround (hi - (e.y - c.getY()) * (double) (hi - lo) / std::max (1, c.getHeight())));
+            owner->change ([=] (S& s) { s.current().lanes[(std::size_t) lane][(std::size_t) step] = (std::int8_t) value; });
+        }
+
+        void mouseWheelMove (const juce::MouseEvent& e, const juce::MouseWheelDetails& w) override
+        {
+            // the wheel moves a step's value (FL: moves the note up / down)
+            const auto step = stepAt (e.x);
+            const auto lane = laneOf (layer());
+            const auto delta = w.deltaY > 0 ? 1 : w.deltaY < 0 ? -1 : 0;
+            if (delta == 0)
+                return;
+            const auto l = layer();
+            owner->change ([=] (S& s) {
+                auto& v = s.current().lanes[(std::size_t) lane][(std::size_t) step];
+                if (l == noteSelect || l == octave) // (shift the bits one row)
+                {
+                    const auto shifted = delta > 0 ? (v << 1) : ((std::uint8_t) v >> 1);
+                    if ((shifted & 0x7f) != 0)
+                        v = (std::int8_t) (shifted & 0x7f);
+                }
+                else
+                    s.set (0x80 + lane * 64 + step, v + delta);
+            });
+        }
+
+        int lastStep = -1, paintRow = 0;
+        bool painting = true;
+    };
+
+    // one lane in brief: its values on the page; a click shows it in the big grid
+    struct LaneRow final : juce::Component
+    {
+        SequencerBody* owner = nullptr;
+        int layer = 0;
+        void paint (juce::Graphics& g) override
+        {
+            const auto steps = owner->settings.get (S::steps);
+            const auto w = getWidth() / 16.0f;
+            const auto colour = laneColour (layer);
+            g.setFont (theme::font (theme::type::caption));
+            for (int k = 0; k < 16; ++k)
+            {
+                const auto step = owner->firstStep() + k;
+                const auto cell = juce::Rectangle<float> (k * w, 0.0f, w, (float) getHeight()).reduced (1.0f, 1.0f);
+                const auto alpha = step < steps ? 1.0f : 0.3f;
+                g.setColour (colour.withMultipliedAlpha (alpha * (layer == owner->shown ? 1.0f : 0.75f)));
+                g.fillRect (cell);
+                g.setColour (juce::Colours::black.withAlpha (0.8f * alpha));
+                g.drawText (owner->text (layer, step), cell, juce::Justification::centred);
+            }
+        }
+        void mouseDown (const juce::MouseEvent&) override { owner->showLayer (layer); }
+    };
+
+private:
+    void showLayer (int l)
+    {
+        shown = l;
+        for (int k = 0; k < layerCount; ++k)
+            laneButtons[(std::size_t) k].setToggleState (k == shown, juce::dontSendNotification);
+        grid.repaint();
+        for (auto& r : rows)
+            r.repaint();
+    }
+
+    void change (std::function<void (S&)> f)
+    {
+        if (edit)
+            edit ([f] (std::vector<std::uint8_t>& fl) {
+                auto s = vfx::parseSequencer (fl).value_or (vfx::defaultSequencer());
+                f (s);
+                fl = vfx::writeSequencer (s);
+            });
+    }
+
+    void toggle (juce::ToggleButton& b, const juce::String& text, int param, const juce::String& hint)
+    {
+        b.setButtonText (text);
+        b.onClick = [this, &b, param] { change ([param, on = b.getToggleState()] (S& s) { s.set (param, on ? 1 : 0); }); };
+        ui::setHint (b, hint);
+        addAndMakeVisible (b);
+        toggles.push_back ({ &b, param });
+    }
+
+    void combo (juce::ComboBox& c, const juce::String& name, int param, const juce::StringArray& items)
+    {
+        c.setName (name);
+        c.addItemList (items, 1);
+        c.onChange = [this, &c, param] { change ([param, v = c.getSelectedItemIndex() + S::minimum (param)] (S& s) { s.set (param, v); }); };
+        ui::setHint (c, name);
+        addAndMakeVisible (c);
+        combos.push_back ({ &c, param });
+    }
+
+    void box (std::unique_ptr<Knob>& k, const juce::String& name, int param, std::function<juce::String (double)> text = nullptr)
+    {
+        k = std::make_unique<Knob> (intSpec (name, S::minimum (param), S::maximum (param), defaultOf (param), std::move (text)),
+                                    [this, param] { return (double) settings.get (param); },
+                                    [this, param] (double v) { change ([param, v] (S& s) { s.set (param, (int) std::lround (v)); }); });
+        k->caption = name;
+        k->box = true;
+        addAndMakeVisible (*k);
+        boxes.push_back (k.get());
+    }
+
+    static int defaultOf (int param)
+    {
+        static const auto blank = [] {
+            auto s = vfx::defaultSequencer();
+            s.set (S::currentProgram, 0);
+            return s;
+        }();
+        return blank.get (param);
+    }
+
+    void showProgramMenu()
+    {
+        juce::PopupMenu menu;
+        for (int group = 0; group < (int) settings.programs.size(); group += 16)
+        {
+            juce::PopupMenu sub;
+            for (int p = group; p < std::min (group + 16, (int) settings.programs.size()); ++p)
+                sub.addItem (juce::String (p).paddedLeft ('0', 3) + ". " + juce::String (settings.programs[(std::size_t) p].nameText()), true,
+                             p == settings.program(), [this, p] { change ([p] (S& s) { s.set (S::currentProgram, p); }); });
+            menu.addSubMenu (juce::String (group).paddedLeft ('0', 3) + "-" + juce::String (group + 15).paddedLeft ('0', 3), sub, true, nullptr,
+                             settings.program() / 16 == group / 16);
+        }
+        menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (&program));
+    }
+
+    void stepProgram (int delta)
+    {
+        const auto n = std::max (1, (int) settings.programs.size());
+        change ([delta, n] (S& s) { s.set (S::currentProgram, (s.program() + delta + n) % n); });
+    }
+
+    S settings = vfx::defaultSequencer();
+    int shown = noteSelect;
+    juce::TextButton program, prevProgram { "<" }, nextProgram { ">" }, dice { "?" }, shiftLeft { "<<" }, shiftRight { ">>" };
+    std::array<juce::TextButton, 4> pages;
+    std::array<juce::TextButton, layerCount> laneButtons;
+    juce::ToggleButton pageLock, latch, polyOctave, polyKeys, gateLaneMode;
+    juce::ComboBox arpMode, programMode, order, missing, missingOctave, quantize, sync, restart, velocityMode, forceKey, forceScale, forceMode;
+    std::unique_ptr<Knob> steps, gatePercent, swing, fixedKey, smartBend, transpose, octaves, randomVelocity, randomGate, randomStart, outLow, outHigh;
+    std::vector<std::pair<juce::ToggleButton*, int>> toggles;
+    std::vector<std::pair<juce::ComboBox*, int>> combos;
+    std::vector<Knob*> boxes;
+    std::array<int, 5> sectionTops {};
+    Grid grid;
+    std::array<LaneRow, layerCount> rows;
+};
+
+// ---------------------------------------------------------------------------------------------------------------
+// VFX Script: the script and the values of its controls, kept as FL saved them (LYNX does not run Python)
+
+class ScriptBody final : public Body
+{
+public:
+    ScriptBody()
+    {
+        for (auto* e : { &source, &values })
+        {
+            e->setMultiLine (true, false);
+            e->setReturnKeyStartsNewLine (true);
+            e->setTabKeyUsedAsCharacter (true);
+            e->setScrollbarsShown (true);
+            e->setFont (juce::FontOptions (juce::Font::getDefaultMonospacedFontName(), 13.0f, juce::Font::plain));
+            addAndMakeVisible (e);
+        }
+        values.setReadOnly (true);
+        source.onTextChange = [this] { save.setEnabled (source.getText().replace ("\r\n", "\n").toStdString() != loaded); };
+        save.setButtonText (tr ("Save the script"));
+        save.setEnabled (false);
+        save.onClick = [this] {
+            const auto text = source.getText().replace ("\r\n", "\n").toStdString();
+            if (edit)
+                edit ([text] (std::vector<std::uint8_t>& fl) {
+                    auto s = vfx::parseScript (fl).value_or (vfx::defaultScript());
+                    s.setSource (text);
+                    fl = vfx::writeScript (s);
+                });
+        };
+        ui::setHint (save, tr ("Keeps the edited script in the project (FL Studio runs it when the project opens there)"));
+        addAndMakeVisible (save);
+    }
+
+    void refresh (const std::vector<std::uint8_t>& fl) override
+    {
+        const auto s = vfx::parseScript (fl).value_or (vfx::defaultScript());
+        const auto text = s.source();
+        if (text != loaded) // (a pending edit stays while other things change)
+        {
+            loaded = text;
+            source.setText (juce::String::fromUTF8 (text.c_str()), juce::dontSendNotification);
+        }
+        save.setEnabled (source.getText().replace ("\r\n", "\n").toStdString() != loaded);
+        juce::String list;
+        for (const auto& [name, value] : s.parameters())
+            list << juce::String::fromUTF8 (name.c_str()) << " = " << juce::String::fromUTF8 (value.c_str()) << "\n";
+        if (s.hasSurface())
+            list << "\n" << tr ("(with an embedded Control Surface)");
+        values.setText (list.isEmpty() ? tr ("(no saved control values)") : list, juce::dontSendNotification);
+    }
+
+    int preferredWidth() const override { return 900; }
+    int preferredHeight() const override { return 520; }
+
+    void resized() override
+    {
+        auto area = getLocalBounds().reduced (12, 6);
+        area.removeFromTop (40);
+        auto bottom = area.removeFromBottom (30);
+        save.setBounds (bottom.removeFromRight (160).withTrimmedTop (4));
+        auto right = area.removeFromRight (260);
+        right.removeFromTop (18);
+        values.setBounds (right);
+        area.removeFromRight (10);
+        area.removeFromTop (18);
+        source.setBounds (area);
+    }
+
+    void paint (juce::Graphics& g) override
+    {
+        auto area = getLocalBounds().reduced (12, 6);
+        g.setColour (theme::colour::warning);
+        g.setFont (theme::font (theme::type::body));
+        g.drawFittedText (tr ("LYNX keeps the script and its settings but does not run Python scripts yet: the notes pass through unchanged."),
+                          area.removeFromTop (36), juce::Justification::centredLeft, 2);
+        g.setFont (theme::font (theme::type::caption));
+        g.setColour (theme::colour::textSecondary);
+        const auto top = area.removeFromTop (18);
+        g.drawText (theme::caps (tr ("Script")), top, juce::Justification::centredLeft);
+        g.drawText (theme::caps (tr ("Control values")), top.withTrimmedLeft (top.getWidth() - 260), juce::Justification::centredLeft);
+    }
+
+private:
+    juce::TextEditor source, values;
+    juce::TextButton save;
+    std::string loaded;
+};
+
+// A kind LYNX does not edit yet: says so (its notes pass through)
+class PendingBody final : public Body
+{
+public:
+    void refresh (const std::vector<std::uint8_t>&) override {}
+    int preferredHeight() const override { return 80; }
+    void paint (juce::Graphics& g) override
+    {
+        g.setColour (theme::colour::textSecondary);
+        g.setFont (theme::font (theme::type::body));
+        g.drawFittedText (tr ("LYNX keeps this plugin's settings (from FL Studio) and passes its notes through unchanged."),
+                          getLocalBounds().reduced (14, 8), juce::Justification::topLeft, 3);
+    }
+};
+
+std::unique_ptr<Body> makeBody (vfx::Kind kind)
+{
+    switch (kind)
+    {
+        case vfx::Kind::keyMapper: return std::make_unique<KeyMapperBody>();
+        case vfx::Kind::colorMapper: return std::make_unique<ColorMapperBody>();
+        case vfx::Kind::levelScaler: return std::make_unique<LevelScalerBody>();
+        case vfx::Kind::keyboardSplitter: return std::make_unique<KeyboardSplitterBody>();
+        case vfx::Kind::envelope: return std::make_unique<EnvelopeBody>();
+        case vfx::Kind::sequencer: return std::make_unique<SequencerBody>();
+        case vfx::Kind::script: return std::make_unique<ScriptBody>();
+    }
+    return std::make_unique<PendingBody>();
+}
+
+juce::String description (vfx::Kind kind)
+{
+    switch (kind)
+    {
+        case vfx::Kind::keyMapper: return tr ("Maps each played note to other notes: transpose, scales, chords");
+        case vfx::Kind::colorMapper: return tr ("Sends each note colour to its own voice output");
+        case vfx::Kind::envelope: return tr ("Envelopes and LFOs on the notes' velocity, pitch, pan and Mod X / Y");
+        case vfx::Kind::keyboardSplitter: return tr ("Splits the keyboard and the velocity into zones, one output each");
+        case vfx::Kind::levelScaler: return tr ("Reshapes the notes' velocity, release, fine pitch, pan and Mod X / Y");
+        case vfx::Kind::sequencer: return tr ("Plays step patterns and arpeggios from the held notes");
+        case vfx::Kind::script: return tr ("FL's Python note scripts");
+    }
+    return {};
+}
+
+// ---------------------------------------------------------------------------------------------------------------
+
+class VfxEditor final : public juce::Component, private juce::ChangeListener
+{
+public:
+    VfxEditor (AudioEngine& e, std::function<ChannelDef* (Song&)> l, int c) : engine (e), locate (std::move (l)), channel (c)
+    {
+        const auto s = state();
+        kind = s ? s->kind : vfx::Kind::keyMapper;
+        body = makeBody (kind);
+        body->edit = [this] (Body::Edit change) { editState ([change] (vfx::State& st) { change (st.fl); }); };
+        addAndMakeVisible (*body);
+
+        presetButton.onClick = [this] { showPresetMenu(); };
+        ui::setHint (presetButton, tr ("Presets: LYNX's own and, with FL Studio installed, FL's factory presets"));
+        addAndMakeVisible (presetButton);
+        for (auto* b : { &prev, &next })
+        {
+            addAndMakeVisible (b);
+            b->setWantsKeyboardFocus (false);
+        }
+        prev.onClick = [this] { stepPreset (-1); };
+        next.onClick = [this] { stepPreset (1); };
+
+        // on a Channel Rack channel: the MIDI port its outputs go out on
+        port.setSliderStyle (juce::Slider::IncDecButtons);
+        port.setRange (0, 255, 1);
+        port.setTextBoxStyle (juce::Slider::TextBoxLeft, false, 48, 22);
+        port.onValueChange = [this] { editState ([v = (int) port.getValue()] (vfx::State& st) { st.port = v; }); };
+        ui::setHint (port, tr ("Output port: output 1 goes out on this MIDI port, output 2 on the next one…; the plugins and Patchers "
+                               "that take that port play it"));
+        portLabel.setText (tr ("Output port"), juce::dontSendNotification);
+        portLabel.setFont (theme::font (theme::type::small));
+        connect.setButtonText (tr ("Send to a plugin..."));
+        connect.onClick = [this] { showConnectMenu(); };
+        ui::setHint (connect, tr ("Sets a plugin channel's MIDI input port to this port, so it plays what this channel sends"));
+        for (juce::Component* comp : { (juce::Component*) &port, (juce::Component*) &portLabel, (juce::Component*) &connect })
+        {
+            addAndMakeVisible (comp);
+            comp->setVisible (channel >= 0);
+        }
+
+        engine.addChangeListener (this);
+        refresh();
+        setSize (std::max (620, body->preferredWidth()), 44 + (channel >= 0 ? 34 : 0) + body->preferredHeight());
+    }
+
+    ~VfxEditor() override { engine.removeChangeListener (this); }
+
+    void paint (juce::Graphics& g) override
+    {
+        g.fillAll (theme::colour::bg2);
+        // the name, and below it what the plugin does (left of the preset selector)
+        auto top = getLocalBounds().removeFromTop (40).reduced (14, 3).withTrimmedRight (280);
+        g.setColour (theme::colour::textPrimary);
+        g.setFont (theme::font (theme::type::title, true));
+        g.drawText (vfx::flName (kind), top.removeFromTop (19), juce::Justification::bottomLeft);
+        g.setColour (theme::colour::textSecondary);
+        g.setFont (theme::font (theme::type::caption));
+        g.drawText (description (kind), top, juce::Justification::centredLeft, true);
+        g.setColour (theme::colour::border);
+        g.drawHorizontalLine (40, 0.0f, (float) getWidth());
+    }
+
+    void resized() override
+    {
+        auto area = getLocalBounds();
+        auto top = area.removeFromTop (40).reduced (10, 7);
+        next.setBounds (top.removeFromRight (26));
+        presetButton.setBounds (top.removeFromRight (210));
+        prev.setBounds (top.removeFromRight (26));
+        area.removeFromTop (4);
+        if (channel >= 0)
+        {
+            auto row = area.removeFromTop (30).reduced (14, 2);
+            portLabel.setBounds (row.removeFromLeft (90));
+            port.setBounds (row.removeFromLeft (130));
+            row.removeFromLeft (10);
+            connect.setBounds (row.removeFromLeft (170));
+        }
+        body->setBounds (area);
+    }
+
+private:
+    std::optional<vfx::State> state() const
+    {
+        const auto* c = locate (const_cast<Song&> (engine.getSong()));
+        return c != nullptr ? vfx::readState (c->pluginState) : std::nullopt;
+    }
+
+    void editState (std::function<void (vfx::State&)> change)
+    {
+        engine.editSong ([this, change] (Song& song) {
+            auto* c = locate (song);
+            if (c == nullptr || c->instrument != InstrumentKind::vfx)
+                return;
+            auto s = vfx::readState (c->pluginState);
+            if (! s)
+                return;
+            change (*s);
+            c->pluginState = vfx::writeState (*s);
+        });
+    }
+
+    struct PresetEntry
+    {
+        juce::String folder, name;
+        std::vector<std::uint8_t> fl; // LYNX's own
+        juce::File file;              // FL's
+    };
+
+    std::vector<PresetEntry> presets() const
+    {
+        std::vector<PresetEntry> out;
+        for (auto& p : vfx::builtInPresets (kind))
+            out.push_back ({ juce::String::fromUTF8 (p.folder.c_str()), juce::String::fromUTF8 (p.name.c_str()), std::move (p.fl), {} });
+        const auto roots = findFlStudioRoots();
+        if (! roots.data.empty())
+        {
+            const auto base = juce::File (juce::String::fromUTF8 (roots.data.c_str())).getChildFile ("Patches/Plugin presets/Effects").getChildFile (vfx::flName (kind));
+            auto files = base.findChildFiles (juce::File::findFiles, true, "*.fst");
+            std::sort (files.begin(), files.end(), [] (const juce::File& a, const juce::File& b) { return a.getFullPathName().compareNatural (b.getFullPathName()) < 0; });
+            for (const auto& f : files)
+            {
+                const auto folder = f.getParentDirectory() == base ? juce::String() : f.getParentDirectory().getFileName();
+                out.push_back ({ "FL Studio" + (folder.isEmpty() ? juce::String() : " / " + folder), f.getFileNameWithoutExtension(), {}, f });
+            }
+            // the Sequencer's factory programs are one bank: the state of FL's plugin database entry
+            const auto bank = juce::File (juce::String::fromUTF8 (roots.data.c_str())).getChildFile ("Patches/Plugin database/Effects/Patcher/VFX Sequencer.fst");
+            if (kind == vfx::Kind::sequencer && bank.existsAsFile())
+                out.push_back ({ "FL Studio", tr ("Factory bank"), {}, bank });
+        }
+        return out;
+    }
+
+    void apply (const PresetEntry& p)
+    {
+        auto fl = p.fl;
+        if (p.file != juce::File())
+        {
+            juce::MemoryBlock data;
+            if (! p.file.loadFileAsData (data))
+                return;
+            const auto* bytes = static_cast<const std::uint8_t*> (data.getData());
+            const auto state = vfx::stateFromFlPreset (std::vector<std::uint8_t> (bytes, bytes + data.getSize()), kind);
+            if (! state)
+                return;
+            fl = *state;
+        }
+        presetName = p.name;
+        editState ([fl] (vfx::State& st) { st.fl = fl; });
+        presetButton.setButtonText (presetName);
+    }
+
+    void showPresetMenu()
+    {
+        const auto all = presets();
+        juce::PopupMenu menu;
+        menu.addItem (tr ("Default"), [this] {
+            presetName = tr ("Default");
+            editState ([k = kind] (vfx::State& st) { st.fl = vfx::defaultState (k); });
+            presetButton.setButtonText (presetName);
+        });
+        std::map<juce::String, juce::PopupMenu> folders;
+        std::vector<juce::String> order;
+        for (std::size_t i = 0; i < all.size(); ++i)
+        {
+            const auto folder = all[i].folder.isEmpty() ? tr ("Presets") : all[i].folder;
+            if (! folders.count (folder))
+                order.push_back (folder);
+            folders[folder].addItem (all[i].name, [this, entry = all[i]] { apply (entry); });
+        }
+        for (const auto& f : order)
+            menu.addSubMenu (f, folders[f]);
+        menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (&presetButton));
+    }
+
+    void stepPreset (int delta)
+    {
+        const auto all = presets();
+        if (all.empty())
+            return;
+        int at = -1;
+        for (int i = 0; i < (int) all.size(); ++i)
+            if (all[(std::size_t) i].name == presetName)
+                at = i;
+        at = at < 0 ? (delta > 0 ? 0 : (int) all.size() - 1) : (at + delta + (int) all.size()) % (int) all.size();
+        apply (all[(std::size_t) at]);
+    }
+
+    void showConnectMenu()
+    {
+        juce::PopupMenu menu;
+        const auto& song = engine.getSong();
+        const auto s = state();
+        const auto p = s ? s->port : 0;
+        for (int c = 0; c < (int) song.channels.size(); ++c)
+            if (song.channels[(std::size_t) c].instrument == InstrumentKind::plugin)
+                menu.addItem (juce::String::fromUTF8 (song.channels[(std::size_t) c].name.c_str()), true,
+                              song.channels[(std::size_t) c].plugin.midiInPort == p, [this, c, p] {
+                                  engine.editSong ([c, p] (Song& song) {
+                                      auto& in = song.channels[(std::size_t) c].plugin.midiInPort;
+                                      in = in == p ? -1 : p;
+                                  });
+                              });
+        if (menu.getNumItems() == 0)
+            menu.addItem (tr ("(no plugin channel in the Channel Rack)"), false, false, [] {});
+        menu.showMenuAsync (juce::PopupMenu::Options().withTargetComponent (&connect));
+    }
+
+    void refresh()
+    {
+        const auto s = state();
+        if (! s)
+            return;
+        body->refresh (s->fl);
+        port.setValue (s->port, juce::dontSendNotification);
+        if (presetName.isEmpty())
+            presetButton.setButtonText (tr ("Presets"));
+    }
+
+    void changeListenerCallback (juce::ChangeBroadcaster*) override { refresh(); }
+
+    AudioEngine& engine;
+    std::function<ChannelDef* (Song&)> locate;
+    int channel;
+    vfx::Kind kind;
+    std::unique_ptr<Body> body;
+    juce::TextButton presetButton, prev { juce::String::fromUTF8 ("\xe2\x97\x80") }, next { juce::String::fromUTF8 ("\xe2\x96\xb6") };
+    juce::String presetName;
+    juce::Slider port;
+    juce::Label portLabel;
+    juce::TextButton connect;
+};
+} // namespace
+
+std::unique_ptr<juce::Component> makeVfxEditor (AudioEngine& engine, std::function<ChannelDef* (Song&)> locate, int channel)
+{
+    return std::make_unique<VfxEditor> (engine, std::move (locate), channel);
+}
+
+std::unique_ptr<juce::Component> makeVfxEditor (AudioEngine& engine, int channel)
+{
+    return makeVfxEditor (
+        engine,
+        [channel] (Song& song) -> ChannelDef* {
+            return channel >= 0 && channel < (int) song.channels.size() ? &song.channels[(std::size_t) channel] : nullptr;
+        },
+        channel);
+}
+} // namespace lynx

+ 19 - 0
src/ui/VfxEditors.h

@@ -0,0 +1,19 @@
+#pragma once
+
+#include <functional>
+#include <memory>
+
+#include <juce_gui_basics/juce_gui_basics.h>
+
+#include "engine/AudioEngine.h"
+
+// Editors of FL's VFX note processors (round 164b, core/Vfx.h), in LYNX's look: a header with the plugin's name,
+// its presets (LYNX's own and, when FL Studio is installed, FL's factory presets) and — on a Channel Rack channel —
+// the MIDI port its outputs go out on; then the plugin's own controls.
+namespace lynx
+{
+// `locate` finds the VFX's ChannelDef in a song (a Channel Rack channel, or a node inside a Patcher); `channel` = its
+// channel index, −1 inside a Patcher
+std::unique_ptr<juce::Component> makeVfxEditor (AudioEngine& engine, std::function<ChannelDef* (Song&)> locate, int channel);
+std::unique_ptr<juce::Component> makeVfxEditor (AudioEngine& engine, int channel);
+} // namespace lynx

+ 881 - 0
tests/Vfx164Tests.inc

@@ -0,0 +1,881 @@
+// Round 164b: FL's VFX note processors (core/Vfx.h) in a Patcher and in the Channel Rack
+
+#include "core/Vfx.h"
+
+namespace vfx164
+{
+std::vector<std::uint8_t> hex (const char* h)
+{
+    std::vector<std::uint8_t> out;
+    for (; h[0] != 0 && h[1] != 0; h += 2)
+        out.push_back ((std::uint8_t) std::stoi (std::string (h, 2), nullptr, 16));
+    return out;
+}
+
+// FL's factory presets (the 0xD5 record of Data/Patches/Plugin presets/Effects/VFX Key Mapper/…)
+const char* keyMapperDefault = "020000000100000000000000000000000000000000000000010000000000010000000100010000000200010000000300010000000400010000000500010000000600010000000700010000000800010000000900010000000a00010000000b00";
+const char* keyMapperOctaveUp = "0200000001000000000000000000000000000000000000000200000000000c000200000001000d000200000002000e000200000003000f00020000000400100002000000050011000200000006001200020000000700130002000000080014000200000009001500020000000a001600020000000b001700";
+const char* keyMapperMajor = "020000000100000000000000000000000000000000000000010000000000010000000000010000000200010000000200010000000400010000000500010000000500010000000700010000000700010000000900010000000900010000000b00";
+const char* colorMapperDefault = "00000000000000000100000002000000030000000400000005000000060000000700000008000000090000000a0000000b0000000c0000000d0000000e0000000f000000000000000100000002000000030000000400000005000000060000000700000008000000090000000a0000000b0000000c0000000d0000000e0000000f000000";
+
+lynx::vfx::Event on (int key, int offset = 0, int colour = 0, float velocity = 0.8f)
+{
+    lynx::vfx::Event e;
+    e.type = lynx::vfx::Event::Type::on;
+    e.offset = offset;
+    e.voice.key = key;
+    e.voice.velocity = velocity;
+    e.voice.colour = colour;
+    e.id = lynx::vfx::inputId (key, colour);
+    return e;
+}
+
+lynx::vfx::Event off (int key, int offset = 0, int colour = 0)
+{
+    auto e = on (key, offset, colour, 0.0f);
+    e.type = lynx::vfx::Event::Type::off;
+    return e;
+}
+
+// runs one block and returns what came out, sorted
+std::vector<lynx::vfx::Event> run (lynx::vfx::Processor& p, std::vector<lynx::vfx::Event> in, int n = 512)
+{
+    lynx::vfx::EventList out;
+    lynx::vfx::Transport t;
+    p.process (in.data(), (int) in.size(), n, t, out);
+    out.sortByOffset();
+    std::vector<lynx::vfx::Event> v;
+    for (int k = 0; k < out.size(); ++k)
+        v.push_back (out[k]);
+    return v;
+}
+
+// An instrument that writes down what it was asked to play, and at which sample of its renders
+struct Probe final : lynx::Instrument
+{
+    struct Hit
+    {
+        bool on = true;
+        int key = 0, sample = 0, channel = -1;
+        float velocity = 0.0f;
+    };
+    std::vector<Hit> hits;
+    int position = 0;
+    void prepare (double) noexcept override {}
+    void noteOn (int key, float velocity) noexcept override { hits.push_back ({ true, key, position, -1, velocity }); }
+    void noteOff (int key) noexcept override { hits.push_back ({ false, key, position, -1, 0.0f }); }
+    void noteOnMidi (int key, float velocity, int channel) noexcept override { hits.push_back ({ true, key, position, channel, velocity }); }
+    void noteOffMidi (int key, int channel) noexcept override { hits.push_back ({ false, key, position, channel, 0.0f }); }
+    void allNotesOff() noexcept override {}
+    void render (float*, float*, int n, float, float) noexcept override { position += n; }
+};
+
+// A generator Patcher: Notes → VFX node (kind, state) → output `output` → a probe synth node (index 1)
+struct Rig
+{
+    lynx::ChannelDef channel;
+    std::vector<std::shared_ptr<Probe>> probes;
+    std::unique_ptr<lynx::Instrument> instrument;
+
+    Rig (lynx::vfx::Kind kind, std::vector<std::uint8_t> fl, int outputs = 1)
+    {
+        channel.instrument = lynx::InstrumentKind::patcher;
+        lynx::PatchNode v;
+        v.generator = true;
+        lynx::vfx::makeChannel (v.channel, kind);
+        lynx::vfx::State s;
+        s.kind = kind;
+        s.fl = std::move (fl);
+        v.channel.pluginState = lynx::vfx::writeState (s);
+        channel.patcher.nodes.push_back (v);
+        channel.patcher.wires.push_back (patcher162::midi (lynx::patchFromHost, 0, 0, 0));
+        for (int k = 0; k < outputs; ++k)
+        {
+            channel.patcher.nodes.push_back (patcher162::generatorNode (lynx::InstrumentKind::synth));
+            channel.patcher.wires.push_back (patcher162::midi (0, k, 1 + k, 0));
+        }
+        auto factories = lynx::patcher::builtInFactories (48000.0);
+        auto builtIn = factories.instrument;
+        factories.instrument = [this, builtIn] (const lynx::ChannelDef& c) -> std::shared_ptr<lynx::Instrument> {
+            if (c.instrument == lynx::InstrumentKind::synth)
+            {
+                probes.push_back (std::make_shared<Probe>());
+                return probes.back();
+            }
+            return builtIn (c);
+        };
+        instrument = lynx::patcher::makeInstrument (channel, 48000.0, factories);
+    }
+    void render (int n)
+    {
+        std::vector<float> l ((std::size_t) n), r ((std::size_t) n);
+        instrument->beginChunk (n);
+        instrument->render (l.data(), r.data(), n, 1.0f, 1.0f);
+    }
+};
+} // namespace vfx164
+
+TEST (vfx_names_and_state_round_trip)
+{
+    using namespace lynx::vfx;
+    for (const auto k : allKinds)
+    {
+        CHECK (kindOfFlName (flName (k)) == k);
+        State s;
+        s.kind = k;
+        s.port = 7;
+        s.fl = { 1, 2, 3 };
+        const auto back = readState (writeState (s));
+        CHECK (back && back->kind == k && back->port == 7 && back->fl == s.fl);
+    }
+    CHECK (kindOfFlName ("vfx key mapper") == Kind::keyMapper);
+    CHECK (! kindOfFlName ("Fruity Delay 3"));
+    CHECK (! readState ({ 1, 2, 3, 4, 5 }));
+}
+
+TEST (vfx_key_mapper_reads_fl_presets_and_writes_them_back)
+{
+    using namespace vfx164;
+    for (const auto* h : { keyMapperDefault, keyMapperOctaveUp, keyMapperMajor })
+    {
+        const auto fl = hex (h);
+        const auto s = lynx::vfx::parseKeyMapper (fl);
+        CHECK (s.has_value());
+        if (s)
+            CHECK (lynx::vfx::writeKeyMapper (*s) == fl); // (byte for byte)
+    }
+    const auto up = lynx::vfx::parseKeyMapper (hex (keyMapperOctaveUp));
+    CHECK (up && up->rows[3].size() == 2 && up->rows[3][0] == 3 && up->rows[3][1] == 15);
+    CHECK (lynx::vfx::writeKeyMapper (lynx::vfx::defaultKeyMapper()) == hex (keyMapperDefault));
+}
+
+TEST (vfx_key_mapper_maps_and_releases_what_it_played)
+{
+    using namespace vfx164;
+    auto p = lynx::vfx::makeProcessor (lynx::vfx::Kind::keyMapper, hex (keyMapperOctaveUp));
+    auto out = run (*p, { on (62, 10) });
+    CHECK (out.size() == 2 && out[0].voice.key == 62 && out[1].voice.key == 74 && out[0].offset == 10);
+    CHECK (p->busy());
+    // the settings change while the note is held: its "off" still ends exactly what it started
+    p->configure (hex (keyMapperDefault));
+    out = run (*p, { off (62, 3) });
+    CHECK (out.size() == 2 && out[0].type == lynx::vfx::Event::Type::off && out[1].type == lynx::vfx::Event::Type::off);
+    CHECK (out.size() == 2 && ((out[0].voice.key == 62 && out[1].voice.key == 74) || (out[0].voice.key == 74 && out[1].voice.key == 62)));
+    CHECK (! p->busy());
+    // C major: C# plays C
+    auto major = lynx::vfx::makeProcessor (lynx::vfx::Kind::keyMapper, hex (keyMapperMajor));
+    out = run (*major, { on (61) });
+    CHECK (out.size() == 1 && out[0].voice.key == 60);
+}
+
+TEST (vfx_color_mapper_sends_each_colour_to_its_voice_port)
+{
+    using namespace vfx164;
+    auto s = lynx::vfx::parseColorMapper (hex (colorMapperDefault));
+    CHECK (s && *s == lynx::vfx::defaultColorMapper());
+    CHECK (lynx::vfx::writeColorMapper (lynx::vfx::defaultColorMapper()) == hex (colorMapperDefault));
+    auto changed = lynx::vfx::defaultColorMapper();
+    changed.port[5] = 1;
+    changed.colour[5] = 0;
+    auto p = lynx::vfx::makeProcessor (lynx::vfx::Kind::colorMapper, lynx::vfx::writeColorMapper (changed));
+    const auto out = run (*p, { on (60, 0, 2), on (64, 0, 5) });
+    CHECK (out.size() == 2 && out[0].output == 2 && out[0].voice.colour == 2);
+    CHECK (out.size() == 2 && out[1].output == 1 && out[1].voice.colour == 0);
+}
+
+TEST (vfx_node_in_a_patcher_plays_its_instruments)
+{
+    using namespace vfx164;
+    Rig rig (lynx::vfx::Kind::keyMapper, hex (keyMapperOctaveUp));
+    CHECK (rig.probes.size() == 1);
+    rig.render (64);
+    rig.instrument->noteOn (60, 0.5f);
+    rig.render (64);
+    rig.instrument->noteOff (60);
+    rig.render (64);
+    const auto& hits = rig.probes[0]->hits;
+    CHECK (hits.size() == 4);
+    if (hits.size() == 4)
+    {
+        CHECK (hits[0].on && hits[1].on && hits[0].key + hits[1].key == 60 + 72);
+        CHECK (hits[0].sample == 64 && hits[0].velocity == 0.5f);
+        CHECK (! hits[2].on && ! hits[3].on && hits[2].sample == 128);
+    }
+    // its kind is structure, its settings are not: a new state keeps the graph running
+    auto other = rig.channel;
+    lynx::vfx::State s { lynx::vfx::Kind::keyMapper, 0, hex (keyMapperDefault) };
+    other.patcher.nodes[0].channel.pluginState = lynx::vfx::writeState (s);
+    CHECK (lynx::patcher::sameStructure (rig.channel.patcher, other.patcher));
+}
+
+TEST (vfx_color_mapper_node_splits_colours_over_its_outputs)
+{
+    using namespace vfx164;
+    Rig rig (lynx::vfx::Kind::colorMapper, hex (colorMapperDefault), 3);
+    CHECK (rig.probes.size() == 3);
+    rig.instrument->setNextNoteColour (2);
+    rig.instrument->noteOn (60, 0.5f);
+    rig.instrument->noteOn (62, 0.5f); // colour 0
+    rig.render (32);
+    CHECK (rig.probes.size() == 3 && rig.probes[2]->hits.size() == 1 && rig.probes[2]->hits[0].key == 60 && rig.probes[2]->hits[0].channel == 2);
+    CHECK (rig.probes.size() == 3 && rig.probes[0]->hits.size() == 1 && rig.probes[0]->hits[0].key == 62);
+    CHECK (rig.probes.size() == 3 && rig.probes[1]->hits.empty());
+    const auto ports = lynx::patcher::nodePorts (rig.channel.patcher.nodes[0]);
+    CHECK (ports.midiIn && ports.midiOuts == 16 && ports.audioOuts == 0);
+    CHECK (lynx::patcher::shownMidiOutputs (rig.channel.patcher, 0) == 4);
+}
+
+TEST (vfx_key_mapper_follows_fl_base_key_offset_and_cycles)
+{
+    using namespace vfx164;
+    using lynx::vfx::KeyMapperSettings;
+    auto minor = lynx::vfx::defaultKeyMapper();
+    // FL's Chords / Minor preset rows
+    const std::vector<std::vector<int>> rows { { 0, 3, 7 },   { 0, 3, 5 },   { 2, 5, 8 },    { 3, 7, 8 },    { 3, 7, 10 },   { 5, 8, 12 },
+                                               { 5, 8, 10 },  { 7, 10, 14 }, { 8, 12, 14 },  { 8, 12, 15 },  { 10, 14, 15 }, { 10, 14, 17 } };
+    for (int r = 0; r < 12; ++r)
+        minor.rows[(std::size_t) r] = rows[(std::size_t) r];
+    auto keys = [] (const std::vector<lynx::vfx::Event>& out) {
+        std::vector<int> k;
+        for (const auto& e : out)
+            if (e.type == lynx::vfx::Event::Type::on)
+                k.push_back (e.voice.key);
+        std::sort (k.begin(), k.end());
+        return k;
+    };
+    auto p = lynx::vfx::makeProcessor (lynx::vfx::Kind::keyMapper, lynx::vfx::writeKeyMapper (minor));
+    CHECK ((keys (run (*p, { on (60) })) == std::vector<int> { 60, 63, 67 }));
+    CHECK ((keys (run (*p, { on (63) })) == std::vector<int> { 63, 67, 68 }));
+    CHECK ((keys (run (*p, { on (71) })) == std::vector<int> { 70, 74, 77 }));
+    // base key D: 62 plays row 0 from D, 60 is row 10 of the octave starting on 50
+    minor.baseKey = 2;
+    p = lynx::vfx::makeProcessor (lynx::vfx::Kind::keyMapper, lynx::vfx::writeKeyMapper (minor));
+    CHECK ((keys (run (*p, { on (62) })) == std::vector<int> { 62, 65, 69 }));
+    CHECK ((keys (run (*p, { on (60) })) == std::vector<int> { 60, 64, 65 }));
+    // the offset transposes what comes out (it does not pick another row)
+    auto identity = lynx::vfx::defaultKeyMapper();
+    identity.offset = -12;
+    p = lynx::vfx::makeProcessor (lynx::vfx::Kind::keyMapper, lynx::vfx::writeKeyMapper (identity));
+    CHECK ((keys (run (*p, { on (60) })) == std::vector<int> { 48 }));
+    // cycle up / down follow the row's own order
+    auto cyc = lynx::vfx::defaultKeyMapper();
+    cyc.rows[0] = { 7, 0, 3 };
+    cyc.multimode = 3;
+    p = lynx::vfx::makeProcessor (lynx::vfx::Kind::keyMapper, lynx::vfx::writeKeyMapper (cyc));
+    std::vector<int> seq;
+    for (int k = 0; k < 4; ++k)
+    {
+        seq.push_back (keys (run (*p, { on (60) }))[0]);
+        run (*p, { off (60) });
+    }
+    CHECK ((seq == std::vector<int> { 67, 60, 63, 67 }));
+    cyc.multimode = 4;
+    p = lynx::vfx::makeProcessor (lynx::vfx::Kind::keyMapper, lynx::vfx::writeKeyMapper (cyc));
+    seq.clear();
+    for (int k = 0; k < 4; ++k)
+    {
+        seq.push_back (keys (run (*p, { on (60) }))[0]);
+        run (*p, { off (60) });
+    }
+    CHECK ((seq == std::vector<int> { 63, 60, 67, 63 }));
+    // an empty row mutes the note
+    auto muted = lynx::vfx::defaultKeyMapper();
+    muted.rows[7].clear();
+    p = lynx::vfx::makeProcessor (lynx::vfx::Kind::keyMapper, lynx::vfx::writeKeyMapper (muted));
+    CHECK (run (*p, { on (67) }).empty() && ! p->busy());
+}
+
+TEST (vfx_key_mapper_pitch_slide_glides_to_the_new_note)
+{
+    using namespace vfx164;
+    auto down = lynx::vfx::defaultKeyMapper();
+    for (int r = 0; r < 12; ++r)
+        down.rows[(std::size_t) r] = { r - 12 };
+    down.slide = 144; // FL's "Slide down": 3 steps
+    auto p = lynx::vfx::makeProcessor (lynx::vfx::Kind::keyMapper, lynx::vfx::writeKeyMapper (down));
+    lynx::vfx::EventList out;
+    lynx::vfx::Transport t;
+    t.sampleRate = 48000.0;
+    t.bpm = 120.0; // a step = 0.125 s = 6000 samples; 3 steps = 18000
+    std::vector<lynx::vfx::Event> in { on (60) };
+    p->process (in.data(), 1, 1000, t, out);
+    CHECK (out.size() == 1 && out[0].voice.key == 48 && std::abs (out[0].voice.cents - 1200.0f) < 0.01f);
+    float last = 1200.0f;
+    int steps = 0;
+    for (int b = 1; b * 1000 <= 18000; ++b)
+    {
+        out.clear();
+        p->process (nullptr, 0, 1000, t, out);
+        CHECK (out.size() == 1 && out[0].type == lynx::vfx::Event::Type::prop && out[0].prop == lynx::vfx::Prop::pitch);
+        if (out.size() == 1)
+        {
+            CHECK (out[0].value < last);
+            last = out[0].value;
+        }
+        ++steps;
+    }
+    CHECK (steps == 18 && last < 1200.0f * 0.02f); // ~99 % of the way after 3 steps
+}
+
+TEST (vfx_level_scaler_curves_match_fl)
+{
+    using L = lynx::vfx::LevelScalerSettings;
+    auto s = lynx::vfx::defaultLevelScaler();
+    const auto fl = lynx::vfx::writeLevelScaler (s);
+    CHECK (fl.size() == 173);
+    CHECK (lynx::vfx::parseLevelScaler (fl) == s);
+    CHECK (lynx::vfx::levelScale (s, L::velocity, 0.3, 0.0, 1.0, 0.5) == 0.3); // identity
+    auto near = [] (double a, double b, double eps = 1e-4) { return std::abs (a - b) < eps; };
+    s.at (L::velocity, L::multiply) = 6842; // AutoBeat Lite
+    CHECK (near (lynx::vfx::levelScale (s, L::velocity, 0.78125, 0.0, 1.0, 0.0), 0.652504));
+    s = lynx::vfx::defaultLevelScaler();
+    s.at (L::velocity, L::tension) = 8192;
+    CHECK (near (lynx::vfx::levelScale (s, L::velocity, 0.5, 0.0, 1.0, 0.0), 0.989073));
+    s.at (L::velocity, L::tension) = -8192;
+    CHECK (near (lynx::vfx::levelScale (s, L::velocity, 0.5, 0.0, 1.0, 0.0), 0.010927));
+    s = lynx::vfx::defaultLevelScaler();
+    s.at (L::finePitch, L::multiply) = 4096;
+    CHECK (near (lynx::vfx::levelScale (s, L::finePitch, 0.5, -1.0, 1.0, 0.0) * 1200.0, 300.0, 0.01));
+    CHECK (near (lynx::vfx::levelScale (s, L::finePitch, -1.0, -1.0, 1.0, 0.0) * 1200.0, -600.0, 0.01));
+    s = lynx::vfx::defaultLevelScaler();
+    s.at (L::pan, L::offset) = 4096;
+    CHECK (near (lynx::vfx::levelScale (s, L::pan, 0.0, -1.0, 1.0, 0.0), 1.0));
+    CHECK (near (lynx::vfx::levelScale (s, L::pan, -1.0, -1.0, 1.0, 0.0), 0.0));
+    s = lynx::vfx::defaultLevelScaler();
+    s.at (L::modX, L::multiply) = -8192;
+    CHECK (near (lynx::vfx::levelScale (s, L::modX, 0.4, -1.0, 1.0, 0.0), -0.4));
+    // humanize: spread around the value, subtract below, add above
+    s = lynx::vfx::defaultLevelScaler();
+    s.at (L::velocity, L::humanize) = 8192;
+    CHECK (near (lynx::vfx::levelScale (s, L::velocity, 0.5, 0.0, 1.0, 0.0), 0.25) && near (lynx::vfx::levelScale (s, L::velocity, 0.5, 0.0, 1.0, 1.0), 0.75));
+    s.at (L::velocity, L::humanizeMode) = 0;
+    CHECK (near (lynx::vfx::levelScale (s, L::velocity, 0.5, 0.0, 1.0, 1.0), 0.5));
+    s.at (L::velocity, L::humanizeMode) = 2;
+    CHECK (near (lynx::vfx::levelScale (s, L::velocity, 0.5, 0.0, 1.0, 0.0), 0.5));
+    // the processor: a fixed velocity
+    auto fixed = lynx::vfx::defaultLevelScaler();
+    fixed.at (L::velocity, L::multiply) = 0;
+    fixed.at (L::velocity, L::offset) = 4096;
+    auto p = lynx::vfx::makeProcessor (lynx::vfx::Kind::levelScaler, lynx::vfx::writeLevelScaler (fixed));
+    const auto out = vfx164::run (*p, { vfx164::on (60, 0, 0, 0.9f), vfx164::on (64, 0, 0, 0.2f) });
+    CHECK (out.size() == 2 && near (out[0].voice.velocity, 0.5) && near (out[1].voice.velocity, 0.5) && out[0].voice.key == 60);
+}
+
+TEST (vfx_keyboard_splitter_zones)
+{
+    using namespace vfx164;
+    using S = lynx::vfx::KeyboardSplitterSettings;
+    auto keys = [] (const std::vector<lynx::vfx::Event>& out) {
+        std::vector<std::pair<int, int>> k; // (output, key)
+        for (const auto& e : out)
+            if (e.type == lynx::vfx::Event::Type::on)
+                k.emplace_back (e.output, e.voice.key);
+        std::sort (k.begin(), k.end());
+        return k;
+    };
+    auto def = lynx::vfx::defaultKeyboardSplitter();
+    CHECK (lynx::vfx::parseKeyboardSplitter (lynx::vfx::writeKeyboardSplitter (def)) == def);
+    auto p = lynx::vfx::makeProcessor (lynx::vfx::Kind::keyboardSplitter, lynx::vfx::writeKeyboardSplitter (def));
+    auto out = run (*p, { on (60, 0, 0, 0.78125f) });
+    CHECK (out.size() == 1 && out[0].output == 0 && out[0].voice.key == 60 && std::abs (out[0].voice.velocity - 0.78125f) < 1e-4f);
+    // FL's "3 zone split transposed"
+    S split;
+    auto zone = [] (double from, double to) {
+        lynx::vfx::MapCurve m;
+        m.points.push_back ({ 0.0, 0.0 });
+        m.points.push_back ({ from / 132.0, 0.0 });
+        m.points.push_back ({ from / 132.0, 1.0 });
+        m.points.push_back ({ (to + 1) / 132.0, 1.0 });
+        m.points.push_back ({ (to + 1) / 132.0, 0.0 });
+        m.points.push_back ({ 1.0, 0.0 });
+        return m;
+    };
+    split.zones[0].keyboard = zone (0, 47);
+    split.zones[0].transpose = 36;
+    split.zones[1].keyboard = zone (48, 83);
+    split.zones[2].keyboard = zone (84, 131);
+    split.zones[2].transpose = -36;
+    p = lynx::vfx::makeProcessor (lynx::vfx::Kind::keyboardSplitter, lynx::vfx::writeKeyboardSplitter (split));
+    CHECK ((keys (run (*p, { on (40) })) == std::vector<std::pair<int, int>> { { 0, 76 } }));
+    CHECK ((keys (run (*p, { on (60) })) == std::vector<std::pair<int, int>> { { 1, 60 } }));
+    CHECK ((keys (run (*p, { on (90) })) == std::vector<std::pair<int, int>> { { 2, 54 } }));
+    out = run (*p, { off (40) });
+    CHECK (out.size() == 1 && out[0].type == lynx::vfx::Event::Type::off && out[0].voice.key == 76 && out[0].output == 0);
+    // Velocity / Limited (absolute): v 1 → map 0.75 → velocity 0.75 / 1.28
+    S limited = lynx::vfx::defaultKeyboardSplitter();
+    limited.zones[0].velocity.points = { { 0.0, 0.0 }, { 0.75, 0.75 }, { 1.0, 0.75 } };
+    limited.zones[0].absolute = true;
+    p = lynx::vfx::makeProcessor (lynx::vfx::Kind::keyboardSplitter, lynx::vfx::writeKeyboardSplitter (limited));
+    out = run (*p, { on (60, 0, 0, 1.0f), on (62, 0, 0, 0.4f) });
+    CHECK (out.size() == 2 && std::abs (out[0].voice.velocity - 0.5859f) < 1e-3f && std::abs (out[1].voice.velocity - 0.3125f) < 1e-3f);
+    // random zones: each note on exactly one of them
+    S rnd;
+    rnd.zones[0].keyboard = rnd.zones[1].keyboard = lynx::vfx::MapCurve::flat (1.0);
+    rnd.zones[0].random = rnd.zones[1].random = true;
+    p = lynx::vfx::makeProcessor (lynx::vfx::Kind::keyboardSplitter, lynx::vfx::writeKeyboardSplitter (rnd));
+    int counts[2] {};
+    for (int k = 0; k < 200; ++k)
+    {
+        out = run (*p, { on (60), off (60, 1) });
+        CHECK (out.size() == 2);
+        if (! out.empty())
+            ++counts[std::clamp (out[0].output, 0, 1)];
+    }
+    CHECK (counts[0] > 50 && counts[1] > 50);
+}
+
+TEST (vfx_reads_fl_factory_presets)
+{
+    if (realFlpDir.empty())
+        return;
+    namespace fs = std::filesystem;
+    int files = 0;
+    for (const auto kind : { lynx::vfx::Kind::keyMapper, lynx::vfx::Kind::keyboardSplitter, lynx::vfx::Kind::envelope })
+    {
+        const auto dir = fs::path (realFlpDir) / "Patches" / "Plugin presets" / "Effects" / lynx::vfx::flName (kind);
+        if (! fs::is_directory (dir))
+            continue;
+        for (const auto& entry : fs::recursive_directory_iterator (dir))
+        {
+            if (entry.path().extension() != ".fst")
+                continue;
+            std::ifstream in (entry.path(), std::ios::binary);
+            const std::vector<std::uint8_t> bytes ((std::istreambuf_iterator<char> (in)), {});
+            const auto state = lynx::vfx::stateFromFlPreset (bytes, kind);
+            CHECK (state.has_value());
+            if (! state)
+            {
+                std::printf ("  not read: %s\n", entry.path().string().c_str());
+                continue;
+            }
+            ++files;
+            if (kind == lynx::vfx::Kind::keyMapper)
+            {
+                const auto s = lynx::vfx::parseKeyMapper (*state);
+                CHECK (s && lynx::vfx::writeKeyMapper (*s) == *state);
+            }
+            if (kind == lynx::vfx::Kind::keyboardSplitter)
+            {
+                const auto s = lynx::vfx::parseKeyboardSplitter (*state);
+                CHECK (s.has_value());
+                if (s)
+                {
+                    const auto again = lynx::vfx::parseKeyboardSplitter (lynx::vfx::writeKeyboardSplitter (*s));
+                    CHECK (again && again->zones == s->zones);
+                }
+            }
+            if (kind == lynx::vfx::Kind::envelope)
+            {
+                const auto s = lynx::vfx::parseEnvelope (*state);
+                CHECK (s.has_value());
+                if (s)
+                {
+                    const auto again = lynx::vfx::parseEnvelope (lynx::vfx::writeEnvelope (*s));
+                    CHECK (again && *again == *s);
+                }
+            }
+        }
+    }
+    CHECK (files >= 50);
+}
+
+TEST (vfx_envelope_moves_the_notes_it_matches)
+{
+    using namespace vfx164;
+    using E = lynx::vfx::EnvelopeSettings;
+    auto def = lynx::vfx::defaultEnvelope();
+    const auto again = lynx::vfx::parseEnvelope (lynx::vfx::writeEnvelope (def));
+    CHECK (again && *again == def);
+    auto p = lynx::vfx::makeProcessor (lynx::vfx::Kind::envelope, lynx::vfx::writeEnvelope (def));
+    lynx::vfx::EventList out;
+    lynx::vfx::Transport t;
+    t.sampleRate = 48000.0;
+    // colour 0: the volume envelope starts silent; colour 3 passes untouched
+    std::vector<lynx::vfx::Event> in { on (60, 0, 0, 0.78125f), on (64, 0, 3, 0.5f) };
+    p->process (in.data(), 2, 480, t, out);
+    out.sortByOffset();
+    CHECK (out.size() == 2 && out[0].voice.velocity < 0.01f && std::abs (out[1].voice.velocity - 0.5f) < 1e-5f);
+    // 0.75 s in: the peak (volume × 2)
+    float peak = 0.0f;
+    for (int b = 0; b < 75; ++b)
+    {
+        out.clear();
+        p->process (nullptr, 0, 480, t, out);
+        for (int k = 0; k < out.size(); ++k)
+            if (out[k].type == lynx::vfx::Event::Type::prop && out[k].prop == lynx::vfx::Prop::velocity)
+                peak = std::max (peak, out[k].value);
+    }
+    const auto twice = (float) (std::log (10.0 * 2.0 + 1.0) / std::log (11.0) / 1.28); // velocity of volume × 2
+    CHECK (std::abs (peak - twice) < 0.02f);
+    CHECK (p->busy());
+    // pitch: articulator 1's pitch envelope flat at the top, 100 %: +48 semitones
+    auto up = lynx::vfx::defaultEnvelope();
+    auto& pitch = up.articulators[0].parts[E::pitch];
+    pitch.env = 1.0f;
+    pitch.envelope.points = { { 0.0, 1.0 }, { 1.0, 1.0 } };
+    pitch.envelope.footer[1] = -1;
+    up.articulators[0].parts[E::velocity].envelope.footer[1] = 0; // (no volume envelope)
+    up.articulators[0].low = 61; // keys 60…71 only
+    up.articulators[0].high = 72;
+    p = lynx::vfx::makeProcessor (lynx::vfx::Kind::envelope, lynx::vfx::writeEnvelope (up));
+    const auto res = run (*p, { on (60), on (72) });
+    CHECK (res.size() == 2 && std::abs (res[0].voice.cents - 4800.0f) < 0.5f && res[1].voice.cents == 0.0f);
+    // the plugin off: everything passes
+    up.enabled = false;
+    p = lynx::vfx::makeProcessor (lynx::vfx::Kind::envelope, lynx::vfx::writeEnvelope (up));
+    const auto off = run (*p, { on (60) });
+    CHECK (off.size() == 1 && off[0].voice.cents == 0.0f);
+}
+
+namespace vfx164
+{
+// A sequencer note heard: its key, start and length in seconds, velocity (FL's 0…127, the volume × 100)
+struct SeqNote
+{
+    int key = 0;
+    double start = 0.0, length = -1.0;
+    int velocity = 0;
+};
+
+// Plays `input` (seconds, key, on / off) through the processor at 120 bpm / 48 kHz with the song playing from 0
+// (or stopped), and returns the notes it sent out
+std::vector<SeqNote> sequence (lynx::vfx::Processor& p, std::vector<std::tuple<double, int, bool>> input, double seconds,
+                               bool playing = true, float velocity = 100.0f / 128.0f)
+{
+    constexpr int block = 480;
+    constexpr double rate = 48000.0;
+    std::vector<SeqNote> notes;
+    std::map<int, std::size_t> open;
+    lynx::vfx::EventList out;
+    lynx::vfx::Transport t;
+    t.sampleRate = rate;
+    t.bpm = 120.0;
+    t.playing = playing;
+    for (long long at = 0; at < (long long) (seconds * rate); at += block)
+    {
+        std::vector<lynx::vfx::Event> in;
+        for (const auto& [time, key, down] : input)
+        {
+            const auto sample = (long long) std::llround (time * rate);
+            if (sample >= at && sample < at + block)
+            {
+                auto e = down ? on (key, (int) (sample - at), 0, velocity) : off (key, (int) (sample - at));
+                in.push_back (e);
+            }
+        }
+        t.ticks = playing ? (double) at / rate * 2.0 * 960.0 : 0.0;
+        out.clear();
+        p.process (in.data(), (int) in.size(), block, t, out);
+        out.sortByOffset();
+        for (int k = 0; k < out.size(); ++k)
+        {
+            const auto& e = out[k];
+            const auto time = (double) (at + e.offset) / rate;
+            if (e.type == lynx::vfx::Event::Type::on)
+            {
+                const auto volume = (std::pow (11.0, 1.28 * (double) e.voice.velocity) - 1.0) / 10.0;
+                open[e.id] = notes.size();
+                notes.push_back ({ e.voice.key, time, -1.0, (int) std::lround (volume * 100.0) });
+            }
+            else if (e.type == lynx::vfx::Event::Type::off && open.count (e.id))
+                notes[open[e.id]].length = time - notes[open[e.id]].start;
+        }
+    }
+    return notes;
+}
+
+lynx::vfx::SequencerSettings blankProgram()
+{
+    auto s = lynx::vfx::defaultSequencer();
+    s.set (lynx::vfx::SequencerSettings::currentProgram, 0); // "Initial": 16 × N1, gate 90 %, 1/16
+    return s;
+}
+
+std::unique_ptr<lynx::vfx::Processor> sequencer (const lynx::vfx::SequencerSettings& s)
+{
+    return lynx::vfx::makeProcessor (lynx::vfx::Kind::sequencer, lynx::vfx::writeSequencer (s));
+}
+} // namespace vfx164
+
+TEST (vfx_sequencer_state_round_trips_and_resolves_fl_params)
+{
+    using namespace lynx::vfx;
+    using S = SequencerSettings;
+    auto s = defaultSequencer();
+    const auto bytes = writeSequencer (s);
+    const auto back = parseSequencer (bytes);
+    CHECK (back && *back == s && writeSequencer (*back) == bytes);
+    CHECK (s.programs.size() == 128 && s.chains.size() == 16);
+    // per program: Steps; global: Transpose
+    s.set (S::currentProgram, 4);
+    s.set (S::steps, 12);
+    s.set (S::transposeSemitones, 5);
+    s.set (S::currentProgram, 6);
+    CHECK (s.get (S::steps) != 12 && s.get (S::transposeSemitones) == 5);
+    s.set (S::currentProgram, 4);
+    CHECK (s.get (S::steps) == 12);
+    // lanes: FL params 0x80 + 64 · lane + step
+    s.set (0x100 + 3, S::tie);
+    CHECK (s.current().lanes[S::stepType][3] == S::tie && s.get (0x100 + 3) == S::tie);
+    s.set (S::gate, 500);
+    CHECK (s.get (S::gate) == 125);
+    // pattern shift rotates the lanes of the steps in use
+    s.set (S::steps, 16);
+    s.current().lanes[S::velocity][0] = 127;
+    shiftPattern (s, 1);
+    CHECK (s.current().lanes[S::velocity][1] == 127);
+    shiftPattern (s, -2);
+    CHECK (s.current().lanes[S::velocity][15] == 127);
+    CHECK (! parseSequencer ({ 1, 0, 0, 0 }));
+    CHECK (defaultState (Kind::sequencer) == writeSequencer (defaultSequencer()));
+}
+
+TEST (vfx_sequencer_reads_fl_factory_bank)
+{
+    if (realFlpDir.empty())
+        return;
+    namespace fs = std::filesystem;
+    const auto file = fs::path (realFlpDir) / "Patches" / "Plugin database" / "Effects" / "Patcher" / "VFX Sequencer.fst";
+    if (! fs::exists (file))
+        return;
+    std::ifstream in (file, std::ios::binary);
+    const std::vector<std::uint8_t> bytes ((std::istreambuf_iterator<char> (in)), {});
+    const auto state = lynx::vfx::stateFromFlPreset (bytes, lynx::vfx::Kind::sequencer);
+    CHECK (state.has_value());
+    if (! state)
+        return;
+    const auto s = lynx::vfx::parseSequencer (*state);
+    CHECK (s.has_value());
+    if (! s)
+        return;
+    CHECK (lynx::vfx::writeSequencer (*s) == *state); // (byte for byte)
+    CHECK (s->programs.size() == 128 && s->program() == 3);
+    CHECK (s->current().nameText() == "Simple 4k Up 4 beats");
+    using S = lynx::vfx::SequencerSettings;
+    CHECK (s->get (S::steps) == 16 && s->get (S::gate) == 50 && s->get (S::missingKeys) == 3 && s->get (S::arpMode) == 1);
+    // T1: C4 E4 G4 held → 60 64 67 67 (N4 missing: the last key) on every 1/16, velocity 96, half a step long
+    auto p = lynx::vfx::makeProcessor (lynx::vfx::Kind::sequencer, *state);
+    const auto notes = vfx164::sequence (*p, { { 0.0, 60, true }, { 0.0, 64, true }, { 0.0, 67, true } }, 1.0);
+    CHECK (notes.size() >= 8);
+    const int expected[8] = { 60, 64, 67, 67, 60, 64, 67, 67 };
+    for (int i = 0; i < 8 && i < (int) notes.size(); ++i)
+    {
+        CHECK (notes[(std::size_t) i].key == expected[i]);
+        CHECK (std::abs (notes[(std::size_t) i].start - 0.125 * i) < 1e-4);
+        CHECK (notes[(std::size_t) i].velocity == 96);
+        CHECK (std::abs (notes[(std::size_t) i].length - 0.0625) < 1e-3);
+    }
+    // T2: output velocity = the key's
+    auto s2 = *s;
+    s2.set (S::velocityMode, 1);
+    auto p2 = vfx164::sequencer (s2);
+    const auto loud = vfx164::sequence (*p2, { { 0.0, 60, true }, { 0.0, 64, true } }, 0.3);
+    CHECK (! loud.empty() && loud[0].velocity == 100);
+    // T3 / T4: missing keys cyclic / not played
+    s2.set (S::velocityMode, 0);
+    s2.set (S::missingKeys, 1);
+    p2 = vfx164::sequencer (s2);
+    auto two = vfx164::sequence (*p2, { { 0.0, 60, true }, { 0.0, 64, true } }, 0.49);
+    CHECK (two.size() == 4 && two[2].key == 60 && two[3].key == 64);
+    s2.set (S::missingKeys, 0);
+    p2 = vfx164::sequencer (s2);
+    two = vfx164::sequence (*p2, { { 0.0, 60, true }, { 0.0, 64, true } }, 0.99);
+    CHECK (two.size() == 4 && two[2].key == 60 && std::abs (two[2].start - 0.5) < 1e-4);
+}
+
+TEST (vfx_sequencer_plays_fl_test_vectors)
+{
+    using namespace vfx164;
+    using S = lynx::vfx::SequencerSettings;
+    // T5: steps 0 = thru, transpose +2: the note passes at once and ends with its key
+    auto s = blankProgram();
+    s.set (S::steps, 0);
+    s.set (S::transposeSemitones, 2);
+    auto p = sequencer (s);
+    auto notes = sequence (*p, { { 0.0, 60, true }, { 1.0, 60, false } }, 1.5);
+    CHECK (notes.size() == 1 && notes[0].key == 62 && notes[0].start == 0.0 && std::abs (notes[0].length - 1.0) < 1e-3
+           && notes[0].velocity == 100);
+    // T6 / T7: C major forced, every scale step +1: D → E, C# snaps down to C → D; 0.9 of a step long
+    s = blankProgram();
+    s.set (S::forceKey, 2);
+    s.set (S::forceScale, 2);
+    for (int i = 0; i < 64; ++i)
+        s.set (0x80 + i, 1);
+    p = sequencer (s);
+    notes = sequence (*p, { { 0.0, 62, true } }, 0.49);
+    CHECK (notes.size() == 4 && notes[0].key == 64 && notes[3].key == 64 && std::abs (notes[0].length - 0.1125) < 1e-3);
+    p = sequencer (s);
+    notes = sequence (*p, { { 0.0, 61, true } }, 0.2);
+    CHECK (! notes.empty() && notes[0].key == 62);
+    // T8: swing +50: odd steps half a step late
+    s = blankProgram();
+    s.set (S::swing, 50);
+    p = sequencer (s);
+    notes = sequence (*p, { { 0.0, 60, true } }, 0.55);
+    CHECK (notes.size() == 5);
+    const double swung[5] = { 0.0, 0.1875, 0.25, 0.4375, 0.5 };
+    for (int i = 0; i < 5 && i < (int) notes.size(); ++i)
+        CHECK (std::abs (notes[(std::size_t) i].start - swung[i]) < 1e-3);
+    // T9: output wrap 48…59: E4 plays E3
+    s = blankProgram();
+    s.set (S::outputLow, 48);
+    s.set (S::outputHigh, 59);
+    p = sequencer (s);
+    notes = sequence (*p, { { 0.0, 64, true } }, 0.2);
+    CHECK (! notes.empty() && notes[0].key == 52);
+    // T10: a rest after a step lengthens it by a step; a tie makes it overlap the next (legato)
+    s = blankProgram();
+    s.set (0x100 + 1, S::rest);
+    s.set (0x100 + 2, S::tie);
+    p = sequencer (s);
+    notes = sequence (*p, { { 0.0, 60, true } }, 0.3);
+    CHECK (notes.size() == 2 && std::abs (notes[0].length - 1.9 * 0.125) < 1e-3 && std::abs (notes[1].start - 0.25) < 1e-4);
+    s.set (0x100 + 1, S::tie);
+    s.set (0x140 + 1, 0x08); // (N2: another key, so the tie overlaps it)
+    p = sequencer (s);
+    notes = sequence (*p, { { 0.0, 60, true }, { 0.0, 64, true } }, 0.2);
+    CHECK (notes.size() == 2 && notes[1].key == 64 && std::abs (notes[0].length - 1.25 * 0.125) < 1e-3);
+    // T11: chord normalized, every step a chord: G3 C4 E4 → C major in root position
+    s = blankProgram();
+    s.set (S::order, 6);
+    for (int i = 0; i < 64; ++i)
+        s.set (0x100 + i, S::chord);
+    p = sequencer (s);
+    notes = sequence (*p, { { 0.0, 55, true }, { 0.0, 60, true }, { 0.0, 64, true } }, 0.1);
+    std::vector<int> keys;
+    for (const auto& n : notes)
+        keys.push_back (n.key);
+    std::sort (keys.begin(), keys.end());
+    CHECK ((keys == std::vector<int> { 60, 64, 67 }));
+    // T12: stopped: the sequencer runs on its own clock while the key is held
+    s = blankProgram();
+    p = sequencer (s);
+    notes = sequence (*p, { { 0.0, 60, true }, { 0.3, 60, false } }, 1.5, false);
+    CHECK (notes.size() == 3 && std::abs (notes[2].start - 0.25) < 1e-3);
+    CHECK (! p->busy());
+    // octaves lane: bit 4 = +1 octave; key select: Fixed / Root
+    s = blankProgram();
+    s.set (0xC0, 0x10);
+    s.set (0x140 + 1, 0x01);
+    p = sequencer (s);
+    notes = sequence (*p, { { 0.0, 60, true } }, 0.2);
+    CHECK (notes.size() == 2 && notes[0].key == 72 && notes[1].key == 64);
+    // Arp mode off: nothing; a stop releases what sounds
+    s = blankProgram();
+    s.set (S::arpMode, 0);
+    p = sequencer (s);
+    CHECK (sequence (*p, { { 0.0, 60, true } }, 0.3).empty());
+}
+
+TEST (vfx_sequencer_cost_per_block)
+{
+    // the audio-thread cost: 4 held keys, 16 steps of chords, 1 s of 128-sample blocks
+    using namespace vfx164;
+    using S = lynx::vfx::SequencerSettings;
+    auto s = blankProgram();
+    for (int i = 0; i < 64; ++i)
+        s.set (0x100 + i, S::chord);
+    auto p = sequencer (s);
+    lynx::vfx::EventList out;
+    lynx::vfx::Transport t;
+    t.sampleRate = 48000.0;
+    t.bpm = 140.0;
+    t.playing = true;
+    std::vector<lynx::vfx::Event> in { on (60), on (64), on (67), on (71) };
+    const auto begin = std::chrono::steady_clock::now();
+    int notes = 0;
+    for (int b = 0; b < 375; ++b)
+    {
+        out.clear();
+        t.ticks = b * 128.0 / 48000.0 * (140.0 / 60.0) * 960.0;
+        p->process (b == 0 ? in.data() : nullptr, b == 0 ? 4 : 0, 128, t, out);
+        for (int k = 0; k < out.size(); ++k)
+            notes += out[k].type == lynx::vfx::Event::Type::on;
+    }
+    const auto ms = std::chrono::duration<double, std::milli> (std::chrono::steady_clock::now() - begin).count();
+    std::printf ("  sequencer: 1 s of audio in %.3f ms (%d notes)\n", ms, notes);
+    CHECK (notes > 30 && ms < 20.0);
+}
+
+TEST (vfx_script_keeps_fl_scripts_as_they_are)
+{
+    using namespace lynx::vfx;
+    auto s = defaultScript();
+    CHECK (s.source() == "import flvfx as vfx");
+    s.setSource ("import flvfx as vfx\n\ndef onTriggerVoice(v):\n    v.trigger()\n");
+    CHECK (s.text.find ("Source=import flvfx as vfx<linebreak><linebreak>def onTriggerVoice(v):<linebreak>") != std::string::npos);
+    CHECK (s.source() == "import flvfx as vfx\n\ndef onTriggerVoice(v):\n    v.trigger()\n");
+    CHECK (parseScript (writeScript (s)) == s);
+    CHECK (! parseScript ({ 9, 0, 0, 0, 'x' }));
+    // a script plays its notes through unchanged
+    auto p = makeProcessor (Kind::script, writeScript (s));
+    const auto out = vfx164::run (*p, { vfx164::on (60) });
+    CHECK (out.size() == 1 && out[0].voice.key == 60);
+    if (realFlpDir.empty())
+        return;
+    namespace fs = std::filesystem;
+    const auto dir = fs::path (realFlpDir) / "Patches" / "Plugin presets" / "Effects" / "VFX Script";
+    if (! fs::is_directory (dir))
+        return;
+    int files = 0;
+    for (const auto& entry : fs::recursive_directory_iterator (dir))
+    {
+        if (entry.path().extension() != ".fst")
+            continue;
+        std::ifstream in (entry.path(), std::ios::binary);
+        const std::vector<std::uint8_t> bytes ((std::istreambuf_iterator<char> (in)), {});
+        const auto state = stateFromFlPreset (bytes, Kind::script);
+        CHECK (state.has_value());
+        if (! state)
+            continue;
+        const auto script = parseScript (*state);
+        CHECK (script && writeScript (*script) == *state);
+        if (! script)
+            continue;
+        ++files;
+        // the source written back as it was read changes nothing
+        auto again = *script;
+        again.setSource (script->source());
+        CHECK (again.text == script->text);
+        if (entry.path().filename() == "Arpeggiator.fst")
+        {
+            const auto params = script->parameters();
+            CHECK (std::find (params.begin(), params.end(), std::pair<std::string, std::string> { "Speed", "2" }) != params.end());
+            CHECK (std::find (params.begin(), params.end(), std::pair<std::string, std::string> { "Duration", "196608" }) != params.end());
+            CHECK (script->source().find ("<linebreak>") == std::string::npos && script->source().size() > 1000);
+        }
+    }
+    std::printf ("  %d FL scripts\n", files);
+    CHECK (files >= 80);
+}
+
+TEST (vfx_sequencer_node_plays_its_synth_in_a_patcher)
+{
+    // a Patcher channel played live (stopped transport): the Sequencer runs on its own clock and plays the synth
+    using namespace vfx164;
+    Rig rig (lynx::vfx::Kind::sequencer, lynx::vfx::writeSequencer (lynx::vfx::defaultSequencer())); // "Up 4 keys"
+    rig.instrument->noteOn (60, 0.8f);
+    rig.instrument->noteOn (64, 0.8f);
+    rig.instrument->noteOn (67, 0.8f);
+    for (int b = 0; b < 100; ++b) // 1 s
+        rig.render (480);
+    std::vector<int> keys;
+    for (const auto& h : rig.probes[0]->hits)
+        if (h.on)
+            keys.push_back (h.key);
+    CHECK (keys.size() >= 6);
+    CHECK (keys.size() >= 4 && keys[0] == 60 && keys[1] == 64 && keys[2] == 67 && keys[3] == 67);
+    rig.instrument->noteOff (60);
+    rig.instrument->noteOff (64);
+    rig.instrument->noteOff (67);
+    for (int b = 0; b < 20; ++b)
+        rig.render (480);
+    const auto before = rig.probes[0]->hits.size();
+    for (int b = 0; b < 100; ++b)
+        rig.render (480);
+    CHECK (rig.probes[0]->hits.size() == before); // (nothing more after the keys are up)
+    int on = 0;
+    for (const auto& h : rig.probes[0]->hits)
+        on += h.on ? 1 : -1;
+    CHECK (on == 0); // (every note ended)
+}

+ 1 - 0
tests/tests.cpp

@@ -16048,4 +16048,5 @@ TEST (fl_low_lifter_matches_fl_engine)
 #include "Rec163Tests.inc"
 #include "Ui163Tests.inc"
 #include "HwInsert164Tests.inc"
+#include "Vfx164Tests.inc"
 #include "Misc164Tests.inc"

Kaikkia tiedostoja ei voida näyttää, sillä liian monta tiedostoa muuttui tässä diffissä