Skip to content

armgit / nota

Public Imported from GitHub
0

Nota — a free DAW for macOS, Windows and Linux. No subscription, no account — just open it and make music.

Redesign of Autofilter

Egor Khindikaynenb77ffc4664d4
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 41117a5c..84ef9f98 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -51,6 +51,30 @@ Entry categories: `Added`, `Changed`, `Fixed`, `Removed`.
level, the effective attack and release, look-ahead latency and how often it kicked in.
### Changed
+- **Nota Auto Filter shows the cutoff moving, not just where it is set.** The card moves onto
+ the Lens / Compressor / Delay frame — a SHAPE column (cutoff and resonance faders, with a
+ mark where the modulation has them now), a centre panel with **Filter**, **Envelope** and
+ **LFO** tabs, a **Mod / Output** panel and a status strip:
+ - **Filter** — the response you drag (sideways for the cutoff, up and down for the
+ resonance) over the input's spectrum, the band the envelope and LFO can walk the cutoff
+ over, and the response where they have it right now.
+ - **Envelope** — the input's envelope and the cutoff it drives over the last 0.6–2 s, so
+ attack, hold and release read as shapes; the onsets in the window are counted.
+ - **LFO** — the LFO's movement over two bars (or a few cycles in free time) with a playhead
+ at its live phase; the right channel is drawn when stereo phase is on.
+ - **New in the engine:** a **modulation target** (the cutoff, the resonance or both),
+ **Hold** gets a length (12 ms … 400 ms, or ∞ as before), **Smooth** slews the modulation,
+ the LFO has a **start phase** and **Retrig** (it restarts on each input onset and at play).
+ The envelope's **Up / Down** flips the amount's sign; the sidechain key's source and gain
+ live behind its switch.
+ - **30 factory presets**, up from six, level-matched to the dry signal — wahs, swells,
+ synced wobbles and gates, random steps, stereo swirls and sidechain pumps. The five new
+ parameters are appended, so older projects open unchanged and every one of them
+ automates (grouped under *Env*, *LFO* and *Mod* in the lane menu), MIDI-learns, saves in
+ a preset and is reachable over MCP; `get_device_text` returns the status line, the live
+ reading and a guide to the parameter values, `device_action` restarts the LFO or resets
+ the envelope, and the new `read_filter_motion` returns the modulated cutoff with its
+ note, the envelope and LFO state and the cutoff's range over the last two seconds.
- **Nota Compressor shows its dynamics, not just its settings.** The card moves onto the
Lens / Delay / Reverb frame — a LEVEL column (threshold against the live key level ·
make-up), a centre panel with **Curve**, **Motion** and **Sidechain** tabs, a
diff --git a/FEATURES.md b/FEATURES.md
index 3432a5ec..e6a71dcb 100644
--- a/FEATURES.md
+++ b/FEATURES.md
@@ -348,8 +348,13 @@ and user presets, automation, persistence and cloning.
(Stereo/Left/Right/Swap), bass mono, mute, phase invert; goniometer/vectorscope,
correlation meter, meters, Gain match.
- **Nota Valve** (5, formerly Amplifier) — tube amplifier and saturator.
-- **Nota Auto Filter** (6) — LP/BP/HP/NO, 12/24 slope, Clean/Analog, ENV + LFO modulation
- (with tempo sync and stereo phase), sidechain; an interactive response graph.
+- **Nota Auto Filter** (7) — LP/BP/HP/Notch with morph, 12/24 slope, Clean/Analog, drive;
+ an envelope follower (attack, release, timed or infinite hold, on the input or a sidechain
+ key) and an LFO (5 waves, morph, free or tempo-synced, start phase, stereo phase, Retrig on
+ onsets) driving the cutoff, the resonance or both, with Smooth. Tabs: Filter (draggable
+ response over the spectrum, modulation range) / Envelope (cutoff over time) / LFO (motion
+ over two bars) and Mod / Output, with a SHAPE column and a status strip. 30 factory
+ presets. MCP: `read_filter_motion`.
- **Nota Auto Shift** (7) — real-time vocal pitch correction: pitch detection, Key +
Scale, Follow scale device, correction amount and speed, Range (guards against octave
jumps), Formant, Mix; a PITCH TRACE visualiser.
diff --git a/src/managed/Nota.App/ArrangementView.Automation.cs b/src/managed/Nota.App/ArrangementView.Automation.cs
index 0a1daffa..6d18be6a 100644
--- a/src/managed/Nota.App/ArrangementView.Automation.cs
+++ b/src/managed/Nota.App/ArrangementView.Automation.cs
@@ -388,9 +388,10 @@ public sealed partial class ArrangementView
var devMenu = new MenuItem { Header = dn };
// Nota Chamber (45 params) groups by its section prefix ("IR", "Algo", "EQ" …),
// Nota Prism (52) by band ("Low", "Mid", "High", "Crossover") and Nota Lens (37) by
- // view ("Spectrum", "Scope", "Waterfall", "Cursor") and the Compressor its key
- // ("SC HP", "SC Gain" …): a word shared by two or more params becomes a submenu.
- bool grouped = e.TrackDeviceBuiltinKind(t.Id, d) is 1 or 20 or 21 or 22;
+ // view ("Spectrum", "Scope", "Waterfall", "Cursor"), the Compressor its key
+ // ("SC HP", "SC Gain" …) and the Auto Filter its sources ("Env", "LFO", "Mod"):
+ // a word shared by two or more params becomes a submenu.
+ bool grouped = e.TrackDeviceBuiltinKind(t.Id, d) is 1 or 7 or 20 or 21 or 22;
var names = new string[builtinPc];
for (int p = 0; p < builtinPc; p++) names[p] = e.DeviceParamName(t.Id, d, p);
static string Head(string n) { int sp = n.IndexOf(' '); return sp > 0 ? n[..sp] : ""; }
diff --git a/src/managed/Nota.App/Controls/AutoFilterCurve.cs b/src/managed/Nota.App/Controls/AutoFilterCurve.cs
index 5ff30d33..c0e70395 100644
--- a/src/managed/Nota.App/Controls/AutoFilterCurve.cs
+++ b/src/managed/Nota.App/Controls/AutoFilterCurve.cs
@@ -1,13 +1,15 @@
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.
//
-// Auto Filter response curve. Three layers over a log-frequency grid:
-// 1) a real-time spectrum analyzer of the pre-filter signal (FFT of the device scope);
-// 2) the filter's magnitude response at the BASE cutoff — interactive: drag the handle
-// (or anywhere) to set cutoff (X) + resonance (Y), recording an automation gesture;
-// 3) a live modulation indicator — a bright marker that rides the current MODULATED
-// cutoff (base + envelope incl. sidechain + LFO), so you see the sidechain working.
-// Frequency axis == the Freq param range (30..18000 Hz) so handle-X ↔ normalized cutoff.
+// Auto Filter response curve (the Filter tab). Layers over a log-frequency grid:
+// 1) a real-time spectrum of the pre-filter signal (FFT of the device's scope ring, fed
+// by the card each tick);
+// 2) the teal range the modulation can walk the cutoff over (from the settings), and the
+// filter's magnitude response at the BASE cutoff — interactive: drag the handle (or
+// anywhere) to set cutoff (X) + resonance (Y), recording an automation gesture;
+// 3) the response at the LIVE modulated cutoff and resonance, dashed, so you see the
+// envelope / LFO / sidechain working.
+// Frequency axis == the Freq param range (30..18000 Hz) so handle-X ↔ normalized cutoff.
using System;
using System.Globalization;
@@ -15,49 +17,32 @@ using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Media;
-using Nota.Application;
namespace Nota.App;
internal sealed class AutoFilterCurve : Control
{
- private static readonly IBrush Bg = NotaPalette.BgSunken;
- private static readonly IBrush BorderB = NotaPalette.BorderDefault;
- private static readonly IPen GridPen = NotaGraph.GridPen;
private static readonly IPen CurvePen = new Pen(NotaPalette.Accent, 1.8); // solid brass = current response
- private static readonly IBrush CurveFill = NotaPalette.Wash(NotaPalette.Accent, 0x18);
- private static readonly IBrush SpecFill = NotaPalette.Wash(NotaPalette.Ink("#8AA6C0"), 0x22);
private static readonly IPen SpecPen = new Pen(NotaPalette.Wash(NotaPalette.Ink("#9CB4CC"), 0x44));
- private static readonly IBrush HandleB = NotaPalette.AccentBright;
-
- private static readonly IPen ModPen = new Pen(NotaPalette.Teal, 1.2)
- { DashStyle = new DashStyle(new double[] { 4, 3 }, 0) }; // dashed teal = at modulation
-
- private static readonly IBrush SweepFill = NotaPalette.Wash(NotaPalette.Teal, 0x12);
-
- private static readonly IPen SweepEdge = new Pen(NotaPalette.Wash(NotaPalette.Teal, 0x55))
- { DashStyle = new DashStyle(new double[] { 3, 3 }, 0) };
-
- private static readonly IBrush AxisB = NotaPalette.TextTertiary;
- private static readonly Typeface Face = NotaFonts.Mono;
+ private static readonly IPen ModPen = new Pen(NotaPalette.Teal, 1.2) { DashStyle = new DashStyle(new double[] { 4, 3 }, 0) }; // dashed teal = at modulation
+ private static readonly IPen RangePen = new Pen(NotaPalette.Wash(NotaPalette.Teal, 0x8C), 1);
+ private static readonly IPen RangePen2 = new Pen(NotaPalette.Wash(NotaPalette.Teal, 0x4C), 1);
+ private static readonly IBrush RangeFill = NotaPalette.Wash(NotaPalette.Teal, 0x10);
private const double FMin = 30.0, FMax = 18000.0;
private const double DbTop = 18.0, DbBot = -36.0;
- private const int FftN = 2048, Bins = FftN / 2;
-
- private readonly IAudioEngine _engine;
- private readonly int _track, _device;
+ public const int FftN = 2048;
+ private const int Bins = FftN / 2;
private double _fcNorm = 0.5, _res;
private int _type;
private float _morph;
private bool _slope24;
private bool _drag;
- private double _liveCut = 0.5; // live modulated cutoff (normalized), from the DSP
- private double _sweepLo = 0.5, _sweepHi = 0.5; // decaying min/max of the modulated cutoff → sweep band
+ private double _liveCut = 0.5, _liveRes; // live modulated cutoff / resonance (normalized)
+ private double _rangeLo = 0.5, _rangeHi = 0.5; // where the modulation can take the cutoff
+ private bool _modAssigned;
- // Analyzer state.
- private readonly float[] _scope = new float[FftN];
private readonly double[] _re = new double[FftN], _im = new double[FftN];
private readonly double[] _specDb = new double[Bins];
private readonly double[] _hann = new double[FftN];
@@ -68,19 +53,18 @@ internal sealed class AutoFilterCurve : Control
public event Action? GestureBegin;
public event Action? GestureEnd;
- public AutoFilterCurve(IAudioEngine engine, int track, int device)
+ public AutoFilterCurve()
{
- _engine = engine;
- _track = track;
- _device = device;
- MinHeight = 90;
- MinWidth = 180;
+ MinHeight = 40;
+ MinWidth = 120;
ClipToBounds = true;
Cursor = new Cursor(StandardCursorType.Cross);
for (var i = 0; i < FftN; i++) _hann[i] = 0.5 - 0.5 * Math.Cos(2 * Math.PI * i / (FftN - 1));
for (var i = 0; i < Bins; i++) _specDb[i] = -120;
}
+ public bool Dragging => _drag;
+
// Base (user-set) filter params — drives the drawn response + the handle.
public void Set(double freqNorm, double res, int type, float morph, bool slope24)
{
@@ -92,42 +76,39 @@ internal sealed class AutoFilterCurve : Control
InvalidateVisual();
}
- // UI tick: pull the scope → FFT → spectrum, and the live modulated cutoff.
- public void Tick()
+ // Live modulation: where the cutoff / resonance are now, and the range the settings allow.
+ public void SetLive(double cutNorm, double resNorm, double rangeLo, double rangeHi, bool assigned)
{
- _liveCut = Math.Clamp(_engine.DeviceGainReduction(_track, _device), 0, 1);
- // Sweep band: grow to include the live cutoff, then relax slowly toward it.
- _sweepLo = Math.Min(_sweepLo, _liveCut) + (_liveCut - Math.Min(_sweepLo, _liveCut)) * 0.006;
- _sweepHi = Math.Max(_sweepHi, _liveCut) + (_liveCut - Math.Max(_sweepHi, _liveCut)) * 0.006;
- var n = _engine.DeviceScope(_track, _device, _scope, FftN);
- if (n < FftN)
+ _liveCut = Math.Clamp(cutNorm, 0, 1);
+ _liveRes = Math.Clamp(resNorm, 0, 1);
+ _rangeLo = Math.Clamp(rangeLo, 0, 1);
+ _rangeHi = Math.Clamp(rangeHi, 0, 1);
+ _modAssigned = assigned;
+ InvalidateVisual();
+ }
+
+ // The pre-filter ring (oldest → newest), FftN samples from `offset`; n < FftN clears it.
+ public void FeedSpectrum(float[] buf, int offset, int n, double sampleRate)
+ {
+ if (n < FftN || offset + FftN > buf.Length)
{
for (var k = 1; k < Bins; k++) _specDb[k] = -120;
- InvalidateVisual();
return;
}
-
- for (var i = 0; i < FftN; i++)
- {
- _re[i] = _scope[i] * _hann[i];
- _im[i] = 0;
- }
-
+ for (var i = 0; i < FftN; i++) { _re[i] = buf[offset + i] * _hann[i]; _im[i] = 0; }
Fft(_re, _im);
- _sr = _engine.SampleRate > 0 ? _engine.SampleRate : 48000;
+ _sr = sampleRate > 0 ? sampleRate : 48000;
var refMag = FftN / 4.0;
for (var k = 1; k < Bins; k++)
{
var mag = Math.Sqrt(_re[k] * _re[k] + _im[k] * _im[k]);
- var db = 20 * Math.Log10(mag / refMag + 1e-9);
- _specDb[k] = db; // no release ballistics: the spectrum shows this frame (almanac § no meter animation)
+ _specDb[k] = 20 * Math.Log10(mag / refMag + 1e-9); // this frame, no ballistics (almanac)
}
-
- InvalidateVisual();
}
protected override void OnPointerPressed(PointerPressedEventArgs e)
{
+ if (!e.GetCurrentPoint(this).Properties.IsLeftButtonPressed) return;
_drag = true;
GestureBegin?.Invoke();
e.Pointer.Capture(this);
@@ -142,32 +123,29 @@ internal sealed class AutoFilterCurve : Control
protected override void OnPointerReleased(PointerReleasedEventArgs e)
{
- if (_drag)
- {
- _drag = false;
- GestureEnd?.Invoke();
- e.Pointer.Capture(null);
- }
+ if (!_drag) return;
+ _drag = false;
+ GestureEnd?.Invoke();
+ e.Pointer.Capture(null);
}
private void Apply(Point p)
{
double w = Bounds.Width, h = Bounds.Height;
if (w <= 0 || h <= 0) return;
- CutoffChanged?.Invoke(Math.Clamp(p.X / w, 0, 1));
- ResChanged?.Invoke(Math.Clamp(1 - p.Y / h, 0, 1));
- }
-
- private static double HzOf(double norm)
- {
- return FMin * Math.Pow(FMax / FMin, norm);
+ _fcNorm = Math.Clamp(p.X / w, 0, 1);
+ _res = Math.Clamp(1 - p.Y / h, 0, 1);
+ CutoffChanged?.Invoke(_fcNorm);
+ ResChanged?.Invoke(_res);
+ InvalidateVisual();
}
- private double Q => 0.5 + _res * 14.5;
+ private static double HzOf(double norm) => FMin * Math.Pow(FMax / FMin, norm);
- private double Mag(int type, double f, double fc)
+ private double Mag(int type, double f, double fc, double res)
{
- double w = f / fc, w2 = w * w, q = Q;
+ double q = 0.5 + res * 14.5;
+ double w = f / fc, w2 = w * w;
var den = Math.Sqrt((1 - w2) * (1 - w2) + w / q * (w / q));
if (den < 1e-9) den = 1e-9;
var m = type switch { 0 => 1.0 / den, 1 => w / q / den, 2 => w2 / den, _ => Math.Abs(1 - w2) / den };
@@ -175,45 +153,33 @@ internal sealed class AutoFilterCurve : Control
return m;
}
- private double MagDb(double f, double fc)
+ private double MagDb(double f, double fc, double res)
{
- var m = Mag(_type, f, fc);
- if (_morph > 0f) m = m * (1 - _morph) + Mag((_type + 1) & 3, f, fc) * _morph;
+ var m = Mag(_type, f, fc, res);
+ if (_morph > 0f) m = m * (1 - _morph) + Mag((_type + 1) & 3, f, fc, res) * _morph;
return 20.0 * Math.Log10(Math.Max(m, 1e-5));
}
- private double YForDb(double db, double h)
- {
- return Math.Clamp((DbTop - db) / (DbTop - DbBot) * h, 0, h);
- }
+ private static double YForDb(double db, double h) => Math.Clamp((DbTop - db) / (DbTop - DbBot) * h, 0, h);
public override void Render(DrawingContext ctx)
{
double w = Bounds.Width, h = Bounds.Height;
if (w <= 0 || h <= 0) return;
- NotaGraph.Window(ctx, new Rect(0, 0, w, h));
+ var frame = new Rect(0, 0, w, h);
+ NotaGraph.Window(ctx, frame);
- double logMin = Math.Log10(FMin), logMax = Math.Log10(FMax), logSpan = logMax - logMin;
+ double logMin = Math.Log10(FMin), logSpan = Math.Log10(FMax) - logMin;
+ double X(double f) => (Math.Log10(f) - logMin) / logSpan * w;
- double X(double f)
- {
- return (Math.Log10(f) - logMin) / logSpan * w;
- }
-
- foreach (var f in new[] { 100.0, 1000, 10000 })
- {
- var p1 = new Point(X(f), 0);
- var p2 = new Point(X(f), h);
- ctx.DrawLine(GridPen, p1, p2);
- }
-
- ctx.DrawLine(GridPen, new Point(0, YForDb(0, h)), new Point(w, YForDb(0, h)));
+ foreach (var f in new[] { 100.0, 1000, 10000 }) ctx.DrawLine(NotaGraph.GridPen, new Point(X(f), 0), new Point(X(f), h));
+ foreach (var db in new[] { 0.0, -18 }) ctx.DrawLine(NotaGraph.GridPen, new Point(0, YForDb(db, h)), new Point(w, YForDb(db, h)));
- // --- 1) spectrum analyzer (behind) ---
+ // 1) spectrum analyzer (behind)
var spec = new StreamGeometry();
using (var g = spec.Open())
{
- g.BeginFigure(new Point(0, h));
+ g.BeginFigure(new Point(0, h), false);
for (var k = 1; k < Bins; k++)
{
var f = k * _sr / FftN;
@@ -221,83 +187,64 @@ internal sealed class AutoFilterCurve : Control
var norm = Math.Clamp((_specDb[k] + 84) / 84, 0, 1);
g.LineTo(new Point(X(f), h - norm * h));
}
-
g.LineTo(new Point(w, h));
- g.EndFigure(true);
+ g.EndFigure(false);
}
-
ctx.DrawGeometry(null, SpecPen, spec);
- // --- teal sweep band: the range the modulation walks the cutoff over ---
- if (_sweepHi - _sweepLo > 0.004)
- {
- double bx0 = _sweepLo * w, bx1 = _sweepHi * w;
- ctx.FillRectangle(SweepFill, new Rect(bx0, 0, bx1 - bx0, h));
- ctx.DrawLine(SweepEdge, new Point(bx0, 0), new Point(bx0, h));
- ctx.DrawLine(SweepEdge, new Point(bx1, 0), new Point(bx1, h));
- }
-
- // --- 2) base response curve (interactive) ---
- var baseFc = HzOf(_fcNorm);
- var n = (int)Math.Max(24, Math.Min(400, w));
- var pts = new Point[n];
- for (var i = 0; i < n; i++)
- {
- var fx = (double)i / (n - 1);
- var f = Math.Pow(10, logMin + fx * logSpan);
- pts[i] = new Point(fx * w, YForDb(MagDb(f, baseFc), h));
- }
-
- var geo = new StreamGeometry();
- using (var gc = geo.Open())
+ // 2a) the range the modulation can walk the cutoff over (two teal rules)
+ if (_modAssigned && _rangeHi - _rangeLo > 0.004)
{
- gc.BeginFigure(new Point(0, h));
- foreach (var pt in pts) gc.LineTo(pt);
- gc.LineTo(new Point(w, h));
- gc.EndFigure(true);
+ double x0 = _rangeLo * w, x1 = _rangeHi * w;
+ ctx.FillRectangle(RangeFill, new Rect(x0, 0, x1 - x0, h));
+ ctx.DrawLine(RangePen, new Point(x0, 0), new Point(x0, h));
+ ctx.DrawLine(RangePen2, new Point(x1, 0), new Point(x1, h));
}
- for (var i = 1; i < n; i++) ctx.DrawLine(CurvePen, pts[i - 1], pts[i]);
- // handle at the base cutoff, sitting on the curve.
- double cx = _fcNorm * w, cy = YForDb(MagDb(baseFc, baseFc), h);
- NotaGraph.Node(ctx, new Point(cx, cy), active: true);
-
- // --- 3) dashed teal response at the live modulated cutoff (envelope + LFO) ---
- if (Math.Abs(_liveCut - _fcNorm) > 0.004)
+ int n = (int)Math.Max(24, Math.Min(400, w));
+ Point[] Curve(double fc, double res)
{
- var modFc = HzOf(_liveCut);
- Point prev = default;
- var has = false;
+ var pts = new Point[n];
for (var i = 0; i < n; i++)
{
var fx = (double)i / (n - 1);
var f = Math.Pow(10, logMin + fx * logSpan);
- var pt = new Point(fx * w, YForDb(MagDb(f, modFc), h));
- if (has) ctx.DrawLine(ModPen, prev, pt);
- prev = pt;
- has = true;
+ pts[i] = new Point(fx * w, YForDb(MagDb(f, fc, res), h));
}
+ return pts;
}
-
- // frequency scale + live cutoff readout + legend.
- void Lbl(string t, double x, double y, IBrush b)
+ void Stroke(IPen pen, Point[] pts)
{
- ctx.DrawText(
- new FormattedText(t, CultureInfo.InvariantCulture, FlowDirection.LeftToRight, Face,
- 8, b), new Point(x, y));
+ var geo = new StreamGeometry();
+ using (var gc = geo.Open())
+ {
+ gc.BeginFigure(pts[0], false);
+ for (int i = 1; i < pts.Length; i++) gc.LineTo(pts[i]);
+ gc.EndFigure(false);
+ }
+ ctx.DrawGeometry(null, pen, geo);
}
- // The range, in the bottom corners only.
- NotaGraph.Axis(ctx, new Rect(0, 0, w, h), NotaGraph.Corner.BottomLeft, "30");
- NotaGraph.Axis(ctx, new Rect(0, 0, w, h), NotaGraph.Corner.BottomRight, "18k Hz");
- var hz = HzOf(_liveCut);
- Lbl(hz >= 1000 ? $"{hz / 1000.0:0.0}\u2009k" : $"{hz:0}\u2009Hz", 4, 2, HandleB);
- // Legend inside the window: a dashed teal sample, then the word.
- var leg = new FormattedText("modulated", CultureInfo.InvariantCulture, FlowDirection.LeftToRight, Face, 8,
- NotaPalette.Teal);
- double lx = w - leg.Width - 4;
- ctx.DrawText(leg, new Point(lx, 2));
- ctx.DrawLine(new Pen(NotaPalette.Teal, 1.2, new DashStyle(new double[] { 2, 2 }, 0)), new Point(lx - 14, 2 + leg.Height / 2), new Point(lx - 4, 2 + leg.Height / 2));
+ // 3) dashed response at the live modulated cutoff / resonance (under the base curve)
+ bool moving = Math.Abs(_liveCut - _fcNorm) > 0.004 || Math.Abs(_liveRes - _res) > 0.01;
+ if (moving) Stroke(ModPen, Curve(HzOf(_liveCut), _liveRes));
+
+ // 2b) base response curve (interactive) with its handle
+ var baseFc = HzOf(_fcNorm);
+ Stroke(CurvePen, Curve(baseFc, _res));
+ double cx = _fcNorm * w, cy = YForDb(MagDb(baseFc, baseFc, _res), h);
+ NotaGraph.Node(ctx, new Point(cx, cy), active: true);
+
+ // Labels: title, legend, the range corners and the cutoff under its handle.
+ NotaGraph.Title(ctx, frame, "Response");
+ if (moving || _modAssigned) NotaGraph.Legend(ctx, w - 5, 3, ("modulated", NotaPalette.TealBright, NotaGraph.Mark.Dashed));
+ NotaGraph.Axis(ctx, frame, NotaGraph.Corner.BottomLeft, "30");
+ NotaGraph.Axis(ctx, frame, NotaGraph.Corner.BottomRight, "18k Hz");
+ var hz = baseFc;
+ string cut = hz >= 1000 ? NotaNum.Str(hz / 1000.0, "0.0") + "k" : NotaNum.Str(hz, "0");
+ var cf = NotaGraph.AxisText(cut, NotaPalette.AccentBright);
+ double lx = Math.Clamp(cx - cf.Width / 2, 24, Math.Max(24, w - 44 - cf.Width));
+ ctx.DrawText(cf, new Point(lx, h - cf.Height - 3));
}
// In-place iterative radix-2 Cooley–Tukey FFT.
@@ -337,4 +284,4 @@ internal sealed class AutoFilterCurve : Control
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/managed/Nota.App/Controls/AutoFilterIcons.cs b/src/managed/Nota.App/Controls/AutoFilterIcons.cs
deleted file mode 100644
index 3ae665b7..00000000
--- a/src/managed/Nota.App/Controls/AutoFilterIcons.cs
+++ /dev/null
@@ -1,120 +0,0 @@
-// SPDX-License-Identifier: AGPL-3.0-only
-// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.
-//
-// Small glyphs + a pill toggle switch for the Auto Filter card (mockup 2b): filter-type
-// response icons, LFO waveform icons, an envelope-shape glyph, and an on/off switch.
-
-using System;
-using Avalonia;
-using Avalonia.Controls;
-using Avalonia.Input;
-using Avalonia.Media;
-
-namespace Nota.App;
-
-// An icon whose stroke colour tracks its chip's selected state.
-internal interface IIconColor { IBrush Color { get; set; } }
-
-// Filter response glyph: 0 LP, 1 BP, 2 HP, 3 Notch. Recolour via Color.
-internal sealed class FilterTypeIcon : Control, IIconColor
-{
- private readonly int _t;
- private IBrush _c;
- public FilterTypeIcon(int type, IBrush color) { _t = type; _c = color; Width = 22; Height = 15; }
- public IBrush Color { get => _c; set { _c = value; InvalidateVisual(); } }
-
- public override void Render(DrawingContext ctx)
- {
- double w = Bounds.Width, h = Bounds.Height;
- var pen = new Pen(_c, 1.6, lineJoin: PenLineJoin.Round);
- double lo = h - 3, hi = 3, mid = h / 2;
- var g = new StreamGeometry();
- using (var c = g.Open())
- {
- switch (_t)
- {
- case 0: c.BeginFigure(new Point(2, hi), false); c.LineTo(new Point(w * 0.5, hi)); c.CubicBezierTo(new Point(w * 0.62, hi), new Point(w * 0.66, lo), new Point(w - 2, lo)); break; // LP
- case 1: c.BeginFigure(new Point(2, lo), false); c.CubicBezierTo(new Point(w * 0.42, lo), new Point(w * 0.44, hi), new Point(w * 0.5, hi)); c.CubicBezierTo(new Point(w * 0.56, hi), new Point(w * 0.58, lo), new Point(w - 2, lo)); break; // BP
- case 2: c.BeginFigure(new Point(2, lo), false); c.CubicBezierTo(new Point(w * 0.34, lo), new Point(w * 0.38, hi), new Point(w * 0.5, hi)); c.LineTo(new Point(w - 2, hi)); break; // HP
- default: c.BeginFigure(new Point(2, hi), false); c.LineTo(new Point(w * 0.4, hi)); c.LineTo(new Point(w * 0.5, lo)); c.LineTo(new Point(w * 0.6, hi)); c.LineTo(new Point(w - 2, hi)); break; // Notch
- }
- c.EndFigure(false);
- }
- ctx.DrawGeometry(null, pen, g);
- }
-}
-
-// LFO waveform glyph: 0 sine, 1 tri, 2 saw, 3 square, 4 S&H. Recolour via Color.
-internal sealed class LfoWaveIcon : Control, IIconColor
-{
- private readonly int _w;
- private IBrush _c;
- public LfoWaveIcon(int wave, IBrush color) { _w = wave; _c = color; Width = 18; Height = 11; }
- public IBrush Color { get => _c; set { _c = value; InvalidateVisual(); } }
-
- public override void Render(DrawingContext ctx)
- {
- double w = Bounds.Width, h = Bounds.Height, mid = h / 2, top = 2, bot = h - 2;
- var pen = new Pen(_c, 1.3, lineJoin: PenLineJoin.Round);
- switch (_w)
- {
- case 1: ctx.DrawLine(pen, new Point(2, bot), new Point(w / 2, top)); ctx.DrawLine(pen, new Point(w / 2, top), new Point(w - 2, bot)); break; // tri
- case 2: ctx.DrawLine(pen, new Point(2, bot), new Point(w - 2, top)); ctx.DrawLine(pen, new Point(w - 2, top), new Point(w - 2, bot)); break; // saw
- case 3: // square
- ctx.DrawLine(pen, new Point(2, mid), new Point(2, top)); ctx.DrawLine(pen, new Point(2, top), new Point(w / 2, top));
- ctx.DrawLine(pen, new Point(w / 2, top), new Point(w / 2, bot)); ctx.DrawLine(pen, new Point(w / 2, bot), new Point(w - 2, bot));
- ctx.DrawLine(pen, new Point(w - 2, bot), new Point(w - 2, mid)); break;
- case 4: // S&H stepped
- double[] hs = { bot, top + 2, mid, top, bot - 1 };
- double sw = (w - 4) / hs.Length; Point? p = null;
- for (int i = 0; i < hs.Length; i++) { double x0 = 2 + i * sw, x1 = x0 + sw; if (p is { } pp) ctx.DrawLine(pen, pp, new Point(x0, hs[i])); ctx.DrawLine(pen, new Point(x0, hs[i]), new Point(x1, hs[i])); p = new Point(x1, hs[i]); }
- break;
- default: // sine
- Point prev = new(2, mid);
- for (int i = 1; i <= 16; i++) { double t = i / 16.0, x = 2 + (w - 4) * t, y = mid - Math.Sin(t * 2 * Math.PI) * (mid - top); var cur = new Point(x, y); ctx.DrawLine(pen, prev, cur); prev = cur; }
- break;
- }
- }
-}
-
-// A small envelope-shape glyph (attack rise → decay/sustain → release fall).
-internal sealed class EnvGlyph : Control
-{
- private static readonly IBrush Line = NotaPalette.Teal;
- private static readonly IBrush Fill = NotaPalette.Wash(NotaPalette.Ink("#5AC8D8"), 0x1E);
- public EnvGlyph() { }
- public override void Render(DrawingContext ctx)
- {
- double w = Bounds.Width, h = Bounds.Height;
- var pts = new[] { new Point(3, h - 4), new Point(w * 0.22, 5), new Point(w * 0.55, h * 0.55), new Point(w - 4, h - 4) };
- var g = new StreamGeometry();
- using (var c = g.Open()) { c.BeginFigure(new Point(3, h), true); foreach (var p in pts) c.LineTo(p); c.LineTo(new Point(w - 4, h)); c.EndFigure(true); }
- ctx.DrawGeometry(Fill, null, g);
- var pen = new Pen(Line, 1.5, lineJoin: PenLineJoin.Round);
- for (int i = 1; i < pts.Length; i++) ctx.DrawLine(pen, pts[i - 1], pts[i]);
- }
-}
-
-// An on/off switch that owns its state and fires Changed — the same 18×10 brass pill as
-// SwitchTrack (almanac § Controls), for call sites that want a self-toggling control.
-internal sealed class ToggleSwitch : Control
-{
- private readonly SwitchTrack _track = new();
- public event Action<bool>? Changed;
- public ToggleSwitch(bool on)
- {
- _track.IsOn = on;
- Width = SwitchTrack.W; Height = SwitchTrack.H;
- Cursor = new Cursor(StandardCursorType.Hand);
- LogicalChildren.Add(_track); VisualChildren.Add(_track);
- }
- public bool IsOn { get => _track.IsOn; set => _track.IsOn = value; }
- protected override void OnPointerPressed(PointerPressedEventArgs e)
- {
- // Left button only — right-click bubbles to the CV-modulate / MIDI Learn menu.
- if (!e.GetCurrentPoint(this).Properties.IsLeftButtonPressed) return;
- _track.IsOn = !_track.IsOn; Changed?.Invoke(_track.IsOn); e.Handled = true;
- }
- protected override Size ArrangeOverride(Size finalSize) { _track.Arrange(new Rect(finalSize)); return finalSize; }
- protected override Size MeasureOverride(Size availableSize) { _track.Measure(availableSize); return new Size(SwitchTrack.W, SwitchTrack.H); }
-}
diff --git a/src/managed/Nota.App/Controls/AutoFilterViews.cs b/src/managed/Nota.App/Controls/AutoFilterViews.cs
new file mode 100644
index 00000000..631c1fb0
--- /dev/null
+++ b/src/managed/Nota.App/Controls/AutoFilterViews.cs
@@ -0,0 +1,304 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.
+//
+// Auto Filter card views (besides the response curve):
+// • AfFader — the SHAPE column's vertical faders (FRQ / RES): the set value as a filled
+// well with a handle, plus a thin marker where modulation has it now;
+// • AfEnvView — the Envelope tab's window: the input envelope (teal) and the cutoff it
+// drives (brass) over the last few hundred ms, with the base cutoff dashed;
+// drag up / down for the amount;
+// • AfLfoView — the LFO tab's window: the LFO's cutoff motion over two bars (or a few
+// cycles in free time), raw shape dashed teal, the smoothed motion in brass,
+// a playhead dot at the live phase; drag up / down for the amount, sideways
+// for the start phase.
+
+using System;
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Input;
+using Avalonia.Media;
+
+namespace Nota.App;
+
+internal sealed class AfFader : Control
+{
+ private double _v, _live = double.NaN;
+ private bool _drag;
+
+ public IBrush Ink { get; init; } = NotaPalette.Accent;
+ public double Default { get; set; } = double.NaN;
+ public bool Dragging => _drag;
+
+ public event Action<double>? Changed;
+ public event Action? GestureBegin;
+ public event Action? GestureEnd;
+
+ public AfFader() { Width = 16; Cursor = new Cursor(StandardCursorType.SizeNorthSouth); }
+
+ /// <summary>The set value, and where modulation has it now (NaN = no marker).</summary>
+ public void Set(double v, double live)
+ {
+ if (!_drag) _v = Math.Clamp(v, 0, 1);
+ _live = double.IsNaN(live) ? live : Math.Clamp(live, 0, 1);
+ InvalidateVisual();
+ }
+
+ private void Apply(PointerEventArgs e)
+ {
+ double h = Bounds.Height; if (h <= 2) return;
+ _v = Math.Clamp(1 - e.GetPosition(this).Y / h, 0, 1);
+ Changed?.Invoke(_v); InvalidateVisual();
+ }
+ protected override void OnPointerPressed(PointerPressedEventArgs e)
+ {
+ base.OnPointerPressed(e);
+ if (!e.GetCurrentPoint(this).Properties.IsLeftButtonPressed) return;
+ if (e.ClickCount == 2 && !double.IsNaN(Default))
+ {
+ GestureBegin?.Invoke(); _v = Default; Changed?.Invoke(_v); GestureEnd?.Invoke();
+ InvalidateVisual(); e.Handled = true; return;
+ }
+ _drag = true; GestureBegin?.Invoke(); e.Pointer.Capture(this); Apply(e); e.Handled = true;
+ }
+ protected override void OnPointerMoved(PointerEventArgs e) { base.OnPointerMoved(e); if (_drag) Apply(e); }
+ protected override void OnPointerReleased(PointerReleasedEventArgs e)
+ {
+ base.OnPointerReleased(e);
+ if (!_drag) return;
+ _drag = false; e.Pointer.Capture(null); GestureEnd?.Invoke();
+ }
+
+ public override void Render(DrawingContext ctx)
+ {
+ double w = Bounds.Width, h = Bounds.Height;
+ if (w < 2 || h < 4) return;
+ var rect = new Rect(0.5, 0.5, w - 1, h - 1);
+ double r = Math.Min(8, w / 2);
+ ctx.DrawRectangle(NotaPalette.BgSunken, null, rect, r, r);
+ double y = (1 - _v) * h;
+ using (ctx.PushClip(new RoundedRect(rect, r)))
+ {
+ ctx.FillRectangle(NotaPalette.Wash((SolidColorBrush)Ink, 0x48), new Rect(0, y, w, h - y));
+ if (!double.IsNaN(_live) && Math.Abs(_live - _v) > 0.005)
+ {
+ double ly = Math.Clamp((1 - _live) * h, 1, h - 1);
+ ctx.DrawLine(new Pen(NotaPalette.Wash((SolidColorBrush)Ink, 0xB0), 1, new DashStyle(new double[] { 2, 1 }, 0)), new Point(2, ly), new Point(w - 2, ly));
+ }
+ }
+ ctx.DrawRectangle(null, new Pen(NotaPalette.BorderDefault, 1), rect, r, r);
+ double hy = Math.Clamp(y, 1.5, h - 2.5);
+ ctx.DrawRectangle(Ink, null, new Rect(1.5, hy - 1, w - 3, 2), 1, 1);
+ }
+}
+
+// Shared by the two time windows: a vertical drag gesture on the whole window.
+internal abstract class AfWindowBase : Control
+{
+ private bool _drag;
+ private Point _start;
+ private double _v0, _h0;
+
+ public event Action? GestureBegin;
+ public event Action? GestureEnd;
+ /// <summary>Vertical drag: the new value for the dragged param (from DragStart's start value).</summary>
+ public event Action<double>? DragV;
+ /// <summary>Horizontal drag: the new value (0..1, wraps) — only raised when HorizontalDrag.</summary>
+ public event Action<double>? DragH;
+ public Func<double>? StartV { get; set; }
+ public Func<double>? StartH { get; set; }
+ public bool Dragging => _drag;
+
+ protected AfWindowBase() { ClipToBounds = true; Cursor = new Cursor(StandardCursorType.SizeAll); MinHeight = 36; }
+
+ protected override void OnPointerPressed(PointerPressedEventArgs e)
+ {
+ if (!e.GetCurrentPoint(this).Properties.IsLeftButtonPressed) return;
+ _drag = true; _start = e.GetPosition(this);
+ _v0 = StartV?.Invoke() ?? 0; _h0 = StartH?.Invoke() ?? 0;
+ GestureBegin?.Invoke(); e.Pointer.Capture(this); e.Handled = true;
+ }
+ protected override void OnPointerMoved(PointerEventArgs e)
+ {
+ if (!_drag) return;
+ var p = e.GetPosition(this);
+ double dy = (_start.Y - p.Y) / Math.Max(40, Bounds.Height), dx = (p.X - _start.X) / Math.Max(40, Bounds.Width);
+ DragV?.Invoke(Math.Clamp(_v0 + dy * 0.5, 0, 1));
+ if (StartH is not null) { double h = _h0 + dx; DragH?.Invoke(h - Math.Floor(h)); }
+ }
+ protected override void OnPointerReleased(PointerReleasedEventArgs e)
+ {
+ if (!_drag) return;
+ _drag = false; e.Pointer.Capture(null); GestureEnd?.Invoke();
+ }
+
+ protected static void Grid(DrawingContext ctx, double w, double h, int cols)
+ {
+ for (int i = 1; i < 4; i++) ctx.DrawLine(NotaGraph.GridPen, new Point(0, h * i / 4), new Point(w, h * i / 4));
+ for (int i = 1; i < cols; i++) ctx.DrawLine(NotaGraph.GridPen, new Point(w * i / cols, 0), new Point(w * i / cols, h));
+ }
+}
+
+internal sealed class AfEnvView : AfWindowBase
+{
+ private float[] _env = Array.Empty<float>(), _cut = Array.Empty<float>();
+ private int _n;
+ private double _base = 0.5, _peakHz, _windowMs = 600;
+ private string _baseText = "", _winText = "";
+
+ /// <summary>The last <paramref name="n"/> history points (1 ms each), oldest first.</summary>
+ public void Set(float[] env, float[] cut, int n, double baseNorm, string baseText, double windowMs, double peakHz)
+ {
+ _env = env; _cut = cut; _n = n; _base = baseNorm; _baseText = baseText; _windowMs = windowMs; _peakHz = peakHz;
+ _winText = windowMs >= 1000 ? NotaNum.F($"{windowMs / 1000:0.#} s") : NotaNum.F($"{windowMs:0} ms");
+ InvalidateVisual();
+ }
+
+ public override void Render(DrawingContext ctx)
+ {
+ double w = Bounds.Width, h = Bounds.Height;
+ if (w <= 0 || h <= 0) return;
+ var frame = new Rect(0, 0, w, h);
+ NotaGraph.Window(ctx, frame);
+ Grid(ctx, w, h, 6);
+ double top = 14, bot = h - 12, span = Math.Max(1, bot - top);
+ double YCut(double norm) => bot - Math.Clamp(norm, 0, 1) * span;
+ double YEnv(double lin) { double db = lin > 1e-6 ? 20 * Math.Log10(lin) : -120; return bot - Math.Clamp((db + 48) / 48, 0, 1) * span; }
+
+ // base cutoff, dashed
+ double by = YCut(_base);
+ ctx.DrawLine(new Pen(NotaPalette.BorderStrong, 1, new DashStyle(new double[] { 2, 4 }, 0)), new Point(0, by), new Point(w, by));
+
+ if (_n > 1)
+ {
+ StreamGeometry Line(float[] src, Func<double, double> y)
+ {
+ var g = new StreamGeometry();
+ using var c = g.Open();
+ c.BeginFigure(new Point(0, y(src[0])), false);
+ // at most one vertex per pixel: the peak of the points under it keeps transients
+ int px = Math.Max(2, (int)w);
+ for (int x = 1; x < px; x++)
+ {
+ int a = (int)((double)(x - 1) / px * _n), b = Math.Max(a + 1, (int)((double)x / px * _n));
+ double best = src[Math.Min(a, _n - 1)];
+ for (int k = a; k < b && k < _n; k++) best = Math.Max(best, src[k]);
+ c.LineTo(new Point(x * w / (px - 1), y(best)));
+ }
+ c.EndFigure(false);
+ return g;
+ }
+ ctx.DrawGeometry(null, new Pen(NotaPalette.Wash(NotaPalette.Teal, 0xC0), 1.1), Line(_env, v => YEnv(v)));
+ ctx.DrawGeometry(null, NotaGraph.PrimaryPen, Line(_cut, v => YCut(v)));
+ }
+
+ NotaGraph.Title(ctx, frame, "Cutoff over time");
+ string pk = NotaNum.Hz(_peakHz);
+ NotaGraph.Axis(ctx, frame, NotaGraph.Corner.TopRight, pk, NotaPalette.AccentBright);
+ NotaGraph.Legend(ctx, w - 5, 16, ("input", NotaPalette.TealBright, NotaGraph.Mark.Line));
+ NotaGraph.Axis(ctx, frame, NotaGraph.Corner.BottomLeft, "0");
+ NotaGraph.Axis(ctx, frame, NotaGraph.Corner.BottomRight, _winText);
+ var bt = NotaGraph.AxisText(_baseText);
+ ctx.DrawText(bt, new Point((w - bt.Width) / 2, h - bt.Height - 3));
+ }
+}
+
+internal sealed class AfLfoView : AfWindowBase
+{
+ private int _wave;
+ private double _morph, _amount, _offset, _stereo, _smoothCycles, _cycles = 8, _phase = double.NaN;
+ private bool _on = true;
+ private string _title = "LFO → Freq", _amt = "", _morphText = "", _mid = "", _end = "";
+ private readonly Random _rng = new(7);
+ private readonly double[] _sh = new double[64];
+
+ public AfLfoView() { for (int i = 0; i < _sh.Length; i++) _sh[i] = _rng.NextDouble() * 2 - 1; }
+
+ /// <summary>
+ /// Shape, depth (0..1), start offset and stereo offset (cycles), the smoothing time in
+ /// cycles, how many cycles the window shows, and the live phase within the current
+ /// cycle (NaN hides the playhead). Labels are pre-formatted by the card.
+ /// </summary>
+ public void Set(bool on, int wave, double morph, double amount, double offset, double stereo, double smoothCycles,
+ double cycles, double livePhase, string title, string amt, string morphText, string mid, string end)
+ {
+ _on = on; _wave = wave; _morph = morph; _amount = amount; _offset = offset; _stereo = stereo;
+ _smoothCycles = smoothCycles; _cycles = Math.Max(0.25, cycles); _phase = livePhase;
+ _title = title; _amt = amt; _morphText = morphText; _mid = mid; _end = end;
+ InvalidateVisual();
+ }
+
+ private double Shape(double ph, int cycle)
+ {
+ ph -= Math.Floor(ph);
+ return _wave switch
+ {
+ 0 => Math.Sin(2 * Math.PI * ph),
+ 1 => 4 * Math.Abs(ph - 0.5) - 1,
+ 2 => 2 * ph - 1,
+ 3 => ph < 0.5 + _morph * 0.49 ? 1 : -1,
+ _ => _sh[((cycle % _sh.Length) + _sh.Length) % _sh.Length],
+ };
+ }
+
+ public override void Render(DrawingContext ctx)
+ {
+ double w = Bounds.Width, h = Bounds.Height;
+ if (w <= 0 || h <= 0) return;
+ var frame = new Rect(0, 0, w, h);
+ NotaGraph.Window(ctx, frame);
+ int cols = _cycles <= 16 && Math.Abs(_cycles - Math.Round(_cycles)) < 1e-6 ? (int)Math.Round(_cycles) : 8;
+ Grid(ctx, w, h, Math.Clamp(cols, 2, 16));
+ double mid = h / 2, amp = (h / 2 - 12) * Math.Max(0.04, _amount);
+ ctx.DrawLine(new Pen(NotaPalette.BorderStrong, 1, new DashStyle(new double[] { 2, 4 }, 0)), new Point(0, mid), new Point(w, mid));
+
+ int px = Math.Max(8, (int)w);
+ double a = _smoothCycles <= 1e-4 ? 0 : Math.Exp(-(_cycles / px) / _smoothCycles); // one-pole per pixel
+ StreamGeometry Trace(double extra, bool smooth)
+ {
+ var g = new StreamGeometry();
+ using var c = g.Open();
+ // run the smoother over one cycle first so the drawn part starts settled
+ double s = 0;
+ if (smooth) for (int x = -px; x < 0; x++) { double ph = x * _cycles / px + _offset + extra; s = Shape(ph, (int)Math.Floor(ph)) + a * (s - Shape(ph, (int)Math.Floor(ph))); }
+ for (int x = 0; x <= px; x++)
+ {
+ double ph = x * _cycles / px + _offset + extra;
+ double v = Shape(ph, (int)Math.Floor(ph));
+ if (smooth) { s = v + a * (s - v); v = s; }
+ var p = new Point(x * w / px, mid - v * amp);
+ if (x == 0) c.BeginFigure(p, false); else c.LineTo(p);
+ }
+ c.EndFigure(false);
+ return g;
+ }
+ if (_on)
+ {
+ var dashed = new Pen(NotaPalette.Wash(NotaPalette.Teal, 0x99), 1.1, new DashStyle(new double[] { 4, 4 }, 0));
+ ctx.DrawGeometry(null, dashed, Trace(0, false));
+ if (_stereo > 1e-4) ctx.DrawGeometry(null, new Pen(NotaPalette.Wash(NotaPalette.Rose, 0x90), 1.1), Trace(_stereo, a > 0));
+ ctx.DrawGeometry(null, NotaGraph.PrimaryPen, Trace(0, a > 0));
+
+ if (!double.IsNaN(_phase))
+ {
+ // the playhead sits in the first cycle of the window at the live phase
+ double rel = _phase - _offset; rel -= Math.Floor(rel);
+ double x = rel / _cycles * w;
+ double v = Shape(_phase, 0);
+ ctx.DrawLine(new Pen(NotaPalette.Wash(NotaPalette.Accent, 0x80), 1), new Point(x, 0), new Point(x, h));
+ ctx.DrawEllipse(NotaPalette.Accent, null, new Point(x, mid - v * amp), 3, 3);
+ }
+ }
+
+ NotaGraph.Title(ctx, frame, _title);
+ NotaGraph.Axis(ctx, frame, NotaGraph.Corner.TopRight, _amt, NotaPalette.AccentBright);
+ if (_morphText.Length > 0)
+ {
+ var t = NotaGraph.AxisText(_morphText, NotaPalette.TealBright);
+ ctx.DrawText(t, new Point(Math.Min(86, w / 2), 3));
+ }
+ NotaGraph.Axis(ctx, frame, NotaGraph.Corner.BottomLeft, "1");
+ var m = NotaGraph.AxisText(_mid);
+ ctx.DrawText(m, new Point(w / 2 + 2, h - m.Height - 3));
+ NotaGraph.Axis(ctx, frame, NotaGraph.Corner.BottomRight, _end);
+ }
+}
diff --git a/src/managed/Nota.App/Controls/ToggleSwitch.cs b/src/managed/Nota.App/Controls/ToggleSwitch.cs
new file mode 100644
index 00000000..4958d7a3
--- /dev/null
+++ b/src/managed/Nota.App/Controls/ToggleSwitch.cs
@@ -0,0 +1,36 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.
+//
+// A self-toggling pill switch, first drawn for the Auto Filter card (mockup 2b).
+
+using System;
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Input;
+using Avalonia.Media;
+
+namespace Nota.App;
+
+// An on/off switch that owns its state and fires Changed — the same 18×10 brass pill as
+// SwitchTrack (almanac § Controls), for call sites that want a self-toggling control.
+internal sealed class ToggleSwitch : Control
+{
+ private readonly SwitchTrack _track = new();
+ public event Action<bool>? Changed;
+ public ToggleSwitch(bool on)
+ {
+ _track.IsOn = on;
+ Width = SwitchTrack.W; Height = SwitchTrack.H;
+ Cursor = new Cursor(StandardCursorType.Hand);
+ LogicalChildren.Add(_track); VisualChildren.Add(_track);
+ }
+ public bool IsOn { get => _track.IsOn; set => _track.IsOn = value; }
+ protected override void OnPointerPressed(PointerPressedEventArgs e)
+ {
+ // Left button only — right-click bubbles to the CV-modulate / MIDI Learn menu.
+ if (!e.GetCurrentPoint(this).Properties.IsLeftButtonPressed) return;
+ _track.IsOn = !_track.IsOn; Changed?.Invoke(_track.IsOn); e.Handled = true;
+ }
+ protected override Size ArrangeOverride(Size finalSize) { _track.Arrange(new Rect(finalSize)); return finalSize; }
+ protected override Size MeasureOverride(Size availableSize) { _track.Measure(availableSize); return new Size(SwitchTrack.W, SwitchTrack.H); }
+}
diff --git a/src/managed/Nota.App/DeviceCards/Bodies/AutoFilterDeviceBody.cs b/src/managed/Nota.App/DeviceCards/Bodies/AutoFilterDeviceBody.cs
index 35ffb5cf..a9a8deda 100644
--- a/src/managed/Nota.App/DeviceCards/Bodies/AutoFilterDeviceBody.cs
+++ b/src/managed/Nota.App/DeviceCards/Bodies/AutoFilterDeviceBody.cs
@@ -1,11 +1,14 @@
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.
//
-// Detail · Devices — built-in Auto Filter (kind 7) body, rebuilt to mockup 2g (the
-// 700×260 standard shell, superseding the old 1440-wide 2b). A LIVE strip (filter type
-// icons · slope · Freq · Res sliders · Clean/Analog) over a body of graph | modulation
-// column (ENV + LFO as two teal lanes, each a switch + shape + three knobs) | a 108px
-// output rail (Drive / Dry-Wet / Gain + a compact sidechain). The graph keeps top billing.
+// Detail · Devices — built-in Auto Filter body (device kind 7), a build of the "Nota Auto
+// Filter" mockup (700 × 260) on the Lens / Compressor / Delay frame: an always-visible
+// SHAPE column (cutoff · resonance faders, with the modulated value marked), a centre
+// panel with Filter / Envelope / LFO tabs — each one window where the cutoff's movement
+// is seen (the response, the cutoff over time, the LFO over two bars) — a right panel with
+// Mod / Output tabs, and a status strip. Every control is a device param, so automation /
+// MIDI learn / presets / A-B / persistence come for free; the sidechain source is routing.
+// FullBleed — the shared shell draws the header (name · preset · badge · bypass).
using System;
using System.Collections.Generic;
@@ -22,401 +25,738 @@ namespace Nota.App;
internal sealed class AutoFilterDeviceBody : IDeviceBody
{
- // Param indices — must match AutoFilter.h.
+ // ── Parameter indices (must match AutoFilter.h) ──────────────────────────
private const int Freq = 0, Res = 1, Type = 2, Slope = 3, Morph = 4, EnvAmt = 5, EnvAtt = 6,
- EnvRel = 7, EnvHold = 8, LfoAmt = 9, LfoRate = 10, LfoWave = 11, LfoMorph = 12,
- Drive = 13, DryWet = 14, EnvOn = 15, LfoOn = 16, Gain = 17, Circuit = 18,
- LfoSync = 19, LfoPhase = 20;
-
+ EnvRel = 7, EnvHold = 8, LfoAmt = 9, LfoRate = 10, LfoWave = 11, LfoMorph = 12,
+ Drive = 13, DryWet = 14, EnvOn = 15, LfoOn = 16, Gain = 17, Circuit = 18,
+ LfoSync = 19, LfoPhase = 20, ModTarget = 21, EnvHoldTime = 22, ModSmooth = 23,
+ LfoOffset = 24, LfoRetrig = 25;
+ // Scope layout (AutoFilter::S_* / kHist / kScope).
+ private const int S_Cut = 0, S_CutR = 1, S_Res = 2, S_Env = 3, S_Lfo = 4, S_LfoPhase = 5, S_InPk = 6,
+ S_OutPk = 7, S_Cpu = 8, S_SampleRate = 9, S_Bpm = 10, S_Onsets = 11, S_EnvHeld = 12, kTele = 16;
+ private const int kHist = 2048, kRing = AutoFilterCurve.FftN, kScope = kTele + 2 * kHist + kRing;
+ private const double OnsetLin = 0.063; // −24 dBFS, the engine's onset threshold
+
+ private static readonly string[] TypeNames = { "LP", "BP", "HP", "Notch" };
+ private static readonly string[] WaveNames = { "Sine", "Tri", "Saw", "Sqr", "S&H" };
private static readonly string[] DivNames = { "2/1", "1/1", "1/2", "1/4", "1/8", "1/16", "1/32", "1/64" };
-
- private static readonly IBrush HdrBg = NotaPalette.SurfaceCard;
- private static readonly IBrush RailBg = NotaPalette.SurfaceInset;
- private static readonly IBrush Border2 = NotaPalette.BorderDefault;
- private static readonly IBrush Inset = NotaPalette.BgSunken;
- private static readonly IBrush FieldBorder = NotaPalette.GraphBorder;
- private static readonly IBrush Amber = NotaPalette.Accent;
- private static readonly IBrush AmberLit = NotaPalette.AccentBright;
- private static readonly IBrush TealC = NotaPalette.Teal;
- private static readonly IBrush TxtC = NotaPalette.TextPrimary;
- private static readonly IBrush MutedC = NotaPalette.TextTertiary;
- private static readonly IBrush AmberSubtle = NotaPalette.Wash(NotaPalette.Accent, 0x28);
- private static readonly IBrush TealSubtle = NotaPalette.Wash(NotaPalette.Teal, 0x24);
- private static readonly IBrush RowLit = NotaPalette.SurfaceRaised;
+ private static readonly double[] DivBeats = { 8.0, 4.0, 2.0, 1.0, 0.5, 0.25, 0.125, 0.0625 };
+ private static readonly double[] EnvWindows = { 600, 800, 1000, 1500, 2000 };
+ private static readonly string[] NoteNames = { "C", "C♯", "D", "D♯", "E", "F", "F♯", "G", "G♯", "A", "A♯", "B" };
public double Width => 700;
-
- public string? Subtitle => "FILTER"; // the processing type, shown as the header badge
public bool FullBleed => true;
+ public string? Subtitle => "FILTER";
public Control Build(DeviceCardContext ctx, int index)
{
var engine = ctx.Engine;
int track = ctx.TrackId, di = index;
float P(int p) => engine.DeviceGetParam(track, di, p);
- void SetP(int p, float v) => engine.DeviceSetParam(track, di, p, v);
void Begin(int p) => engine.BeginAutomationWrite(track, AutomationTarget.DeviceParam, di, p, "");
void End(int p) => engine.EndAutomationWrite(track, AutomationTarget.DeviceParam, di, p, "");
- static double Exp(double v, double lo, double hi) => lo * Math.Pow(hi / lo, Math.Clamp(v, 0, 1));
-
- var curve = new AutoFilterCurve(engine, track, di) { VerticalAlignment = VerticalAlignment.Stretch };
- void SyncCurve() => curve.Set(P(Freq), P(Res), (int)Math.Round(P(Type) * 3), P(Morph), P(Slope) >= 0.5f);
- curve.GestureBegin += () => { Begin(Freq); Begin(Res); };
- curve.GestureEnd += () => { End(Freq); End(Res); };
- curve.CutoffChanged += v => { SetP(Freq, (float)v); SyncCurve(); };
- curve.ResChanged += v => { SetP(Res, (float)v); SyncCurve(); };
- ctx.AddDeviceRefresher(curve.Tick);
-
- // ---- formatters ----
- string Hz(double v) { double f = Exp(v, 30, 18000); return f >= 1000 ? $"{f / 1000:0.0}\u2009k" : $"{(int)Math.Round(f)}\u2009Hz"; }
- static string PctF(double v) => $"{v * 100:0}\u2009%";
- static string Bip(double v) => $"{(v - 0.5) * 200:+0;−0;0}\u2009%";
- static string GainF(double v) => $"{(v - 0.5) * 48:+0.0;−0.0;0.0}";
- static string Ms(double v, double lo, double hi) { double m = lo * Math.Pow(hi / lo, v); return m >= 100 ? $"{m:0}\u2009ms" : $"{m:0.0}\u2009ms"; }
- string AttF(double v) => Ms(v, 0.1, 500);
- string RelF(double v) => Ms(v, 1, 2000);
- string RateF(double v) => P(LfoSync) >= 0.5f ? DivNames[Math.Clamp((int)Math.Round(v * 7), 0, 7)] : $"{Exp(v, 0.01, 40):0.00}\u2009Hz";
+ void Raw(int p, float v) => engine.DeviceSetParam(track, di, p, Math.Clamp(v, 0f, 1f));
+ // A discrete edit (a click) is one automation gesture, so it records while the transport does.
+ void SetP(int p, float v) { Begin(p); Raw(p, v); End(p); }
+ void Reset(int p) { Begin(p); Raw(p, engine.DeviceParamDefault(track, di, p)); End(p); }
+ bool On(int p) => P(p) >= 0.5f;
+ int Sel(int p, int n) => Math.Clamp((int)Math.Round(P(p) * (n - 1)), 0, n - 1);
var readouts = new List<Action>();
+ void RefreshAll() { foreach (var a in readouts) a(); }
+ var scope = new float[kScope];
+ int scN = 0;
+ double Sc(int i) => scN > i ? scope[i] : 0;
+ var envHist = new float[kHist];
+ var cutHist = new float[kHist];
+
+ // ---- units ----------------------------------------------------------------
+ static double Exp(double v, double lo, double hi) => lo * Math.Pow(hi / lo, Math.Clamp(v, 0, 1));
+ static double HzOf(double norm) => Exp(norm, 30, 18000);
+ static double NormOf(double hz) => Math.Clamp(Math.Log(hz / 30.0) / Math.Log(18000.0 / 30.0), 0, 1);
+ static string Hz(double hz) => hz >= 1000 ? NotaNum.F($"{hz / 1000:0.00} k") : NotaNum.F($"{hz:0} Hz");
+ static string HzLong(double hz) => hz >= 1000 ? NotaNum.F($"{hz / 1000:0.00} kHz") : NotaNum.F($"{hz:0} Hz");
+ static string Pct(double v) => NotaNum.F($"{v * 100:0} %");
+ static string Bip(double v) => NotaNum.F($"{(v - 0.5) * 200:+0;−0;0} %");
+ static string Ms(double ms) => ms >= 100 ? NotaNum.F($"{ms:0} ms") : ms >= 10 ? NotaNum.F($"{ms:0.0} ms") : NotaNum.F($"{ms:0.0#} ms");
+ static double Q(double res) => 0.5 + res * 14.5;
+ static string GainF(double v) => NotaNum.F($"{(v - 0.5) * 48:+0.0;−0.0;0.0}");
+ static string DbF(double lin) => lin > 1e-5 ? NotaNum.F($"{20 * Math.Log10(lin):0.0;−0.0} dB") : "−∞ dB";
+ static double AttMs(double v) => Exp(v, 0.1, 500);
+ static double RelMs(double v) => Exp(v, 1, 2000);
+ static bool HoldInf(double v) => v >= 0.995;
+ static double HoldMs(double v) => 400 * v * v;
+ static string HoldF(double v) => HoldInf(v) ? "∞" : Ms(HoldMs(v));
+ static double SmoothMs(double v) => 120 * v * v;
+ static string SmoothF(double v) => v <= 0.001 ? "off" : Ms(SmoothMs(v));
+ static string Deg(double v, double full) => NotaNum.F($"{v * full:0}°");
+ string NoteOf(double hz)
+ {
+ double midi = 69 + 12 * Math.Log2(hz / 440.0);
+ int n = (int)Math.Round(midi);
+ int cents = (int)Math.Round((midi - n) * 100);
+ return NotaNum.F($"{NoteNames[((n % 12) + 12) % 12]}{n / 12 - 1} {cents:+0;−0;0} ¢");
+ }
+
+ double Bpm() => Sc(S_Bpm) > 1 ? Sc(S_Bpm) : 120;
+ bool Synced() => On(LfoSync);
+ double LfoHz() => Synced() ? Bpm() / 60.0 / DivBeats[Sel(LfoRate, 8)] : Exp(P(LfoRate), 0.01, 40);
+ string RateF(double v) => Synced() ? DivNames[Math.Clamp((int)Math.Round(v * 7), 0, 7)] : LfoHzF(Exp(v, 0.01, 40));
+ static string LfoHzF(double hz) => hz >= 10 ? NotaNum.F($"{hz:0.0} Hz") : NotaNum.F($"{hz:0.00} Hz");
+ int Target() => Sel(ModTarget, 3); // 0 Freq, 1 Reso, 2 Both
+ bool ToFreq() => Target() != 1;
+ bool ToRes() => Target() != 0;
+ string TargetName() => Target() switch { 0 => "Freq", 1 => "Reso", _ => "Freq + Reso" };
+ double EnvBip() => On(EnvOn) ? (P(EnvAmt) - 0.5) * 2 : 0;
+ double LfoDepth() => On(LfoOn) ? P(LfoAmt) : 0;
+ bool EnvAssigned() => Math.Abs(EnvBip()) > 0.004;
+ bool LfoAssigned() => LfoDepth() > 0.004;
+ bool Assigned() => EnvAssigned() || LfoAssigned();
+ double BaseHz() => HzOf(P(Freq));
+ double LiveHz() => scN > S_Cut ? HzOf(Sc(S_Cut)) : BaseHz();
+ // The cutoff range the settings allow (ENV one way, LFO both ways).
+ (double Lo, double Hi) RangeOct()
+ {
+ if (!ToFreq()) return (0, 0);
+ double e = EnvBip() * 6, l = LfoDepth() * 4;
+ return (Math.Min(0, e) - l, Math.Max(0, e) + l);
+ }
- // ---- gauge-knob cell (own live-follow so unit text isn't overwritten) ----
- Control Cell(string name, int p, Func<double, string> fmt, IBrush? arc = null, double size = 34, double cellW = 0)
+ // ---- small builders ---------------------------------------------------------
+ static TextBlock Caps(string t, IBrush? c = null, double fs = 7) => new()
+ { Text = t, FontSize = fs, FontWeight = FontWeight.Bold, Foreground = c ?? TextTertiary, LetterSpacing = 0.8, VerticalAlignment = VerticalAlignment.Center };
+ static TextBlock Mono(string t, double fs, IBrush c)
+ { var tb = new TextBlock { Text = t, FontSize = fs, Foreground = c, VerticalAlignment = VerticalAlignment.Center }; tb.BindResource(TextBlock.FontFamilyProperty, "Font.Mono"); return tb; }
+ static StackPanel Row(double sp, params Control[] cs)
+ { var s = new StackPanel { Orientation = Orientation.Horizontal, Spacing = sp, VerticalAlignment = VerticalAlignment.Center }; foreach (var c in cs) s.Children.Add(c); return s; }
+ static T Docked<T>(T c, Dock d) where T : Control { DockPanel.SetDock(c, d); return c; }
+ static T Col<T>(T c, int col) where T : Control { Grid.SetColumn(c, col); return c; }
+ static T GRow<T>(T c, int row) where T : Control { Grid.SetRow(c, row); return c; }
+ void Learn(Control c, int p) => MidiLearn.Bind(c, MidiTarget.DeviceParam(track, di, p), engine.DeviceParamName(track, di, p));
+
+ // Gauge knob bound to a device param (automation gesture + MIDI learn + live follow).
+ Control K(int p, string name, Func<double, string> fmt, IBrush? arc = null, double cellW = 46)
{
- var value = new TextBlock { Text = fmt(P(p)), FontSize = 9, Foreground = TxtC };
- value.BindResource(TextBlock.FontFamilyProperty, "Font.Mono");
- var knob = new Knob(P(p), 1.0) { Accent = true, ArcColor = arc, Default = engine.DeviceParamDefault(track, di, p), Width = size, Height = size };
- knob.ValueChanged += v => { SetP(p, (float)v); value.Text = fmt(v); SyncCurve(); };
+ var val = Mono(fmt(P(p)), 7, TextPrimary);
+ var knob = new Knob(P(p), 1.0) { Accent = true, ArcColor = arc, Default = engine.DeviceParamDefault(track, di, p), Width = 34, Height = 34 };
+ knob.ValueChanged += v => { Raw(p, (float)v); val.Text = fmt(v); };
knob.GestureBegin += () => Begin(p);
knob.GestureEnd += () => End(p);
- MidiLearn.Bind(knob, MidiTarget.DeviceParam(track, di, p), name);
- readouts.Add(() => { if (!knob.Dragging) { float c = P(p); if (Math.Abs(c - knob.Value) > 1e-3) knob.Value = c; value.Text = fmt(P(p)); } });
- return KnobCell(name, knob, value, cellW > 0 ? cellW : size + 20);
+ Learn(knob, p);
+ readouts.Add(() => { if (knob.Dragging) return; float c = P(p); if (Math.Abs(c - knob.Value) > 1e-4) knob.Value = c; val.Text = fmt(c); });
+ return KnobCell(name, knob, val, cellW);
}
- Control Cap(string t, IBrush? c = null) => new TextBlock { Text = t, FontSize = 8, FontWeight = FontWeight.Bold, Foreground = c ?? MutedC, VerticalAlignment = VerticalAlignment.Center };
- // Segmented pill over a normalized param.
- Control Seg(int p, string[] opts, bool teal = false)
+ // On/off switch bound to a param (> 0.5 = on).
+ Control Toggle(int p, string label, Func<string>? live = null, Func<bool>? dim = null)
{
- int n = opts.Length;
- var seg = DeviceCardKit.Segments(opts, () => Math.Clamp((int)Math.Round(P(p) * (n - 1)), 0, n - 1), iv => { SetP(p, n > 1 ? iv / (float)(n - 1) : 0f); SyncCurve(); RefreshAll(); }, out var sync);
+ var wrap = Switch(label, () => On(p), () => { SetP(p, On(p) ? 0f : 1f); RefreshAll(); }, out var sync, dim, live);
readouts.Add(sync);
- MidiLearn.Bind(seg, MidiTarget.DeviceParam(track, di, p), engine.DeviceParamName(track, di, p));
- return seg;
+ Learn(wrap, p);
+ return wrap;
}
- // Horizontal param slider (LIVE strip + rails).
- Control HSlider(int p, string label, Func<double, string> fmt, double lw, double vw, bool bipolar = false)
+ // Segmented pill over a discrete param (n options spread over 0..1).
+ Control Seg(int p, string[] names, bool fill = false)
{
- var row = DeviceCardKit.SliderRow(lw > 0 ? label : "", () => P(p), n => { SetP(p, (float)n); SyncCurve(); }, () => fmt(P(p)), out var sync,
- begin: () => Begin(p), end: () => End(p), bipolar: bipolar, labelWidth: lw, valueWidth: vw);
+ int n = names.Length;
+ var seg = Segments(names, () => Sel(p, n), iv => { SetP(p, n > 1 ? iv / (float)(n - 1) : 0f); RefreshAll(); }, out var sync, fill: fill, padX: 6);
readouts.Add(sync);
- MidiLearn.Bind(row, MidiTarget.DeviceParam(track, di, p), engine.DeviceParamName(track, di, p));
- return row;
+ Learn(seg, p);
+ return seg;
}
- // Filter-type icons row (icon-only) for the LIVE strip.
- Control TypeRow()
+ // Outlined chips (the mockup's TYPE / WAVE / target row): lit = brass edge + wash.
+ Control Chips(string[] names, Func<int, bool> lit, Action<int> pick, int learnParam, double h = 16, double padX = 7)
{
- var cells = new Border[4]; var icons = new IIconColor[4];
- void Sync() { int cur = (int)Math.Round(P(Type) * 3); for (int i = 0; i < 4; i++) { bool on = i == cur; cells[i].Background = on ? Amber : Inset; cells[i].BorderBrush = on ? Amber : Border2; icons[i].Color = on ? NotaPalette.TextOnAccent : MutedC; } }
- var row = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 3 };
- for (int i = 0; i < 4; i++) { int iv = i; var ic = new FilterTypeIcon(i, MutedC); var c = new Border { Width = 34, Height = 22, BorderThickness = new Thickness(1), CornerRadius = NotaRadius.Control, Cursor = new Cursor(StandardCursorType.Hand), Child = new Border { Child = ic, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center } }; c.PointerPressed += (_, e) => { e.Handled = true; SetP(Type, iv / 3f); SyncCurve(); RefreshAll(); }; cells[i] = c; icons[i] = ic; row.Children.Add(c); }
- readouts.Add(Sync);
- MidiLearn.Bind(row, MidiTarget.DeviceParam(track, di, Type), engine.DeviceParamName(track, di, Type));
+ var row = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 3, VerticalAlignment = VerticalAlignment.Center };
+ var cells = new Border[names.Length];
+ var texts = new TextBlock[names.Length];
+ for (int i = 0; i < names.Length; i++)
+ {
+ int iv = i;
+ var tb = new TextBlock { Text = names[i], FontSize = 8, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center };
+ var b = new Border { Height = h, Padding = new Thickness(padX, 0), CornerRadius = NotaRadius.Badge, BorderThickness = new Thickness(1), Cursor = new Cursor(StandardCursorType.Hand), Child = tb };
+ b.PointerPressed += (_, e) => { if (!e.GetCurrentPoint(b).Properties.IsLeftButtonPressed) return; pick(iv); RefreshAll(); e.Handled = true; };
+ cells[i] = b; texts[i] = tb; row.Children.Add(b);
+ }
+ readouts.Add(() =>
+ {
+ for (int i = 0; i < names.Length; i++)
+ {
+ bool on = lit(i);
+ cells[i].BorderBrush = on ? Brass : NotaPalette.BorderStrong;
+ cells[i].Background = on ? NotaPalette.AccentSubtle : Brushes.Transparent;
+ texts[i].Foreground = on ? AccentBright : TextSecondary;
+ texts[i].FontWeight = on ? FontWeight.SemiBold : FontWeight.Normal;
+ }
+ });
+ Learn(row, learnParam);
return row;
}
- // Vertical LFO wave picker (icon + label).
- Control WavePicker()
+ // A latching chip over a toggle param; its text can follow the value.
+ Border Latch(int p, Func<string> text, string tip, bool fill = false)
{
- var names = new[] { "Sine", "Tri", "Saw", "Sqr", "S&H" };
- var cells = new Border[5];
- var icons = new IIconColor[5];
- var texts = new TextBlock[5];
-
- void Sync()
+ var tb = new TextBlock { FontSize = 8, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center };
+ var b = new Border { Height = 16, Padding = new Thickness(7, 0), CornerRadius = NotaRadius.Badge, BorderThickness = new Thickness(1), Cursor = new Cursor(StandardCursorType.Hand), VerticalAlignment = VerticalAlignment.Center, Child = tb };
+ if (fill) b.HorizontalAlignment = HorizontalAlignment.Stretch;
+ void Hi()
{
- var cur = (int)Math.Round(P(LfoWave) * 4);
- for (var i = 0; i < 5; i++)
- {
- var on = i == cur;
- cells[i].Background = on ? TealSubtle : Inset;
- cells[i].BorderBrush = on ? TealC : Border2;
- icons[i].Color = on ? TealC : MutedC;
- texts[i].Foreground = on ? TealC : MutedC;
- }
- }
-
- var col = new UniformGrid { ColumnSpacing = 2, Rows = 1 };
- for (var i = 0; i < 5; i++)
- {
- var iv = i;
- var ic = new LfoWaveIcon(i, MutedC);
- var tb = new TextBlock
- {
- Text = names[i], FontSize = 7, FontWeight = FontWeight.SemiBold, Foreground = MutedC,
- VerticalAlignment = VerticalAlignment.Center
- };
- var c = new Border
- {
- BorderThickness = new Thickness(1),
- CornerRadius = NotaRadius.Badge,
- Padding = new Thickness(3, 2),
- Cursor = new Cursor(StandardCursorType.Hand),
- Child = new StackPanel
- {
- Orientation = Orientation.Horizontal,
- Spacing = 3,
- VerticalAlignment = VerticalAlignment.Center,
- HorizontalAlignment = HorizontalAlignment.Center,
- Children = {
- new Border
- {
- Child = ic,
- VerticalAlignment = VerticalAlignment.Center,
- }, tb }
- }
- };
- c.PointerPressed += (_, e) =>
- {
- e.Handled = true;
- SetP(LfoWave, iv / 4f);
- RefreshAll();
- };
- cells[i] = c;
- icons[i] = ic;
- texts[i] = tb;
- col.Children.Add(c);
+ bool on = On(p);
+ b.Background = on ? NotaPalette.AccentSubtle : fill ? Raised : Brushes.Transparent;
+ b.BorderBrush = on ? Brass : fill ? Brushes.Transparent : NotaPalette.BorderStrong;
+ tb.Foreground = on ? AccentBright : fill ? TextPrimary : TextSecondary;
+ tb.FontWeight = on ? FontWeight.SemiBold : FontWeight.Normal;
+ tb.Text = text();
}
+ b.PointerPressed += (_, e) => { if (!e.GetCurrentPoint(b).Properties.IsLeftButtonPressed) return; SetP(p, On(p) ? 0f : 1f); RefreshAll(); e.Handled = true; };
+ ToolTip.SetTip(b, tip);
+ Learn(b, p);
+ readouts.Add(Hi); Hi();
+ return b;
+ }
- readouts.Add(Sync);
- MidiLearn.Bind(col, MidiTarget.DeviceParam(track, di, LfoWave), engine.DeviceParamName(track, di, LfoWave));
- return col;
+ // Slider row: caps label · track · mono value.
+ Control SliderRow(string label, int p, Func<double, string> fmt, bool bipolar = false, bool modulation = false, Func<bool>? dim = null, double labW = 40)
+ {
+ var bar = DeviceCardKit.SliderRow("", () => P(p), v => Raw(p, (float)v), () => fmt(P(p)), out var sync,
+ begin: () => Begin(p), end: () => End(p), reset: () => Reset(p), bipolar: bipolar, dim: dim, valueWidth: 34, modulation: modulation);
+ readouts.Add(sync);
+ Learn(bar, p);
+ var g = new Grid { ColumnDefinitions = new ColumnDefinitions(NotaNum.F($"{labW},*")), VerticalAlignment = VerticalAlignment.Center };
+ g.Children.Add(Caps(label));
+ g.Children.Add(Col(bar, 1));
+ return g;
}
- // Small teal on/off toggle backed by a 0/1 param.
- Control MiniToggle(int p, string label)
+ // Tab head row: a fixed 18px strip over the window.
+ static Grid HeadRow(Control left, Control right)
+ {
+ var g = new Grid { ColumnDefinitions = new ColumnDefinitions("*,Auto"), Height = 18, ColumnSpacing = 6 };
+ g.Children.Add(left); g.Children.Add(Col(right, 1));
+ return g;
+ }
+ // The knob row under a window: knobs on the left, two mono info lines on the right.
+ Control KnobRow(Control[] knobs, Func<string> info1, Func<string> info2)
{
- var sw = new ToggleSwitch(P(p) >= 0.5f);
- sw.Changed += on => { SetP(p, on ? 1f : 0f); SyncCurve(); };
- readouts.Add(() => { bool on = P(p) >= 0.5f; if (sw.IsOn != on) sw.IsOn = on; });
- var mt = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 5, VerticalAlignment = VerticalAlignment.Center, Children = { sw, new TextBlock { Text = label, FontSize = 9, FontWeight = FontWeight.Bold, Foreground = TxtC, VerticalAlignment = VerticalAlignment.Center } } };
- MidiLearn.Bind(mt, MidiTarget.DeviceParam(track, di, p), engine.DeviceParamName(track, di, p));
- return mt;
+ var i1 = Mono("", 7, TextTertiary); i1.HorizontalAlignment = HorizontalAlignment.Right;
+ var i2 = Mono("", 7, TextTertiary); i2.HorizontalAlignment = HorizontalAlignment.Right;
+ readouts.Add(() => { i1.Text = info1(); i2.Text = info2(); });
+ var g = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,*"), Height = 52 };
+ g.Children.Add(Row(4, knobs));
+ g.Children.Add(Col(new StackPanel { Spacing = 3, VerticalAlignment = VerticalAlignment.Center, Children = { i1, i2 } }, 1));
+ return g;
}
+ static Control TabBody(Control head, Control window, Control knobs) => new DockPanel
+ {
+ LastChildFill = true, Margin = new Thickness(8, 5, 8, 0),
+ Children = { Docked(head, Dock.Top), Docked(knobs, Dock.Bottom), new Border { Margin = new Thickness(0, 5, 0, 0), Child = window } },
+ };
- // Clickable "Sync"/"Stereo N°" chips (LFO header).
- Control ToggleChip(int p, Func<double, string> fmt, bool cycle = false)
+ // ======================================================================
+ // LEFT — SHAPE column (cutoff · resonance)
+ // ======================================================================
+ Control ShapeFader(int p, string label, IBrush ink, int liveSlot, string tip)
{
- var tb = new TextBlock { Text = fmt(P(p)), FontSize = 8, Foreground = MutedC, VerticalAlignment = VerticalAlignment.Center };
- var b = new Border { CornerRadius = NotaRadius.Badge, BorderThickness = new Thickness(1), Padding = new Thickness(5, 1), Cursor = new Cursor(StandardCursorType.Hand), VerticalAlignment = VerticalAlignment.Center, Child = tb };
- void Sync() { bool on = P(p) >= 0.5f; b.Background = on ? NotaPalette.AccentSubtle : Brushes.Transparent; b.BorderBrush = on ? NotaPalette.BorderBrass : Border2; tb.Foreground = on ? NotaPalette.AccentHover : MutedC; tb.Text = fmt(P(p)); }
- b.PointerPressed += (_, e) => { e.Handled = true; if (cycle) { float nx = P(p) + 0.25f; if (nx > 1.001f) nx = 0f; SetP(p, nx); } else SetP(p, P(p) >= 0.5f ? 0f : 1f); Sync(); };
- readouts.Add(Sync);
- MidiLearn.Bind(b, MidiTarget.DeviceParam(track, di, p), engine.DeviceParamName(track, di, p));
- return b;
+ var f = new AfFader { Ink = ink, Width = 16, VerticalAlignment = VerticalAlignment.Stretch, Default = engine.DeviceParamDefault(track, di, p) };
+ f.Changed += v => { Raw(p, (float)v); RefreshAll(); };
+ f.GestureBegin += () => Begin(p);
+ f.GestureEnd += () => End(p);
+ Learn(f, p);
+ ToolTip.SetTip(f, tip);
+ readouts.Add(() => f.Set(P(p), scN > liveSlot && Assigned() ? Sc(liveSlot) : double.NaN));
+ var lb = Caps(label); lb.HorizontalAlignment = HorizontalAlignment.Center;
+ return new DockPanel { Children = { Docked(lb, Dock.Bottom), new Border { Margin = new Thickness(0, 0, 0, 3), Child = f } } };
}
+ var shapeTitle = Caps("SHAPE"); shapeTitle.HorizontalAlignment = HorizontalAlignment.Center;
+ var shapeFreq = Mono("", 7, AccentBright); shapeFreq.HorizontalAlignment = HorizontalAlignment.Center;
+ var shapeRes = Mono("", 7, TextPrimary); shapeRes.HorizontalAlignment = HorizontalAlignment.Center;
+ readouts.Add(() =>
+ {
+ shapeFreq.Text = Hz(BaseHz());
+ shapeRes.Text = Pct(P(Res));
+ shapeTitle.Foreground = Assigned() && scN > 0 && Math.Abs(Sc(S_Cut) - P(Freq)) > 0.01 ? AccentBright : TextTertiary;
+ });
+ var faders = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,Auto"), ColumnSpacing = 9, HorizontalAlignment = HorizontalAlignment.Center, Margin = new Thickness(0, 4, 0, 4) };
+ faders.Children.Add(ShapeFader(Freq, "FRQ", Brass, S_Cut, "Cutoff — the base the modulation moves from; the dashed mark is where it is now. Double-click resets."));
+ faders.Children.Add(Col(ShapeFader(Res, "RES", Teal, S_Res, "Resonance — the peak at the cutoff; the dashed mark is where it is now. Double-click resets."), 1));
+ var shapeCol = new Border
+ {
+ Width = 56, Background = Card2, BorderBrush = BorderDef, BorderThickness = new Thickness(1), CornerRadius = NotaRadius.Tile, Padding = new Thickness(0, 5, 0, 4),
+ Child = new DockPanel { Children = { Docked(shapeTitle, Dock.Top), Docked(shapeRes, Dock.Bottom), Docked(shapeFreq, Dock.Bottom), faders } },
+ };
+ DockPanel.SetDock(shapeCol, Dock.Left);
- // ================= LIVE strip =================
- var live = new Border { Height = 34, Background = HdrBg, BorderBrush = Border2, BorderThickness = new Thickness(0, 0, 0, 1),
- Child = new DockPanel { LastChildFill = false, Margin = new Thickness(9, 0), Children = {
- new StackPanel { Orientation = Orientation.Horizontal, Spacing = 9, VerticalAlignment = VerticalAlignment.Center, Children = {
- TypeRow(),
- Seg(Slope, new[] { "12", "24" }),
- new StackPanel { Orientation = Orientation.Horizontal, Spacing = 6, VerticalAlignment = VerticalAlignment.Center, Width = 150, Children = { Cap("FREQ"), HSlider(Freq, "", Hz, 0, 52) } },
- new StackPanel { Orientation = Orientation.Horizontal, Spacing = 6, VerticalAlignment = VerticalAlignment.Center, Width = 116, Children = { Cap("RESO"), HSlider(Res, "", PctF, 0, 34) } } } },
- new StackPanel { [DockPanel.DockProperty] = Dock.Right, VerticalAlignment = VerticalAlignment.Center, Children = { Seg(Circuit, new[] { "Clean", "Analog" }) } } } } };
-
- // ================= graph =================
- var graph = new Border { Padding = new Thickness(8, 7), Child = new Border { Background = Inset, BorderBrush = FieldBorder, BorderThickness = new Thickness(1), CornerRadius = NotaRadius.Panel, Child = curve, ClipToBounds = true } };
-
- // ================= modulation column (ENV + LFO lanes) =================
- Control LaneHeader(int onParam, string name, params Control[] trailing)
+ // ======================================================================
+ // CENTRE — Filter
+ // ======================================================================
+ AutoFilterCurve? curve = null;
+ Control FilterTab()
{
- var dp = new DockPanel { LastChildFill = false, Height = 13 };
- var lead = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 6, VerticalAlignment = VerticalAlignment.Center, Children = { } };
- lead.Children.Add(MiniToggle(onParam, name));
- lead.Children.Add(new TextBlock { Text = "→ Freq", FontSize = 8, Foreground = MutedC, VerticalAlignment = VerticalAlignment.Center });
- dp.Children.Add(lead);
- var trail = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 6, VerticalAlignment = VerticalAlignment.Center, [DockPanel.DockProperty] = Dock.Right };
- foreach (var c in trailing) trail.Children.Add(c);
- dp.Children.Add(trail);
- return dp;
+ curve = new AutoFilterCurve();
+ curve.GestureBegin += () => { Begin(Freq); Begin(Res); };
+ curve.GestureEnd += () => { End(Freq); End(Res); };
+ curve.CutoffChanged += v => Raw(Freq, (float)v);
+ curve.ResChanged += v => Raw(Res, (float)v);
+ ToolTip.SetTip(curve, "Drag sideways for the cutoff, up and down for the resonance. The teal band is how far the envelope and LFO can move the cutoff; the dashed curve is where they have it now.");
+ Learn(curve, Freq);
+
+ var q = Mono("", 7, TextTertiary);
+ readouts.Add(() => q.Text = NotaNum.F($"Q {Q(P(Res)):0.00}"));
+ var types = Chips(TypeNames, i => Sel(Type, 4) == i, i => SetP(Type, i / 3f), Type);
+ var head = HeadRow(Row(6, Caps("TYPE"), types, Seg(Slope, new[] { "12", "24" }), Seg(Circuit, new[] { "Clean", "Analog" })), q);
+
+ var knobs = KnobRow(new[]
+ {
+ K(Freq, "FREQ", v => Hz(HzOf(v))),
+ K(Res, "RESO", Pct),
+ K(Morph, "MORPH", Pct),
+ K(Drive, "DRIVE", v => v <= 0.001 ? "off" : Pct(v)),
+ K(DryWet, "DRY/WET", Pct, Teal),
+ },
+ () =>
+ {
+ if (!Assigned() || !ToFreq()) return NotaNum.F($"cutoff {Hz(BaseHz())} → no modulation");
+ var (lo, hi) = RangeOct();
+ return NotaNum.F($"cutoff {Hz(BaseHz())} → {Hz(Math.Min(18000, BaseHz() * Math.Pow(2, lo)))}…{Hz(Math.Min(18000, BaseHz() * Math.Pow(2, hi)))}");
+ },
+ () => NotaNum.F($"slope {(On(Slope) ? 24 : 12)} dB/oct · Q {Q(P(Res)):0.00}"));
+ return TabBody(head, curve, knobs);
}
- var envAmtRead = new TextBlock { FontSize = 8, Foreground = TealC, VerticalAlignment = VerticalAlignment.Center }; envAmtRead.BindResource(TextBlock.FontFamilyProperty, "Font.Mono");
- readouts.Add(() => envAmtRead.Text = Bip(P(EnvAmt)));
- var envLaneHeader = LaneHeader(EnvOn, "ENV", ToggleChip(EnvHold, _ => "Hold"), envAmtRead);
- var envLaneKnobs = new UniformGrid()
+ // ======================================================================
+ // CENTRE — Envelope
+ // ======================================================================
+ AfEnvView? envView = null;
+ double envWindowMs = 600;
+ int envEvents = 0;
+ double envPeakHz = 0;
+ Control EnvelopeTab()
{
- ColumnSpacing = 6,
- Rows = 1,
- HorizontalAlignment = HorizontalAlignment.Center,
- VerticalAlignment = VerticalAlignment.Center,
- Children =
+ envView = new AfEnvView();
+ envView.StartV = () => P(EnvAmt);
+ envView.DragV += v => Raw(EnvAmt, (float)v);
+ envView.GestureBegin += () => Begin(EnvAmt);
+ envView.GestureEnd += () => End(EnvAmt);
+ ToolTip.SetTip(envView, "The input's envelope (teal) and the cutoff it drives (brass), the base cutoff dashed. Drag up or down for the amount.");
+ Learn(envView, EnvAmt);
+
+ // → Freq / → Reso: the shared Mod Target, as two switches that can both be lit.
+ void PickTarget(int i)
{
- Cell("ATTACK", EnvAtt, AttF),
- Cell("RELEASE", EnvRel, RelF),
- Cell("AMOUNT", EnvAmt, Bip, TealC)
+ bool f = ToFreq(), r = ToRes();
+ if (i == 0) f = !f; else r = !r;
+ if (!f && !r) return; // one of them stays on
+ SetP(ModTarget, f && r ? 1f : r ? 0.5f : 0f);
}
- };
- var envLane = new Grid()
+ var target = Chips(new[] { "→ Freq", "→ Reso" }, i => i == 0 ? ToFreq() : ToRes(), PickTarget, ModTarget);
+ // Up / Down: the sign of the bipolar amount.
+ var dir = Segments(new[] { "Up", "Down" }, () => P(EnvAmt) >= 0.5f ? 0 : 1, iv =>
+ {
+ double mag = Math.Abs(P(EnvAmt) - 0.5);
+ if (mag < 0.004) mag = 0.19;
+ SetP(EnvAmt, (float)(iv == 0 ? 0.5 + mag : 0.5 - mag));
+ RefreshAll();
+ }, out var dirSync, padX: 6);
+ readouts.Add(dirSync);
+ Learn(dir, EnvAmt);
+ var hold = Latch(EnvHold, () => NotaNum.F($"Hold {HoldF(P(EnvHoldTime))}"), "Hold — keep the envelope at its peak for the HOLD time before it releases (∞ freezes it)");
+ var amt = Mono("", 7, AccentBright);
+ readouts.Add(() => { amt.Text = NotaNum.F($"amount {Bip(P(EnvAmt))}"); amt.Foreground = EnvAssigned() ? AccentBright : TextTertiary; });
+ var envSw = Toggle(EnvOn, "ENV");
+ ToolTip.SetTip(envSw, "Envelope follower on / off");
+ var head = HeadRow(Row(6, envSw, target, dir, hold), amt);
+
+ var knobs = KnobRow(new[]
+ {
+ K(EnvAtt, "ATTACK", v => Ms(AttMs(v))),
+ K(EnvRel, "RELEASE", v => Ms(RelMs(v))),
+ K(EnvAmt, "AMOUNT", Bip),
+ K(EnvHoldTime, "HOLD", HoldF, Teal),
+ },
+ () => ToFreq() ? NotaNum.F($"cutoff {Hz(BaseHz())} → {Hz(envPeakHz)}") : NotaNum.F($"reso {Pct(P(Res))} {Bip(P(EnvAmt))}"),
+ () => NotaNum.F($"{envEvents} {(envEvents == 1 ? "event" : "events")} / window · threshold −24 dB"));
+ return TabBody(head, envView, knobs);
+ }
+ void SyncEnvView()
{
- Margin = new Thickness(9, 6),
- Children = { envLaneHeader, envLaneKnobs },
- RowSpacing = 6,
- RowDefinitions = new RowDefinitions("Auto,*"),
- };
- Grid.SetRow(envLane, 0);
- Grid.SetRow(envLaneKnobs, 1);
-
- // ================= LFO LANE HEADER =================
- var lfoLaneHeader = LaneHeader(
- LfoOn,
- "LFO",
- ToggleChip(LfoSync, v => v >= 0.5 ? "Sync" : "Free"),
- ToggleChip(LfoPhase, v => $"{v * 180:0}°", cycle: true));
- var lfoLaneWavePicker = WavePicker();
- var lfoLaneKnobs = new UniformGrid()
+ double span = AttMs(P(EnvAtt)) + RelMs(P(EnvRel)) + (On(EnvHold) && !HoldInf(P(EnvHoldTime)) ? HoldMs(P(EnvHoldTime)) : 0);
+ envWindowMs = EnvWindows[^1];
+ foreach (var wv in EnvWindows) if (wv >= span * 2.5) { envWindowMs = wv; break; }
+ int n = Math.Clamp((int)envWindowMs, 2, kHist);
+ if (scN >= kTele + 2 * kHist)
+ {
+ Array.Copy(scope, kTele + kHist - n, envHist, 0, n);
+ Array.Copy(scope, kTele + 2 * kHist - n, cutHist, 0, n);
+ }
+ else { Array.Clear(envHist); Array.Clear(cutHist); }
+ envEvents = 0; double peak = 0; bool armed = true;
+ for (int i = 0; i < n; i++)
+ {
+ if (armed && envHist[i] >= OnsetLin) { envEvents++; armed = false; }
+ else if (!armed && envHist[i] < OnsetLin / 2) armed = true;
+ peak = Math.Max(peak, cutHist[i]);
+ }
+ envPeakHz = scN >= kTele + 2 * kHist ? HzOf(peak) : BaseHz();
+ envView?.Set(envHist, cutHist, n, P(Freq), NotaNum.F($"base {Hz(BaseHz())}"), envWindowMs, envPeakHz);
+ }
+
+ // ======================================================================
+ // CENTRE — LFO
+ // ======================================================================
+ AfLfoView? lfoView = null;
+ double LfoCycles() => Synced() ? 8.0 / DivBeats[Sel(LfoRate, 8)] : Math.Clamp(LfoHz() * 2, 1, 16);
+ Control LfoTab()
{
- ColumnSpacing = 6,
- Rows = 1,
- HorizontalAlignment = HorizontalAlignment.Center,
- VerticalAlignment = VerticalAlignment.Center,
- Children =
+ lfoView = new AfLfoView();
+ lfoView.StartV = () => P(LfoAmt);
+ lfoView.StartH = () => P(LfoOffset);
+ lfoView.DragV += v => Raw(LfoAmt, (float)v);
+ lfoView.DragH += v => Raw(LfoOffset, (float)v);
+ lfoView.GestureBegin += () => { Begin(LfoAmt); Begin(LfoOffset); };
+ lfoView.GestureEnd += () => { End(LfoAmt); End(LfoOffset); };
+ ToolTip.SetTip(lfoView, "The LFO's movement over the window — raw shape dashed, what the filter follows (after Smooth) in brass, the right channel in rose when stereo is on. Drag up or down for the amount, sideways for the start phase.");
+ Learn(lfoView, LfoAmt);
+
+ var waves = Chips(WaveNames, i => Sel(LfoWave, 5) == i, i => SetP(LfoWave, i / 4f), LfoWave, padX: 6);
+ var rate = Mono("", 7, AccentBright);
+ readouts.Add(() => rate.Text = LfoHzF(LfoHz()));
+ var lfoSw = Toggle(LfoOn, "LFO");
+ ToolTip.SetTip(lfoSw, "LFO on / off");
+ var head = HeadRow(Row(6, lfoSw, waves, Seg(LfoSync, new[] { "Free", "Sync" })), rate);
+
+ var knobs = KnobRow(new[]
{
- Cell("RATE", LfoRate, RateF),
- Cell("AMOUNT", LfoAmt, PctF, TealC),
- Cell("MORPH", LfoMorph, PctF, TealC),
+ K(LfoRate, "RATE", RateF),
+ K(LfoAmt, "AMOUNT", Pct),
+ K(LfoMorph, "MORPH", Pct, Teal),
+ K(LfoOffset, "PHASE", v => Deg(v, 360), Teal),
+ },
+ () =>
+ {
+ if (!ToFreq()) return NotaNum.F($"reso {Pct(P(Res))} ±{Pct(LfoDepth() * 0.5)}");
+ double b = BaseHz(), o = LfoDepth() * 4;
+ return NotaNum.F($"cutoff {Hz(b)} ±{Pct(P(LfoAmt))} · {Hz(b * Math.Pow(2, -o))}…{Hz(Math.Min(18000, b * Math.Pow(2, o)))}");
+ },
+ () => Synced() ? NotaNum.F($"{DivNames[Sel(LfoRate, 8)]} at {Bpm():0} BPM = {LfoHzF(LfoHz())}") : NotaNum.F($"free · period {Ms(1000 / LfoHz())}"));
+ return TabBody(head, lfoView, knobs);
+ }
+ void SyncLfoView()
+ {
+ if (lfoView is null) return;
+ double cycles = LfoCycles();
+ double hz = LfoHz();
+ double smoothCycles = SmoothMs(P(ModSmooth)) / 1000.0 * hz;
+ string mid, end;
+ if (Synced()) { mid = "2"; end = "bar"; }
+ else { double sec = cycles / hz; mid = NotaNum.Time(sec / 2); end = NotaNum.Time(sec); }
+ string title = "LFO → " + (Target() switch { 0 => "Freq", 1 => "Reso", _ => "Freq + Reso" });
+ double phase = scN > S_LfoPhase && On(LfoOn) && Sc(S_Cpu) > 0 ? Sc(S_LfoPhase) : double.NaN;
+ lfoView.Set(On(LfoOn), Sel(LfoWave, 5), P(LfoMorph), P(LfoAmt), P(LfoOffset), P(LfoPhase) * 0.5, smoothCycles, cycles, phase,
+ title, NotaNum.F($"±{Pct(P(LfoAmt))}"), P(LfoMorph) > 0.004 ? NotaNum.F($"morph {Pct(P(LfoMorph))}") : "", mid, end);
+ }
+
+ // ======================================================================
+ // RIGHT — Mod / Output
+ // ======================================================================
+ int centreTab = 0;
+
+ // Sidechain key: the switch picks a source (a flyout with the tracks and the key gain).
+ string SrcName(int id)
+ {
+ for (int i = 0; i < engine.TrackCount; i++)
+ if (engine.TryGetTrackInfo(i, out var ti) && ti.Id == id)
+ { string n = engine.GetTrackName(id); return n.Length > 0 ? n : NotaNum.F($"Track {i + 1}"); }
+ return "—";
+ }
+ Control SidechainSwitch()
+ {
+ Border? host = null;
+ void ShowPicker()
+ {
+ var list = new StackPanel { Spacing = 1 };
+ var fly = new Flyout();
+ void Item(string name, int id)
+ {
+ bool cur = engine.DeviceSidechainSource(track, di) == id;
+ var tb = new TextBlock { Text = name, FontSize = 10, Foreground = cur ? AccentBright : TextPrimary, FontWeight = cur ? FontWeight.SemiBold : FontWeight.Normal };
+ var b = new Border { Padding = new Thickness(8, 3), CornerRadius = NotaRadius.Badge, Background = cur ? NotaPalette.AccentSubtle : Brushes.Transparent, Cursor = new Cursor(StandardCursorType.Hand), Child = tb };
+ b.PointerPressed += (_, e) => { engine.SetDeviceSidechainSource(track, di, id); ctx.NotifyChanged(); RefreshAll(); fly.Hide(); e.Handled = true; };
+ list.Children.Add(b);
+ }
+ Item("None — this track's input", -1);
+ for (int i = 0; i < engine.TrackCount; i++)
+ if (engine.TryGetTrackInfo(i, out var ti) && ti.Id != track) Item(SrcName(ti.Id), ti.Id);
+ var gain = DeviceCardKit.SliderRow("KEY GAIN", () => (engine.DeviceSidechainGain(track, di) + 24) / 48.0,
+ v => engine.SetDeviceSidechainGain(track, di, (float)(v * 48 - 24)),
+ () => NotaNum.F($"{engine.DeviceSidechainGain(track, di):+0.0;−0.0;0.0} dB"), out _, bipolar: true,
+ reset: () => engine.SetDeviceSidechainGain(track, di, 0), valueWidth: 46);
+ fly.Content = new StackPanel { Width = 200, Spacing = 6, Children = { Caps("SIDECHAIN KEY — ENVELOPE SOURCE", null, 8), list, new Border { Height = 1, Background = BorderDef }, gain } };
+ fly.ShowAt(host!);
}
- };
- var lfoLane = new Grid()
+ var sw = Switch("", () => engine.DeviceSidechainSource(track, di) >= 0, () =>
+ {
+ if (engine.DeviceSidechainSource(track, di) >= 0) { engine.SetDeviceSidechainSource(track, di, -1); ctx.NotifyChanged(); RefreshAll(); }
+ else ShowPicker();
+ }, out var sync, liveLabel: () =>
+ {
+ int src = engine.DeviceSidechainSource(track, di);
+ return src >= 0 ? "Key: " + SrcName(src) : "Sidechain key";
+ });
+ host = sw;
+ readouts.Add(sync);
+ // a right-click (or a click on the name while on) re-opens the picker
+ sw.PointerReleased += (_, e) => { if (e.InitialPressMouseButton == MouseButton.Right) { ShowPicker(); e.Handled = true; } };
+ ToolTip.SetTip(sw, "Sidechain key — the envelope follows another track instead of this one. Switch on to pick the source and the key gain; right-click to change it.");
+ return sw;
+ }
+
+ Control ModTab()
{
- Margin = new Thickness(9, 6),
- RowDefinitions = new RowDefinitions("Auto, Auto, *"),
- RowSpacing = 6,
- Children = { lfoLaneHeader, lfoLaneWavePicker, lfoLaneKnobs }
- };
- Grid.SetRow(lfoLaneHeader, 0);
- Grid.SetRow(lfoLaneWavePicker, 1);
- Grid.SetRow(lfoLaneKnobs, 2);
-
- var modCol = new Border { Background = RailBg, BorderBrush = RowLit, BorderThickness = new Thickness(1, 0, 1, 0), Child =
- new Grid { RowDefinitions = new RowDefinitions("Auto,Auto,*"), Children = {
- envLane,
- new Border { Height = 1, Background = RowLit, [Grid.RowProperty] = 1 },
- new Border { Child = lfoLane, [Grid.RowProperty] = 2 } } } };
-
- // ================= output rail + sidechain =================
- var driveCell = Cell("DRIVE", Drive, PctF);
- var dryWetCell = Cell("DRY/WET", DryWet, PctF, TealC);
- var outRailKnobs = new StackPanel()
+ var target = Chips(new[] { "Freq", "Reso", "Both" }, i => Target() == i, i => SetP(ModTarget, i / 2f), ModTarget, h: 15, padX: 6);
+ var tRow = new Grid { ColumnDefinitions = new ColumnDefinitions("40,*") };
+ tRow.Children.Add(Caps("TARGET")); tRow.Children.Add(Col(target, 1));
+
+ var env = SliderRow("ENV", EnvAmt, Bip, bipolar: true, dim: () => !On(EnvOn));
+ var lfo = SliderRow("LFO", LfoAmt, Pct, modulation: true, dim: () => !On(LfoOn));
+ var gain = SliderRow("GAIN", Gain, GainF, bipolar: true);
+ var smooth = SliderRow("SMOOTH", ModSmooth, SmoothF);
+ var ctxHost = new ContentControl();
+ readouts.Add(() => { Control want = centreTab == 0 ? gain : smooth; if (!ReferenceEquals(ctxHost.Content, want)) ctxHost.Content = want; });
+ var ctxRow = new Border { BorderBrush = NotaPalette.GraphBorder, BorderThickness = new Thickness(0, 1, 0, 0), Padding = new Thickness(0, 5, 0, 0), Child = ctxHost };
+
+ // The cutoff, live: Hz · note · cents, and where the movement comes from.
+ var boxTitle = Caps("CUTOFF");
+ var boxHz = Mono("", 9, AccentBright);
+ var boxSub = Mono("", 8, TextSecondary);
+ var box = new Border
+ {
+ Background = Sunken, BorderThickness = new Thickness(1), CornerRadius = NotaRadius.Badge, Padding = new Thickness(6, 4),
+ Child = new StackPanel { Spacing = 2, Children = { boxTitle, boxHz, boxSub } },
+ };
+ readouts.Add(() =>
+ {
+ double live = LiveHz();
+ bool moving = Assigned() && Math.Abs(NormOf(live) - P(Freq)) > 0.01;
+ boxHz.Text = NotaNum.F($"{HzLong(live)} · {NoteOf(live)}");
+ box.BorderBrush = moving ? NotaPalette.BorderBrass : NotaPalette.GraphBorder;
+ boxTitle.Foreground = moving ? AccentBright : TextTertiary;
+ if (!Assigned()) boxSub.Text = "no modulation assigned";
+ else
+ {
+ var parts = new List<string> { NotaNum.F($"base {Hz(BaseHz())}") };
+ if (EnvAssigned()) parts.Add(NotaNum.F($"{Bip(P(EnvAmt))} ENV"));
+ if (LfoAssigned()) parts.Add(NotaNum.F($"±{Pct(P(LfoAmt))} LFO"));
+ boxSub.Text = string.Join(" · ", parts);
+ }
+ });
+
+ // Two switches that follow the centre tab.
+ var sc = SidechainSwitch();
+ var analog = Toggle(Circuit, "Analog model");
+ var envIn = Toggle(EnvOn, "Envelope on input", live: () => engine.DeviceSidechainSource(track, di) >= 0 ? "Envelope on key" : "Envelope on input");
+ var lfoOnSw = Toggle(LfoOn, "LFO on");
+ var retrig = Toggle(LfoRetrig, "Retrig on onsets");
+ var sw1 = new ContentControl();
+ var sw2 = new ContentControl();
+ readouts.Add(() =>
+ {
+ (Control a, Control b) = centreTab switch { 1 => (envIn, sc), 2 => (lfoOnSw, retrig), _ => (sc, analog) };
+ if (!ReferenceEquals(sw1.Content, a)) { sw1.Content = null; sw2.Content = null; sw1.Content = a; sw2.Content = b; }
+ });
+
+ var grid = new Grid { RowDefinitions = new RowDefinitions("Auto,*,Auto,*,Auto,*,Auto,*,Auto,*,Auto,5,Auto") };
+ grid.Children.Add(GRow(tRow, 0));
+ grid.Children.Add(GRow(env, 2));
+ grid.Children.Add(GRow(lfo, 4));
+ grid.Children.Add(GRow(ctxRow, 6));
+ grid.Children.Add(GRow(box, 8));
+ grid.Children.Add(GRow(sw1, 10));
+ grid.Children.Add(GRow(sw2, 12));
+ return new Border { Padding = new Thickness(8, 6), Child = grid };
+ }
+
+ Control OutputTab()
{
- Orientation = Orientation.Horizontal,
- Children = { driveCell, dryWetCell },
- Spacing = 3,
- HorizontalAlignment = HorizontalAlignment.Center,
- VerticalAlignment = VerticalAlignment.Center,
- };
- var gainGrid = new Grid
+ Control Line(string k, Func<string> v, IBrush? ink = null)
+ {
+ var val = Mono("", 8, ink ?? TextPrimary); val.HorizontalAlignment = HorizontalAlignment.Right;
+ readouts.Add(() => val.Text = v());
+ var g = new Grid { ColumnDefinitions = new ColumnDefinitions("*,Auto") };
+ g.Children.Add(new TextBlock { Text = k, FontSize = 8, Foreground = TextSecondary, VerticalAlignment = VerticalAlignment.Center });
+ g.Children.Add(Col(val, 1));
+ return g;
+ }
+ var box = new Border
+ {
+ Background = Sunken, BorderBrush = NotaPalette.GraphBorder, BorderThickness = new Thickness(1), CornerRadius = NotaRadius.Badge, Padding = new Thickness(6, 4),
+ Child = new StackPanel { Spacing = 2, Children = {
+ Caps("OUTPUT"),
+ Line("in", () => DbF(Sc(S_InPk))),
+ Line("out", () => DbF(Sc(S_OutPk))),
+ Line("cutoff", () => HzLong(LiveHz()), AccentBright) } },
+ };
+ var sliders = new StackPanel { Spacing = 6, Children = {
+ SliderRow("DRIVE", Drive, v => v <= 0.001 ? "off" : Pct(v)),
+ SliderRow("DRY/WET", DryWet, Pct),
+ SliderRow("GAIN", Gain, GainF, bipolar: true) } };
+ var btns = new Grid { ColumnDefinitions = new ColumnDefinitions("*,*"), ColumnSpacing = 6 };
+ btns.Children.Add(Latch(LfoRetrig, () => "Retrig", "Retrig — restart the LFO on each input onset (−24 dBFS) and when play starts", fill: true));
+ btns.Children.Add(Col(Latch(Circuit, () => "Analog", "Analog — a gentle saturation after the filter, like an analog circuit", fill: true), 1));
+ var tempo = Toggle(LfoSync, "Tempo sync");
+ // Stereo phase: on sets 90°, a click on the value steps 45° → 180°.
+ var stereo = Switch("", () => P(LfoPhase) > 0.001f, () => SetP(LfoPhase, P(LfoPhase) > 0.001f ? 0f : 0.5f), out var stSync,
+ liveLabel: () => P(LfoPhase) > 0.001f ? NotaNum.F($"Stereo phase {P(LfoPhase) * 180:0}°") : "Stereo phase");
+ readouts.Add(stSync);
+ Learn(stereo, LfoPhase);
+ stereo.PointerReleased += (_, e) =>
+ {
+ if (e.InitialPressMouseButton != MouseButton.Right || P(LfoPhase) <= 0.001f) return;
+ float nx = P(LfoPhase) + 0.25f; if (nx > 1.001f) nx = 0.25f;
+ SetP(LfoPhase, nx); RefreshAll(); e.Handled = true;
+ };
+ ToolTip.SetTip(stereo, "Stereo phase — the right channel's LFO runs ahead of the left (90° when switched on; right-click steps 45° … 180°)");
+
+ var body = new DockPanel { LastChildFill = false, Children = {
+ Docked(box, Dock.Top),
+ Docked(new Border { Margin = new Thickness(0, 7, 0, 0), Child = sliders }, Dock.Top),
+ Docked(new StackPanel { Spacing = 5, Children = { tempo, stereo } }, Dock.Bottom),
+ Docked(new Border { BorderBrush = NotaPalette.GraphBorder, BorderThickness = new Thickness(0, 1, 0, 0), Padding = new Thickness(0, 5, 0, 5), Child = btns }, Dock.Bottom) } };
+ return new Border { Padding = new Thickness(8, 6), Child = body };
+ }
+
+ // ======================================================================
+ // Tab frames
+ // ======================================================================
+ var centreHost = new ContentControl();
+ var rightHost = new ContentControl();
+ var centreBodies = new Control?[3];
+ var rightBodies = new Control?[2];
+ var extras = Mono("", 7, TextTertiary);
+ readouts.Add(() =>
{
- ColumnDefinitions = new ColumnDefinitions("Auto,*"), ColumnSpacing = 5,
- Children =
+ extras.Text = centreTab switch
{
- Cap("GAIN"),
- WithCol(HSlider(Gain, "", GainF, 0, 30), 1)
- },
- Margin = new Thickness(0,0,0,6)
- };
- var sideChainGrid = BuildSidechain(engine, track, di, Cap, MutedC);
-
- var outRail = new Grid()
+ 1 => NotaNum.F($"window {(envWindowMs >= 1000 ? NotaNum.F($"{envWindowMs / 1000:0.#} s") : NotaNum.F($"{envWindowMs:0} ms"))} · {TypeNames[Sel(Type, 4)]} {(On(Slope) ? 24 : 12)}"),
+ 2 => Synced() ? NotaNum.F($"2 bars · sync {DivNames[Sel(LfoRate, 8)]} · phase {Deg(P(LfoOffset), 360)}")
+ : NotaNum.F($"free {LfoHzF(LfoHz())} · phase {Deg(P(LfoOffset), 360)}"),
+ _ => NotaNum.F($"{TypeNames[Sel(Type, 4)]} · {(On(Slope) ? 24 : 12)} dB/oct · {(On(Circuit) ? "analog" : "clean")}"),
+ };
+ });
+ Control CentreBody(int t) => centreBodies[t] ??= t switch { 1 => EnvelopeTab(), 2 => LfoTab(), _ => FilterTab() };
+ Control RightBody(int t) => rightBodies[t] ??= t == 1 ? OutputTab() : ModTab();
+
+ var centre = TabFrame(new[] { "Filter", "Envelope", "LFO" }, centreHost, CentreBody, false, t => { centreTab = t; Refresh(); }, extras);
+ var rightFrame = TabFrame(new[] { "Mod", "Output" }, rightHost, RightBody, true, _ => RefreshAll(), null);
+ var right = new Border { Width = 186, Background = Card2, BorderBrush = BorderDef, BorderThickness = new Thickness(1), CornerRadius = NotaRadius.Tile, ClipToBounds = true, Child = rightFrame };
+ DockPanel.SetDock(right, Dock.Right);
+ var centreBox = new Border { Background = Card2, BorderBrush = BorderDef, BorderThickness = new Thickness(1), CornerRadius = NotaRadius.Tile, Margin = new Thickness(5, 0), ClipToBounds = true, Child = centre };
+
+ // ======================================================================
+ // Status strip
+ // ======================================================================
+ var statusLeft = new TextBlock { FontSize = 8, Foreground = TextSecondary, VerticalAlignment = VerticalAlignment.Center, TextTrimming = TextTrimming.CharacterEllipsis };
+ var statusRight = Mono("", 8, TextSecondary);
+ string StatusText()
{
- Margin = new Thickness(7, 6),
- RowDefinitions = new RowDefinitions("*,Auto,Auto"),
- Children =
+ string filter = NotaNum.F($"{TypeNames[Sel(Type, 4)]} {(On(Slope) ? 24 : 12)} dB/oct");
+ string baseHz = NotaNum.F($"base {Hz(BaseHz())}");
+ string env = EnvAssigned()
+ ? NotaNum.F($"ENV → {TargetName()} {Bip(P(EnvAmt))} · {Ms(AttMs(P(EnvAtt)))} / {Ms(RelMs(P(EnvRel)))}{(On(EnvHold) ? " · hold " + HoldF(P(EnvHoldTime)) : "")}")
+ : "";
+ string lfo = LfoAssigned()
+ ? NotaNum.F($"LFO {WaveNames[Sel(LfoWave, 5)]} · {(Synced() ? DivNames[Sel(LfoRate, 8)] + " sync" : LfoHzF(LfoHz()))} · amount {Pct(P(LfoAmt))}{(P(LfoMorph) > 0.004f ? " · morph " + Pct(P(LfoMorph)) : "")}")
+ : "";
+ var parts = new List<string>();
+ switch (centreTab)
{
- outRailKnobs,
- gainGrid,
- sideChainGrid,
+ case 1: parts.Add(filter); parts.Add(baseHz); parts.Add(env.Length > 0 ? env : "envelope not assigned"); break;
+ case 2: parts.Add(lfo.Length > 0 ? lfo : "LFO not assigned"); parts.Add(NotaNum.F($"cutoff {HzLong(LiveHz())}")); if (P(Drive) > 0.004f) parts.Add(NotaNum.F($"drive {Pct(P(Drive))}")); break;
+ default:
+ parts.Add(filter); parts.Add(baseHz); parts.Add(NotaNum.F($"Q {Q(P(Res)):0.00}"));
+ if (env.Length > 0) parts.Add(NotaNum.F($"ENV {Bip(P(EnvAmt))}"));
+ if (lfo.Length > 0) parts.Add(NotaNum.F($"LFO {Pct(P(LfoAmt))}"));
+ parts.Add(NotaNum.F($"mix {Pct(P(DryWet))}"));
+ break;
}
- };
- Grid.SetRow(outRailKnobs, 0);
- Grid.SetRow(gainGrid, 1);
- Grid.SetRow(sideChainGrid, 2);
-
- // ================= assemble =================
- DockPanel.SetDock(outRail, Dock.Right);
- DockPanel.SetDock(modCol, Dock.Right);
- var body = new DockPanel
- {
- LastChildFill = true,
- Children = { outRail, modCol, graph }
- };
- DockPanel.SetDock(live, Dock.Top);
- var root = new DockPanel
+ if (engine.DeviceSidechainSource(track, di) >= 0) parts.Add("key: " + SrcName(engine.DeviceSidechainSource(track, di)));
+ return string.Join(" · ", parts);
+ }
+ readouts.Add(() =>
{
- LastChildFill = true,
- Background = NotaPalette.BgApp,
- Children = { live, body }
- };
-
- void RefreshAll() { foreach (var a in readouts) a(); }
- SyncCurve();
- ctx.AddDeviceRefresher(() => { SyncCurve(); RefreshAll(); });
- RefreshAll();
+ statusLeft.Text = StatusText();
+ double sr = Sc(S_SampleRate);
+ statusRight.Text = sr > 0 ? NotaNum.F($"{sr / 1000:0.#} kHz · latency 0 smp · CPU {Sc(S_Cpu) * 100:0.0} %") : "";
+ });
+ var statusGrid = new Grid { ColumnDefinitions = new ColumnDefinitions("*,Auto"), ColumnSpacing = 8 };
+ statusGrid.Children.Add(statusLeft);
+ statusGrid.Children.Add(Col(statusRight, 1));
+ var status = new Border { Height = 18, Background = Sunken, BorderBrush = BorderDef, BorderThickness = new Thickness(0, 1, 0, 0), Padding = new Thickness(8, 0), Child = statusGrid };
+ DockPanel.SetDock(status, Dock.Bottom);
+
+ // ---- assemble ---------------------------------------------------------------
+ var bodyRow = new DockPanel { LastChildFill = true, Margin = new Thickness(5), Children = { shapeCol, right, centreBox } };
+ var root = new DockPanel { LastChildFill = true, Background = NotaPalette.SurfaceInset, Children = { status, bodyRow } };
+
+ void Refresh()
+ {
+ scN = engine.DeviceScope(track, di, scope, kScope);
+ if (centreTab == 0 && curve is not null)
+ {
+ if (!curve.Dragging) curve.Set(P(Freq), P(Res), Sel(Type, 4), P(Morph), On(Slope));
+ var (lo, hi) = RangeOct();
+ double b = P(Freq), oct = Math.Log2(18000.0 / 30.0);
+ curve.SetLive(scN > S_Cut ? Sc(S_Cut) : b, scN > S_Res ? Sc(S_Res) : P(Res), b + lo / oct, b + hi / oct, Assigned() && ToFreq());
+ curve.FeedSpectrum(scope, kTele + 2 * kHist, scN - (kTele + 2 * kHist), Sc(S_SampleRate));
+ }
+ if (centreTab == 1) SyncEnvView();
+ if (centreTab == 2) SyncLfoView();
+ RefreshAll();
+ }
+ ctx.AddDeviceRefresher(Refresh);
+ Refresh();
return root;
- }
- private static Control WithDock(Control c, Dock d) { DockPanel.SetDock(c, d); return c; }
- private static Control WithCol(Control c, int col) { Grid.SetColumn(c, col); return c; }
-
- // Compact sidechain block for the output rail: switch + source + gain slider.
- private Control BuildSidechain(IAudioEngine engine, int track, int di, Func<string, IBrush?, Control> Cap, IBrush muted)
- {
- var ids = new List<int> { -1 };
- var combo = new ComboBox { HorizontalAlignment = HorizontalAlignment.Stretch, FontSize = 9, Height = 22, Padding = new Thickness(5, 0) };
- combo.Items.Add("None");
- for (int i = 0; i < engine.TrackCount; i++)
+ // local: a tab frame (bar + swapping body), optional extras on the right of the bar.
+ Control TabFrame(string[] tabs, ContentControl host, Func<int, Control> body, bool centered, Action<int>? changed, Control? extrasCtl)
{
- if (!engine.TryGetTrackInfo(i, out var ti) || ti.Id == track) continue;
- string kind = ti.IsReturn ? "Return" : ti.IsInstrument ? "Inst" : "Audio";
- ids.Add(ti.Id); combo.Items.Add($"{i + 1} · {kind}");
+ int sel = 0;
+ var btns = new Border[tabs.Length];
+ void Hi()
+ {
+ for (int i = 0; i < tabs.Length; i++)
+ {
+ bool on = i == sel;
+ btns[i].Background = on ? Card2 : Brushes.Transparent;
+ btns[i].BorderBrush = on ? Brass : Brushes.Transparent;
+ var tb = (TextBlock)btns[i].Child!;
+ tb.Foreground = on ? AccentBright : TextTertiary;
+ tb.FontWeight = on ? FontWeight.SemiBold : FontWeight.Normal;
+ }
+ }
+ var bar = centered ? (Avalonia.Controls.Panel)new UniformGrid { Rows = 1 } : new StackPanel { Orientation = Orientation.Horizontal };
+ for (int i = 0; i < tabs.Length; i++)
+ {
+ int iv = i;
+ var b = new Border
+ {
+ Padding = new Thickness(9, 0), BorderThickness = new Thickness(0, 0, 0, 2), BorderBrush = Brushes.Transparent, Cursor = new Cursor(StandardCursorType.Hand),
+ Child = new TextBlock { Text = tabs[i], FontSize = 9, Foreground = TextTertiary, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center },
+ };
+ b.PointerPressed += (_, _) => { sel = iv; Hi(); host.Content = body(iv); changed?.Invoke(iv); };
+ btns[i] = b;
+ bar.Children.Add(b);
+ }
+ var barDock = new DockPanel { Height = 20, LastChildFill = centered };
+ if (extrasCtl != null) { var ex = new Border { Padding = new Thickness(0, 0, 8, 0), Child = extrasCtl }; DockPanel.SetDock(ex, Dock.Right); barDock.Children.Add(ex); }
+ if (!centered) DockPanel.SetDock(bar, Dock.Left);
+ barDock.Children.Add(bar);
+ var barBorder = new Border { BorderBrush = BorderDef, BorderThickness = new Thickness(0, 0, 0, 1), Child = barDock };
+ DockPanel.SetDock(barBorder, Dock.Top);
+ Hi();
+ host.Content = body(sel);
+ return new DockPanel { LastChildFill = true, Children = { barBorder, host } };
}
- int src0 = engine.DeviceSidechainSource(track, di);
- combo.SelectedIndex = Math.Max(0, ids.IndexOf(src0));
- var sw = new ToggleSwitch(src0 >= 0);
-
- // Sidechain gain slider (dB, ±24, bipolar).
- var gVal = new TextBlock { Text = $"{engine.DeviceSidechainGain(track, di):0.0}", FontSize = 9, Foreground = TxtC, VerticalAlignment = VerticalAlignment.Center, TextAlignment = TextAlignment.Right, Width = 28 };
- gVal.BindResource(TextBlock.FontFamilyProperty, "Font.Mono");
- var gFill = new Border { Height = 3, Background = NotaPalette.BorderStrong, CornerRadius = NotaRadius.Clip, HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Center };
- var gTrack = new Border { Height = 3, Background = Inset, CornerRadius = NotaRadius.Clip, VerticalAlignment = VerticalAlignment.Center };
- var gHandle = new Border { Width = 8, Height = 9, Background = NotaPalette.TextSecondary, CornerRadius = NotaRadius.Clip, HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Center };
- var gSlot = new Panel { Height = 10, MinWidth = 34, Children = { gTrack, gFill, gHandle } };
- void GUpd() { double db = engine.DeviceSidechainGain(track, di); double v = Math.Clamp((db + 24) / 48.0, 0, 1); double W = gSlot.Bounds.Width; gHandle.Margin = new Thickness(Math.Clamp(v * W - 4, 0, Math.Max(0, W - 8)), 0, 0, 0); gFill.Width = v * W; gVal.Text = $"{db:0.0}"; }
- bool gd = false;
- void GSet(double x) { double v = Math.Clamp(x / Math.Max(1, gSlot.Bounds.Width), 0, 1); engine.SetDeviceSidechainGain(track, di, (float)(v * 48 - 24)); GUpd(); }
- gSlot.PointerPressed += (_, e) => { gd = true; e.Pointer.Capture(gSlot); GSet(e.GetPosition(gSlot).X); };
- gSlot.PointerMoved += (_, e) => { if (gd) GSet(e.GetPosition(gSlot).X); };
- gSlot.PointerReleased += (_, e) => { if (gd) { gd = false; e.Pointer.Capture(null); } };
-
- var body = new StackPanel { Spacing = 4, Children = {
- combo,
- new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,*,Auto"), ColumnSpacing = 4, Children = { Cap("GAIN", muted), WithCol(gSlot, 1), WithCol(gVal, 2) } } } };
-
- void Reflect(int src) { bool on = src >= 0; Inactive.Set(body, !on, interactive: true); if (sw.IsOn != on) sw.IsOn = on; }
- combo.SelectionChanged += (_, _) => { int sel = combo.SelectedIndex; if (sel < 0 || sel >= ids.Count) return; engine.SetDeviceSidechainSource(track, di, ids[sel]); Reflect(ids[sel]); };
- sw.Changed += on => { int src = on ? (ids.Count > 1 ? ids[1] : -1) : -1; engine.SetDeviceSidechainSource(track, di, src); combo.SelectedIndex = Math.Max(0, ids.IndexOf(src)); Reflect(src); };
- Avalonia.Threading.Dispatcher.UIThread.Post(GUpd);
-
- var hdr = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 5, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(0, 6, 0, 4), Children = { sw, Cap("SIDECHAIN", muted) } };
- return new StackPanel { Children = { new Border { Height = 1, Background = RowLit }, hdr, body } };
}
}
-
-// DockPanel dock helper that also adds the child to the panel (top-docked lane headers).
-internal static class DockExt
-{
- public static void SetDock2(this DockPanel dp, Control child, Dock dock) { DockPanel.SetDock(child, dock); dp.Children.Add(child); }
-}
diff --git a/src/managed/Nota.Infrastructure/Persistence/FactoryPresetCatalog.cs b/src/managed/Nota.Infrastructure/Persistence/FactoryPresetCatalog.cs
index 920e49e4..9c31a17b 100644
--- a/src/managed/Nota.Infrastructure/Persistence/FactoryPresetCatalog.cs
+++ b/src/managed/Nota.Infrastructure/Persistence/FactoryPresetCatalog.cs
@@ -1210,14 +1210,46 @@ public sealed class FactoryPresetCatalog : IFactoryPresets
Fx("amp", 6, "Heavy Chug", ("Model", 5f), ("Gain", 8.0f), ("Bass", 7f), ("Middle", 3.5f), ("Treble", 6f), ("Presence", 7f), ("Output", 4f), ("Mix", 1f), ("Cabinet", 3f), ("Gate", 0.4f), ("Axis", 0.3f));
Fx("amp", 6, "Bass Amp", ("Model", 6f), ("Gain", 3.0f), ("Bass", 7f), ("Middle", 5f), ("Treble", 4f), ("Presence", 3f), ("Output", 5f), ("Mix", 1f), ("Cabinet", 4f));
- // ---- Auto Filter (kind 7) — all params normalized 0..1. Type 0 LP/.33 BP/.67 HP/
- // 1 Notch; Slope 0=12dB/1=24dB; Env Amt 0.5=0 (bipolar); LFO Wave 0..1 in .25 steps.
- Fx("autofilter", 7, "Envelope Wah", ("Type", 0f), ("Freq", 0.32f), ("Res", 0.55f), ("Env Amt", 0.85f), ("Env Attack", 0.08f), ("Env Release", 0.40f), ("Drive", 0.18f), ("Dry/Wet", 1f));
- Fx("autofilter", 7, "Slow LFO Sweep", ("Type", 0f), ("Freq", 0.48f), ("Res", 0.35f), ("Env Amt", 0.5f), ("LFO Amt", 0.7f), ("LFO Rate", 0.22f), ("LFO Wave", 0f), ("Dry/Wet", 1f));
- Fx("autofilter", 7, "24 dB Low Cut", ("Type", 0.667f),("Slope", 1f), ("Freq", 0.22f), ("Res", 0.12f), ("Env Amt", 0.5f), ("Dry/Wet", 1f));
- Fx("autofilter", 7, "Sidechain Duck", ("Type", 0f), ("Freq", 0.72f), ("Res", 0.20f), ("Env Amt", 0.14f), ("Env Attack", 0.05f), ("Env Release", 0.45f), ("Dry/Wet", 1f));
- Fx("autofilter", 7, "S&H Random", ("Type", 0f), ("Freq", 0.50f), ("Res", 0.42f), ("LFO Amt", 0.62f), ("LFO Rate", 0.42f), ("LFO Wave", 1f), ("Dry/Wet", 1f));
- Fx("autofilter", 7, "Notch Motion", ("Type", 1f), ("Freq", 0.55f), ("Res", 0.30f), ("Morph", 0.4f), ("LFO Amt", 0.5f), ("LFO Rate", 0.3f), ("LFO Wave", 1f), ("Dry/Wet", 1f));
+ // ---- Auto Filter (kind 7) — all params normalized 0..1. Freq 30·600^v Hz (.55 ≈ 1 k);
+ // Res Q 0.5+14.5v; Type 0 LP/.333 BP/.667 HP/1 Notch; Slope 0=12/1=24 dB; Env Amt
+ // 0.5 = 0 (bipolar); Env Attack 0.1·5000^v ms; Env Release 2000^v ms; Env Hold Time
+ // 400v² ms (1 = ∞); LFO Rate free 0.01·4000^v Hz, Sync round(v·7) → 2/1…1/64 (.429 =
+ // 1/4, .571 = 1/8, .714 = 1/16); LFO Wave .25 steps; Mod Target 0 Freq/.5 Reso/1 Both;
+ // Mod Smooth 120v² ms; LFO Stereo 0.5 = 90°; LFO Offset 0..360°. Unnamed → default.
+ // Sweeps and static tone
+ Fx("autofilter", 7, "Clean Sweep", ("Type", 0f), ("Freq", 0.548f), ("Res", 0.015f), ("Env Amt", 0.5f), ("Dry/Wet", 1f));
+ Fx("autofilter", 7, "24 dB Low Cut", ("Type", 0.667f), ("Slope", 1f), ("Freq", 0.22f), ("Res", 0.12f), ("Env Amt", 0.5f), ("Gain", 0.34f), ("Dry/Wet", 1f));
+ Fx("autofilter", 7, "Telephone", ("Type", 0.333f), ("Slope", 1f), ("Freq", 0.62f), ("Res", 0.18f), ("Drive", 0.35f), ("Circuit", 1f), ("Gain", 0.344f), ("Dry/Wet", 1f));
+ Fx("autofilter", 7, "Warm Analog LP", ("Type", 0f), ("Slope", 1f), ("Freq", 0.70f), ("Res", 0.22f), ("Drive", 0.25f), ("Circuit", 1f), ("Gain", 0.3125f), ("Dry/Wet", 1f));
+ Fx("autofilter", 7, "Resonant Peak", ("Type", 0f), ("Freq", 0.60f), ("Res", 0.72f), ("Circuit", 1f), ("Gain", 0.44f), ("Dry/Wet", 1f));
+ Fx("autofilter", 7, "Notch Carve", ("Type", 1f), ("Freq", 0.55f), ("Res", 0.10f), ("Dry/Wet", 1f));
+ // Envelope — the input plays the filter
+ Fx("autofilter", 7, "Envelope Wah", ("Type", 0f), ("Freq", 0.32f), ("Res", 0.55f), ("Env Amt", 0.85f), ("Env Attack", 0.08f), ("Env Release", 0.40f), ("Drive", 0.18f), ("Gain", 0.4f), ("Dry/Wet", 1f));
+ Fx("autofilter", 7, "Clav Wah", ("Type", 0.333f), ("Slope", 1f), ("Freq", 0.37f), ("Res", 0.44f), ("Env Amt", 0.69f), ("Env Attack", 0.163f), ("Env Release", 0.447f), ("Env Hold", 1f), ("Env Hold Time", 0.173f), ("Mod Smooth", 0.258f), ("Gain", 0.229f), ("Dry/Wet", 1f));
+ Fx("autofilter", 7, "Funk Quack", ("Type", 0.333f), ("Freq", 0.34f), ("Res", 0.62f), ("Env Amt", 0.92f), ("Env Attack", 0.10f), ("Env Release", 0.52f), ("Dry/Wet", 1f));
+ Fx("autofilter", 7, "Bass Auto-Wah", ("Type", 0f), ("Slope", 1f), ("Freq", 0.24f), ("Res", 0.40f), ("Env Amt", 0.80f), ("Env Attack", 0.20f), ("Env Release", 0.58f), ("Drive", 0.20f), ("Circuit", 1f), ("Gain", 0.17f), ("Dry/Wet", 1f));
+ Fx("autofilter", 7, "Reverse Wah", ("Type", 0f), ("Freq", 0.78f), ("Res", 0.38f), ("Env Amt", 0.18f), ("Env Attack", 0.30f), ("Env Release", 0.62f), ("Dry/Wet", 1f));
+ Fx("autofilter", 7, "Drum Snap", ("Type", 0.667f), ("Freq", 0.30f), ("Res", 0.25f), ("Env Amt", 0.82f), ("Env Attack", 0.05f), ("Env Release", 0.35f), ("Dry/Wet", 1f));
+ Fx("autofilter", 7, "Swell Opener", ("Type", 0f), ("Slope", 1f), ("Freq", 0.30f), ("Res", 0.20f), ("Env Amt", 0.90f), ("Env Attack", 0.78f), ("Env Release", 0.85f), ("Mod Smooth", 0.40f), ("Gain", 0.3125f), ("Dry/Wet", 1f));
+ Fx("autofilter", 7, "Resonance Bloom", ("Type", 0f), ("Freq", 0.55f), ("Res", 0.15f), ("Mod Target", 0.5f), ("Env Amt", 0.90f), ("Env Attack", 0.35f), ("Env Release", 0.65f), ("Circuit", 1f), ("Gain", 0.42f), ("Dry/Wet", 1f));
+ Fx("autofilter", 7, "Hold & Release", ("Type", 0f), ("Freq", 0.40f), ("Res", 0.45f), ("Env Amt", 0.80f), ("Env Attack", 0.20f), ("Env Release", 0.70f), ("Env Hold", 1f), ("Env Hold Time", 0.55f), ("Dry/Wet", 1f));
+ // LFO — motion and rhythm
+ Fx("autofilter", 7, "Slow LFO Sweep", ("Type", 0f), ("Freq", 0.48f), ("Res", 0.35f), ("Env Amt", 0.5f), ("LFO Amt", 0.7f), ("LFO Rate", 0.22f), ("LFO Wave", 0f), ("Dry/Wet", 1f));
+ Fx("autofilter", 7, "Pad Motion", ("Type", 0f), ("Freq", 0.64f), ("Res", 0.28f), ("LFO Sync", 1f), ("LFO Rate", 0.429f), ("LFO Amt", 0.32f), ("LFO Wave", 0f), ("LFO Morph", 0.40f), ("Drive", 0.36f), ("LFO Retrig", 1f), ("Gain", 0.39f), ("Dry/Wet", 0.82f));
+ Fx("autofilter", 7, "Wobble 1/8", ("Type", 0f), ("Slope", 1f), ("Freq", 0.35f), ("Res", 0.55f), ("LFO Sync", 1f), ("LFO Rate", 0.571f), ("LFO Amt", 0.60f), ("LFO Wave", 0f), ("Drive", 0.40f), ("Circuit", 1f), ("Gain", 0.125f), ("Dry/Wet", 1f));
+ Fx("autofilter", 7, "Dubstep Wub 1/16",("Type", 0f), ("Slope", 1f), ("Freq", 0.30f), ("Res", 0.62f), ("LFO Sync", 1f), ("LFO Rate", 0.714f), ("LFO Amt", 0.72f), ("LFO Wave", 0.25f), ("Drive", 0.55f), ("Circuit", 1f), ("LFO Retrig", 1f), ("Gain", 0.104f), ("Dry/Wet", 1f));
+ Fx("autofilter", 7, "Trance Gate", ("Type", 0f), ("Slope", 1f), ("Freq", 0.45f), ("Res", 0.20f), ("LFO Sync", 1f), ("LFO Rate", 0.714f), ("LFO Amt", 0.85f), ("LFO Wave", 0.75f), ("LFO Morph", 0.2f), ("Mod Smooth", 0.12f), ("Gain", 0.38f), ("Dry/Wet", 1f));
+ Fx("autofilter", 7, "S&H Random", ("Type", 0f), ("Freq", 0.50f), ("Res", 0.42f), ("LFO Amt", 0.62f), ("LFO Rate", 0.42f), ("LFO Wave", 1f), ("Dry/Wet", 1f));
+ Fx("autofilter", 7, "Glide Random", ("Type", 0.333f), ("Freq", 0.55f), ("Res", 0.40f), ("LFO Sync", 1f), ("LFO Rate", 0.571f), ("LFO Amt", 0.55f), ("LFO Wave", 1f), ("Mod Smooth", 0.45f), ("Dry/Wet", 1f));
+ Fx("autofilter", 7, "Saw Ramp Bar", ("Type", 0f), ("Slope", 1f), ("Freq", 0.45f), ("Res", 0.35f), ("LFO Sync", 1f), ("LFO Rate", 0.143f), ("LFO Amt", 0.55f), ("LFO Wave", 0.5f), ("LFO Retrig", 1f), ("Gain", 0.07f), ("Dry/Wet", 1f));
+ Fx("autofilter", 7, "Stereo Swirl", ("Type", 0.333f), ("Freq", 0.58f), ("Res", 0.35f), ("LFO Amt", 0.45f), ("LFO Rate", 0.42f), ("LFO Wave", 0f), ("LFO Stereo", 1f), ("Dry/Wet", 0.9f));
+ Fx("autofilter", 7, "Notch Motion", ("Type", 1f), ("Freq", 0.55f), ("Res", 0.30f), ("Morph", 0.4f), ("LFO Amt", 0.5f), ("LFO Rate", 0.3f), ("LFO Wave", 1f), ("Dry/Wet", 1f));
+ Fx("autofilter", 7, "Phaser-ish Notch",("Type", 1f), ("Freq", 0.55f), ("Res", 0.25f), ("LFO Amt", 0.55f), ("LFO Rate", 0.33f), ("LFO Wave", 0.25f), ("LFO Stereo", 0.5f), ("Dry/Wet", 0.6f));
+ Fx("autofilter", 7, "Reso Pulse", ("Type", 0f), ("Freq", 0.62f), ("Res", 0.30f), ("Mod Target", 0.5f), ("LFO Sync", 1f), ("LFO Rate", 0.571f), ("LFO Amt", 0.70f), ("LFO Wave", 0.5f), ("Circuit", 1f), ("Dry/Wet", 1f));
+ // Sidechain and combined
+ Fx("autofilter", 7, "Sidechain Duck", ("Type", 0f), ("Freq", 0.72f), ("Res", 0.20f), ("Env Amt", 0.14f), ("Env Attack", 0.05f), ("Env Release", 0.45f), ("Dry/Wet", 1f));
+ Fx("autofilter", 7, "Kick Pump HP", ("Type", 0.667f), ("Slope", 1f), ("Freq", 0.15f), ("Res", 0.15f), ("Env Amt", 0.85f), ("Env Attack", 0.08f), ("Env Release", 0.62f), ("Mod Smooth", 0.2f), ("Gain", 0.38f), ("Dry/Wet", 1f));
+ Fx("autofilter", 7, "Talking Filter", ("Type", 0.333f), ("Slope", 1f), ("Freq", 0.45f), ("Res", 0.55f), ("Mod Target", 1f), ("Env Amt", 0.75f), ("Env Attack", 0.25f), ("Env Release", 0.55f), ("LFO Amt", 0.25f), ("LFO Rate", 0.60f), ("LFO Wave", 0.25f), ("Morph", 0.3f), ("Gain", 0.22f), ("Dry/Wet", 1f));
// ---- Nota Vintage (kind 8) — all params normalized 0..1. Mode 0 Vinyl/.2 Cassette/
// .4 Reel/.6 VHS/.8 Tube/1 Analog; Tone 0.5 = neutral tilt; Output 0.5 = 0 dB.
diff --git a/src/managed/Nota.Mcp/Tools/DeviceTools.cs b/src/managed/Nota.Mcp/Tools/DeviceTools.cs
index 74273fa5..6863bf51 100644
--- a/src/managed/Nota.Mcp/Tools/DeviceTools.cs
+++ b/src/managed/Nota.Mcp/Tools/DeviceTools.cs
@@ -67,10 +67,10 @@ public sealed class DeviceTools(IAudioEngine engine, IEngineDispatch dispatch, I
[McpServerTool(Name = "load_device_file"), Description("Load an audio file into a device that takes one — Nota Chamber: a user impulse response (WAV / FLAC / MP3; mono, stereo or 4-channel true stereo), which also selects it. Returns true on success.")]
public Task<bool> LoadDeviceFile(int trackId, int deviceIndex, [Description("Absolute path to the audio file")] string path) => Mutate(() => E.DeviceLoadFile(trackId, deviceIndex, path));
- [McpServerTool(Name = "get_device_text"), Description("Read a device's resource text. Nota Chamber: id 0 = current IR name, 1 = its category, 2 = the loaded user IR's name, 10 = the built-in IR list (name, category, seconds per line; the IR param selects entry round(v × 16), 1.0 = the user IR). Nota Lens: id 0 = the analysis summary, 1 = the third-octave band table, 2 = the scope measurements, 3 = the strongest spectral peaks, 4 = the A/B cursor measurements — or use read_analyzer, which returns all of it parsed. Delay (kind 3): id 0 = a one-line summary of what it is doing now (sync division or free times, ping-pong, feedback, mix, or that it is frozen). Reverb (kind 2): id 0 = a one-line summary (algorithm, RT60, pre-delay, diffusion, mix, early reflections / vintage, or that the tail is frozen). Compressor (kind 1): id 0 = a one-line summary (character, threshold, ratio, knee, attack / release, detector, range, mix, the reduction right now, external key / unlinked / Listen) — or use read_dynamics for the numbers.")]
+ [McpServerTool(Name = "get_device_text"), Description("Read a device's resource text. Nota Chamber: id 0 = current IR name, 1 = its category, 2 = the loaded user IR's name, 10 = the built-in IR list (name, category, seconds per line; the IR param selects entry round(v × 16), 1.0 = the user IR). Nota Lens: id 0 = the analysis summary, 1 = the third-octave band table, 2 = the scope measurements, 3 = the strongest spectral peaks, 4 = the A/B cursor measurements — or use read_analyzer, which returns all of it parsed. Delay (kind 3): id 0 = a one-line summary of what it is doing now (sync division or free times, ping-pong, feedback, mix, or that it is frozen). Reverb (kind 2): id 0 = a one-line summary (algorithm, RT60, pre-delay, diffusion, mix, early reflections / vintage, or that the tail is frozen). Compressor (kind 1): id 0 = a one-line summary (character, threshold, ratio, knee, attack / release, detector, range, mix, the reduction right now, external key / unlinked / Listen) — or use read_dynamics for the numbers. Auto Filter (kind 7): id 0 = a one-line summary (type, slope, cutoff, Q, what the envelope and LFO drive and by how much, drive, mix, sidechain key), 1 = the live reading (modulated cutoff with its note, resonance, envelope level, LFO value and phase, onsets counted), 2 = a guide to what each 0..1 parameter value means — or use read_filter_motion for the numbers.")]
public Task<string> GetDeviceText(int trackId, int deviceIndex, int id) => Read(() => E.DeviceText(trackId, deviceIndex, id));
- [McpServerTool(Name = "device_action"), Description("Run a device's own command — the few things that are actions rather than parameters. Delay (kind 3): id 0 clears the loop (empties the delay buffer, so whatever is still circulating stops; useful after Freeze). Reverb (kind 2): id 0 kills the tail (empties the reverb's buffers, so whatever is still ringing — or frozen — stops). Devices without a command ignore the call.")]
+ [McpServerTool(Name = "device_action"), Description("Run a device's own command — the few things that are actions rather than parameters. Delay (kind 3): id 0 clears the loop (empties the delay buffer, so whatever is still circulating stops; useful after Freeze). Reverb (kind 2): id 0 kills the tail (empties the reverb's buffers, so whatever is still ringing — or frozen — stops). Auto Filter (kind 7): id 0 restarts the LFO (from its start phase; in Sync the cycle is re-anchored to the current beat), id 1 resets the envelope follower (drops a held peak). Devices without a command ignore the call.")]
public Task DeviceAction(int trackId, int deviceIndex, [Description("Command id — see the device's list in this description")] int id,
int intArg = 0, float floatArg = 0) => Mutate(() => E.DeviceAction(trackId, deviceIndex, id, intArg, floatArg));
@@ -120,6 +120,45 @@ public sealed class DeviceTools(IAudioEngine engine, IEngineDispatch dispatch, I
Db(V(5)), V(12) > 0.5f, Math.Round(V(6), 2), Math.Round(V(7), 1), (int)V(10), V(8), hits, Math.Round(deepest, 1));
});
+ public sealed record FilterMotion(string Summary, string Live, double CutoffHz, double CutoffRightHz, string CutoffNote,
+ double BaseCutoffHz, double Resonance, double EnvelopeDb, bool EnvelopeHeld, double Lfo, double LfoPhaseDeg,
+ double InputPeakDb, double OutputPeakDb, int Onsets, int OnsetsLast2s, double CutoffMinLast2sHz, double CutoffMaxLast2sHz,
+ double SampleRate);
+
+ [McpServerTool(Name = "read_filter_motion"), Description(
+ "Read what a Nota Auto Filter (built-in effect kind 7) is doing right now: the modulated cutoff in Hz (left and "
+ + "right — they differ with LFO Stereo) with its note and cents, the base cutoff the modulation moves from, the "
+ + "live resonance (0..1), the envelope follower level in dBFS and whether Hold has it frozen, the LFO value (−1..1) "
+ + "and phase, the input / output peaks, the onsets counted (input rising through −24 dBFS — what LFO Retrig "
+ + "restarts on) in total and over the last 2 s, the cutoff's range over the last 2 s, and the one-line summary. "
+ + "Values move only while audio plays through the track. Use get_device_text id 2 for what each parameter value means.")]
+ public Task<FilterMotion> ReadFilterMotion(int trackId, int deviceIndex) => Read(() =>
+ {
+ const int tele = 16, hist = 2048;
+ var sc = new float[tele + 2 * hist];
+ int n = E.DeviceScope(trackId, deviceIndex, sc, sc.Length);
+ float V(int i) => n > i ? sc[i] : 0f;
+ static double HzOf(double norm) => Math.Round(30 * Math.Pow(600, Math.Clamp(norm, 0, 1)), 1);
+ static double Db(float lin) => lin > 1e-6f ? Math.Round(20 * Math.Log10(lin), 1) : -120;
+ int recent = 0; bool armed = true; double lo = 1, hi = 0;
+ if (n >= sc.Length)
+ for (int i = 0; i < hist; i++)
+ {
+ float env = sc[tele + i], cut = sc[tele + hist + i];
+ if (armed && env >= 0.063f) { recent++; armed = false; } else if (!armed && env < 0.0316f) armed = true;
+ lo = Math.Min(lo, cut); hi = Math.Max(hi, cut);
+ }
+ if (hi < lo) { lo = hi = V(0); }
+ double hz = HzOf(V(0));
+ double midi = 69 + 12 * Math.Log2(hz / 440.0);
+ int note = (int)Math.Round(midi);
+ string[] names = { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" };
+ string noteName = $"{names[((note % 12) + 12) % 12]}{note / 12 - 1} {(int)Math.Round((midi - note) * 100):+0;-0;0} ct";
+ return new FilterMotion(E.DeviceText(trackId, deviceIndex, 0), E.DeviceText(trackId, deviceIndex, 1), hz, HzOf(V(1)), noteName,
+ HzOf(E.DeviceGetParam(trackId, deviceIndex, 0)), Math.Round(V(2), 3), Db(V(3)), V(12) > 0.5f, Math.Round(V(4), 3),
+ Math.Round(V(5) * 360, 1), Db(V(6)), Db(V(7)), (int)V(11), recent, HzOf(lo), HzOf(hi), V(9));
+ });
+
public sealed record AnalyzerBand(double Hz, double Db);
public sealed record AnalyzerPeak(double Hz, double Db, string Note);
public sealed record AnalyzerReading(string Summary, string Scope, string Cursors, AnalyzerBand[] Bands, AnalyzerPeak[] Peaks);
diff --git a/src/native/nota.engine/src/AutoFilter.h b/src/native/nota.engine/src/AutoFilter.h
index ddd6898d..5b715cff 100644
--- a/src/native/nota.engine/src/AutoFilter.h
+++ b/src/native/nota.engine/src/AutoFilter.h
@@ -2,12 +2,20 @@
// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.
//
// Built-in Auto Filter (device kind 7) — a classic envelope/LFO-driven dynamic
-// filter: a TPT state-variable filter (LP/HP/BP/Notch with a continuous Morph and a
-// 12/24 dB slope) whose cutoff is swept by an envelope follower (attack / release /
-// hold, keyed off this track OR a sidechain source) and an LFO (rate / amount / wave
-// incl. sample-&-hold / morph). A pre-filter Drive stage adds colour; Dry/Wet blends.
+// filter: a TPT state-variable filter (LP/BP/HP/Notch with a continuous Morph and a
+// 12/24 dB slope) whose cutoff — and/or resonance (Mod Target) — is swept by an
+// envelope follower (attack / release / timed or infinite hold, keyed off this track OR
+// a sidechain source) and an LFO (rate free or tempo-synced / amount / wave incl.
+// sample-&-hold / morph / start phase / stereo phase / retrigger). Mod Smooth slews the
+// modulation. A pre-filter Drive stage adds colour; Analog saturates; Dry/Wet blends.
+//
// A core Device (JUCE-free), lock-free params. All params are normalized 0..1 and
-// denormalized in process(); persistence/automation/clone flow generically.
+// denormalized in process(); persistence/automation/clone flow generically. Param order
+// is the persisted layout — APPEND ONLY. process() never allocates.
+//
+// Telemetry for the card and MCP (scopeRead): kTele live values, then the envelope and
+// cutoff histories (1 ms per point, oldest → newest), then the pre-filter mono ring for
+// the spectrum. deviceText: 0 = status line, 1 = live reading, 2 = parameter guide.
#pragma once
@@ -15,8 +23,11 @@
#include <algorithm>
#include <atomic>
+#include <chrono>
#include <cmath>
#include <cstdint>
+#include <cstdio>
+#include <string>
namespace nota {
@@ -28,12 +39,12 @@ public:
Type, // filter type: 0 LP, 1 BP, 2 HP, 3 Notch
Slope, // 0 = 12 dB/oct, 1 = 24 dB/oct
Morph, // blend from Type toward the next type (continuous)
- EnvAmt, // bipolar env→cutoff depth (0.5 = 0, ±6 oct)
+ EnvAmt, // bipolar env depth (0.5 = 0; ±6 oct on Freq, ±80 % on Res)
EnvAtt, // envelope attack (exp 0.1..500 ms)
EnvRel, // envelope release (exp 1..2000 ms)
- EnvHold, // peak-hold toggle (>=0.5)
- LfoAmt, // LFO→cutoff depth (0..4 oct)
- LfoRate, // LFO rate (exp 0.01..40 Hz)
+ EnvHold, // peak hold on/off (>=0.5); how long = EnvHoldTime
+ LfoAmt, // LFO depth (0..4 oct on Freq, ±50 % on Res)
+ LfoRate, // LFO rate (exp 0.01..40 Hz; in Sync picks a division)
LfoWave, // 0 Sine, 1 Tri, 2 Saw, 3 Square, 4 S&H (random)
LfoMorph, // LFO shape skew / pulse-width (0..1)
Drive, // pre-filter drive (0..1)
@@ -44,8 +55,41 @@ public:
Circuit, // 0 = Clean, 1 = Analog (mild saturation)
LfoSync, // 0 = Free (Hz), 1 = tempo-synced (Rate selects a division)
LfoPhase, // stereo LFO phase offset for the right channel (0..180°)
+ // ---- appended for the almanac redesign — keep the order, append only ----
+ ModTarget, // what ENV + LFO move: 0 Freq, 0.5 Reso, 1 Both
+ EnvHoldTime,// hold length when Hold is on: 400·v² ms; the top (≥ 0.995) = ∞ (freeze)
+ ModSmooth, // slew on the modulation: 120·v² ms (0 = none)
+ LfoOffset, // LFO start phase (0..360°)
+ LfoRetrig, // restart the LFO on each input onset and at play (>=0.5)
kNumParams
};
+ // Scope telemetry layout (read by the card and MCP).
+ enum {
+ S_Cut = 0, // live modulated cutoff, normalized over 30..18000 Hz (left channel)
+ S_CutR, // right channel (differs with LFO stereo phase)
+ S_Res, // live modulated resonance, normalized
+ S_Env, // envelope follower level, linear 0..1
+ S_Lfo, // LFO value (−1..1, left)
+ S_LfoPhase, // LFO phase 0..1 (left, incl. start offset)
+ S_InPk, // input peak (decaying), linear
+ S_OutPk, // output peak (decaying), linear
+ S_Cpu, // share of real time spent in process()
+ S_SampleRate,
+ S_Bpm, // 0 until the transport has run
+ S_Onsets, // input onsets counted since load (retrig events)
+ S_EnvHeld, // 1 while the envelope is held at its peak
+ S_HistLen, // points per history (kHist)
+ S_HistMs, // ms per history point
+ S_Reserved,
+ kTele
+ };
+ enum { A_RetrigLfo = 0, A_ResetEnv = 1 }; // deviceAction ids
+ static constexpr int kHist = 2048; // 1 ms per point → ~2 s
+ static constexpr int kScope = 2048; // pre-filter ring (power of two)
+ static constexpr int kScopeTotal = kTele + 2 * kHist + kScope;
+ static constexpr float kOnsetOn = 0.063f; // −24 dBFS — an onset (Retrig, event count)
+ static constexpr float kOnsetOff = 0.0316f; // −30 dBFS — re-arms
+
// Tempo-synced LFO divisions (beats per cycle), fastest → slowest by Rate.
static constexpr double kLfoDiv[8] = { 8.0, 4.0, 2.0, 1.0, 0.5, 0.25, 0.125, 0.0625 };
@@ -71,16 +115,25 @@ public:
p_[Circuit].store(0.0f); // Clean
p_[LfoSync].store(0.0f); // Free
p_[LfoPhase].store(0.0f);// 0° (mono)
+ p_[ModTarget].store(0.0f); // Freq
+ p_[EnvHoldTime].store(1.0f); // ∞ — what Hold did before it had a length
+ p_[ModSmooth].store(0.0f);
+ p_[LfoOffset].store(0.0f);
+ p_[LfoRetrig].store(0.0f);
}
void setSampleRate(double sr, int32_t /*maxBlock*/) override {
sr_ = sr > 0 ? sr : 44100.0;
for (auto& s : svf_) s.reset();
- env_ = 0.0f; lfoPhase_ = 0.0f; shHeld_ = 0.0f; shCycle_ = -1.0;
+ env_ = 0.0f; lfoPhase_ = 0.0; shHeld_ = 0.0f; shCycle_ = -1.0;
+ smOct_ = smRes_ = 0.0; holdLeft_ = 0; armed_ = true;
+ histAcc_ = 0.0; histEnvMax_ = 0.0f;
+ srA_.store(static_cast<float>(sr_), std::memory_order_relaxed);
}
// Musical clock for the tempo-synced LFO (engine calls this before process()).
void setTransport(double beatStart, double spb, bool playing) override {
+ if (playing && !playing_) playStarted_ = true; // Retrig restarts the LFO at play
beatStart_ = beatStart; spb_ = spb > 0 ? spb : 0.0; playing_ = playing;
}
@@ -90,34 +143,62 @@ public:
void setSidechain(const float* interleaved, int32_t frames) override { scBuf_ = interleaved; scFrames_ = frames; }
bool acceptsSidechain() const override { return true; }
- // Real-time analyzer feed: the pre-filter mono signal, oldest→newest (like EQ-8),
- // for the UI's spectrum behind the response curve. Lock-free; torn reads are fine.
+ // Telemetry block, then the histories, then the pre-filter ring (see the header note).
+ // Writes as much of that layout as fits in maxSamples. Lock-free; torn reads are fine.
int32_t scopeRead(float* out, int32_t maxSamples) const override {
if (!out || maxSamples <= 0) return 0;
- const int32_t n = std::min(maxSamples, kScope);
+ float t[kTele] = {};
+ t[S_Cut] = cutA_.load(std::memory_order_relaxed);
+ t[S_CutR] = cutRA_.load(std::memory_order_relaxed);
+ t[S_Res] = resA_.load(std::memory_order_relaxed);
+ t[S_Env] = envA_.load(std::memory_order_relaxed);
+ t[S_Lfo] = lfoA_.load(std::memory_order_relaxed);
+ t[S_LfoPhase] = lfoPhA_.load(std::memory_order_relaxed);
+ t[S_InPk] = inPkA_.load(std::memory_order_relaxed);
+ t[S_OutPk] = outPkA_.load(std::memory_order_relaxed);
+ t[S_Cpu] = cpuA_.load(std::memory_order_relaxed);
+ t[S_SampleRate] = srA_.load(std::memory_order_relaxed);
+ t[S_Bpm] = bpmA_.load(std::memory_order_relaxed);
+ t[S_Onsets] = static_cast<float>(onsets_.load(std::memory_order_relaxed));
+ t[S_EnvHeld] = heldA_.load(std::memory_order_relaxed);
+ t[S_HistLen] = static_cast<float>(kHist);
+ t[S_HistMs] = 1.0f;
+ int32_t n = 0;
+ for (int k = 0; k < kTele && n < maxSamples; ++k) out[n++] = t[k];
+ const uint32_t hw = histW_.load(std::memory_order_relaxed);
+ for (int k = 0; k < kHist && n < maxSamples; ++k) out[n++] = histEnv_[(hw + (uint32_t)k) & (kHist - 1)];
+ for (int k = 0; k < kHist && n < maxSamples; ++k) out[n++] = histCut_[(hw + (uint32_t)k) & (kHist - 1)];
const uint32_t w = scopeW_.load(std::memory_order_relaxed);
- const uint32_t start = w - static_cast<uint32_t>(n);
- for (int32_t k = 0; k < n; ++k) out[k] = scope_[(start + (uint32_t)k) & (kScope - 1)];
+ for (int k = 0; k < kScope && n < maxSamples; ++k) out[n++] = scope_[(w + (uint32_t)k) & (kScope - 1)];
return n;
}
- // The live modulated cutoff, normalized 0..1 over the Freq range (30..18000 Hz),
- // published so the UI curve sweeps as the envelope (incl. sidechain) + LFO move it.
- // Reuses the generic per-device live-scalar channel (audio writes, UI reads lock-free)
- // — this device carries no gain reduction, so the slot is free.
- float gainReductionDb() const override { return modCutoffNorm_.load(std::memory_order_relaxed); }
+ // The live modulated cutoff, normalized 0..1 over the Freq range (30..18000 Hz), on the
+ // generic per-device live-scalar channel — this device carries no gain reduction.
+ float gainReductionDb() const override { return cutA_.load(std::memory_order_relaxed); }
+
+ void deviceAction(int32_t id, int32_t, float) override {
+ if (id == A_RetrigLfo) retrigReq_.store(true, std::memory_order_relaxed);
+ else if (id == A_ResetEnv) envResetReq_.store(true, std::memory_order_relaxed);
+ }
void process(float* buf, int32_t frames) override {
+ const auto t0 = std::chrono::steady_clock::now();
const double baseHz = expMap(get(Freq), 30.0, 18000.0);
- const double q = 0.5 + (double)std::clamp(get(Res), 0.0f, 1.0f) * 14.5;
+ const float resBase = std::clamp(get(Res), 0.0f, 1.0f);
const int type = std::clamp((int)std::lround(get(Type) * 3.0f), 0, 3);
const bool slope24 = get(Slope) >= 0.5f;
const float morph = std::clamp(get(Morph), 0.0f, 1.0f);
- const double envOct = get(EnvOn) >= 0.5f ? ((double)get(EnvAmt) - 0.5) * 2.0 * 6.0 : 0.0; // ±6 oct
+ const bool envOn = get(EnvOn) >= 0.5f;
+ const double envBip = envOn ? ((double)get(EnvAmt) - 0.5) * 2.0 : 0.0; // −1..1
const float attMs = (float)expMap(get(EnvAtt), 0.1, 500.0);
const float relMs = (float)expMap(get(EnvRel), 1.0, 2000.0);
const bool hold = get(EnvHold) >= 0.5f;
- const double lfoOct = get(LfoOn) >= 0.5f ? (double)std::clamp(get(LfoAmt), 0.0f, 1.0f) * 4.0 : 0.0;
+ const float holdV = std::clamp(get(EnvHoldTime), 0.0f, 1.0f);
+ const bool holdInf = holdV >= 0.995f;
+ const int64_t holdN = (int64_t)(400.0 * holdV * holdV * 0.001 * sr_);
+ const bool lfoOn = get(LfoOn) >= 0.5f;
+ const double lfoDep = lfoOn ? (double)std::clamp(get(LfoAmt), 0.0f, 1.0f) : 0.0; // 0..1
const double lfoHz = expMap(get(LfoRate), 0.01, 40.0);
const int lfoWave = std::clamp((int)std::lround(get(LfoWave) * 4.0f), 0, 4);
const float lfoMorph= std::clamp(get(LfoMorph), 0.0f, 1.0f);
@@ -125,6 +206,12 @@ public:
const float wet = std::clamp(get(DryWet), 0.0f, 1.0f);
const float outGain = std::pow(10.0f, (get(Gain) - 0.5f) * 48.0f / 20.0f); // ±24 dB
const bool analog = get(Circuit) >= 0.5f; // mild saturation
+ const int target = std::clamp((int)std::lround(get(ModTarget) * 2.0f), 0, 2);
+ const bool toFreq = target != 1, toRes = target != 0;
+ const double smMs = 120.0 * (double)get(ModSmooth) * (double)get(ModSmooth);
+ const double smCoef = smMs < 0.05 ? 0.0 : std::exp(-(double)kCtrl / (smMs * 0.001 * sr_));
+ const double offset = (double)std::clamp(get(LfoOffset), 0.0f, 1.0f);
+ const bool retrig = get(LfoRetrig) >= 0.5f;
// Per-sample envelope coefficients (one-pole).
const float aCoef = attMs <= 0.0f ? 0.0f : (float)std::exp(-1.0 / (attMs * 0.001 * sr_));
@@ -135,40 +222,61 @@ public:
const float* sc = (scBuf_ && scFrames_ >= frames) ? scBuf_ : nullptr;
const double phaseInc = lfoHz / sr_;
- const double k = 1.0 / q;
const bool sync = get(LfoSync) >= 0.5f && spb_ > 0.0;
const double divBeats= kLfoDiv[std::clamp((int)std::lround(get(LfoRate) * 7.0f), 0, 7)];
const double stPhase = (double)std::clamp(get(LfoPhase), 0.0f, 1.0f) * 0.5; // 0..0.5 cycle (0..180°)
const double nyq = std::min(20000.0, sr_ * 0.45);
+ const double histStep = sr_ * 0.001; // 1 ms per history point
+ if (envResetReq_.exchange(false, std::memory_order_relaxed)) { env_ = 0.0f; holdLeft_ = 0; }
+ bool doRetrig = retrigReq_.exchange(false, std::memory_order_relaxed);
+ if (playStarted_) { playStarted_ = false; if (retrig) doRetrig = true; }
+
+ float inPk = 0.0f, outPk = 0.0f;
+ double lastLfoL = 0.0, lastPhase = 0.0, fcLast = baseHz, fcRLast = baseHz, resLast = resBase;
+ bool held = false;
int32_t i = 0;
while (i < frames) {
const int32_t block = std::min(kCtrl, frames - i);
+ const double beat = sync ? beatStart_ + (double)i / spb_ : 0.0;
+ if (doRetrig) { doRetrig = false; lfoPhase_ = 0.0; anchorBeat_ = sync ? beat : 0.0; shCycle_ = -1.0; }
// --- control-rate modulation: LFO phase (free or tempo-locked), per-channel cutoff ---
double phase;
if (sync) {
- const double beat = beatStart_ + (double)i / spb_;
- phase = beat / divBeats; phase -= std::floor(phase);
- const double cyc = std::floor(beat / divBeats);
+ const double rel = (beat - (retrig ? anchorBeat_ : 0.0)) / divBeats;
+ phase = rel - std::floor(rel);
+ const double cyc = std::floor(rel);
if (cyc != shCycle_) { shCycle_ = cyc; shHeld_ = whiteNoise(); } // S&H reseed per cycle
} else phase = lfoPhase_;
+ phase += offset; phase -= std::floor(phase);
const double lfoL = lfoValue(lfoWave, lfoMorph, phase);
double pr = phase + stPhase; pr -= std::floor(pr);
const double lfoR = stPhase > 1e-4 ? lfoValue(lfoWave, lfoMorph, pr) : lfoL;
- const double fcL = std::clamp(baseHz * std::exp2(envOct * (double)env_ + lfoOct * lfoL), 20.0, nyq);
- const double fcR = std::clamp(baseHz * std::exp2(envOct * (double)env_ + lfoOct * lfoR), 20.0, nyq);
- modCutoffNorm_.store((float)std::clamp(std::log(fcL / 30.0) / std::log(18000.0 / 30.0), 0.0, 1.0),
- std::memory_order_relaxed); // publish for the UI curve sweep
+ // Modulation in "depth units": env ±1 · amount, LFO ±1 · amount — then smoothed.
+ const double envMod = envBip * (double)env_;
+ const double rawL = envMod * 6.0 + lfoDep * 4.0 * lfoL; // octaves (Freq)
+ const double rawR = envMod * 6.0 + lfoDep * 4.0 * lfoR;
+ const double rawRes = envMod * 0.8 + lfoDep * 0.5 * lfoL; // resonance offset
+ smOct_ = rawL + smCoef * (smOct_ - rawL);
+ smOctR_ = rawR + smCoef * (smOctR_ - rawR);
+ smRes_ = rawRes + smCoef * (smRes_ - rawRes);
+
+ const double fcL = std::clamp(baseHz * std::exp2(toFreq ? smOct_ : 0.0), 20.0, nyq);
+ const double fcR = std::clamp(baseHz * std::exp2(toFreq ? smOctR_ : 0.0), 20.0, nyq);
+ const double resN = std::clamp((double)resBase + (toRes ? smRes_ : 0.0), 0.0, 1.0);
+ const double k = 1.0 / (0.5 + resN * 14.5);
const double gL = std::tan(3.14159265358979323846 * fcL / sr_);
const double a1L = 1.0 / (1.0 + gL * (gL + k)), a2L = gL * a1L, a3L = gL * a2L;
const double gR = std::tan(3.14159265358979323846 * fcR / sr_);
const double a1R = 1.0 / (1.0 + gR * (gR + k)), a2R = gR * a1R, a3R = gR * a2R;
+ lastLfoL = lfoL; lastPhase = phase; fcLast = fcL; fcRLast = fcR; resLast = resN;
for (int32_t n = 0; n < block; ++n, ++i) {
const float l = buf[i * 2], r = buf[i * 2 + 1];
+ inPk = std::max(inPk, std::max(std::fabs(l), std::fabs(r)));
// Publish the pre-filter mono signal for the UI spectrum analyzer.
const uint32_t sw = scopeW_.load(std::memory_order_relaxed);
@@ -178,19 +286,65 @@ public:
// Envelope detector: sidechain source if routed, else this track.
const float det = sc ? scGainLin * std::max(std::fabs(sc[i * 2]), std::fabs(sc[i * 2 + 1]))
: std::max(std::fabs(l), std::fabs(r));
- if (det > env_) env_ = det + aCoef * (env_ - det);
- else if (!hold) env_ = det + rCoef * (env_ - det); // hold = freeze the peak
+ if (det > env_) {
+ env_ = det + aCoef * (env_ - det);
+ holdLeft_ = holdN;
+ } else if (hold && (holdInf || holdLeft_ > 0)) {
+ if (holdLeft_ > 0) --holdLeft_; // hold = keep the peak a while
+ held = true;
+ } else env_ = det + rCoef * (env_ - det);
if (env_ > 1.0f) env_ = 1.0f;
buf[i * 2] = filterOne(0, l, drive, driveGain, driveComp, type, morph, (float)k, a1L, a2L, a3L, slope24, wet, outGain, analog);
buf[i * 2 + 1] = filterOne(1, r, drive, driveGain, driveComp, type, morph, (float)k, a1R, a2R, a3R, slope24, wet, outGain, analog);
+ outPk = std::max(outPk, std::max(std::fabs(buf[i * 2]), std::fabs(buf[i * 2 + 1])));
+ }
+
+ // Onsets: the follower rising through −24 dBFS (re-arms under −30). Retrig restarts the LFO.
+ if (armed_ && env_ >= kOnsetOn) {
+ armed_ = false;
+ onsets_.fetch_add(1, std::memory_order_relaxed);
+ if (retrig) doRetrig = true;
+ } else if (!armed_ && env_ < kOnsetOff) armed_ = true;
+
+ // History: 1 ms per point — the follower's peak over the point, and the cutoff.
+ histEnvMax_ = std::max(histEnvMax_, env_);
+ histAcc_ += block;
+ while (histAcc_ >= histStep) {
+ histAcc_ -= histStep;
+ const uint32_t hw = histW_.load(std::memory_order_relaxed);
+ histEnv_[hw & (kHist - 1)] = histEnvMax_;
+ histCut_[hw & (kHist - 1)] = (float)std::clamp(std::log(fcL / 30.0) / std::log(18000.0 / 30.0), 0.0, 1.0);
+ histW_.store(hw + 1, std::memory_order_relaxed);
+ histEnvMax_ = env_;
}
+
if (!sync) {
lfoPhase_ += phaseInc * block;
if (lfoPhase_ >= 1.0) { lfoPhase_ -= std::floor(lfoPhase_); shHeld_ = whiteNoise(); }
}
}
scBuf_ = nullptr; // consume once
+
+ // ---- telemetry -----------------------------------------------------------
+ auto norm = [](double hz) { return (float)std::clamp(std::log(hz / 30.0) / std::log(18000.0 / 30.0), 0.0, 1.0); };
+ cutA_.store(norm(fcLast), std::memory_order_relaxed);
+ cutRA_.store(norm(fcRLast), std::memory_order_relaxed);
+ resA_.store((float)resLast, std::memory_order_relaxed);
+ envA_.store(env_, std::memory_order_relaxed);
+ lfoA_.store(lfoOn ? (float)lastLfoL : 0.0f, std::memory_order_relaxed);
+ lfoPhA_.store((float)lastPhase, std::memory_order_relaxed);
+ heldA_.store(held ? 1.0f : 0.0f, std::memory_order_relaxed);
+ const float fall = std::exp(-(float)frames / (float)(0.3 * sr_)); // ~300 ms peak fall
+ inPkA_.store(std::max(inPk, inPkA_.load(std::memory_order_relaxed) * fall), std::memory_order_relaxed);
+ outPkA_.store(std::max(outPk, outPkA_.load(std::memory_order_relaxed) * fall), std::memory_order_relaxed);
+ bpmA_.store(spb_ > 0.0 ? (float)(60.0 * sr_ / spb_) : 0.0f, std::memory_order_relaxed);
+ srA_.store((float)sr_, std::memory_order_relaxed);
+ if (frames > 0) {
+ const double el = std::chrono::duration<double>(std::chrono::steady_clock::now() - t0).count();
+ cpuS_ = cpuS_ * 0.9 + (el / (frames / sr_)) * 0.1;
+ cpuA_.store((float)cpuS_, std::memory_order_relaxed);
+ }
}
const char* displayName() const override { return "Nota Auto Filter"; }
@@ -198,16 +352,12 @@ public:
int32_t paramCount() const override { return kNumParams; }
const char* paramName(int32_t i) const override {
- switch (i) {
- case Freq: return "Freq"; case Res: return "Res"; case Type: return "Type"; case Slope: return "Slope";
- case Morph: return "Morph"; case EnvAmt: return "Env Amt"; case EnvAtt: return "Env Attack";
- case EnvRel: return "Env Release"; case EnvHold: return "Env Hold"; case LfoAmt: return "LFO Amt";
- case LfoRate: return "LFO Rate"; case LfoWave: return "LFO Wave"; case LfoMorph: return "LFO Morph";
- case Drive: return "Drive"; case DryWet: return "Dry/Wet";
- case EnvOn: return "Env On"; case LfoOn: return "LFO On"; case Gain: return "Gain"; case Circuit: return "Circuit";
- case LfoSync: return "LFO Sync"; case LfoPhase: return "LFO Stereo";
- default: return "";
- }
+ static const char* nm[kNumParams] = {
+ "Freq", "Res", "Type", "Slope", "Morph", "Env Amt", "Env Attack", "Env Release", "Env Hold",
+ "LFO Amt", "LFO Rate", "LFO Wave", "LFO Morph", "Drive", "Dry/Wet", "Env On", "LFO On", "Gain",
+ "Circuit", "LFO Sync", "LFO Stereo",
+ "Mod Target", "Env Hold Time", "Mod Smooth", "LFO Offset", "LFO Retrig" };
+ return (i >= 0 && i < kNumParams) ? nm[i] : "";
}
float paramMin(int32_t /*i*/) const override { return 0.0f; }
float paramMax(int32_t /*i*/) const override { return 1.0f; }
@@ -218,11 +368,86 @@ public:
if (i >= 0 && i < kNumParams) p_[i].store(std::clamp(v, 0.0f, 1.0f), std::memory_order_relaxed);
}
+ // 0 — a one-line status (what the filter is set to do); 1 — the live reading;
+ // 2 — a guide to the normalized parameter values (for an assistant over MCP).
+ std::string deviceText(int32_t id) const override {
+ char b[1024];
+ static const char* types[4] = { "LP", "BP", "HP", "Notch" };
+ static const char* waves[5] = { "Sine", "Tri", "Saw", "Square", "S&H" };
+ static const char* divs[8] = { "2/1", "1/1", "1/2", "1/4", "1/8", "1/16", "1/32", "1/64" };
+ static const char* targets[3] = { "Freq", "Reso", "Freq+Reso" };
+ if (id == 0) {
+ const int type = std::clamp((int)std::lround(getParam(Type) * 3.0f), 0, 3);
+ const int target = std::clamp((int)std::lround(getParam(ModTarget) * 2.0f), 0, 2);
+ std::string s;
+ std::snprintf(b, sizeof b, "%s %d dB/oct%s - %s - Q %.2f", types[type], getParam(Slope) >= 0.5f ? 24 : 12,
+ getParam(Circuit) >= 0.5f ? " analog" : "", hzText(expMap(getParam(Freq), 30.0, 18000.0)).c_str(),
+ 0.5 + getParam(Res) * 14.5);
+ s = b;
+ if (getParam(EnvOn) >= 0.5f && std::fabs(getParam(EnvAmt) - 0.5f) > 0.004f) {
+ std::snprintf(b, sizeof b, " - ENV -> %s %+.0f %% (%.1f / %.1f ms%s)", targets[target], (getParam(EnvAmt) - 0.5f) * 200.0f,
+ expMap(getParam(EnvAtt), 0.1, 500.0), expMap(getParam(EnvRel), 1.0, 2000.0), holdText().c_str());
+ s += b;
+ }
+ if (getParam(LfoOn) >= 0.5f && getParam(LfoAmt) > 0.004f) {
+ const bool sync = getParam(LfoSync) >= 0.5f;
+ char rate[32];
+ if (sync) std::snprintf(rate, sizeof rate, "%s", divs[std::clamp((int)std::lround(getParam(LfoRate) * 7.0f), 0, 7)]);
+ else std::snprintf(rate, sizeof rate, "%.2f Hz", expMap(getParam(LfoRate), 0.01, 40.0));
+ std::snprintf(b, sizeof b, " - LFO %s %s -> %s %.0f %%%s", waves[std::clamp((int)std::lround(getParam(LfoWave) * 4.0f), 0, 4)],
+ rate, targets[target], getParam(LfoAmt) * 100.0f, getParam(LfoRetrig) >= 0.5f ? " retrig" : "");
+ s += b;
+ }
+ if (getParam(Drive) > 0.004f) { std::snprintf(b, sizeof b, " - drive %.0f %%", getParam(Drive) * 100.0f); s += b; }
+ std::snprintf(b, sizeof b, " - mix %.0f %%", getParam(DryWet) * 100.0f);
+ s += b;
+ if (sidechainSourceTrackId() >= 0) s += " - sidechain key";
+ return s;
+ }
+ if (id == 1) {
+ const double hz = 30.0 * std::pow(18000.0 / 30.0, (double)cutA_.load(std::memory_order_relaxed));
+ const double midi = 69.0 + 12.0 * std::log2(hz / 440.0);
+ const int note = (int)std::lround(midi);
+ static const char* nn[12] = { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" };
+ const float env = envA_.load(std::memory_order_relaxed);
+ std::snprintf(b, sizeof b, "cutoff %s (%s%d %+.0f ct) - reso %.0f %% - env %.1f dB%s - lfo %+.2f phase %.0f deg - onsets %u",
+ hzText(hz).c_str(), nn[((note % 12) + 12) % 12], note / 12 - 1, (midi - note) * 100.0,
+ resA_.load(std::memory_order_relaxed) * 100.0f, env > 1e-6f ? 20.0f * std::log10(env) : -120.0f,
+ heldA_.load(std::memory_order_relaxed) > 0.5f ? " (held)" : "",
+ lfoA_.load(std::memory_order_relaxed), lfoPhA_.load(std::memory_order_relaxed) * 360.0f,
+ onsets_.load(std::memory_order_relaxed));
+ return b;
+ }
+ if (id == 2) {
+ return "All params are 0..1. Freq: 30*600^v Hz. Res: Q 0.5+14.5v. Type: 0 LP, 0.333 BP, 0.667 HP, 1 Notch. "
+ "Slope: 0 = 12, 1 = 24 dB/oct. Morph: blend toward the next type. Env Amt: bipolar, 0.5 = 0 (+/-6 oct on Freq, "
+ "+/-80 % on Res). Env Attack: 0.1*5000^v ms. Env Release: 2000^v ms. Env Hold: on/off; Env Hold Time: 400v^2 ms, "
+ ">= 0.995 = infinite. LFO Amt: 0..4 oct on Freq (+/-50 % on Res). LFO Rate: free 0.01*4000^v Hz; with LFO Sync on "
+ "round(v*7) picks 2/1,1/1,1/2,1/4,1/8,1/16,1/32,1/64. LFO Wave: 0 Sine, 0.25 Tri, 0.5 Saw, 0.75 Square, 1 S&H. "
+ "LFO Morph: skew / pulse width. LFO Stereo: right-channel phase 0..180 deg. LFO Offset: start phase 0..360 deg. "
+ "LFO Retrig: restart on each input onset (-24 dBFS) and at play. Mod Target: 0 Freq, 0.5 Reso, 1 both. "
+ "Mod Smooth: 120v^2 ms slew. Drive: pre-filter saturation. Circuit: 0 Clean, 1 Analog. Gain: 0.5 = 0 dB, +/-24 dB. "
+ "Env On / LFO On / toggles: >= 0.5 = on.";
+ }
+ return {};
+ }
+
private:
static constexpr int32_t kCtrl = 16; // control-rate block for coefficient updates
float get(int i) const { return p_[i].load(std::memory_order_relaxed); }
static double expMap(float v, double lo, double hi) { return lo * std::pow(hi / lo, std::clamp((double)v, 0.0, 1.0)); }
+ static std::string hzText(double hz) {
+ char b[32];
+ if (hz >= 1000.0) std::snprintf(b, sizeof b, "%.2f kHz", hz / 1000.0); else std::snprintf(b, sizeof b, "%.0f Hz", hz);
+ return b;
+ }
+ std::string holdText() const {
+ if (getParam(EnvHold) < 0.5f) return {};
+ const float v = getParam(EnvHoldTime);
+ if (v >= 0.995f) return ", hold inf";
+ char b[32]; std::snprintf(b, sizeof b, ", hold %.0f ms", 400.0f * v * v); return b;
+ }
// TPT state-variable filter: one stage yields LP/BP/HP/Notch simultaneously.
struct Svf {
@@ -272,21 +497,33 @@ private:
float whiteNoise() { rng_ = rng_ * 1664525u + 1013904223u; return (float)((int32_t)(rng_ >> 8) / 8388608.0 - 1.0); }
- static constexpr int kScope = 4096; // power of two
-
double sr_ = 44100.0;
std::atomic<float> p_[kNumParams] = {};
Svf svf_[4]; // [ch*2 + stage]
float env_ = 0.0f;
+ int64_t holdLeft_ = 0; // samples of hold left at the current peak
+ bool armed_ = true; // onset detector armed
double lfoPhase_ = 0.0;
+ double anchorBeat_ = 0.0; // synced LFO restarts here after a retrig
+ double smOct_ = 0.0, smOctR_ = 0.0, smRes_ = 0.0; // smoothed modulation
float shHeld_ = 0.0f;
double shCycle_ = -1.0; // last synced S&H cycle index
double beatStart_ = 0.0, spb_ = 0.0; // transport (for LFO sync)
- bool playing_ = false;
+ bool playing_ = false, playStarted_ = false;
uint32_t rng_ = 0x1234567u;
+ std::atomic<bool> retrigReq_{false}, envResetReq_{false};
+
+ // Telemetry.
mutable float scope_[kScope] = {}; // pre-filter mono ring (UI spectrum)
std::atomic<uint32_t> scopeW_{0};
- std::atomic<float> modCutoffNorm_{0.5f}; // live modulated cutoff, normalized (UI)
+ float histEnv_[kHist] = {}, histCut_[kHist] = {}; // 1 ms history rings
+ std::atomic<uint32_t> histW_{0};
+ double histAcc_ = 0.0;
+ float histEnvMax_ = 0.0f;
+ std::atomic<uint32_t> onsets_{0};
+ double cpuS_ = 0.0;
+ std::atomic<float> cutA_{0.5f}, cutRA_{0.5f}, resA_{0.1f}, envA_{0}, lfoA_{0}, lfoPhA_{0}, inPkA_{0}, outPkA_{0},
+ cpuA_{0}, srA_{44100.0f}, bpmA_{0}, heldA_{0};
// Sidechain (engine hands the source buffer just before process()).
std::atomic<int32_t> scTrackId_{-1};
diff --git a/tests/Nota.SmokeTest/Program.cs b/tests/Nota.SmokeTest/Program.cs
index 0250705e..13c9268b 100644
--- a/tests/Nota.SmokeTest/Program.cs
+++ b/tests/Nota.SmokeTest/Program.cs
@@ -6777,23 +6777,131 @@ Console.WriteLine("-- Auto Filter (effect kind 7) --");
Check(afdi >= 0, "add Auto Filter device");
Check(afeng.TrackDeviceBuiltinKind(aft, afdi) == 7, "device reports builtin kind 7");
int afpc = afeng.DeviceParamCount(aft, afdi);
- Check(afpc == 21, $"Auto Filter exposes 21 params ({afpc})");
+ Check(afpc == 26, $"Auto Filter exposes 26 params ({afpc})");
+ const int AfFreq = 0, AfRes = 1, AfType = 2, AfSlope = 3, AfEnvAmt = 5, AfEnvOn = 15, AfLfoAmt = 9, AfLfoRate = 10,
+ AfLfoWave = 11, AfLfoSync = 19, AfTarget = 21, AfHoldTime = 22, AfSmooth = 23, AfOffset = 24, AfRetrig = 25;
+ Check(afeng.DeviceParamName(aft, afdi, AfTarget) == "Mod Target" && afeng.DeviceParamName(aft, afdi, AfHoldTime) == "Env Hold Time"
+ && afeng.DeviceParamName(aft, afdi, AfSmooth) == "Mod Smooth" && afeng.DeviceParamName(aft, afdi, AfOffset) == "LFO Offset"
+ && afeng.DeviceParamName(aft, afdi, AfRetrig) == "LFO Retrig", "appended params: Mod Target · Env Hold Time · Mod Smooth · LFO Offset · LFO Retrig");
+ Check(Math.Abs(afeng.DeviceParamDefault(aft, afdi, AfHoldTime) - 1f) < 1e-6f, "Env Hold Time defaults to ∞, so an old project's Hold still freezes");
Check(afeng.DeviceAcceptsSidechain(aft, afdi), "Auto Filter accepts a sidechain");
- afeng.DeviceSetParam(aft, afdi, 0, 0.35f); // Freq
- afeng.DeviceSetParam(aft, afdi, 1, 0.6f); // Res
- Check(Math.Abs(afeng.DeviceGetParam(aft, afdi, 1) - 0.6f) < 1e-3f, "device param set/get round-trips");
- var afbuf = new float[2048 * 2];
- afeng.SetBpm(120); afeng.Seek(0); afeng.Play();
- afeng.RenderOffline(afbuf, 2048);
- afeng.StopTransport();
- Check(Rms(afbuf, 2048) > 1e-4f, $"Auto Filter passes audio (rms={Rms(afbuf, 2048):0.0000})");
- // Real-time viz feed: the pre-filter scope (UI spectrum) + the live modulated cutoff.
- var afscope = new float[2048];
- int afn = afeng.DeviceScope(aft, afdi, afscope, 2048);
- float afe = 0; for (int s = 0; s < afn; s++) afe += Math.Abs(afscope[s]);
- Check(afn == 2048 && afe > 0f, $"Auto Filter scope feeds the spectrum ({afn} samples, energy {afe:0.0})");
+ afeng.DeviceSetParam(aft, afdi, AfFreq, 0.35f);
+ afeng.DeviceSetParam(aft, afdi, AfRes, 0.6f);
+ Check(Math.Abs(afeng.DeviceGetParam(aft, afdi, AfRes) - 0.6f) < 1e-3f, "device param set/get round-trips");
+ var afbuf = new float[4096 * 2];
+ void AfRender(int n = 4096) { afeng.SetBpm(120); afeng.Seek(0); afeng.Play(); for (int k = 0; k < n; k += 4096) afeng.RenderOffline(afbuf, 4096); afeng.StopTransport(); }
+ bool Finite(float[] b) { foreach (var x in b) if (!float.IsFinite(x) || Math.Abs(x) > 8f) return false; return true; }
+ AfRender();
+ Check(Rms(afbuf, 4096) > 1e-4f, $"Auto Filter passes audio (rms={Rms(afbuf, 4096):0.0000})");
+
+ // Scope layout: 16 telemetry values, two 2048-point histories, the 2048-sample spectrum ring.
+ const int afTele = 16, afHist = 2048, afRing = 2048;
+ var afscope = new float[afTele + 2 * afHist + afRing];
+ int afn = afeng.DeviceScope(aft, afdi, afscope, afscope.Length);
+ float afe = 0; for (int k = 0; k < afRing; k++) afe += Math.Abs(afscope[afTele + 2 * afHist + k]);
+ Check(afn == afscope.Length && afe > 0f, $"Auto Filter scope carries telemetry + histories + the spectrum ring ({afn} values, energy {afe:0.0})");
+ Check(afscope[9] > 1000 && afscope[13] == afHist, $"telemetry reports sample rate and history length ({afscope[9]:0}, {afscope[13]:0})");
+ Check(afscope[11] >= 1, $"the onset detector counts the clip's start ({afscope[11]:0})");
float liveCut = afeng.DeviceGainReduction(aft, afdi);
Check(liveCut > 0f && liveCut < 1f, $"Auto Filter publishes live modulated cutoff ({liveCut:0.00})");
+
+ // Every type × slope renders audible + finite.
+ int afBad = 0;
+ for (int ty = 0; ty < 4; ty++)
+ for (int sl = 0; sl < 2; sl++)
+ {
+ afeng.DeviceSetParam(aft, afdi, AfType, ty / 3f); afeng.DeviceSetParam(aft, afdi, AfSlope, sl);
+ afeng.DeviceSetParam(aft, afdi, AfFreq, ty == 2 ? 0.2f : 0.7f);
+ AfRender();
+ if (!Finite(afbuf) || Rms(afbuf, 4096) < 1e-5f) afBad++;
+ }
+ Check(afBad == 0, $"every filter type and slope renders audible + finite ({afBad} failed)");
+ afeng.DeviceSetParam(aft, afdi, AfType, 0f); afeng.DeviceSetParam(aft, afdi, AfSlope, 0f);
+
+ // Envelope → Freq opens the cutoff above its base; → Reso leaves the cutoff and lifts the resonance.
+ afeng.DeviceSetParam(aft, afdi, AfFreq, 0.3f); afeng.DeviceSetParam(aft, afdi, AfRes, 0.2f);
+ afeng.DeviceSetParam(aft, afdi, AfEnvOn, 1f); afeng.DeviceSetParam(aft, afdi, AfEnvAmt, 1f); afeng.DeviceSetParam(aft, afdi, AfLfoAmt, 0f);
+ afeng.DeviceSetParam(aft, afdi, AfTarget, 0f);
+ AfRender();
+ float cutUp = afeng.DeviceGainReduction(aft, afdi);
+ Check(cutUp > 0.4f, $"ENV → Freq opens the cutoff above its base ({cutUp:0.00} > 0.30)");
+ afeng.DeviceSetParam(aft, afdi, AfTarget, 0.5f);
+ AfRender();
+ afeng.DeviceScope(aft, afdi, afscope, afscope.Length);
+ Check(Math.Abs(afscope[0] - 0.3f) < 0.01f && afscope[2] > 0.4f, $"ENV → Reso keeps the cutoff and lifts the resonance (cut {afscope[0]:0.00}, res {afscope[2]:0.00})");
+ afeng.DeviceSetParam(aft, afdi, AfTarget, 0f);
+ // History: the cutoff history shows the envelope moving it.
+ float hmax = 0; for (int k = 0; k < afHist; k++) hmax = Math.Max(hmax, afscope[afTele + afHist + k]);
+ Check(hmax > 0.29f, $"cutoff history is written (max {hmax:0.00})");
+
+ // Mod Smooth slows the movement: after one short block the smoothed cutoff lags behind.
+ afeng.DeviceSetParam(aft, afdi, AfSmooth, 1f);
+ afeng.SetBpm(120); afeng.Seek(0); afeng.Play(); afeng.RenderOffline(afbuf, 512); afeng.StopTransport();
+ float cutSlow = afeng.DeviceGainReduction(aft, afdi);
+ afeng.DeviceSetParam(aft, afdi, AfSmooth, 0f);
+ Check(cutSlow < cutUp, $"Mod Smooth slews the modulation ({cutSlow:0.00} < {cutUp:0.00})");
+
+ // LFO: synced, every wave stable; the device action restarts it at its start phase.
+ afeng.DeviceSetParam(aft, afdi, AfEnvAmt, 0.5f);
+ afeng.DeviceSetParam(aft, afdi, AfLfoAmt, 0.6f); afeng.DeviceSetParam(aft, afdi, AfLfoSync, 1f); afeng.DeviceSetParam(aft, afdi, AfLfoRate, 3f / 7f);
+ int lfoBad = 0;
+ for (int wv = 0; wv < 5; wv++) { afeng.DeviceSetParam(aft, afdi, AfLfoWave, wv / 4f); AfRender(); if (!Finite(afbuf) || Rms(afbuf, 4096) < 1e-5f) lfoBad++; }
+ Check(lfoBad == 0, $"every LFO wave renders stable ({lfoBad} failed)");
+ afeng.DeviceSetParam(aft, afdi, AfLfoSync, 0f); afeng.DeviceSetParam(aft, afdi, AfLfoRate, 0.2f);
+ afeng.DeviceSetParam(aft, afdi, AfOffset, 0.25f); afeng.DeviceSetParam(aft, afdi, AfRetrig, 1f);
+ afeng.DeviceAction(aft, afdi, 0, 0, 0);
+ afeng.SetBpm(120); afeng.Seek(0); afeng.Play(); afeng.RenderOffline(afbuf, 64); afeng.StopTransport();
+ afeng.DeviceScope(aft, afdi, afscope, afscope.Length);
+ Check(Math.Abs(afscope[5] - 0.25f) < 0.02f, $"LFO restart puts the phase at the start offset ({afscope[5] * 360:0}° ≈ 90°)");
+ Check(Finite(afbuf), "retriggered LFO stays finite");
+
+ // Status + guide text.
+ string aftext = afeng.DeviceText(aft, afdi, 0);
+ Check(aftext.StartsWith("LP 12 dB/oct") && aftext.Contains("LFO S&H"), $"status text names the filter and the LFO (got '{aftext}')");
+ Check(afeng.DeviceText(aft, afdi, 1).StartsWith("cutoff ") && afeng.DeviceText(aft, afdi, 2).Contains("Mod Target"), "live reading and parameter guide texts");
+
+ // MCP: the filter-motion reading.
+ var afTools = new Nota.Mcp.Tools.DeviceTools(afeng, new Nota.SmokeTest.SyncDispatch(), new Nota.SmokeTest.NoRefresh());
+ AfRender(16384);
+ var fm = afTools.ReadFilterMotion(aft, afdi).Result;
+ Check(fm.CutoffHz >= 30 && fm.CutoffHz <= 18000 && fm.SampleRate > 1000 && fm.Summary.Contains("LFO") && fm.CutoffNote.Length > 0 && fm.CutoffMaxLast2sHz >= fm.CutoffMinLast2sHz,
+ $"MCP read_filter_motion reports the cutoff, its note and the range ({fm.CutoffHz:0} Hz {fm.CutoffNote}, {fm.CutoffMinLast2sHz:0}…{fm.CutoffMaxLast2sHz:0})");
+
+ // Clone: duplicating the track keeps the appended params.
+ afeng.DeviceSetParam(aft, afdi, AfHoldTime, 0.3f);
+ int afcopy = afeng.DuplicateTrack(aft);
+ Check(afcopy > 0 && Math.Abs(afeng.DeviceGetParam(afcopy, afdi, AfHoldTime) - 0.3f) < 1e-3f && Math.Abs(afeng.DeviceGetParam(afcopy, afdi, AfOffset) - 0.25f) < 1e-3f,
+ "duplicate track clones the Auto Filter's appended params");
+
+ // Automation drives an appended param.
+ int aflane = afeng.AddAutomationLane(aft, AutomationTarget.DeviceParam, afdi, AfTarget);
+ afeng.SetAutomationPoints(aft, aflane, new[] { new AutomationPoint(0, 1f), new AutomationPoint(16, 1f) });
+ AfRender();
+ Check(afeng.DeviceGetParam(aft, afdi, AfTarget) > 0.9f, $"automation drives Mod Target ({afeng.DeviceGetParam(aft, afdi, AfTarget):0.00})");
+ afeng.RemoveAutomationLane(aft, aflane);
+
+ // Factory presets: ≥ 25, every named param exists, each applies in place and renders.
+ {
+ var names = new HashSet<string>();
+ for (int k = 0; k < afpc; k++) names.Add(afeng.DeviceParamName(aft, afdi, k));
+ var cat = new FactoryPresetCatalog();
+ var mine = cat.All().Where(p => !p.IsInstrument && !p.IsMidiEffect && p.BuiltinKind == 7).ToList();
+ Check(mine.Count >= 25, $"Auto Filter ships ≥ 25 factory presets ({mine.Count})");
+ var bad = mine.SelectMany(p => cat.Document(p.Id)!.NamedParams!.Keys.Where(k => !names.Contains(k)).Select(k => $"{p.DisplayName}:{k}")).ToList();
+ Check(bad.Count == 0, $"every Auto Filter preset param name exists{(bad.Count > 0 ? " — bad: " + string.Join(", ", bad) : "")}");
+ int pf = 0;
+ foreach (var p in mine)
+ {
+ if (cat.ApplyInPlace(afeng, p.Id, aft, afdi).Length != 0) { pf++; continue; }
+ AfRender();
+ if (!Finite(afbuf) || Rms(afbuf, 4096) < 1e-5f) pf++;
+ }
+ Check(pf == 0, $"every Auto Filter preset applies and renders ({pf} failed)");
+ cat.ApplyInPlace(afeng, "autofilter/Clav Wah", aft, afdi);
+ Check(Math.Abs(afeng.DeviceGetParam(aft, afdi, AfType) - 0.333f) < 1e-3f && afeng.DeviceGetParam(aft, afdi, AfHoldTime) < 0.2f, "Clav Wah preset: BP with a 12 ms hold");
+ cat.ApplyInPlace(afeng, "autofilter/Clean Sweep", aft, afdi);
+ Check(Math.Abs(afeng.DeviceGetParam(aft, afdi, AfHoldTime) - 1f) < 1e-3f, "unnamed params reset to defaults between presets");
+ }
}
// ===================== Nota Vintage (effect kind 8) ========================