Nota — a free DAW for macOS, Windows and Linux. No subscription, no account — just open it and make music.
C# audioaudio-unitavaloniacpp20cross-platformdawdigital-audio-workstationdspjucelinux-audiomcp-servermidimusicmusic-productionpiano-rollplugin-hostsequencersynthesizervstvst3
Redesign of Valve
Egor Khindikaynen2a10b18057b3
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 619f9faf..7f4442a8 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -51,6 +51,35 @@ Entry categories: `Added`, `Changed`, `Fixed`, `Removed`.level, the effective attack and release, look-ahead latency and how often it kicked in.### Changed+- **Nota Valve shows the amp it runs, not just its knobs.** The card moves onto the Vintage /+ Auto Filter / Lens frame — a STAGE column (gain and output faders), a centre panel with+ **Amp**, **Cab** and **Harmonics** tabs, a **Cabinet / Output** panel and a status strip.+ The seven models are now a list in the tab's head row instead of a row of buttons, and the+ cabinet and mic get a tab of their own with a real response instead of chips with no+ feedback:+ - **Amp** — the tone stack's response (read from the engine, so it is the real one) against+ the stack flat; drag sideways for the middle's frequency, up and down for the middle.+ - **Cab** — the cabinet as the mic hears it against the same mic on axis at the cap, and how+ much the placement costs at 4 kHz; drag sideways to move the mic off axis, up to bring it+ closer.+ - **Harmonics** — the harmonics the preamp adds at the input's level (f … 7f), the THD and an+ estimate of the aliasing at the current oversampling.+ - **New in the engine:** a **sweepable middle** (200 Hz … 2 kHz), **Bright** and **Deep**+ switches, an **even-harmonics-only** preamp, cabinets with their own **low resonance and+ presence peak**, **mic distance** (proximity bass up close, thinner far away) and **cap /+ edge position**, a stronger **off-axis** roll-off, **low and high cuts** and **auto gain+ compensation**. The panel's gate switch turns the gate on at its last threshold.+ - **31 factory presets**, up from six, level-matched to the dry signal — cleans, blues,+ rock, leads, heavy, bass and a few for keys, vocals and drums. The first fourteen+ parameters keep their units and the nine new ones are appended and default to the old+ sound, so older projects open with the same settings (a project that used one of the+ four fixed cabinets or the mic off axis now hears the cab's peaks and the stronger+ off-axis roll-off); every one of them automates (the mic ones grouped+ 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` 0 resets the amp, and the new `read_valve` returns the THD with+ the harmonics, the aliasing estimate, the gate state, the auto-comp gain, the cabinet's+ loss at 4 kHz and the tone stack's and cabinet's responses.- **Nota Vintage shows what the era does to the signal, not just its knobs.** The card movesonto the Auto Filter / Lens / Compressor frame — a STATE column (drive and wear faders), acentre panel with **Curve**, **Wear** and **Output** tabs, a **Tone / Output** panel and adiff --git a/FEATURES.md b/FEATURES.mdindex 23a73d02..1499a521 100644--- a/FEATURES.md+++ b/FEATURES.md@@ -347,7 +347,15 @@ and user presets, automation, persistence and cloning.- **Nota Utility** (4) — gain, L/R balance, stereo width (mid/side 0–400%), channel mode(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 Valve** (6, formerly Amplifier) — guitar amp: 7 models (Clean / Boost / Blues /+ Rock / Lead / Heavy / Bass), gain, a Bass / Middle / Treble / Presence tone stack with a+ sweepable middle, Bright and Deep, an even-harmonics-only preamp; a cabinet (Match / 1×12 /+ 2×12 / 4×12 / 1×15 with their resonance and presence peak) heard through a Dynamic /+ Condenser / Ribbon mic at a distance, off axis, at the cap or the edge; low / high cut,+ noise gate, auto gain compensation, mix, output, oversampling. Tabs: Amp (the tone stack's+ response, drag the middle) / Cab (the cabinet against on-axis, drag the mic) / Harmonics+ (f … 7f, THD, aliasing) and Cabinet / Output, with a STAGE column and a status strip.+ 31 factory presets. MCP: `read_valve`.- **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 sidechainkey) and an LFO (5 waves, morph, free or tempo-synced, start phase, stereo phase, Retrig ondiff --git a/src/managed/Nota.App/ArrangementView.Automation.cs b/src/managed/Nota.App/ArrangementView.Automation.csindex 5583a88b..ec799776 100644--- a/src/managed/Nota.App/ArrangementView.Automation.cs+++ b/src/managed/Nota.App/ArrangementView.Automation.cs@@ -389,10 +389,10 @@ public sealed partial class ArrangementView// 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"), the Compressor its key- // ("SC HP", "SC Gain" …), the Auto Filter its sources ("Env", "LFO", "Mod") and Nota- // Vintage its tone and wow ("Tone Low", "Wow Rate" …):+ // ("SC HP", "SC Gain" …), the Auto Filter its sources ("Env", "LFO", "Mod"), Nota+ // Vintage its tone and wow ("Tone Low", "Wow Rate" …) and Nota Valve its mic ("Mic Distance" …):// a word shared by two or more params becomes a submenu.- bool grouped = e.TrackDeviceBuiltinKind(t.Id, d) is 1 or 7 or 8 or 20 or 21 or 22;+ bool grouped = e.TrackDeviceBuiltinKind(t.Id, d) is 1 or 6 or 7 or 8 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/AmpCurve.cs b/src/managed/Nota.App/Controls/AmpCurve.csdeleted file mode 100644index 40fd1982..00000000--- a/src/managed/Nota.App/Controls/AmpCurve.cs+++ /dev/null@@ -1,89 +0,0 @@-// SPDX-License-Identifier: AGPL-3.0-only-// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.-//-// Amp waveshaper transfer curve (input -> output) for the built-in Amp device.-// Redraws when the model or Gain moves so you see how hard the preamp is-// clipping — a near-diagonal line stays clean, an S/square shape is saturated.-// Drawn in the app style like CompViz (faint grid + unity reference + label).--using System;-using System.Globalization;-using Avalonia;-using Avalonia.Controls;-using Avalonia.Media;--namespace Nota.App;--internal sealed class AmpCurve : Control-{- private static readonly IBrush Sunken = NotaPalette.BgSunken;- private static readonly IBrush BorderDef = NotaPalette.BorderDefault;- private static readonly IBrush AccentBright = NotaPalette.AccentBright;- private static readonly IBrush TextTertiary = NotaPalette.TextTertiary;- private static readonly IBrush Grid = NotaGraph.Grid;- private static readonly Typeface Face = NotaFonts.Mono;-- private float _drive = 1f, _bias;- private int _stages = 1;- private string _model = "";-- public AmpCurve() { MinWidth = 120; MinHeight = 70; }-- public void Set(float drive, int stages, float bias, string model)- { _drive = drive; _stages = Math.Max(1, stages); _bias = bias; _model = model; InvalidateVisual(); }-- // The Amp's memoryless waveshaper (mirrors Amp.h: bias + tanh cascade, DC-recentered).- private float Shape(float x)- {- float v = _drive * x + _bias;- for (int s = 0; s < _stages; s++) { v = MathF.Tanh(v); if (s < _stages - 1) v *= 2f; }- return v - MathF.Tanh(_bias);- }-- 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));- double pad = 7, x0 = pad, x1 = w - pad, top = pad + 10, bot = h - pad - 9;-- var gridPen = new Pen(Grid, 1);- for (int i = 1; i <= 3; i++)- {- double gy = top + (bot - top) * i / 4.0;- ctx.DrawLine(gridPen, new Point(x0, gy), new Point(x1, gy));- double gx = x0 + (x1 - x0) * i / 4.0;- ctx.DrawLine(gridPen, new Point(gx, top), new Point(gx, bot));- }- ctx.DrawLine(new Pen(Grid, 1) { DashStyle = DashStyle.Dash }, new Point(x0, bot), new Point(x1, top)); // unity ref-- float norm = Math.Max(1e-3f, Math.Abs(Shape(1f))); // fit the S-curve to the box- var pen = new Pen(AccentBright, 1.6, lineCap: PenLineCap.Round, lineJoin: PenLineJoin.Round);- var g = new StreamGeometry();- using (var gc = g.Open())- {- int n = 64;- for (int i = 0; i <= n; i++)- {- double t = (double)i / n; // 0..1 across x = -1..+1- float xin = (float)(t * 2.0 - 1.0);- double y = Shape(xin) / norm; // -1..+1- var pt = new Point(x0 + t * (x1 - x0), bot - (y * 0.5 + 0.5) * (bot - top));- if (i == 0) gc.BeginFigure(pt, false); else gc.LineTo(pt);- }- }- ctx.DrawGeometry(null, pen, g);-- ctx.DrawText(new FormattedText("TRANSFER", CultureInfo.InvariantCulture, FlowDirection.LeftToRight, Face, 8, TextTertiary), new Point(x0, pad - 2));- if (_model.Length > 0)- {- var t2 = new FormattedText(_model, CultureInfo.InvariantCulture, FlowDirection.LeftToRight, Face, 8, AccentBright);- ctx.DrawText(t2, new Point(x1 - t2.Width, pad - 2));- }- // input-drive axis (−40 dB … 0 dB).- var axisB = NotaPalette.TextDisabled;- ctx.DrawText(new FormattedText("in −40\u2009dB", CultureInfo.InvariantCulture, FlowDirection.LeftToRight, Face, 7, axisB), new Point(x0, bot + 2));- var zt = new FormattedText("0\u2009dB", CultureInfo.InvariantCulture, FlowDirection.LeftToRight, Face, 7, axisB);- ctx.DrawText(zt, new Point(x1 - zt.Width, bot + 2));- }-}diff --git a/src/managed/Nota.App/Controls/AmpHarmonics.cs b/src/managed/Nota.App/Controls/AmpHarmonics.csdeleted file mode 100644index 078cbc51..00000000--- a/src/managed/Nota.App/Controls/AmpHarmonics.cs+++ /dev/null@@ -1,88 +0,0 @@-// SPDX-License-Identifier: AGPL-3.0-only-// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.-//-// Amplifier harmonic spectrum (mockup 2m): a unit sine is pushed through the same waveshaper-// the DSP runs (bias + tanh cascade), and a DFT gives the 2nd…7th harmonic levels relative to-// the fundamental, plus the total harmonic distortion — so "how much it clips" is a number.--using System;-using System.Globalization;-using Avalonia;-using Avalonia.Controls;-using Avalonia.Media;--namespace Nota.App;--internal sealed class AmpHarmonics : Control-{- private static readonly IBrush Well = NotaPalette.BgSunken;- private static readonly IBrush BorderIn = NotaPalette.GraphBorder;- private static Color Amber => NotaPalette.Accent.Color;- private static readonly IBrush Muted = NotaPalette.TextTertiary;- private static readonly IBrush Sub = NotaPalette.TextSecondary;- private static readonly Typeface Mono = NotaFonts.Mono;-- private float _drive = 1, _bias;- private int _stages = 1;- private readonly double[] _h = new double[7]; // harmonics 1..7 (index 0 = fundamental)- private double _thd;-- public AmpHarmonics() { MinHeight = 40; }-- public void Set(float drive, int stages, float bias)- {- _drive = drive; _stages = Math.Max(1, stages); _bias = bias;- Compute();- InvalidateVisual();- }-- private float Shape(float x)- {- float v = _drive * x + _bias;- for (int s = 0; s < _stages; s++) { v = MathF.Tanh(v); if (s < _stages - 1) v *= 2f; }- return v - MathF.Tanh(_bias);- }-- private void Compute()- {- const int N = 512;- for (int k = 0; k < 7; k++)- {- double re = 0, im = 0;- for (int n = 0; n < N; n++)- {- double ph = 2 * Math.PI * n / N;- double y = Shape((float)(0.7 * Math.Sin(ph))); // ~ -3 dBFS drive test tone- re += y * Math.Cos((k + 1) * ph); im += y * Math.Sin((k + 1) * ph);- }- _h[k] = Math.Sqrt(re * re + im * im) / N;- }- double f = Math.Max(1e-9, _h[0]), sum = 0;- for (int k = 1; k < 7; k++) sum += _h[k] * _h[k];- _thd = Math.Sqrt(sum) / f;- }-- 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));- double padX = 8, top = 13, bot = h - 11;- ctx.DrawText(new FormattedText("HARMONICS", CultureInfo.InvariantCulture, FlowDirection.LeftToRight, NotaFonts.SansBold, 8, Muted), new Point(padX, 2));- var thd = new FormattedText($"THD {_thd * 100:0}\u2009%", CultureInfo.InvariantCulture, FlowDirection.LeftToRight, Mono, 8, Sub);- ctx.DrawText(thd, new Point(w - padX - thd.Width, 2));-- // Bars for harmonics 2..7, normalised to the fundamental.- double f = Math.Max(1e-9, _h[0]);- int nb = 6; double bw = (w - 2 * padX) / nb;- for (int i = 0; i < nb; i++)- {- double rel = Math.Clamp(_h[i + 1] / f, 0, 1);- double bh = Math.Max(1, rel * (bot - top));- double cx = padX + i * bw + bw / 2;- ctx.DrawRectangle(NotaPalette.Accent, null, new Rect(cx - 4, bot - bh, 8, bh), NotaRadius.BarValue, NotaRadius.BarValue); // height is the magnitude; no opacity ramp- var lbl = new FormattedText((i + 2).ToString(), CultureInfo.InvariantCulture, FlowDirection.LeftToRight, Mono, 7, Muted);- ctx.DrawText(lbl, new Point(cx - lbl.Width / 2, bot + 1));- }- }-}diff --git a/src/managed/Nota.App/Controls/AmpToneCurve.cs b/src/managed/Nota.App/Controls/AmpToneCurve.csdeleted file mode 100644index 89d69fa3..00000000--- a/src/managed/Nota.App/Controls/AmpToneCurve.cs+++ /dev/null@@ -1,107 +0,0 @@-// SPDX-License-Identifier: AGPL-3.0-only-// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.-//-// Amplifier tone-stack EQ response (mockup 2m): the combined magnitude of the Bass low-shelf,-// Middle peak, Treble + Presence high-shelves — the same RBJ biquads the DSP runs — over a-// log-frequency axis, so the tone knobs draw their own curve.--using System;-using System.Globalization;-using Avalonia;-using Avalonia.Controls;-using Avalonia.Media;--namespace Nota.App;--internal sealed class AmpToneCurve : Control-{- private static readonly IBrush Well = NotaPalette.BgSunken;- private static readonly IBrush BorderIn = NotaPalette.GraphBorder;- private static readonly IBrush Amber = NotaPalette.Accent;- private static readonly IBrush Grid = NotaGraph.Grid;- private static readonly IBrush Ref = NotaPalette.SurfaceRaised;- private static readonly IBrush Axis = NotaPalette.TextAxis;- private static readonly Typeface Mono = NotaFonts.Mono;-- private double _bass, _mid, _treb, _pres; // dB- private const double Sr = 44100, FLo = 40, FHi = 12000, DbSpan = 15;-- public AmpToneCurve() { MinHeight = 40; }-- // Params are the amp's 0..10 knobs; convert to dB with the DSP's mapping.- public void Set(float bass, float middle, float treble, float presence)- {- _bass = (bass - 5) / 5.0 * 12; _mid = (middle - 5) / 5.0 * 10;- _treb = (treble - 5) / 5.0 * 12; _pres = (presence - 5) / 5.0 * 8;- InvalidateVisual();- }-- private double DbAt(double f)- {- return 20 * Math.Log10(Math.Max(1e-6,- Mag(BiLowShelf(110, _bass), f) * Mag(BiPeak(650, _mid, 0.70), f)- * Mag(BiHighShelf(3000, _treb), f) * Mag(BiHighShelf(4500, _pres), f)));- }-- 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));- double padB = 10, bot = h - padB, top = 3;- double Y(double db) => top + (bot - top) * (0.5 - Math.Clamp(db / DbSpan, -1, 1) * 0.5);- double X(double f) => w * (Math.Log(f / FLo) / Math.Log(FHi / FLo));-- ctx.DrawLine(new Pen(Ref, 1, dashStyle: new DashStyle(new double[] { 3, 3 }, 0)), new Point(0, Y(0)), new Point(w, Y(0)));- foreach (var (f, lbl) in new[] { (80.0, "80"), (400.0, "400"), (1500.0, "1.5 k"), (6000.0, "6 k") })- {- double gx = X(f);- ctx.DrawLine(new Pen(Grid, 1), new Point(gx, top), new Point(gx, bot));- var ft = new FormattedText(lbl, CultureInfo.InvariantCulture, FlowDirection.LeftToRight, Mono, 7, Axis);- ctx.DrawText(ft, new Point(Math.Min(gx + 2, w - ft.Width - 1), bot + 1));- }-- var geo = new StreamGeometry();- using (var g = geo.Open())- {- for (int i = 0; i <= 96; i++)- {- double f = FLo * Math.Pow(FHi / FLo, i / 96.0);- var pt = new Point(X(f), Y(DbAt(f)));- if (i == 0) g.BeginFigure(pt, false); else g.LineTo(pt);- }- g.EndFigure(false);- }- ctx.DrawGeometry(null, new Pen(Amber, NotaGraph.PrimaryWidth, lineJoin: PenLineJoin.Round), geo);- }-- // --- RBJ biquad coefficients + magnitude (mirrors Amp.h) ---- private readonly record struct Coef(double b0, double b1, double b2, double a1, double a2);- private static double W0(double f) => 2 * Math.PI * Math.Clamp(f, 10, Sr * 0.45) / Sr;- private static Coef Norm(double b0, double b1, double b2, double a0, double a1, double a2)- => new(b0 / a0, b1 / a0, b2 / a0, a1 / a0, a2 / a0);- private static Coef BiPeak(double f, double dB, double q)- {- double w = W0(f), cw = Math.Cos(w), a = Math.Sin(w) / (2 * q), A = Math.Pow(10, dB / 40);- return Norm(1 + a * A, -2 * cw, 1 - a * A, 1 + a / A, -2 * cw, 1 - a / A);- }- private static Coef BiLowShelf(double f, double dB)- {- double w = W0(f), cw = Math.Cos(w), a = Math.Sin(w) / (2 * 0.707), A = Math.Pow(10, dB / 40), s = 2 * Math.Sqrt(A) * a;- return Norm(A * ((A + 1) - (A - 1) * cw + s), 2 * A * ((A - 1) - (A + 1) * cw), A * ((A + 1) - (A - 1) * cw - s),- (A + 1) + (A - 1) * cw + s, -2 * ((A - 1) + (A + 1) * cw), (A + 1) + (A - 1) * cw - s);- }- private static Coef BiHighShelf(double f, double dB)- {- double w = W0(f), cw = Math.Cos(w), a = Math.Sin(w) / (2 * 0.707), A = Math.Pow(10, dB / 40), s = 2 * Math.Sqrt(A) * a;- return Norm(A * ((A + 1) + (A - 1) * cw + s), -2 * A * ((A - 1) + (A + 1) * cw), A * ((A + 1) + (A - 1) * cw - s),- (A + 1) - (A - 1) * cw + s, 2 * ((A - 1) - (A + 1) * cw), (A + 1) - (A - 1) * cw - s);- }- private static double Mag(Coef c, double f)- {- double w = W0(f), cw = Math.Cos(w), c2 = Math.Cos(2 * w), sw = Math.Sin(w), s2 = Math.Sin(2 * w);- double nr = c.b0 + c.b1 * cw + c.b2 * c2, ni = -(c.b1 * sw + c.b2 * s2);- double dr = 1 + c.a1 * cw + c.a2 * c2, di = -(c.a1 * sw + c.a2 * s2);- return Math.Sqrt((nr * nr + ni * ni) / Math.Max(1e-12, dr * dr + di * di));- }-}diff --git a/src/managed/Nota.App/Controls/ValveViews.cs b/src/managed/Nota.App/Controls/ValveViews.csnew file mode 100644index 00000000..67c4496e--- /dev/null+++ b/src/managed/Nota.App/Controls/ValveViews.cs@@ -0,0 +1,97 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.+//+// Nota Valve card windows: VlResponseView — a magnitude response on a log-frequency grid,+// read from the engine (so the picture is the filters the amp runs): the curve now in brass,+// a reference dashed in teal (the tone stack flat, or the cabinet on axis) and an optional+// node. The Amp tab uses it for the tone stack (drag: sideways = the middle frequency, up /+// down = the middle), the Cab tab for the cabinet (sideways = off-axis, up / down = the mic+// distance). The Harmonics tab reuses VtHarmView.++using System;+using Avalonia;+using Avalonia.Media;++namespace Nota.App;++internal sealed class VlResponseView : VtWindowBase+{+ private float[] _now = Array.Empty<float>(), _ref = Array.Empty<float>();+ private int _n;+ private double _gridLo = 30, _gridHi = 16000, _nodeHz = double.NaN;+ private string _title = "", _legend = "";++ /// <summary>Visible band (Hz) and dB span; the frequency labels under the window.</summary>+ public double LoHz { get; init; } = 60;+ public double HiHz { get; init; } = 12000;+ public double TopDb { get; init; } = 15;+ public double BottomDb { get; init; } = -15;+ public double[] Ticks { get; init; } = Array.Empty<double>();++ /// <summary>The two responses (dB, n points from gridLo to gridHi on a log scale), the node's+ /// frequency (NaN = none; it sits on the curve), the title and the top-right legend.</summary>+ public void Set(float[] src, int nowAt, int refAt, int n, double gridLo, double gridHi, double nodeHz, string title, string legend)+ {+ if (_now.Length != n) { _now = new float[n]; _ref = new float[n]; }+ if (n > 0 && nowAt + n <= src.Length && refAt + n <= src.Length) { Array.Copy(src, nowAt, _now, 0, n); Array.Copy(src, refAt, _ref, 0, n); }+ _n = n; _gridLo = gridLo > 0 ? gridLo : 30; _gridHi = gridHi > _gridLo ? gridHi : 16000;+ _nodeHz = nodeHz; _title = title; _legend = legend;+ InvalidateVisual();+ }++ private double At(float[] a, double hz)+ {+ if (_n < 2) return 0;+ double t = Math.Log(hz / _gridLo) / Math.Log(_gridHi / _gridLo) * (_n - 1);+ t = Math.Clamp(t, 0, _n - 1);+ int i = (int)Math.Floor(t), j = Math.Min(_n - 1, i + 1);+ return a[i] + (a[j] - a[i]) * (t - i);+ }++ 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);+ double top = 14, bot = h - 12;+ double X(double hz) => Math.Log(hz / LoHz) / Math.Log(HiHz / LoHz) * w;+ double Y(double db) => top + (TopDb - Math.Clamp(db, BottomDb - 2, TopDb + 2)) / (TopDb - BottomDb) * (bot - top);++ foreach (double t in Ticks) ctx.DrawLine(NotaGraph.GridPen, new Point(X(t), 0), new Point(X(t), h));+ for (double db = Math.Ceiling(BottomDb / 6) * 6; db <= TopDb; db += 6)+ if (db > BottomDb) ctx.DrawLine(db == 0 ? new Pen(NotaPalette.BorderDefault, 1) : NotaGraph.GridPen, new Point(0, Y(db)), new Point(w, Y(db)));++ if (_n > 1)+ {+ StreamGeometry Line(float[] a)+ {+ var g = new StreamGeometry();+ using var c = g.Open();+ int px = Math.Max(2, (int)(w / 2));+ for (int x = 0; x <= px; x++)+ {+ double hz = LoHz * Math.Pow(HiHz / LoHz, (double)x / px);+ var p = new Point(x * w / px, Y(At(a, hz)));+ if (x == 0) c.BeginFigure(p, false); else c.LineTo(p);+ }+ c.EndFigure(false);+ return g;+ }+ ctx.DrawGeometry(null, new Pen(NotaPalette.Wash(NotaPalette.Teal, 0x90), 1.1, new DashStyle(new double[] { 4, 4 }, 0)), Line(_ref));+ ctx.DrawGeometry(null, NotaGraph.PrimaryPen, Line(_now));+ if (!double.IsNaN(_nodeHz)) NotaGraph.Node(ctx, new Point(X(_nodeHz), Y(At(_now, _nodeHz))), true);+ }++ NotaGraph.Title(ctx, frame, _title);+ NotaGraph.Axis(ctx, frame, NotaGraph.Corner.TopRight, _legend, NotaPalette.TealBright);+ for (int i = 0; i < Ticks.Length; i++)+ {+ double t = Ticks[i];+ bool near = !double.IsNaN(_nodeHz) && Math.Abs(Math.Log(t / _nodeHz)) < 0.25;+ var ft = NotaGraph.AxisText(t >= 1000 ? NotaNum.F($"{t / 1000:0.#} k") : NotaNum.F($"{t:0}"), near ? NotaPalette.AccentBright : null);+ double x = Math.Clamp(X(t) - ft.Width / 2, 4, Math.Max(4, w - ft.Width - 4));+ ctx.DrawText(ft, new Point(x, h - ft.Height - 2));+ }+ }+}diff --git a/src/managed/Nota.App/DeviceCards/Bodies/AmpDeviceBody.cs b/src/managed/Nota.App/DeviceCards/Bodies/AmpDeviceBody.csdeleted file mode 100644index 6b76fb74..00000000--- a/src/managed/Nota.App/DeviceCards/Bodies/AmpDeviceBody.cs+++ /dev/null@@ -1,186 +0,0 @@-// SPDX-License-Identifier: AGPL-3.0-only-// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.-//-// Detail · Devices — the built-in Amplifier (guitar amp, kind 6) body, mockup 2m: a full-// 700×260 shell. Model, Gain and Mix ride the LIVE strip; the body shows the waveshaper-// TRANSFER curve + HARMONICS spectrum (left), the TONE STACK with its own EQ response and the-// four tone knobs (middle), and a CABINET/OUTPUT rail (cab type · mic · axis · gate · output).-// Was "Nota Amp". The transfer / harmonics / EQ maths mirror Amp.h so picture == sound.--using System;-using Avalonia;-using Avalonia.Controls;-using Avalonia.Input;-using Avalonia.Layout;-using Avalonia.Media;-using Nota.Application;--namespace Nota.App;--internal sealed class AmpDeviceBody : IDeviceBody-{- // Param indices — mirror Amp.h.- private const int PModel = 0, PGain = 1, PBass = 2, PMiddle = 3, PTreble = 4, PPresence = 5,- POutput = 6, PMix = 7, PCabOn = 8, PCabType = 9, PMic = 10, PAxis = 11, PGate = 12, POs = 13;- private static readonly string[] Models = { "Clean", "Boost", "Blues", "Rock", "Lead", "Heavy", "Bass" };- private static readonly string[] OsNames = { "Off", "2×", "4×", "8×" };- private static readonly float[] DriveMul = { 1.5f, 3.0f, 6.0f, 12.0f, 22.0f, 40.0f, 4.0f };- private static readonly int[] Stages = { 1, 1, 1, 2, 2, 3, 1 };- private static readonly float[] Bias = { 0.00f, 0.05f, 0.10f, 0.15f, 0.20f, 0.28f, 0.00f };- private static readonly string[] Cabs = { "Match", "1×12", "2×12", "4×12", "1×15" };- private static readonly string[] Mics = { "Dyn", "Cond", "Rib" };-- private static readonly IBrush HdrBg = NotaPalette.SurfaceCard;- private static readonly IBrush Rail = NotaPalette.SurfaceInset;- private static readonly IBrush Bd = NotaPalette.BorderDefault;- private static readonly IBrush Inset = NotaPalette.BgSunken;- private static readonly IBrush Amber = NotaPalette.Accent;- private static readonly IBrush AmberLit = NotaPalette.AccentBright;- private static readonly IBrush Txt = NotaPalette.TextPrimary;- private static readonly IBrush Muted = NotaPalette.TextTertiary;- private static readonly IBrush Sub = NotaPalette.TextSecondary;- private static readonly IBrush Card = NotaPalette.SurfaceRaised;- private static readonly IBrush Ink = NotaPalette.TextOnAccent;- private static readonly IBrush AmberSubtle = NotaPalette.Wash(NotaPalette.Accent, 0x28);-- public double Width => 700;-- public string? Subtitle => "AMP SIM"; // the processing type, shown as the header badge- public bool FullBleed => true;-- public Control Build(DeviceCardContext ctx, int index)- {- var engine = ctx.Engine;- int track = ctx.TrackId, di = index;- float G(int p) => engine.DeviceGetParam(track, di, p);- void S(int p, double v) => engine.DeviceSetParam(track, di, p, (float)v);- void Begin(int p) => engine.BeginAutomationWrite(track, AutomationTarget.DeviceParam, di, p, "");- void End(int p) => engine.EndAutomationWrite(track, AutomationTarget.DeviceParam, di, p, "");- int Gi(int p) => (int)Math.Round(G(p));-- static TextBlock Cap(string t, IBrush? c = null, double fs = 8) => new() { Text = t, FontSize = fs, FontWeight = FontWeight.Bold, Foreground = c ?? Muted, VerticalAlignment = VerticalAlignment.Center };- static TextBlock Mono(string t, IBrush c, double fs = 9) { var tb = new TextBlock { Text = t, FontSize = fs, Foreground = c, VerticalAlignment = VerticalAlignment.Center }; tb.BindResource(TextBlock.FontFamilyProperty, "Font.Mono"); return tb; }-- // ---- viz ----- var transfer = new AmpCurve { VerticalAlignment = VerticalAlignment.Stretch, MinHeight = 60 };- var harm = new AmpHarmonics { Height = 54 };- var tone = new AmpToneCurve { Height = 56 };- void Sync()- {- int m = Math.Clamp(Gi(PModel), 0, 6);- float g01 = Math.Clamp(G(PGain) / 10f, 0f, 1f);- float drive = DriveMul[m] * (0.35f + g01 * g01 * 3f);- transfer.Set(drive, Stages[m], Bias[m], $"{Models[m]} · {G(PGain):0.0}");- harm.Set(drive, Stages[m], Bias[m]);- tone.Set(G(PBass), G(PMiddle), G(PTreble), G(PPresence));- }- ctx.AddDeviceRefresher(Sync);-- // ---- generic controls ----- Control MiniSlider(string label, int p, double min, double max, Func<double, string> fmt, double w)- {- var row = DeviceCardKit.SliderRow(label, () => (G(p) - min) / (max - min), n => { S(p, min + n * (max - min)); Sync(); }, () => fmt(G(p)), out var sync,- begin: () => Begin(p), end: () => End(p), trackWidth: w, valueWidth: 28);- ctx.AddDeviceRefresher(sync);- MidiLearn.Bind(row, MidiTarget.DeviceParam(track, di, p), label);- return row;- }- // Discrete chip group over a param (0..n-1).- Control Chips(int p, string[] names, double fs = 9, double padX = 5, double minW = 0)- {- var seg = DeviceCardKit.Segments(names, () => Math.Clamp(Gi(p), 0, names.Length - 1), iv => { S(p, iv); Sync(); }, out var sync, minSegWidth: minW);- ctx.AddDeviceRefresher(sync);- MidiLearn.Bind(seg, MidiTarget.DeviceParam(track, di, p), engine.DeviceParamName(track, di, p));- return seg;- }- // Oversampling quality chips (normalized param 0..1 → Off/2×/4×/8×).- Control OsChips()- {- var seg = DeviceCardKit.Segments(OsNames, () => Math.Clamp((int)Math.Round(G(POs) * 3), 0, 3), i => S(POs, i / 3f), out var sync, minSegWidth: 22);- ctx.AddDeviceRefresher(sync);- MidiLearn.Bind(seg, MidiTarget.DeviceParam(track, di, POs), engine.DeviceParamName(track, di, POs));- return seg;- }- // Segmented (inset frame) over a param.- Control Seg(int p, string[] names)- {- var seg = DeviceCardKit.Segments(names, () => Math.Clamp(Gi(p), 0, names.Length - 1), iv => S(p, iv), out var sync, fill: true);- ctx.AddDeviceRefresher(sync);- MidiLearn.Bind(seg, MidiTarget.DeviceParam(track, di, p), engine.DeviceParamName(track, di, p));- return seg;- }- Control MiniRow(string label, int p, Func<double, string> fmt)- {- var row = DeviceCardKit.SliderRow(label, () => G(p), n => S(p, n), () => fmt(G(p)), out var sync,- begin: () => Begin(p), end: () => End(p), labelWidth: 26, valueWidth: 34);- ctx.AddDeviceRefresher(sync);- return row;- }- Control Toggle(int p)- {- var sw = DeviceCardKit.Switch("", () => G(p) >= 0.5f, () => { S(p, G(p) >= 0.5f ? 0 : 1); Sync(); }, out var syncT);- ctx.AddDeviceRefresher(syncT);- return sw;- }-- // ---- LIVE strip ----- var liveL = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 10, VerticalAlignment = VerticalAlignment.Center, Children = { Chips(PModel, Models, 9, 5, 34), MiniSlider("GAIN", PGain, 0, 10, v => $"{v:0.0}", 62) } };- var mix = MiniSlider("MIX", PMix, 0, 1, v => $"{v * 100:0}\u2009%", 44); mix.HorizontalAlignment = HorizontalAlignment.Right;- var liveGrid = new Grid { ColumnDefinitions = new ColumnDefinitions("*,Auto") };- Grid.SetColumn(mix, 1); liveGrid.Children.Add(liveL); liveGrid.Children.Add(mix);- var liveStrip = new Border { Height = 34, Background = HdrBg, BorderBrush = Bd, BorderThickness = new Thickness(0, 0, 0, 1), Padding = new Thickness(9, 0), Child = liveGrid };-- // ---- left column: transfer + harmonics ----- var leftCol = new DockPanel { Width = 250, LastChildFill = true };- DockPanel.SetDock(harm, Dock.Bottom); harm.Margin = new Thickness(0, 5, 0, 0);- leftCol.Children.Add(harm); leftCol.Children.Add(transfer);- var leftPanel = new Border { Width = 250, Padding = new Thickness(8, 7), Child = leftCol };-- // ---- middle: tone stack ----- var toneHead = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 6, VerticalAlignment = VerticalAlignment.Center, Children = { Cap("TONE STACK"), Cap("pre-cab, model-dependent", Muted) } };- var toneKnobs = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 2, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center };- foreach (int p in new[] { PBass, PMiddle, PTreble, PPresence }) toneKnobs.Children.Add(DeviceParamControls.ParamRow(ctx, di, p));- var toneDock = new DockPanel { LastChildFill = true };- DockPanel.SetDock(toneHead, Dock.Top); DockPanel.SetDock(tone, Dock.Top); tone.Margin = new Thickness(0, 5, 0, 0);- toneDock.Children.Add(toneHead); toneDock.Children.Add(tone); toneDock.Children.Add(toneKnobs);- var tonePanel = new Border { Background = Rail, BorderBrush = Bd, BorderThickness = new Thickness(1, 0, 1, 0), Padding = new Thickness(9, 6), Child = toneDock };-- // ---- right rail: cabinet + output ----- var cabHead = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 5, VerticalAlignment = VerticalAlignment.Center, Children = { Toggle(PCabOn), Cap("CABINET") } };- // Lay the 5 cab chips as a 3×2 grid so they fit the 124px rail.- var cabGrid = new Grid { ColumnDefinitions = new ColumnDefinitions("*,*,*"), RowDefinitions = new RowDefinitions("Auto,Auto"), ColumnSpacing = 2, RowSpacing = 2 };- {- var arr = new Border[Cabs.Length];- void Hi() { int cur = Math.Clamp(Gi(PCabType), 0, Cabs.Length - 1); for (int i = 0; i < Cabs.Length; i++) { bool on = i == cur; arr[i].Background = on ? Amber : Card; arr[i].BorderBrush = on ? Amber : Bd; ((TextBlock)arr[i].Child!).Foreground = on ? NotaPalette.TextOnAccent : Sub; } }- for (int i = 0; i < Cabs.Length; i++) { int iv = i; var c = new Border { CornerRadius = NotaRadius.Badge, BorderThickness = new Thickness(1), Padding = new Thickness(0, 1), Cursor = new Cursor(StandardCursorType.Hand), Child = new TextBlock { Text = Cabs[i], FontSize = 8, FontWeight = FontWeight.SemiBold, Foreground = Sub, HorizontalAlignment = HorizontalAlignment.Center } }; c.PointerPressed += (_, _) => { S(PCabType, iv); Hi(); Sync(); }; arr[i] = c; Grid.SetColumn(c, i % 3); Grid.SetRow(c, i / 3); cabGrid.Children.Add(c); }- ctx.AddDeviceRefresher(Hi); Hi();- }- var micRow = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,*"), ColumnSpacing = 4, VerticalAlignment = VerticalAlignment.Center };- var micSeg = Seg(PMic, Mics); Grid.SetColumn(micSeg, 1); micRow.Children.Add(Cap("MIC")); micRow.Children.Add(micSeg);- var outKnob = DeviceParamControls.ParamRow(ctx, di, POutput);- var railStack = new StackPanel { Spacing = 5, Children =- {- cabHead, cabGrid, micRow,- MiniRow("AXIS", PAxis, v => v <= 0.02 ? "on" : $"off {v * 100:0}"),- new Border { Height = 1, Background = Card },- MiniRow("GATE", PGate, v => v <= 0.001 ? "off" : $"−{75 - v * 55:0.0}\u2009dB"),- new Border { Height = 1, Background = Card },- Cap("OVERSAMPLE"), OsChips(),- } };- var railDock = new DockPanel { LastChildFill = false, VerticalAlignment = VerticalAlignment.Stretch };- DockPanel.SetDock(railStack, Dock.Top);- var outWrap = new StackPanel { HorizontalAlignment = HorizontalAlignment.Center, Children = { outKnob } };- DockPanel.SetDock(outWrap, Dock.Bottom);- railDock.Children.Add(railStack); railDock.Children.Add(outWrap);- var rightRail = new Border { Width = 124, Background = Rail, Padding = new Thickness(8, 6), Child = railDock };-- var body = new DockPanel { LastChildFill = true };- DockPanel.SetDock(leftPanel, Dock.Left); DockPanel.SetDock(rightRail, Dock.Right);- body.Children.Add(leftPanel); body.Children.Add(rightRail); body.Children.Add(tonePanel);- var root = new DockPanel { LastChildFill = true, Background = NotaPalette.BgApp };- DockPanel.SetDock(liveStrip, Dock.Top); root.Children.Add(liveStrip); root.Children.Add(body);-- Sync();- return root;- }-}diff --git a/src/managed/Nota.App/DeviceCards/Bodies/ValveDeviceBody.cs b/src/managed/Nota.App/DeviceCards/Bodies/ValveDeviceBody.csnew file mode 100644index 00000000..9d2626fc--- /dev/null+++ b/src/managed/Nota.App/DeviceCards/Bodies/ValveDeviceBody.cs@@ -0,0 +1,664 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.+//+// Detail · Devices — built-in Nota Valve body (guitar amp, device kind 6), a build of the+// "Nota Valve" mockup (700 × 260) on the Vintage / Auto Filter / Lens frame: an always-+// visible STAGE column (gain · output faders), a centre panel with Amp / Cab / Harmonics+// tabs — the tone stack's response, the cabinet's response against on-axis, the harmonics+// the preamp adds — each with the model or cabinet list in its head row, a right panel with+// Cabinet / Output tabs, and a status strip. The responses and harmonics come from the+// engine (Amp.h scopeRead), so the picture is what the amp runs. Every control is a device+// param, so automation / MIDI learn / presets / A-B / persistence come for free.+// Params 0..13 are in raw units (Gain 0..10 …); the controls work on 0..1 and scale.+// FullBleed — the shared shell draws the header (name · preset · badge · bypass).++using System;+using System.Collections.Generic;+using Avalonia;+using Avalonia.Controls;+using Avalonia.Controls.Primitives;+using Avalonia.Input;+using Avalonia.Layout;+using Avalonia.Media;+using Nota.Application;+using static Nota.App.DeviceCardKit;++namespace Nota.App;++internal sealed class ValveDeviceBody : IDeviceBody+{+ // ── Parameter indices (must match Amp.h) ─────────────────────────────────+ private const int Model = 0, Gain = 1, Bass = 2, Middle = 3, Treble = 4, Presence = 5, Output = 6, Mix = 7,+ CabOn = 8, CabType = 9, Mic = 10, Axis = 11, Gate = 12, OS = 13, MidFreq = 14, MicDistance = 15, MicPosition = 16,+ LowCut = 17, HighCut = 18, EvenOnly = 19, AutoComp = 20, Bright = 21, Deep = 22, kParams = 23;+ // Scope layout (Amp::S_* / kTele / kResp).+ private const int S_InPk = 0, S_OutPk = 1, S_Cpu = 2, S_SampleRate = 3, S_Thd = 4, S_H1 = 5, S_TestLvl = 12, S_CompDb = 13,+ S_GateGain = 14, S_AliasDb = 15, S_CabLossDb = 19, S_MidHz = 20, S_RespLo = 24, S_RespHi = 25, S_RespN = 26,+ kTele = 32, kResp = 96;+ private const int kScope = kTele + 4 * kResp;+ private const int R_Tone = kTele, R_ToneFlat = kTele + kResp, R_Cab = kTele + 2 * kResp, R_CabRef = kTele + 3 * kResp;++ private static readonly string[] Models = { "Clean", "Boost", "Blues", "Rock", "Lead", "Heavy", "Bass" };+ private static readonly string[] Cabs = { "Match", "1×12 Open", "2×12 Combo", "4×12 Closed", "1×15 Bass" };+ private static readonly string[] CabShort = { "Match", "1×12", "2×12", "4×12", "1×15" };+ private static readonly string[] Mics = { "Dyn", "Cond", "Ribbon" };+ private static readonly string[] MicNames = { "dynamic", "condenser", "ribbon" };+ private static readonly string[] OsNames = { "Off", "2×", "4×", "8×" };++ public double Width => 700;+ public bool FullBleed => true;+ public string? Subtitle => "AMP SIM";++ public Control Build(DeviceCardContext ctx, int index)+ {+ var engine = ctx.Engine;+ int track = ctx.TrackId, di = index;+ var mx = new float[kParams];+ for (int p = 0; p < kParams; p++) mx[p] = Math.Max(1e-6f, engine.DeviceParamMax(track, di, p));+ float P(int p) => engine.DeviceGetParam(track, di, p);+ double N(int p) => P(p) / mx[p]; // 0..1 whatever the unit+ void Begin(int p) => engine.BeginAutomationWrite(track, AutomationTarget.DeviceParam, di, p, "");+ void End(int p) => engine.EndAutomationWrite(track, AutomationTarget.DeviceParam, di, p, "");+ void Raw(int p, float v) => engine.DeviceSetParam(track, di, p, Math.Clamp(v, 0f, mx[p]));+ void RawN(int p, double v) => Raw(p, (float)(Math.Clamp(v, 0, 1) * mx[p]));+ // 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); }+ double DefN(int p) => engine.DeviceParamDefault(track, di, p) / mx[p];+ bool On(int p) => P(p) >= 0.5f;+ int Idx(int p) => Math.Clamp((int)Math.Round(P(p)), 0, (int)Math.Round(mx[p])); // raw index params+ int Sel(int p, int n) => Math.Clamp((int)Math.Round(P(p) * (n - 1)), 0, n - 1); // normalized choices++ var readouts = new List<Action>();+ void RefreshAll() { for (int i = 0; i < readouts.Count; i++) readouts[i](); }+ var scope = new float[kScope];+ int scN = 0;+ double Sc(int i) => scN > i ? scope[i] : 0;++ // ---- units ----------------------------------------------------------------+ static double Exp(double v, double lo, double hi) => lo * Math.Pow(hi / lo, Math.Clamp(v, 0, 1));+ static string Pct(double v) => NotaNum.F($"{v * 100:0} %");+ static string Ten(double v) => NotaNum.F($"{v:0.0}");+ static string HzF(double hz) => hz >= 1000 ? NotaNum.F($"{hz / 1000:0.0#} k") : NotaNum.F($"{hz:0} Hz");+ static string OutDb(double v) => NotaNum.F($"{(v - 5) / 5 * 12:+0.0;−0.0;0.0} dB");+ static string DbF(double lin) => lin > 1e-5 ? NotaNum.F($"{20 * Math.Log10(lin):0.0;−0.0} dB") : "−∞ dB";+ static string DbfsF(double lin) => lin > 1e-5 ? NotaNum.F($"{20 * Math.Log10(lin):0.0;−0.0} dBFS") : "−∞ dBFS";+ static string ThdF(double v) => v < 0.001 ? "< 0.1 %" : NotaNum.F($"{v * 100:0.0} %");+ static string AxisF(double v) => v <= 0.005 ? "on" : NotaNum.F($"{v * 100:0} %");+ static string GateF(double v) => v <= 0.001 ? "off" : NotaNum.F($"−{75 - v * 55:0} dB");+ static string MidF(double v) => HzF(Exp(v, 200, 2000));+ static string DistF(double v) => NotaNum.F($"{Exp(v, 1, 30):0.#} cm");+ static string LowCutF(double v) => v <= 0.005 ? "off" : HzF(Exp(v, 20, 300));+ static string HighCutF(double v) => v >= 0.995 ? "off" : HzF(Exp(v, 2000, 20000));+ string ModelName() => Models[Idx(Model)];+ string OsText() => Sel(OS, 4) == 0 ? "no oversampling" : NotaNum.F($"{OsNames[Sel(OS, 4)]} OS");+ string AliasText() => Sc(S_AliasDb) <= -119 ? "aliasing < −120 dB" : NotaNum.F($"aliasing {Sc(S_AliasDb):0} dB");+ string AxisText() => P(Axis) <= 0.005f ? "on-axis" : NotaNum.F($"{P(Axis) * 100:0} % off-axis");+ string CabLine() => On(CabOn) ? NotaNum.F($"{CabShort[Idx(CabType)]} · {Mics[Idx(Mic)].ToLowerInvariant()} {AxisText()}") : "no cabinet";+ double H(int k) => Sc(S_H1 + k - 1); // harmonic k, dB re the fundamental+ string Dominant()+ {+ double even = 0, odd = 0;+ for (int k = 2; k <= 7; k++) { double pw = Math.Pow(10, H(k) / 10); if (k % 2 == 0) even += pw; else odd += pw; }+ if (even + odd < 1e-9) return "clean";+ return even > odd * 1.5 ? "even dominant" : odd > even * 1.5 ? "odd dominant" : "even + odd";+ }++ // ---- 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);+ // fmt gets the param's own value (raw units for 0..13).+ Control K(int p, string name, Func<double, string> fmt, IBrush? arc = null, double cellW = 44)+ {+ var val = Mono(fmt(P(p)), 7, TextPrimary);+ var knob = new Knob(N(p), 1.0) { Accent = true, ArcColor = arc, Default = DefN(p), Width = 34, Height = 34 };+ knob.ValueChanged += v => { RawN(p, v); val.Text = fmt(P(p)); };+ knob.GestureBegin += () => Begin(p);+ knob.GestureEnd += () => End(p);+ Learn(knob, p);+ readouts.Add(() => { if (knob.Dragging) return; double c = N(p); if (Math.Abs(c - knob.Value) > 1e-4) knob.Value = c; val.Text = fmt(P(p)); });+ return KnobCell(name, knob, val, cellW);+ }++ // On/off switch bound to a param (> 0.5 = on).+ Control Toggle(int p, string label, Func<string>? live = null)+ {+ var wrap = Switch(label, () => On(p), () => { SetP(p, On(p) ? 0f : 1f); RefreshAll(); }, out var sync, null, live);+ readouts.Add(sync);+ Learn(wrap, p);+ return wrap;+ }++ // Segmented pill over a normalized discrete param (n options spread over 0..1).+ Control Seg(int p, string[] names)+ {+ 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, padX: 6);+ readouts.Add(sync);+ Learn(seg, p);+ return seg;+ }++ // Outlined chips: lit = brass edge + wash.+ Control Chips(string[] names, Func<int, bool> lit, Action<int> pick, int learnParam, double h = 16, double padX = 7)+ {+ 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;+ }+ });+ if (learnParam >= 0) Learn(row, learnParam);+ return row;+ }+ Control IndexChips(int p, string[] names, double h = 16, double padX = 7)+ => Chips(names, i => Idx(p) == i, i => SetP(p, i), p, h, padX);++ // A latching chip: lit when `lit()`, a click runs `click`; its text can follow the value.+ Border Latch(int p, Func<bool> lit, Action click, Func<string> text, string tip, bool fill = false)+ {+ 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()+ {+ bool on = lit();+ 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; click(); RefreshAll(); e.Handled = true; };+ ToolTip.SetTip(b, tip);+ Learn(b, p);+ readouts.Add(Hi); Hi();+ return b;+ }+ Border ToggleLatch(int p, Func<string> text, string tip, bool fill = false)+ => Latch(p, () => On(p), () => SetP(p, On(p) ? 0f : 1f), text, tip, fill);++ // Slider row: caps label · track · mono value (the track works on 0..1).+ Control SliderRow(string label, int p, Func<double, string> fmt, bool bipolar = false, bool modulation = false, double labW = 40)+ {+ var bar = DeviceCardKit.SliderRow("", () => N(p), v => RawN(p, v), () => fmt(P(p)), out var sync,+ begin: () => Begin(p), end: () => End(p), reset: () => Reset(p), bipolar: bipolar, 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;+ }++ // A list box: [name ▾] opens the entries; the wheel steps through them.+ Control Drop(int p, string[] names, string tip)+ {+ var name = new TextBlock { FontSize = 8, FontWeight = FontWeight.SemiBold, Foreground = AccentBright, VerticalAlignment = VerticalAlignment.Center };+ var box = new Border+ {+ Height = 16, MinWidth = 74, Background = Sunken, BorderBrush = Brass, BorderThickness = new Thickness(1), CornerRadius = NotaRadius.Badge,+ Padding = new Thickness(6, 0), Cursor = new Cursor(StandardCursorType.Hand), VerticalAlignment = VerticalAlignment.Center,+ Child = new DockPanel { Children = { Docked(new Glyph(GlyphKind.ChevronDown, 7) { Foreground = NotaPalette.AccentDim, Margin = new Thickness(6, 0, 0, 0) }, Dock.Right), name } },+ };+ readouts.Add(() => name.Text = names[Idx(p)]);+ ToolTip.SetTip(box, tip);+ Learn(box, p);+ box.PointerPressed += (_, e) =>+ {+ if (!e.GetCurrentPoint(box).Properties.IsLeftButtonPressed) return;+ var fly = new MenuFlyout();+ int cur = Idx(p);+ for (int i = 0; i < names.Length; i++)+ {+ int iv = i;+ var mi = new MenuItem { Header = names[i] };+ if (i == cur) mi.Icon = new Avalonia.Controls.Shapes.Ellipse { Width = 6, Height = 6, Fill = Brass };+ mi.Click += (_, _) => { SetP(p, iv); RefreshAll(); };+ fly.Items.Add(mi);+ }+ fly.ShowAt(box);+ e.Handled = true;+ };+ box.PointerWheelChanged += (_, e) =>+ {+ int m = Math.Clamp(Idx(p) + (e.Delta.Y < 0 ? 1 : -1), 0, names.Length - 1);+ SetP(p, m); RefreshAll(); e.Handled = true;+ };+ return box;+ }+ Control ModelDrop() => Drop(Model, Models, "Model — the amp's voicing: how hard the preamp drives, how many stages clip, how tight the low end is and which cabinet it matches. Scroll to step.");+ Control CabDrop() => Drop(CabType, Cabs, "Cabinet — Match follows the model; the others bring their own low resonance and presence peak. Scroll to step.");++ 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;+ }+ Control KnobRow(Control[] knobs, Func<string> info1, Func<string> info2)+ {+ 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 } },+ };++ // ======================================================================+ // LEFT — STAGE column (gain · output)+ // ======================================================================+ Control StageFader(int p, string label, IBrush ink, string tip)+ {+ var f = new AfFader { Ink = ink, Width = 16, VerticalAlignment = VerticalAlignment.Stretch, Default = DefN(p) };+ f.Changed += v => { RawN(p, v); RefreshAll(); };+ f.GestureBegin += () => Begin(p);+ f.GestureEnd += () => End(p);+ Learn(f, p);+ ToolTip.SetTip(f, tip);+ readouts.Add(() => f.Set(N(p), 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 stageTitle = Caps("STAGE"); stageTitle.HorizontalAlignment = HorizontalAlignment.Center;+ var stageGain = Mono("", 7, AccentBright); stageGain.HorizontalAlignment = HorizontalAlignment.Center;+ var stageOut = Mono("", 7, TextPrimary); stageOut.HorizontalAlignment = HorizontalAlignment.Center;+ readouts.Add(() =>+ {+ stageGain.Text = Ten(P(Gain));+ stageOut.Text = OutDb(P(Output));+ stageTitle.Foreground = Sc(S_InPk) > 0.01 ? AccentBright : TextTertiary; // lit while signal passes+ });+ var faders = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,Auto"), ColumnSpacing = 9, HorizontalAlignment = HorizontalAlignment.Center, Margin = new Thickness(0, 4, 0, 4) };+ faders.Children.Add(StageFader(Gain, "GAIN", Brass, "Gain — how hard the signal hits the preamp. Double-click resets."));+ faders.Children.Add(Col(StageFader(Output, "OUT", Teal, "Output — the master level after the cabinet, ±12 dB. Double-click resets."), 1));+ var stageCol = 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(stageTitle, Dock.Top), Docked(stageOut, Dock.Bottom), Docked(stageGain, Dock.Bottom), faders } },+ };+ DockPanel.SetDock(stageCol, Dock.Left);++ // ======================================================================+ // CENTRE — Amp (tone stack)+ // ======================================================================+ VlResponseView? toneView = null;+ Control AmpTab()+ {+ toneView = new VlResponseView { LoHz = 60, HiHz = 9000, TopDb = 15, BottomDb = -15, Ticks = new double[] { 80, 400, 1500, 6000 } };+ toneView.StartV = () => N(Middle);+ toneView.StartH = () => P(MidFreq);+ toneView.DragV += v => RawN(Middle, v);+ toneView.DragH += v => Raw(MidFreq, (float)v);+ toneView.GestureBegin += () => { Begin(Middle); Begin(MidFreq); };+ toneView.GestureEnd += () => { End(Middle); End(MidFreq); };+ ToolTip.SetTip(toneView, "The tone stack before the cabinet — the pre-distortion tightness of the model, Bright, Bass / Middle / Treble / Presence and Deep; dashed is the stack flat. Drag sideways for the middle's frequency, up or down for the middle.");+ Learn(toneView, Middle);++ var thd = Mono("", 7, TextTertiary);+ readouts.Add(() => thd.Text = "THD " + ThdF(Sc(S_Thd)));+ var count = Mono("", 7, TextTertiary);+ readouts.Add(() => count.Text = NotaNum.F($"{Idx(Model) + 1} / {Models.Length}"));+ var head = HeadRow(Row(6, Caps("MODEL"), ModelDrop(), count, new Border { Width = 4 }, Caps("OS"), Seg(OS, OsNames)), thd);+ var knobs = KnobRow(new[]+ {+ K(Bass, "BASS", Ten),+ K(Middle, "MIDDLE", Ten),+ K(MidFreq, "MID FREQ", MidF),+ K(Treble, "TREBLE", Ten),+ K(Presence, "PRESENCE", Ten),+ },+ () => NotaNum.F($"peak {DbF(Sc(S_InPk))} → {DbF(Sc(S_OutPk))} · mix {Pct(P(Mix))}"),+ () => NotaNum.F($"{OsText()} · {AliasText()}"));+ return TabBody(head, toneView, knobs);+ }++ // ======================================================================+ // CENTRE — Cab (cabinet response)+ // ======================================================================+ VlResponseView? cabView = null;+ Control CabTab()+ {+ cabView = new VlResponseView { LoHz = 50, HiHz = 14000, TopDb = 10, BottomDb = -30, Ticks = new double[] { 60, 800, 4000, 12000 } };+ cabView.StartH = () => P(Axis);+ cabView.StartV = () => 1 - P(MicDistance);+ cabView.DragH += v => Raw(Axis, (float)v);+ cabView.DragV += v => Raw(MicDistance, (float)(1 - v));+ cabView.GestureBegin += () => { Begin(Axis); Begin(MicDistance); };+ cabView.GestureEnd += () => { End(Axis); End(MicDistance); };+ ToolTip.SetTip(cabView, "The cabinet as the mic hears it, with the low / high cuts — dashed is the same cab and mic on axis at the cap, 5 cm away. Drag sideways to move the mic off axis, up to bring it closer.");+ Learn(cabView, Axis);++ var loss = Mono("", 7, AccentBright);+ readouts.Add(() => loss.Text = On(CabOn) ? NotaNum.F($"{Sc(S_CabLossDb):+0.0;−0.0;0.0} dB @ 4 k") : "cabinet off");+ var mics = IndexChips(Mic, Mics);+ ToolTip.SetTip(mics, "Mic — Dynamic: the classic close mic; Condenser: brighter, less proximity bass; Ribbon: dark, the most proximity bass");+ var pos = Seg(MicPosition, new[] { "Cap", "Edge" });+ ToolTip.SetTip(pos, "Mic position — at the cone's cap (bright) or its edge (darker)");+ var head = HeadRow(Row(6, Caps("CAB"), CabDrop(), mics, pos), loss);+ var knobs = KnobRow(new[]+ {+ K(MicDistance, "DISTANCE", DistF),+ K(Axis, "AXIS", AxisF),+ K(LowCut, "LOW CUT", LowCutF, Teal),+ K(HighCut, "HIGH CUT", HighCutF, Teal),+ },+ () => On(CabOn) ? NotaNum.F($"{AxisText()} → {Sc(S_CabLossDb):+0.0;−0.0;0.0} dB at 4 kHz") : "cabinet off · cuts only",+ () => "cab model · minimum phase · latency 0");+ return TabBody(head, cabView, knobs);+ }++ // ======================================================================+ // CENTRE — Harmonics+ // ======================================================================+ VtHarmView? harm = null;+ Control HarmTab()+ {+ harm = new VtHarmView();+ harm.StartV = () => N(Gain);+ harm.DragV += v => RawN(Gain, v);+ harm.GestureBegin += () => Begin(Gain);+ harm.GestureEnd += () => End(Gain);+ ToolTip.SetTip(harm, "The harmonics the preamp adds at the input's level (the fundamental at the top). Drag up or down for the gain.");+ Learn(harm, Gain);++ var peak = Mono("", 7, AccentBright);+ readouts.Add(() => peak.Text = DbfsF(Sc(S_OutPk)));+ var even = ToggleLatch(EvenOnly, () => "Even only", "Even only — the preamp adds even harmonics only: warmth without the fizz of the odd ones");+ var head = HeadRow(Row(6, Caps("MODEL"), ModelDrop(), new Border { Width = 4 }, Caps("OS"), Seg(OS, OsNames), even), peak);+ var knobs = KnobRow(new[]+ {+ K(Gain, "GAIN", Ten),+ K(Mix, "MIX", Pct),+ K(Gate, "GATE", GateF, Teal),+ K(Output, "OUTPUT", OutDb),+ },+ () => H(2) > -100 || H(3) > -100 ? NotaNum.F($"2nd {H(2):0} dB · 3rd {H(3):0} dB · {Dominant()}") : "no harmonics — clean",+ () => NotaNum.F($"{OsText()} · {AliasText()}"));+ return TabBody(head, harm, knobs);+ }++ // ======================================================================+ // RIGHT — Cabinet / Output+ // ======================================================================+ int centreTab = 0;+ Control Box(Func<string> title, Func<string> line1, Func<string> line2, Func<bool>? lit = null)+ {+ var t = Caps("");+ var l1 = Mono("", 9, AccentBright);+ var l2 = Mono("", 8, TextSecondary);+ l1.TextTrimming = l2.TextTrimming = TextTrimming.CharacterEllipsis;+ var b = new Border { Background = Sunken, BorderThickness = new Thickness(1), CornerRadius = NotaRadius.Badge, Padding = new Thickness(6, 4),+ Child = new StackPanel { Spacing = 2, Children = { t, l1, l2 } } };+ readouts.Add(() =>+ {+ t.Text = title(); l1.Text = line1(); l2.Text = line2();+ bool on = lit?.Invoke() ?? false;+ b.BorderBrush = on ? NotaPalette.BorderBrass : NotaPalette.GraphBorder;+ t.Foreground = on ? AccentBright : TextTertiary;+ });+ return b;+ }+ static Control LabelRow(string label, Control c, double labW = 40)+ {+ var g = new Grid { ColumnDefinitions = new ColumnDefinitions(NotaNum.F($"{labW},*")) };+ g.Children.Add(new TextBlock { Text = label, FontSize = 7, FontWeight = FontWeight.Bold, Foreground = TextTertiary, LetterSpacing = 0.8, VerticalAlignment = VerticalAlignment.Center });+ g.Children.Add(Col(c, 1));+ return g;+ }+ static Control Spread(params Control[] rows)+ {+ var defs = new List<string>();+ for (int i = 0; i < rows.Length; i++) { if (i > 0) defs.Add("*"); defs.Add("Auto"); }+ var g = new Grid { RowDefinitions = new RowDefinitions(string.Join(",", defs)) };+ for (int i = 0; i < rows.Length; i++) g.Children.Add(GRow(rows[i], i * 2));+ return new Border { Padding = new Thickness(8, 6), Child = g };+ }++ // The gate switch is the Gate amount: off = 0, on = the last setting (or −59 dB).+ float lastGate = P(Gate) > 0.001f ? P(Gate) : 0.3f;+ Control GateToggle()+ {+ var wrap = Switch("Noise gate", () => P(Gate) > 0.001f, () =>+ {+ if (P(Gate) > 0.001f) { lastGate = P(Gate); SetP(Gate, 0f); } else SetP(Gate, lastGate);+ RefreshAll();+ }, out var sync, null, () => P(Gate) > 0.001f ? "Gate " + GateF(P(Gate)) + (Sc(S_GateGain) > 0.5 ? " · open" : " · shut") : "Noise gate");+ readouts.Add(sync);+ Learn(wrap, Gate);+ return wrap;+ }++ Control CabinetTab()+ {+ var cabs = IndexChips(CabType, CabShort, h: 15, padX: 3);+ ToolTip.SetTip(cabs, "Cabinet — Match follows the model; 1×12 open, 2×12 combo, 4×12 closed, 1×15 bass");+ var mics = IndexChips(Mic, Mics, h: 15, padX: 6);+ return Spread(+ LabelRow("CAB", cabs, 26),+ LabelRow("MIC", mics, 26),+ SliderRow("AXIS", Axis, AxisF, labW: 26),+ SliderRow("GATE", Gate, GateF, modulation: true, labW: 26),+ Box(() => centreTab == 1 ? "CABINET" : "MODEL",+ () => centreTab == 1 ? NotaNum.F($"{Cabs[Idx(CabType)]} · {Mics[Idx(Mic)]}") : NotaNum.F($"{ModelName()} · gain {Ten(P(Gain))}"),+ () => centreTab == 1+ ? (On(CabOn) ? NotaNum.F($"{DistF(P(MicDistance))} · {AxisText()} · {(On(MicPosition) ? "edge" : "cap")}") : "cabinet off")+ : (On(CabOn) ? (Idx(CabType) == 0 ? "cab by model · " : CabShort[Idx(CabType)] + " · ") + NotaNum.F($"{Mics[Idx(Mic)].ToLowerInvariant()} {AxisText()}") : "no cabinet"),+ () => centreTab == 1 && On(CabOn)),+ new StackPanel { Spacing = 5, Children = {+ Toggle(CabOn, "Cabinet sim"),+ GateToggle() } });+ }++ Control OutTab()+ {+ 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("THD", () => ThdF(Sc(S_Thd)), AccentBright) } },+ };+ var sliders = new StackPanel { Spacing = 6, Children = {+ SliderRow("MIX", Mix, Pct),+ SliderRow("GATE", Gate, GateF, modulation: true),+ SliderRow("OUTPUT", Output, OutDb, bipolar: true) } };+ var btns = new Grid { ColumnDefinitions = new ColumnDefinitions("*,*"), ColumnSpacing = 6 };+ btns.Children.Add(ToggleLatch(Bright, () => "Bright", "Bright — a treble lift before the preamp, strongest at low gain (the bright cap on a volume pot)", fill: true));+ btns.Children.Add(Col(ToggleLatch(Deep, () => "Deep", "Deep — a low resonance boost after the tone stack, for a fuller, tighter bottom", fill: true), 1));+ 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 = { Toggle(AutoComp, "Auto-compensation", () => On(AutoComp) ? NotaNum.F($"Auto-comp {Sc(S_CompDb):+0.0;−0.0;0.0} dB") : "Auto-compensation"), Toggle(EvenOnly, "Even harmonics only") } }, 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(() =>+ {+ string m = ModelName().ToLowerInvariant();+ extras.Text = centreTab switch+ {+ 1 => On(CabOn) ? NotaNum.F($"{Cabs[Idx(CabType)].ToLowerInvariant()} · {MicNames[Idx(Mic)]} · {AxisText()}") : "cabinet off",+ 2 => NotaNum.F($"{m} · {(Sel(OS, 4) == 0 ? "no OS" : OsNames[Sel(OS, 4)] + " OS")} · 2nd…7th"),+ _ => NotaNum.F($"tone stack before the cab · {m}"),+ };+ });+ Control CentreBody(int t) => centreBodies[t] ??= t switch { 1 => CabTab(), 2 => HarmTab(), _ => AmpTab() };+ Control RightBody(int t) => rightBodies[t] ??= t == 1 ? OutTab() : CabinetTab();++ var centre = TabFrame(new[] { "Amp", "Cab", "Harmonics" }, centreHost, CentreBody, false, t => { centreTab = t; Refresh(); }, extras);+ var rightFrame = TabFrame(new[] { "Cabinet", "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()+ {+ var parts = new List<string> { ModelName(), "gain " + Ten(P(Gain)) };+ switch (centreTab)+ {+ case 1:+ parts.Add(On(CabOn) ? CabShort[Idx(CabType)] : "no cab");+ if (On(CabOn))+ {+ parts.Add(NotaNum.F($"{Mics[Idx(Mic)]} {DistF(P(MicDistance))}"));+ parts.Add("axis " + AxisF(P(Axis)));+ if (On(MicPosition)) parts.Add("edge");+ }+ if (P(LowCut) > 0.005f || P(HighCut) < 0.995f)+ parts.Add(NotaNum.F($"{(P(LowCut) > 0.005f ? LowCutF(P(LowCut)) : "open")}…{(P(HighCut) < 0.995f ? HighCutF(P(HighCut)) : "open")}"));+ if (P(Gate) > 0.001f) parts.Add("gate " + GateF(P(Gate)));+ break;+ case 2:+ parts.Add("THD " + ThdF(Sc(S_Thd)));+ parts.Add("mix " + Pct(P(Mix)));+ if (P(Gate) > 0.001f) parts.Add("gate " + GateF(P(Gate)));+ parts.Add("out " + OutDb(P(Output)));+ if (On(EvenOnly)) parts.Add("even only");+ parts.Add(Sel(OS, 4) == 0 ? "OS off" : OsNames[Sel(OS, 4)] + " OS");+ break;+ default:+ parts.Add(NotaNum.F($"{Ten(P(Bass))} / {Ten(P(Middle))} / {Ten(P(Treble))} / {Ten(P(Presence))}"));+ parts.Add("mid " + MidF(P(MidFreq)));+ if (On(Bright)) parts.Add("bright");+ if (On(Deep)) parts.Add("deep");+ parts.Add(CabLine());+ parts.Add("mix " + Pct(P(Mix)));+ if (On(AutoComp)) parts.Add("auto-comp");+ break;+ }+ return string.Join(" · ", parts);+ }+ readouts.Add(() =>+ {+ 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 = { stageCol, right, centreBox } };+ var root = new DockPanel { LastChildFill = true, Background = NotaPalette.SurfaceInset, Children = { status, bodyRow } };++ void Refresh()+ {+ scN = engine.DeviceScope(track, di, scope, kScope);+ int n = scN >= kScope ? kResp : 0;+ double lo = Sc(S_RespLo), hi = Sc(S_RespHi);+ if (centreTab == 0 && toneView is not null && !toneView.Dragging)+ toneView.Set(scope, R_Tone, R_ToneFlat, n, lo, hi, Sc(S_MidHz) > 0 ? Sc(S_MidHz) : Exp(P(MidFreq), 200, 2000), "Tone stack", "flat");+ if (centreTab == 1 && cabView is not null && !cabView.Dragging)+ cabView.Set(scope, R_Cab, R_CabRef, n, lo, hi, On(CabOn) ? 4000 : double.NaN, "Cabinet response", On(CabOn) ? "on-axis" : "cabinet off");+ if (centreTab == 2 && harm is not null)+ harm.Set(scope, S_H1, -200, "THD " + ThdF(Sc(S_Thd)), "");+ RefreshAll();+ }+ ctx.AddDeviceRefresher(Refresh);+ Refresh();+ return root;++ // 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)+ {+ 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 } };+ }+ }+}diff --git a/src/managed/Nota.App/DeviceCards/DeviceCardFactory.cs b/src/managed/Nota.App/DeviceCards/DeviceCardFactory.csindex 34682cc5..ebcd6f18 100644--- a/src/managed/Nota.App/DeviceCards/DeviceCardFactory.cs+++ b/src/managed/Nota.App/DeviceCards/DeviceCardFactory.cs@@ -24,7 +24,7 @@ internal sealed class DeviceCardFactory[2] = new ReverbDeviceBody(),[3] = new DelayDeviceBody(),[4] = new UtilityDeviceBody(),- [6] = new AmpDeviceBody(),+ [6] = new ValveDeviceBody(),[7] = new AutoFilterDeviceBody(),[8] = new VintageDeviceBody(),[9] = new AutoPanDeviceBody(),diff --git a/src/managed/Nota.Infrastructure/Persistence/FactoryPresetCatalog.cs b/src/managed/Nota.Infrastructure/Persistence/FactoryPresetCatalog.csindex 76112299..05241337 100644--- a/src/managed/Nota.Infrastructure/Persistence/FactoryPresetCatalog.cs+++ b/src/managed/Nota.Infrastructure/Persistence/FactoryPresetCatalog.cs@@ -1201,14 +1201,53 @@ public sealed class FactoryPresetCatalog : IFactoryPresetsFx("util", 4, "Trim −6 dB", ("Gain", -6f));Fx("util", 4, "Swap L/R", ("Channel Mode", 3f));- // ---- Amplifier (kind 6) — Model 0..6, Gain/tone/Output 0..10, Mix 0..1;- // Cabinet 0 Match/1 1×12/2 2×12/3 4×12/4 1×15; Mic 0 Dyn/1 Cond/2 Rib; Axis/Gate 0..1- Fx("amp", 6, "Clean Combo", ("Model", 0f), ("Gain", 2.0f), ("Bass", 5f), ("Middle", 5f), ("Treble", 6f), ("Presence", 5f), ("Output", 5f), ("Mix", 1f), ("Cabinet", 1f), ("Mic", 1f));- Fx("amp", 6, "Blues Breakup", ("Model", 2f), ("Gain", 5.0f), ("Bass", 5f), ("Middle", 6f), ("Treble", 5f), ("Presence", 5f), ("Output", 5f), ("Mix", 1f), ("Cabinet", 2f));- Fx("amp", 6, "Rock Crunch", ("Model", 3f), ("Gain", 6.0f), ("Bass", 6f), ("Middle", 5f), ("Treble", 6f), ("Presence", 6f), ("Output", 4.5f), ("Mix", 1f), ("Cabinet", 3f));- Fx("amp", 6, "Lead Sustain", ("Model", 4f), ("Gain", 7.5f), ("Bass", 5f), ("Middle", 7f), ("Treble", 6f), ("Presence", 6f), ("Output", 4.5f), ("Mix", 1f), ("Cabinet", 3f), ("Gate", 0.25f));- 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));+ // ---- Nota Valve (kind 6) — the first 14 params keep their raw units: Model 0 Clean/1 Boost/+ // 2 Blues/3 Rock/4 Lead/5 Heavy/6 Bass; Gain / Bass / Middle / Treble / Presence / Output+ // 0..10 (tone and Output 5 = flat / 0 dB); Mix 0..1; Cab On 0/1; Cabinet 0 Match/1 1×12/+ // 2 2×12/3 4×12/4 1×15; Mic 0 Dyn/1 Cond/2 Ribbon; Axis / Gate 0..1; Oversampling .333 2×/+ // .667 4×. The appended ones are 0..1: Mid Freq 200·10^v Hz (.301 = 400, .398 = 500, .512 =+ // 650, .602 = 800, .699 = 1 k, .875 = 1.5 k); Mic Distance 1·30^v cm (.204 = 2, .323 = 3,+ // .473 = 5, .611 = 8); Mic Position 0 cap/1 edge; Low Cut 0 off, else 20·15^v Hz (.256 = 40,+ // .512 = 80, .594 = 100, .662 = 120); High Cut 1 off, else 2000·10^v Hz (.176 = 3 k, .398 =+ // 5 k, .477 = 6 k, .602 = 8 k); toggles 1 = on. Unnamed → default. Output level-matched.+ // Clean+ Fx("amp", 6, "Clean Combo", ("Model", 0f), ("Gain", 2.0f), ("Treble", 6f), ("Cabinet", 1f), ("Mic", 1f), ("Output", 4.12f));+ Fx("amp", 6, "Jazz Box", ("Model", 0f), ("Gain", 2.5f), ("Bass", 6f), ("Middle", 4.5f), ("Treble", 4f), ("Presence", 3.5f), ("Cabinet", 1f), ("Mic", 2f), ("Mic Distance", 0.611f), ("High Cut", 0.602f), ("Output", 4.25f));+ Fx("amp", 6, "Glassy Clean", ("Model", 0f), ("Gain", 2.0f), ("Treble", 6.5f), ("Presence", 6f), ("Bright", 1f), ("Cabinet", 2f), ("Mic", 1f), ("Axis", 0.1f), ("Output", 4.12f));+ Fx("amp", 6, "Funk Snap", ("Model", 0f), ("Gain", 3.0f), ("Middle", 6f), ("Mid Freq", 0.699f), ("Treble", 6.5f), ("Bright", 1f), ("Cabinet", 1f), ("Low Cut", 0.594f), ("Output", 3.5f));+ Fx("amp", 6, "Country Twang", ("Model", 1f), ("Gain", 3.5f), ("Bass", 4.5f), ("Middle", 4f), ("Mid Freq", 0.398f), ("Treble", 7f), ("Presence", 6.5f), ("Bright", 1f), ("Cabinet", 2f), ("Mic", 1f), ("Output", 4.33f));+ // Edge of breakup · blues+ Fx("amp", 6, "Blues Breakup", ("Model", 2f), ("Gain", 5.0f), ("Middle", 6f), ("Cabinet", 2f), ("Output", 4.17f));+ Fx("amp", 6, "Edge of Breakup", ("Model", 1f), ("Gain", 5.5f), ("Middle", 5.5f), ("Cabinet", 2f), ("Axis", 0.2f), ("Output", 3.71f));+ Fx("amp", 6, "Texas Blues", ("Model", 2f), ("Gain", 6.0f), ("Middle", 6.5f), ("Mid Freq", 0.602f), ("Treble", 5.5f), ("Cabinet", 2f), ("Mic Distance", 0.323f), ("Output", 4.46f));+ Fx("amp", 6, "Smooth Blues Lead", ("Model", 2f), ("Gain", 7.5f), ("Middle", 6f), ("Treble", 4.5f), ("Mic", 2f), ("Axis", 0.3f), ("Oversampling", 0.333f), ("Output", 5.33f));+ Fx("amp", 6, "Even Warmth", ("Model", 2f), ("Gain", 6.0f), ("Even Only", 1f), ("Deep", 1f), ("Auto Comp", 1f), ("Cabinet", 2f), ("Oversampling", 0.333f), ("Output", 5f));+ // Rock+ Fx("amp", 6, "Rock Crunch", ("Model", 3f), ("Gain", 6.0f), ("Bass", 6f), ("Treble", 6f), ("Presence", 6f), ("Cabinet", 3f), ("Output", 6.29f));+ Fx("amp", 6, "Classic Stack", ("Model", 3f), ("Gain", 6.5f), ("Bass", 6f), ("Middle", 6.5f), ("Treble", 6f), ("Presence", 6f), ("Cabinet", 3f), ("Mic Distance", 0.323f), ("Oversampling", 0.333f), ("Output", 5.71f));+ Fx("amp", 6, "Arena Rhythm", ("Model", 3f), ("Gain", 7.0f), ("Bass", 5.5f), ("Treble", 6f), ("Deep", 1f), ("Cabinet", 3f), ("Gate", 0.2f), ("Oversampling", 0.333f), ("Output", 6.67f));+ Fx("amp", 6, "Indie Jangle", ("Model", 1f), ("Gain", 4.0f), ("Middle", 4.5f), ("Mid Freq", 0.699f), ("Treble", 6.5f), ("Bright", 1f), ("Cabinet", 2f), ("Mic", 1f), ("Mic Distance", 0.611f), ("Output", 3.75f));+ Fx("amp", 6, "Garage Fuzz", ("Model", 3f), ("Gain", 9.5f), ("Bass", 6f), ("Middle", 7f), ("Mid Freq", 0.699f), ("Treble", 4f), ("Cabinet", 1f), ("Low Cut", 0.594f), ("High Cut", 0.398f), ("Oversampling", 0.333f), ("Output", 7.08f));+ // Lead+ Fx("amp", 6, "Lead Sustain", ("Model", 4f), ("Gain", 7.5f), ("Middle", 7f), ("Treble", 6f), ("Presence", 6f), ("Cabinet", 3f), ("Gate", 0.25f), ("Output", 6.92f));+ Fx("amp", 6, "Singing Lead", ("Model", 4f), ("Gain", 8.0f), ("Middle", 7f), ("Mid Freq", 0.602f), ("Treble", 5.5f), ("Deep", 1f), ("Cabinet", 3f), ("Axis", 0.25f), ("Gate", 0.2f), ("Oversampling", 0.667f), ("Output", 7.38f));+ Fx("amp", 6, "Shred Lead", ("Model", 4f), ("Gain", 9.0f), ("Middle", 6.5f), ("Mid Freq", 0.699f), ("Presence", 6.5f), ("Cabinet", 3f), ("Low Cut", 0.512f), ("Gate", 0.35f), ("Oversampling", 0.667f), ("Output", 8.12f));+ // Heavy+ Fx("amp", 6, "Heavy Chug", ("Model", 5f), ("Gain", 8.0f), ("Bass", 7f), ("Middle", 3.5f), ("Treble", 6f), ("Presence", 7f), ("Cabinet", 3f), ("Gate", 0.4f), ("Axis", 0.3f), ("Output", 9.58f));+ Fx("amp", 6, "Modern Metal", ("Model", 5f), ("Gain", 8.5f), ("Bass", 6f), ("Middle", 3.5f), ("Treble", 6.5f), ("Presence", 7f), ("Deep", 1f), ("Cabinet", 3f), ("Mic Distance", 0.204f), ("Low Cut", 0.512f), ("Gate", 0.45f), ("Oversampling", 0.667f), ("Output", 9.29f));+ Fx("amp", 6, "Doom Sludge", ("Model", 5f), ("Gain", 9.0f), ("Bass", 8f), ("Middle", 6f), ("Mid Freq", 0.301f), ("Treble", 3.5f), ("Presence", 3f), ("Deep", 1f), ("Cabinet", 3f), ("Mic", 2f), ("High Cut", 0.398f), ("Oversampling", 0.333f), ("Output", 8.04f));+ Fx("amp", 6, "Djent Tight", ("Model", 5f), ("Gain", 7.5f), ("Bass", 4.5f), ("Middle", 6f), ("Mid Freq", 0.602f), ("Treble", 6f), ("Presence", 7f), ("Cabinet", 3f), ("Low Cut", 0.662f), ("Gate", 0.5f), ("Oversampling", 0.667f), ("Output", 8.25f));+ // Bass+ Fx("amp", 6, "Bass Amp", ("Model", 6f), ("Gain", 3.0f), ("Bass", 7f), ("Treble", 4f), ("Presence", 3f), ("Cabinet", 4f), ("Output", 3.58f));+ Fx("amp", 6, "Bass Growl", ("Model", 6f), ("Gain", 7.0f), ("Bass", 6.5f), ("Middle", 6.5f), ("Mid Freq", 0.602f), ("Cabinet", 4f), ("Oversampling", 0.333f), ("Output", 4.25f));+ Fx("amp", 6, "Bass DI Clean", ("Model", 6f), ("Gain", 2.0f), ("Cab On", 0f), ("Bass", 6f), ("Treble", 5.5f), ("Low Cut", 0.256f), ("Output", 3.54f));+ Fx("amp", 6, "Bass Drive Blend", ("Model", 6f), ("Gain", 9.0f), ("Bass", 6f), ("Cabinet", 4f), ("Mix", 0.5f), ("Oversampling", 0.333f), ("Output", 5.46f));+ // Beyond guitar+ Fx("amp", 6, "Lo-Fi Radio Amp", ("Model", 0f), ("Gain", 5.0f), ("Middle", 7f), ("Mid Freq", 0.875f), ("Cabinet", 1f), ("Mic", 1f), ("Low Cut", 1f), ("High Cut", 0.176f), ("Output", 3.5f));+ Fx("amp", 6, "Keys Grit", ("Model", 1f), ("Gain", 5.0f), ("Treble", 5.5f), ("Cabinet", 2f), ("Mix", 0.7f), ("Oversampling", 0.333f), ("Output", 4.17f));+ Fx("amp", 6, "Vocal Tube Color", ("Model", 0f), ("Gain", 4.0f), ("Even Only", 1f), ("Cab On", 0f), ("Auto Comp", 1f), ("Mix", 0.6f), ("Oversampling", 0.333f));+ Fx("amp", 6, "Drum Crunch", ("Model", 3f), ("Gain", 6.0f), ("Cab On", 0f), ("Auto Comp", 1f), ("Mix", 0.4f), ("Oversampling", 0.333f));+ Fx("amp", 6, "Parallel Grind", ("Model", 5f), ("Gain", 7.0f), ("Cabinet", 3f), ("Auto Comp", 1f), ("Mix", 0.35f), ("Oversampling", 0.667f));// ---- 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 Amtdiff --git a/src/managed/Nota.Mcp/Tools/DeviceTools.cs b/src/managed/Nota.Mcp/Tools/DeviceTools.csindex d08b375e..33cd2d5e 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. 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. Nota Vintage (kind 8): id 0 = a one-line summary (character, drive, tone model and shelves, wow / flutter with their rates, noise, crackle, wear, stage, mix, output, oversampling, auto-comp), 1 = the live reading (in / out peaks, THD with the 2nd and 3rd harmonics, asymmetry, wow and flutter in cents, band-limit, hiss level, auto-comp gain), 2 = a guide to what each 0..1 parameter value means — or use read_vintage 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. Nota Vintage (kind 8): id 0 = a one-line summary (character, drive, tone model and shelves, wow / flutter with their rates, noise, crackle, wear, stage, mix, output, oversampling, auto-comp), 1 = the live reading (in / out peaks, THD with the 2nd and 3rd harmonics, asymmetry, wow and flutter in cents, band-limit, hiss level, auto-comp gain), 2 = a guide to what each 0..1 parameter value means — or use read_vintage for the numbers. Nota Valve (kind 6): id 0 = a one-line summary (model, gain, the tone stack with the middle's frequency, bright / deep, even-only, cabinet with mic, distance, axis and position, low / high cut, gate, mix, output, oversampling, auto-comp), 1 = the live reading (in / out peaks, THD with the 2nd and 3rd harmonics, estimated aliasing, drive, gate open / closed, auto-comp gain, the cab's loss at 4 kHz vs on-axis), 2 = a guide to the parameter values and units — or use read_valve 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). 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). Nota Vintage (kind 8): id 0 resets the wear (restarts the wow and flutter at their zero phase and silences a ringing crackle). 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). Nota Vintage (kind 8): id 0 resets the wear (restarts the wow and flutter at their zero phase and silences a ringing crackle). Nota Valve (kind 6): id 0 resets the amp (clears the filters, the gate and the auto-comp). 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));@@ -194,6 +194,50 @@ public sealed class DeviceTools(IAudioEngine engine, IEngineDispatch dispatch, IMath.Round(V(10)), Math.Round(V(11), 1), Math.Round(V(22), 1), V(3) > 0 ? Math.Round(V(5) / V(3) * 1000, 2) : 0, V(3));});+ public sealed record ValveResponsePoint(double Hz, double Db);+ public sealed record ValveReading(string Summary, string Live, string Model, double InputPeakDb, double OutputPeakDb,+ double ThdPercent, double TestLevelDb, double[] HarmonicsDb, double AliasingDb, int Oversampling, double Drive,+ bool GateOpen, double GateThresholdDb, double AutoCompDb, double MidHz, double CabLossAt4kDb, double MicDistanceCm,+ ValveResponsePoint[] ToneStack, ValveResponsePoint[] Cabinet, double SampleRate);++ [McpServerTool(Name = "read_valve"), Description(+ "Read what a Nota Valve (built-in effect kind 6, the guitar amp) is doing right now: the model (Clean / Boost / Blues / Rock / "+ + "Lead / Heavy / Bass), the input / output peaks, the preamp's THD at the input's level (or −6 dBFS when silent) with the "+ + "2nd…7th harmonics in dB relative to the fundamental, the estimated aliasing of a 2.5 kHz tone at the current oversampling, "+ + "the effective drive, whether the gate is open and its threshold, the auto-comp gain, the middle's frequency, how much the "+ + "mic placement costs at 4 kHz against on-axis, the mic distance, and the tone stack's and the cabinet's magnitude responses "+ + "(dB at 60, 120, 250, 500, 1k, 2k, 4k, 8k Hz — the cabinet including the low / high cuts). Peaks and the gate move only "+ + "while audio plays through the track. Use get_device_text id 2 for what each parameter value means.")]+ public Task<ValveReading> ReadValve(int trackId, int deviceIndex) => Read(() =>+ {+ const int tele = 32, resp = 96;+ var sc = new float[tele + 4 * resp];+ int n = E.DeviceScope(trackId, deviceIndex, sc, sc.Length);+ float V(int i) => n > i ? sc[i] : 0f;+ static double Db(float lin) => lin > 1e-6f ? Math.Round(20 * Math.Log10(lin), 1) : -120;+ string[] models = { "Clean", "Boost", "Blues", "Rock", "Lead", "Heavy", "Bass" };+ double lo = V(24) > 0 ? V(24) : 30, hi = V(25) > 0 ? V(25) : 16000;+ ValveResponsePoint[] Curve(int at)+ {+ double[] hz = { 60, 120, 250, 500, 1000, 2000, 4000, 8000 };+ var pts = new ValveResponsePoint[hz.Length];+ for (int i = 0; i < hz.Length; i++)+ {+ double t = Math.Clamp(Math.Log(hz[i] / lo) / Math.Log(hi / lo) * (resp - 1), 0, resp - 1);+ int a = (int)Math.Floor(t), b = Math.Min(resp - 1, a + 1);+ double db = n >= sc.Length ? sc[at + a] + (sc[at + b] - sc[at + a]) * (t - a) : 0;+ pts[i] = new ValveResponsePoint(hz[i], Math.Round(db, 1));+ }+ return pts;+ }+ var h = new double[6];+ for (int k = 0; k < 6; k++) h[k] = Math.Round(V(6 + k), 1);+ return new ValveReading(E.DeviceText(trackId, deviceIndex, 0), E.DeviceText(trackId, deviceIndex, 1),+ models[Math.Clamp((int)V(17), 0, 6)], Db(V(0)), Db(V(1)), Math.Round(V(4) * 100, 2), Db(V(12)), h, Math.Round(V(15), 1),+ Math.Max(1, (int)V(18)), Math.Round(V(16), 2), V(14) > 0.5f, Math.Round(V(23), 1), Math.Round(V(13), 1), Math.Round(V(20)),+ Math.Round(V(19), 1), Math.Round(V(27), 1), Curve(tele), Curve(tele + 2 * resp), V(3));+ });+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/Amp.h b/src/native/nota.engine/src/Amp.hindex 948b26ea..5fcf1d26 100644--- a/src/native/nota.engine/src/Amp.h+++ b/src/native/nota.engine/src/Amp.h@@ -1,13 +1,27 @@// SPDX-License-Identifier: AGPL-3.0-only// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.//-// Built-in guitar-amp emulation (Amp, device kind 6) — a classic guitar-amp-style-// insert. A preamp waveshaper (tanh cascade, per-model drive + bias) feeds a-// Fender/Marshall-ish tone stack (Bass/Middle/Treble + Presence) and a simple-// speaker-cabinet band-pass, then a master Output and Dry/Wet. Seven voicings-// from Clean to Heavy plus a Bass amp. All processing is memoryless per sample-// except the biquad filter states (per channel); coefficients are recomputed at-// block rate from the atomic params. A core Device (JUCE-free), lock-free params.+// Built-in Nota Valve (device kind 6, was "Amp") — a guitar-amp insert. A preamp+// waveshaper (tanh cascade, per-model drive + bias — or an even-harmonics-only stage)+// feeds a Bass / Middle (sweepable) / Treble / Presence tone stack with Bright and Deep+// switches, then a speaker cabinet (five cabs with their low resonance and presence+// peak; a Dynamic / Condenser / Ribbon mic at a distance, on or off axis, at the cap or+// the edge), low / high cuts, auto gain compensation, a noise gate keyed on the input,+// the master Output and Dry/Wet. Seven voicings from Clean to Heavy plus a Bass amp.+//+// in ─▶ pre-HP ─▶ bright ─▶ [oversampled preamp] ─▶ tone stack ─▶ deep ─▶ cabinet+// ─▶ low / high cut ─▶ makeup · auto-comp ─▶ output ─▶ gate ─▶ mix ─▶ out+//+// Header-only, allocation-free after construction. Params 0..13 keep their original raw+// units (Gain / tone / Output 0..10, Model / Cabinet / Mic indices) so older projects and+// presets load unchanged; the appended ones are normalized 0..1 and default to the old+// sound. Persistence / automation / clone flow generically through the base Device.+//+// Telemetry for the card and MCP (scopeRead): kTele live values, then four kResp-point+// magnitude responses in dB on a log grid 30 Hz … 16 kHz — the tone stack now, the tone+// stack flat (knobs at noon, no bright / deep), the cabinet now, the cabinet on axis+// (at the cap, 5 cm) — computed from the same coefficients process() runs.+// deviceText: 0 = status line, 1 = live reading, 2 = parameter guide.#pragma once@@ -16,20 +30,66 @@#include <algorithm>#include <atomic>+#include <chrono>#include <cmath>+#include <complex>#include <cstdint>+#include <cstdio>+#include <string>#include <vector>namespace nota {class Amp : public Device {public:- // Appended for the mockup-2m rework (old projects default these to neutral / model-cab).+ // Param layout — order is the persisted/automation layout. APPEND ONLY.enum { Model = 0, Gain, Bass, Middle, Treble, Presence, Output, Mix,CabOn, CabType, Mic, Axis, Gate,- Oversampling, // 0..1 → Off/2×/4×/8× (appended last: keeps saved indices stable)+ Oversampling, // 0..1 → Off/2×/4×/8×+ MidFreq, // middle peak 200·10^v Hz (0.512 = 650 Hz, the old fixed one)+ MicDistance, // 1·30^v cm (0.473 = 5 cm = neutral proximity)+ MicPosition, // 0 cap, 1 edge (darker)+ LowCut, // 0 off, else 20·15^v Hz (12 dB/oct)+ HighCut, // 1 off, else 2000·10^v Hz (12 dB/oct)+ EvenOnly, // preamp adds even harmonics only+ AutoComp, // output level follows the input's+ Bright, // bright cap: treble lift before the preamp, strongest at low gain+ Deep, // low resonance boost after the tone stackkNumParams };+ // Telemetry slots (scopeRead).+ enum {+ S_InPk = 0, // input peak (decaying), linear+ S_OutPk, // output peak (decaying), linear+ S_Cpu, // share of real time spent in process()+ S_SampleRate,+ S_Thd, // THD of the preamp at the test level, 0..1+ S_H1, // harmonic levels 1..7, dB relative to the fundamental (H1 = 0)+ S_H7 = S_H1 + 6,+ S_TestLvl, // the level the THD was measured at (the input peak, or −6 dBFS)+ S_CompDb, // auto-comp gain now, dB+ S_GateGain, // gate gain now 0..1 (1 = open, or no gate)+ S_AliasDb, // estimated aliasing of a 2.5 kHz tone at the test level, dB re the fundamental+ S_Drive, // effective preamp drive+ S_Model,+ S_OsFactor, // 1 / 2 / 4 / 8+ S_CabLossDb, // the cabinet now vs on axis at 4 kHz, dB+ S_MidHz, // middle peak frequency+ S_CabLpHz, // cabinet band-pass edges+ S_CabHpHz,+ S_GateThrDb, // gate threshold dBFS (−120 = off)+ S_RespLoHz, // response grid+ S_RespHiHz,+ S_RespN,+ S_DistCm, // mic distance+ S_Reserved0, S_Reserved1, S_Reserved2, S_Reserved3, S_Reserved4,+ kTele = 32+ };+ static constexpr int kResp = 96;+ static constexpr double kRespLo = 30.0, kRespHi = 16000.0;+ static constexpr int kScopeTotal = kTele + 4 * kResp;+ enum { A_Reset = 0 }; // deviceAction ids+Amp() {p_[Model].store(2.0f); // Bluesp_[Gain].store(3.0f);@@ -40,106 +100,103 @@ public:p_[Output].store(5.0f);p_[Mix].store(1.0f);p_[CabOn].store(1.0f); // cabinet on = the pre-rework behaviour- p_[CabType].store(0.0f); // 0 = model-matched cab (no change)- p_[Mic].store(0.0f); // 0 = dynamic (no change)- p_[Axis].store(0.0f); // on-axis (no change)+ p_[CabType].store(0.0f); // 0 = model-matched cab+ p_[Mic].store(0.0f); // 0 = dynamic+ p_[Axis].store(0.0f); // on-axisp_[Gate].store(0.0f); // gate off+ p_[MidFreq].store(kMidFreqDefault);+ p_[MicDistance].store(kDistDefault);+ p_[HighCut].store(1.0f); // open}void setSampleRate(double sr, int32_t maxBlock) override {sr_ = sr > 0 ? sr : 44100.0;- for (int c = 0; c < 2; ++c) {- preHP_[c].reset(); bassSh_[c].reset(); midPk_[c].reset();- trebSh_[c].reset(); presSh_[c].reset(); cabLP_[c].reset(); cabHP_[c].reset();- gateEnv_[c] = 0.0f; gateGain_[c] = 1.0f;- }+ resetState();maxFrames_ = maxBlock > 0 ? maxBlock : 4096;os_.prepare(maxFrames_);dry_.assign(maxFrames_ * 2, 0.0f);+ srA_.store((float)sr_, std::memory_order_relaxed);+ }++ void deviceAction(int32_t id, int32_t, float) override {+ if (id == A_Reset) resetReq_.store(true, std::memory_order_relaxed);}void process(float* buf, int32_t frames) override {- const int m = std::clamp((int)std::lround(get(Model)), 0, kModels - 1);- const float g01 = std::clamp(get(Gain) / 10.0f, 0.0f, 1.0f);- const AmpModel& md = kModel[m];-- // Drive into the preamp: squared taper so the knob's top half is where the- // real breakup lives. Makeup counteracts the tanh loudness so voicings match.- const float drive = md.driveMul * (0.35f + g01 * g01 * 3.0f);- const float makeup = std::clamp(1.6f / std::sqrt(std::max(drive, 1e-3f)), 0.2f, 2.5f);- const float biasDC = std::tanh(md.bias);-- const float bassDb = (get(Bass) - 5.0f) / 5.0f * 12.0f;- const float midDb = (get(Middle) - 5.0f) / 5.0f * 10.0f;- const float trebDb = (get(Treble) - 5.0f) / 5.0f * 12.0f;- const float presDb = (get(Presence) - 5.0f) / 5.0f * 8.0f;+ const auto t0 = std::chrono::steady_clock::now();+ if (resetReq_.exchange(false, std::memory_order_relaxed)) resetState();++ const Params P = params();+ const Shaper sh = shaperFor(P);+ const Chain ch = chainFor(P, sr_);const float outGain = std::pow(10.0f, (get(Output) - 5.0f) / 5.0f * 12.0f / 20.0f);- const float mix = std::clamp(get(Mix), 0.0f, 1.0f);-- // Cabinet: model-matched band-pass shifted by the chosen cab size, mic and off-axis.- const bool cabOn = get(CabOn) >= 0.5f;- const int cabType = std::clamp((int)std::lround(get(CabType)), 0, kCabs - 1);- const int mic = std::clamp((int)std::lround(get(Mic)), 0, kMics - 1);- const float axis = std::clamp(get(Axis), 0.0f, 1.0f);- const double cabLpHz = std::clamp(md.cabLpHz * kCabLp[cabType] * kMicLp[mic] * (1.0 - axis * 0.45), 800.0, sr_ * 0.45);- const double cabHpHz = md.cabHpHz * kCabHp[cabType];-- // Gate: threshold + smoothing coefficients (0 = off).- const float gateAmt = std::clamp(get(Gate), 0.0f, 1.0f);- const float gateThr = gateAmt > 0.001f ? std::pow(10.0f, (-75.0f + gateAmt * 55.0f) / 20.0f) : 0.0f;-- // Recompute coefficients once per block (shared L/R; states stay per channel).- Biquad::Coef preHP = Biquad::highpass (sr_, md.preHpHz, 0.707);- Biquad::Coef bassSh = Biquad::lowShelf (sr_, 110.0, bassDb);- Biquad::Coef midPk = Biquad::peak (sr_, 650.0, midDb, 0.70);- Biquad::Coef trebSh = Biquad::highShelf(sr_, 3000.0, trebDb);- Biquad::Coef presSh = Biquad::highShelf(sr_, 4500.0, presDb);- Biquad::Coef cabHP = Biquad::highpass (sr_, cabHpHz, 0.707);- Biquad::Coef cabLP = Biquad::lowpass (sr_, cabLpHz, 0.707);+ const float mix = P.mix;+ const float gateThr = P.gate > 0.001f ? std::pow(10.0f, (-75.0f + P.gate * 55.0f) / 20.0f) : 0.0f;+ const double msA = std::exp(-1.0 / (0.3 * sr_)); // auto-comp RMS window+ const float compA = (float)std::exp(-1.0 / (0.05 * sr_));+ const float dcR = (float)std::exp(-2.0 * kPi * 8.0 / sr_);+for (int c = 0; c < 2; ++c) {- preHP_[c].set(preHP); bassSh_[c].set(bassSh); midPk_[c].set(midPk);- trebSh_[c].set(trebSh); presSh_[c].set(presSh); cabHP_[c].set(cabHP); cabLP_[c].set(cabLP);+ preHP_[c].set(ch.preHP); bright_[c].set(ch.bright);+ bassSh_[c].set(ch.bass); midPk_[c].set(ch.mid); trebSh_[c].set(ch.treb); presSh_[c].set(ch.pres); deep_[c].set(ch.deep);+ cabHP_[c].set(ch.cabHP); cabLP_[c].set(ch.cabLP); cabRes_[c].set(ch.cabRes); cabPk_[c].set(ch.cabPk);+ prox_[c].set(ch.prox); distSh_[c].set(ch.distSh); edge_[c].set(ch.edge);+ lowCut_[c].set(ch.lowCut); highCut_[c].set(ch.highCut);}- // Oversample the preamp waveshaper (the only aliasing source — the tone stack- // and cabinet are linear and stay at base rate; the pre-distortion high-pass- // runs at base rate before the up-sampling).- const int osIdx = std::clamp((int)std::lround(get(Oversampling) * 3.0f), 0, 3);- os_.setActive(1 << osIdx);-+ // Oversample the preamp waveshaper only (the only aliasing source — the filters are+ // linear and stay at base rate; the pre-HP and bright run before the up-sampling).+ os_.setActive(1 << P.os);if (frames > maxFrames_) frames = maxFrames_;+ float inPk = 0.0f, outPk = 0.0f, gateSum = 0.0f;- // Base-rate pre: stash the dry input, then replace the buffer with the- // pre-HP'd signal that feeds the (oversampled) shaper.+ // Base-rate pre: stash the dry input, then replace the buffer with what feeds the shaper.for (int32_t i = 0; i < frames; ++i) {for (int c = 0; c < 2; ++c) {const float in = buf[i * 2 + c];dry_[i * 2 + c] = in;- buf[i * 2 + c] = preHP_[c].process(in);+ inPk = std::max(inPk, std::fabs(in));+ buf[i * 2 + c] = bright_[c].process(preHP_[c].process(in));}}- // Oversampled memoryless preamp: drive + bias + cascaded soft clipping.- const int stages = md.stages;- os_.process(buf, frames, [&](float& l, float& r, int /*i*/) {- auto shape = [&](float x) {- x = x * drive + md.bias;- for (int s = 0; s < stages; ++s) { x = std::tanh(x); if (s < stages - 1) x *= 2.0f; }- return x - biasDC;- };- l = shape(l); r = shape(r);- });-- // Base-rate post: tone stack, cabinet, makeup/output, gate, dry/wet.+ os_.process(buf, frames, [&](float& l, float& r, int /*i*/) { l = sh.eval(l); r = sh.eval(r); });++ // Base-rate post: DC block, tone stack, deep, cabinet, cuts, makeup / auto-comp, output, gate, dry/wet.for (int32_t i = 0; i < frames; ++i) {+ float y[2];for (int c = 0; c < 2; ++c) {float x = buf[i * 2 + c];+ const float d = x - dcX_[c] + dcR * dcY_[c];+ dcX_[c] = x; dcY_[c] = d; x = d;x = bassSh_[c].process(x);x = midPk_[c].process(x);x = trebSh_[c].process(x);x = presSh_[c].process(x);- if (cabOn) { x = cabHP_[c].process(x); x = cabLP_[c].process(x); }- float wet = x * makeup * outGain;+ x = deep_[c].process(x);+ if (ch.cabOn) {+ x = cabHP_[c].process(x); x = cabLP_[c].process(x);+ x = cabRes_[c].process(x); x = cabPk_[c].process(x);+ x = prox_[c].process(x); x = distSh_[c].process(x); x = edge_[c].process(x);+ }+ x = lowCut_[c].process(x);+ x = highCut_[c].process(x);+ y[c] = x * sh.makeup;+ }+ if (P.autoComp) {+ const float dl = dry_[i * 2], dr = dry_[i * 2 + 1];+ inMs_ = inMs_ * msA + (1.0 - msA) * 0.5 * (dl * dl + dr * dr);+ wetMs_ = wetMs_ * msA + (1.0 - msA) * 0.5 * (y[0] * y[0] + y[1] * y[1]);+ if (inMs_ > 1e-8 && wetMs_ > 1e-10) {+ const float want = (float)std::clamp(std::sqrt(inMs_ / wetMs_), 0.125, 8.0); // ±18 dB+ compG_ = want + (compG_ - want) * compA;+ }+ y[0] *= compG_; y[1] *= compG_;+ } else if (compG_ != 1.0f) {+ compG_ = 1.0f; inMs_ = wetMs_ = 0.0;+ }+ for (int c = 0; c < 2; ++c) {+ float wet = y[c] * outGain;const float in = dry_[i * 2 + c];if (gateThr > 0.0f) { // noise gate keyed on the input levelconst float lvl = std::fabs(in);@@ -147,47 +204,367 @@ public:const float target = gateEnv_[c] > gateThr ? 1.0f : 0.0f;gateGain_[c] += (target - gateGain_[c]) * (target > gateGain_[c] ? 0.30f : 0.02f);wet *= gateGain_[c];+ } else {+ gateGain_[c] = 1.0f;}- buf[i * 2 + c] = in * (1.0f - mix) + wet * mix;+ const float o = in * (1.0f - mix) + wet * mix;+ buf[i * 2 + c] = o;+ outPk = std::max(outPk, std::fabs(o));}+ gateSum += 0.5f * (gateGain_[0] + gateGain_[1]);+ }++ 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);+ compA_.store(compG_, std::memory_order_relaxed);+ if (frames > 0) {+ gateA_.store(gateSum / (float)frames, std::memory_order_relaxed);+ 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);}}+ // Telemetry block, then the four responses (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 Params P = params();+ const Shaper sh = shaperFor(P);+ const double sr = sr_;+ float t[kTele] = {};+ 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] = (float)sr;+ const float lvl = t[S_InPk] > 0.004f ? std::min(t[S_InPk], 1.0f) : 0.5f;+ t[S_TestLvl] = lvl;+ double h[kHarm + 1] = {};+ harmonics(sh, lvl, h);+ double sq = 0.0;+ for (int k = 2; k <= 7; ++k) sq += h[k] * h[k];+ t[S_Thd] = h[1] > 1e-9 ? (float)(std::sqrt(sq) / h[1]) : 0.0f;+ for (int k = 1; k <= 7; ++k)+ t[S_H1 + k - 1] = h[1] > 1e-9 && h[k] > 1e-9 ? (float)std::max(-120.0, 20.0 * std::log10(h[k] / h[1])) : -120.0f;+ // Aliasing: the harmonics of a 2.5 kHz tone above the (oversampled) Nyquist fold back;+ // with oversampling only what folds below the base Nyquist survives the decimator.+ const int osF = 1 << P.os;+ const double fsOs = sr * osF;+ double al = 0.0;+ for (int k = 2; k <= kHarm; ++k) {+ const double fk = k * kAliasHz;+ if (fk <= 0.5 * fsOs) continue;+ double f = std::fmod(fk, fsOs);+ if (f > 0.5 * fsOs) f = fsOs - f;+ if (f < 0.5 * sr) al += h[k] * h[k];+ }+ t[S_AliasDb] = h[1] > 1e-9 && al > 1e-30 ? (float)std::max(-140.0, 10.0 * std::log10(al / (h[1] * h[1]))) : -140.0f;+ const float cg = compA_.load(std::memory_order_relaxed);+ t[S_CompDb] = P.autoComp && cg > 1e-6f ? 20.0f * std::log10(cg) : 0.0f;+ t[S_GateGain] = P.gate > 0.001f ? gateA_.load(std::memory_order_relaxed) : 1.0f;+ t[S_Drive] = sh.drive;+ t[S_Model] = (float)P.model;+ t[S_OsFactor] = (float)osF;+ const Chain ch = chainFor(P, sr);+ Params ref = P; ref.axis = 0.0f; ref.edge = false; ref.distCm = 5.0;+ const Chain chRef = chainFor(ref, sr);+ t[S_CabLossDb] = (float)(cabDb(ch, sr, 4000.0) - cabDb(chRef, sr, 4000.0));+ t[S_MidHz] = (float)P.midHz;+ t[S_CabLpHz] = (float)ch.cabLpHz;+ t[S_CabHpHz] = (float)ch.cabHpHz;+ t[S_GateThrDb] = P.gate > 0.001f ? -75.0f + P.gate * 55.0f : -120.0f;+ t[S_RespLoHz] = (float)kRespLo;+ t[S_RespHiHz] = (float)kRespHi;+ t[S_RespN] = (float)kResp;+ t[S_DistCm] = (float)P.distCm;+ Params flat = P;+ flat.bass = flat.middle = flat.treble = flat.presence = 5.0f; flat.bright = flat.deep = false;+ const Chain chFlat = chainFor(flat, sr);++ int32_t n = 0;+ for (int k = 0; k < kTele && n < maxSamples; ++k) out[n++] = t[k];+ for (int k = 0; k < kResp && n < maxSamples; ++k) out[n++] = (float)toneDb(ch, sr, respHz(k));+ for (int k = 0; k < kResp && n < maxSamples; ++k) out[n++] = (float)toneDb(chFlat, sr, respHz(k));+ for (int k = 0; k < kResp && n < maxSamples; ++k) out[n++] = (float)cabDb(ch, sr, respHz(k));+ for (int k = 0; k < kResp && n < maxSamples; ++k) out[n++] = (float)cabDb(chRef, sr, respHz(k));+ return n;+ }+const char* displayName() const override { return "Nota Valve"; }int32_t builtinKind() const override { return 6; }int32_t paramCount() const override { return kNumParams; }const char* paramName(int32_t i) const override {- switch (i) {- case Model: return "Model"; case Gain: return "Gain"; case Bass: return "Bass";- case Middle: return "Middle"; case Treble: return "Treble"; case Presence: return "Presence";- case Output: return "Output"; case Mix: return "Mix";- case CabOn: return "Cab On"; case CabType: return "Cabinet"; case Mic: return "Mic";- case Axis: return "Axis"; case Gate: return "Gate";- case Oversampling: return "Oversampling"; default: return "";- }+ static const char* nm[kNumParams] = {+ "Model", "Gain", "Bass", "Middle", "Treble", "Presence", "Output", "Mix",+ "Cab On", "Cabinet", "Mic", "Axis", "Gate", "Oversampling",+ "Mid Freq", "Mic Distance", "Mic Position", "Low Cut", "High Cut", "Even Only", "Auto Comp", "Bright", "Deep" };+ return (i >= 0 && i < kNumParams) ? nm[i] : "";}float paramMin(int32_t /*i*/) const override { return 0.0f; }float paramMax(int32_t i) const override {- if (i == Model) return (float)(kModels - 1);- if (i == CabType) return (float)(kCabs - 1);- if (i == Mic) return (float)(kMics - 1);- if (i == Mix || i == CabOn || i == Axis || i == Gate || i == Oversampling) return 1.0f;- return 10.0f;+ switch (i) {+ case Model: return (float)(kModels - 1);+ case CabType: return (float)(kCabs - 1);+ case Mic: return (float)(kMics - 1);+ case Gain: case Bass: case Middle: case Treble: case Presence: case Output: return 10.0f;+ default: return 1.0f;+ }}float getParam(int32_t i) const override {return (i >= 0 && i < kNumParams) ? p_[i].load(std::memory_order_relaxed) : 0.0f;}void setParam(int32_t i, float v) override {- if (i >= 0 && i < kNumParams) p_[i].store(v, std::memory_order_relaxed);+ if (i >= 0 && i < kNumParams) p_[i].store(std::clamp(v, 0.0f, paramMax(i)), std::memory_order_relaxed);+ }++ // 0 — a one-line status; 1 — the live reading; 2 — a guide to the parameter values.+ std::string deviceText(int32_t id) const override {+ char b[1024];+ const Params P = params();+ if (id == 0) {+ std::string s = kModelName[P.model];+ std::snprintf(b, sizeof b, " - gain %.1f - bass %.1f / mid %.1f @ %s / treble %.1f / presence %.1f",+ get(Gain), P.bass, P.middle, hzText(P.midHz).c_str(), P.treble, P.presence);+ s += b;+ if (P.bright) s += " - bright";+ if (P.deep) s += " - deep";+ if (P.even) s += " - even harmonics only";+ if (P.cabOn) {+ std::snprintf(b, sizeof b, " - cab %s, %s mic %.0f cm, %s, %s", kCabName[P.cab], kMicName[P.mic], P.distCm,+ P.axis <= 0.005f ? "on-axis" : (std::to_string((int)std::lround(P.axis * 100)) + " % off-axis").c_str(),+ P.edge ? "edge" : "cap");+ s += b;+ } else {+ s += " - no cabinet";+ }+ if (P.lowCutHz > 0) s += " - low cut " + hzText(P.lowCutHz);+ if (P.highCutHz > 0) s += " - high cut " + hzText(P.highCutHz);+ if (P.gate > 0.001f) { std::snprintf(b, sizeof b, " - gate %.0f dB", -75.0f + P.gate * 55.0f); s += b; }+ std::snprintf(b, sizeof b, " - mix %.0f %% - out %+.1f dB - OS %s%s", P.mix * 100.0f, (get(Output) - 5.0f) / 5.0f * 12.0f,+ kOsName[P.os], P.autoComp ? " - auto-comp" : "");+ s += b;+ return s;+ }+ if (id == 1) {+ float sc[kTele];+ scopeRead(sc, kTele);+ auto db = [](float lin) { return lin > 1e-6f ? 20.0f * std::log10(lin) : -120.0f; };+ std::snprintf(b, sizeof b,+ "in %.1f dB - out %.1f dB - THD %.1f %% at %.1f dBFS (2nd %.0f dB, 3rd %.0f dB) - aliasing %.0f dB at %s OS - "+ "drive %.1f - gate %s - comp %+.1f dB - cab %+.1f dB at 4 kHz vs on-axis",+ db(sc[S_InPk]), db(sc[S_OutPk]), sc[S_Thd] * 100.0f, db(sc[S_TestLvl]), sc[S_H1 + 1], sc[S_H1 + 2],+ sc[S_AliasDb], kOsName[P.os], sc[S_Drive],+ P.gate <= 0.001f ? "off" : sc[S_GateGain] > 0.5f ? "open" : "closed", sc[S_CompDb], sc[S_CabLossDb]);+ return b;+ }+ if (id == 2) {+ return "Model: 0 Clean, 1 Boost, 2 Blues, 3 Rock, 4 Lead, 5 Heavy, 6 Bass. Gain 0..10. Bass / Middle / Treble / Presence 0..10, "+ "5 = flat (bass +/-12 dB shelf at 110 Hz, middle +/-10 dB peak, treble +/-12 dB shelf at 3 kHz, presence +/-8 dB at 4.5 kHz). "+ "Output 0..10, 5 = 0 dB, +/-12 dB. Mix 0..1. Cab On 0/1. Cabinet: 0 Match (the model's own), 1 1x12 Open, 2 2x12 Combo, "+ "3 4x12 Closed, 4 1x15 Bass. Mic: 0 Dynamic, 1 Condenser, 2 Ribbon. Axis 0..1: 0 on-axis, 1 fully off-axis (darker). "+ "Gate 0..1: 0 off, else threshold -75 + 55*v dBFS. Oversampling: 0 off, 0.333 2x, 0.667 4x, 1 8x. "+ "The rest are 0..1: Mid Freq 200*10^v Hz (0.512 = 650 Hz). Mic Distance 1*30^v cm (0.473 = 5 cm; closer = more "+ "proximity bass, farther = thinner and darker). Mic Position: 0 cap, 1 edge (darker). Low Cut: 0 off, else 20*15^v Hz. "+ "High Cut: 1 off, else 2000*10^v Hz. Even Only: the preamp adds even harmonics only. Auto Comp: output level matched to "+ "the input. Bright: treble lift before the preamp, strongest at low gain. Deep: low resonance boost. Toggles: >= 0.5 = on.";+ }+ return {};}private:+ static constexpr double kPi = 3.14159265358979323846;+ static constexpr int kModels = 7, kCabs = 5, kMics = 3;+ static constexpr int kHarm = 96, kDft = 256;+ static constexpr double kAliasHz = 2500.0;+ static constexpr float kMidFreqDefault = 0.5119f; // log10(650/200)+ static constexpr float kDistDefault = 0.4732f; // ln 5 / ln 30+ static constexpr const char* kModelName[kModels] = { "Clean", "Boost", "Blues", "Rock", "Lead", "Heavy", "Bass" };+ static constexpr const char* kCabName[kCabs] = { "Match", "1x12 Open", "2x12 Combo", "4x12 Closed", "1x15 Bass" };+ static constexpr const char* kMicName[kMics] = { "dynamic", "condenser", "ribbon" };+ static constexpr const char* kOsName[4] = { "off", "2x", "4x", "8x" };+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, "%.1f kHz", hz / 1000.0); else std::snprintf(b, sizeof b, "%.0f Hz", hz);+ return b;+ }+ static double respHz(int k) { return kRespLo * std::pow(kRespHi / kRespLo, (double)k / (kResp - 1)); }++ void resetState() {+ for (int c = 0; c < 2; ++c) {+ preHP_[c].reset(); bright_[c].reset(); bassSh_[c].reset(); midPk_[c].reset(); trebSh_[c].reset(); presSh_[c].reset();+ deep_[c].reset(); cabHP_[c].reset(); cabLP_[c].reset(); cabRes_[c].reset(); cabPk_[c].reset(); prox_[c].reset();+ distSh_[c].reset(); edge_[c].reset(); lowCut_[c].reset(); highCut_[c].reset();+ gateEnv_[c] = 0.0f; gateGain_[c] = 1.0f; dcX_[c] = dcY_[c] = 0.0f;+ }+ inMs_ = wetMs_ = 0.0; compG_ = 1.0f;+ }++ // Per-voicing character: preamp drive, clipping asymmetry + stage count, the+ // pre-distortion low-cut (tightness) and the speaker-cabinet band edges.+ struct AmpModel { float driveMul; float bias; int stages; float preHpHz; float cabHpHz; float cabLpHz; };+ static constexpr AmpModel kModel[kModels] = {+ /* Clean */ { 1.5f, 0.00f, 1, 20.0f, 70.0f, 7000.0f },+ /* Boost */ { 3.0f, 0.05f, 1, 30.0f, 75.0f, 6500.0f },+ /* Blues */ { 6.0f, 0.10f, 1, 45.0f, 80.0f, 6000.0f },+ /* Rock */ { 12.0f, 0.15f, 2, 70.0f, 85.0f, 5200.0f },+ /* Lead */ { 22.0f, 0.20f, 2, 95.0f, 90.0f, 5000.0f },+ /* Heavy */ { 40.0f, 0.28f, 3, 120.0f, 95.0f, 4500.0f },+ /* Bass */ { 4.0f, 0.00f, 1, 20.0f, 40.0f, 3800.0f },+ };+ // Cabinet / mic voicing: multipliers on the model's band-pass edges, plus each cab's low+ // resonance and presence peak. Index 0 = the model-matched cab (no peaks — the old sound).+ // Match 1×12 2×12 4×12 1×15+ static constexpr float kCabLp[kCabs] = { 1.00f, 0.90f, 1.00f, 1.15f, 0.72f };+ static constexpr float kCabHp[kCabs] = { 1.00f, 1.10f, 1.00f, 0.90f, 0.70f };+ static constexpr float kCabResHz[kCabs] = { 100.f, 125.f, 105.f, 90.f, 70.f };+ static constexpr float kCabResDb[kCabs] = { 0.0f, 2.0f, 3.0f, 4.5f, 4.0f };+ static constexpr float kCabPkHz[kCabs] = { 2500.f, 2200.f, 2600.f, 2900.f, 1800.f };+ static constexpr float kCabPkDb[kCabs] = { 0.0f, 3.0f, 3.0f, 4.0f, 2.0f };+ // Dyn Cond Ribbon+ static constexpr float kMicLp[kMics] = { 1.00f, 1.28f, 0.80f };+ static constexpr float kMicProx[kMics] = { 2.0f, 0.8f, 3.0f }; // dB of low shelf per halving of the distance under 5 cm++ // A snapshot of the params in musical terms (process() and the message thread alike).+ struct Params {+ int model, cab, mic, os;+ float g01, bass, middle, treble, presence, mix, axis, gate;+ double midHz, distCm, lowCutHz, highCutHz;+ bool cabOn, edge, even, autoComp, bright, deep;+ };+ Params params() const {+ Params P{};+ P.model = std::clamp((int)std::lround(get(Model)), 0, kModels - 1);+ P.cab = std::clamp((int)std::lround(get(CabType)), 0, kCabs - 1);+ P.mic = std::clamp((int)std::lround(get(Mic)), 0, kMics - 1);+ P.os = std::clamp((int)std::lround(get(Oversampling) * 3.0f), 0, 3);+ P.g01 = std::clamp(get(Gain) / 10.0f, 0.0f, 1.0f);+ P.bass = get(Bass); P.middle = get(Middle); P.treble = get(Treble); P.presence = get(Presence);+ P.mix = std::clamp(get(Mix), 0.0f, 1.0f);+ P.axis = std::clamp(get(Axis), 0.0f, 1.0f);+ P.gate = std::clamp(get(Gate), 0.0f, 1.0f);+ P.midHz = expMap(get(MidFreq), 200.0, 2000.0);+ P.distCm = expMap(get(MicDistance), 1.0, 30.0);+ P.lowCutHz = get(LowCut) > 0.005f ? expMap(get(LowCut), 20.0, 300.0) : 0.0;+ P.highCutHz = get(HighCut) < 0.995f ? expMap(get(HighCut), 2000.0, 20000.0) : 0.0;+ P.cabOn = get(CabOn) >= 0.5f;+ P.edge = get(MicPosition) >= 0.5f;+ P.even = get(EvenOnly) >= 0.5f;+ P.autoComp = get(AutoComp) >= 0.5f;+ P.bright = get(Bright) >= 0.5f;+ P.deep = get(Deep) >= 0.5f;+ return P;+ }++ // The memoryless preamp: the model's tanh cascade, or the even-harmonics-only stage.+ struct Shaper {+ float drive = 1.0f, bias = 0.0f, biasDC = 0.0f, makeup = 1.0f, evenAmt = 0.0f;+ int stages = 1;+ bool even = false;+ inline float eval(float x) const {+ if (even) {+ // An even function of the driven input added to the clean one: only even+ // harmonics (and DC, which the DC blocker removes).+ const float pre = x * drive * 0.5f;+ const float e = 0.5f * (std::tanh(pre + 0.6f) + std::tanh(0.6f - pre)) - 0.53705f; // tanh(0.6)+ return x - e * evenAmt;+ }+ float y = x * drive + bias;+ for (int s = 0; s < stages; ++s) { y = std::tanh(y); if (s < stages - 1) y *= 2.0f; }+ return y - biasDC;+ }+ };+ static Shaper shaperFor(const Params& P) {+ const AmpModel& md = kModel[P.model];+ Shaper s;+ // Drive into the preamp: squared taper so the knob's top half is where the real+ // breakup lives. Makeup counteracts the tanh loudness so voicings match.+ s.drive = md.driveMul * (0.35f + P.g01 * P.g01 * 3.0f);+ s.stages = md.stages;+ s.bias = md.bias;+ s.biasDC = std::tanh(md.bias);+ s.even = P.even;+ if (P.even) {+ s.evenAmt = 0.4f + 1.4f * P.g01;+ s.makeup = 1.0f;+ } else {+ s.makeup = std::clamp(1.6f / std::sqrt(std::max(s.drive, 1e-3f)), 0.2f, 2.5f);+ }+ return s;+ }++ // Every linear filter of the chain, from the params (process() and the responses alike).+ struct Chain {+ struct C { float b0 = 1, b1 = 0, b2 = 0, a1 = 0, a2 = 0; };+ C preHP, bright, bass, mid, treb, pres, deep;+ C cabHP, cabLP, cabRes, cabPk, prox, distSh, edge, lowCut, highCut;+ bool cabOn = true;+ double cabLpHz = 0, cabHpHz = 0;+ };+ static Chain chainFor(const Params& P, double sr) {+ const AmpModel& md = kModel[P.model];+ Chain c;+ c.preHP = Biquad::highpass (sr, md.preHpHz, 0.707);+ c.bright = Biquad::highShelf(sr, 2500.0, P.bright ? 6.0 * (1.0 - 0.7 * P.g01) : 0.0);+ c.bass = Biquad::lowShelf (sr, 110.0, (P.bass - 5.0f) / 5.0f * 12.0f);+ c.mid = Biquad::peak (sr, P.midHz, (P.middle - 5.0f) / 5.0f * 10.0f, 0.70);+ c.treb = Biquad::highShelf(sr, 3000.0, (P.treble - 5.0f) / 5.0f * 12.0f);+ c.pres = Biquad::highShelf(sr, 4500.0, (P.presence - 5.0f) / 5.0f * 8.0f);+ c.deep = Biquad::peak (sr, 85.0, P.deep ? 5.0 : 0.0, 0.9);+ c.cabOn = P.cabOn;+ c.cabLpHz = std::clamp(md.cabLpHz * kCabLp[P.cab] * kMicLp[P.mic] * (1.0 - P.axis * 0.45), 800.0, sr * 0.45);+ c.cabHpHz = md.cabHpHz * kCabHp[P.cab];+ c.cabHP = Biquad::highpass (sr, c.cabHpHz, 0.707);+ c.cabLP = Biquad::lowpass (sr, c.cabLpHz, 0.707);+ c.cabRes = Biquad::peak (sr, kCabResHz[P.cab], kCabResDb[P.cab], 1.4);+ c.cabPk = Biquad::peak (sr, kCabPkHz[P.cab], kCabPkDb[P.cab] * (1.0 - 0.6 * P.axis), 1.0);+ const double halvings = std::log2(5.0 / std::max(1.0, P.distCm)); // > 0 closer than 5 cm+ c.prox = Biquad::lowShelf (sr, 150.0, std::clamp(kMicProx[P.mic] * halvings, -6.0, 9.0));+ c.distSh = Biquad::highShelf(sr, 5000.0, std::min(0.0, halvings) * 2.0);+ c.edge = Biquad::highShelf(sr, 3000.0, (P.edge ? -4.5 : 0.0) - 6.0 * P.axis); // edge + off-axis beaming+ c.lowCut = P.lowCutHz > 0 ? Biquad::highpass(sr, P.lowCutHz, 0.707) : Chain::C{};+ c.highCut = P.highCutHz > 0 ? Biquad::lowpass(sr, P.highCutHz, 0.707) : Chain::C{};+ return c;+ }+ static double magDb(const Chain::C& c, double sr, double hz) {+ const double w = 2.0 * kPi * std::min(hz, sr * 0.499) / sr;+ const std::complex<double> z1 = std::polar(1.0, -w), z2 = z1 * z1;+ const std::complex<double> num = (double)c.b0 + (double)c.b1 * z1 + (double)c.b2 * z2;+ const std::complex<double> den = 1.0 + (double)c.a1 * z1 + (double)c.a2 * z2;+ const double m = std::abs(num) / std::max(1e-12, std::abs(den));+ return 20.0 * std::log10(std::max(m, 1e-9));+ }+ static double toneDb(const Chain& c, double sr, double hz) {+ return magDb(c.preHP, sr, hz) + magDb(c.bright, sr, hz) + magDb(c.bass, sr, hz) + magDb(c.mid, sr, hz)+ + magDb(c.treb, sr, hz) + magDb(c.pres, sr, hz) + magDb(c.deep, sr, hz);+ }+ static double cabDb(const Chain& c, double sr, double hz) {+ double d = magDb(c.lowCut, sr, hz) + magDb(c.highCut, sr, hz);+ if (c.cabOn)+ d += magDb(c.cabHP, sr, hz) + magDb(c.cabLP, sr, hz) + magDb(c.cabRes, sr, hz) + magDb(c.cabPk, sr, hz)+ + magDb(c.prox, sr, hz) + magDb(c.distSh, sr, hz) + magDb(c.edge, sr, hz);+ return d;+ }++ // Harmonic amplitudes 1..kHarm of the preamp driven by a sine of amplitude `a` (DFT, kDft pts).+ static void harmonics(const Shaper& sh, float a, double* h) {+ static const struct Tw { double c[kDft], s[kDft]; Tw() { for (int n = 0; n < kDft; ++n) { c[n] = std::cos(2.0 * kPi * n / kDft); s[n] = std::sin(2.0 * kPi * n / kDft); } } } tw;+ double y[kDft];+ for (int n = 0; n < kDft; ++n) y[n] = sh.eval(a * (float)tw.s[n]);+ for (int k = 1; k <= kHarm; ++k) {+ double re = 0.0, im = 0.0;+ for (int n = 0; n < kDft; ++n) { const int j = (k * n) & (kDft - 1); re += y[n] * tw.c[j]; im += y[n] * tw.s[j]; }+ h[k] = 2.0 * std::sqrt(re * re + im * im) / kDft;+ }+ }// RBJ biquad (transposed direct form II). Coeffs computed off-thread of state.struct Biquad {- struct Coef { float b0 = 1, b1 = 0, b2 = 0, a1 = 0, a2 = 0; };+ using Coef = Chain::C;float b0 = 1, b1 = 0, b2 = 0, a1 = 0, a2 = 0, z1 = 0, z2 = 0;void reset() { z1 = z2 = 0; }void set(const Coef& c) { b0 = c.b0; b1 = c.b1; b2 = c.b2; a1 = c.a1; a2 = c.a2; }@@ -203,7 +580,7 @@ private:}static double w0(double sr, double f) {f = std::clamp(f, 10.0, sr * 0.45);- return 2.0 * 3.14159265358979323846 * f / sr;+ return 2.0 * kPi * f / sr;}static Coef lowpass(double sr, double f, double q) {double w = w0(sr, f), cw = std::cos(w), a = std::sin(w) / (2.0 * q);@@ -214,45 +591,37 @@ private:return norm((1 + cw) / 2, -(1 + cw), (1 + cw) / 2, 1 + a, -2 * cw, 1 - a);}static Coef peak(double sr, double f, double dB, double q) {+ if (std::fabs(dB) < 1e-3) return Coef{};double w = w0(sr, f), cw = std::cos(w), a = std::sin(w) / (2.0 * q), A = std::pow(10.0, dB / 40.0);return norm(1 + a * A, -2 * cw, 1 - a * A, 1 + a / A, -2 * cw, 1 - a / A);}static Coef lowShelf(double sr, double f, double dB) {+ if (std::fabs(dB) < 1e-3) return Coef{};double w = w0(sr, f), cw = std::cos(w), a = std::sin(w) / (2.0 * 0.707), A = std::pow(10.0, dB / 40.0), s = 2 * std::sqrt(A) * a;return norm(A * ((A + 1) - (A - 1) * cw + s), 2 * A * ((A - 1) - (A + 1) * cw), A * ((A + 1) - (A - 1) * cw - s),(A + 1) + (A - 1) * cw + s, -2 * ((A - 1) + (A + 1) * cw), (A + 1) + (A - 1) * cw - s);}static Coef highShelf(double sr, double f, double dB) {+ if (std::fabs(dB) < 1e-3) return Coef{};double w = w0(sr, f), cw = std::cos(w), a = std::sin(w) / (2.0 * 0.707), A = std::pow(10.0, dB / 40.0), s = 2 * std::sqrt(A) * a;return norm(A * ((A + 1) + (A - 1) * cw + s), -2 * A * ((A - 1) + (A + 1) * cw), A * ((A + 1) + (A - 1) * cw - s),(A + 1) - (A - 1) * cw + s, 2 * ((A - 1) - (A + 1) * cw), (A + 1) - (A - 1) * cw - s);}};- // Per-voicing character: preamp drive, clipping asymmetry + stage count, the- // pre-distortion low-cut (tightness) and the speaker-cabinet band edges.- struct AmpModel { float driveMul; float bias; int stages; float preHpHz; float cabHpHz; float cabLpHz; };- static constexpr int kModels = 7;- // Cabinet / mic voicing: multipliers on the model's band-pass edges. Index 0 = neutral- // (model-matched cab / dynamic mic) so old projects at defaults sound identical.- static constexpr int kCabs = 5, kMics = 3; // Match · 1×12 · 2×12 · 4×12 · 1×15 / Dynamic · Condenser · Ribbon- static constexpr float kCabLp[kCabs] = { 1.00f, 0.90f, 1.00f, 1.15f, 0.72f };- static constexpr float kCabHp[kCabs] = { 1.00f, 1.10f, 1.00f, 0.90f, 0.70f };- static constexpr float kMicLp[kMics] = { 1.00f, 1.28f, 0.80f };- static constexpr AmpModel kModel[kModels] = {- /* Clean */ { 1.5f, 0.00f, 1, 20.0f, 70.0f, 7000.0f },- /* Boost */ { 3.0f, 0.05f, 1, 30.0f, 75.0f, 6500.0f },- /* Blues */ { 6.0f, 0.10f, 1, 45.0f, 80.0f, 6000.0f },- /* Rock */ { 12.0f, 0.15f, 2, 70.0f, 85.0f, 5200.0f },- /* Lead */ { 22.0f, 0.20f, 2, 95.0f, 90.0f, 5000.0f },- /* Heavy */ { 40.0f, 0.28f, 3, 120.0f, 95.0f, 4500.0f },- /* Bass */ { 4.0f, 0.00f, 1, 20.0f, 40.0f, 3800.0f },- };-double sr_ = 44100.0;std::atomic<float> p_[kNumParams] = {};- Biquad preHP_[2], bassSh_[2], midPk_[2], trebSh_[2], presSh_[2], cabLP_[2], cabHP_[2];+ Biquad preHP_[2], bright_[2], bassSh_[2], midPk_[2], trebSh_[2], presSh_[2], deep_[2];+ Biquad cabHP_[2], cabLP_[2], cabRes_[2], cabPk_[2], prox_[2], distSh_[2], edge_[2], lowCut_[2], highCut_[2];float gateEnv_[2] = {0, 0}, gateGain_[2] = {1, 1};+ float dcX_[2] = {0, 0}, dcY_[2] = {0, 0};+ double inMs_ = 0.0, wetMs_ = 0.0;+ float compG_ = 1.0f;+ std::atomic<bool> resetReq_{false};++ // Telemetry.+ double cpuS_ = 0.0;+ std::atomic<float> inPkA_{0}, outPkA_{0}, cpuA_{0}, srA_{44100.0f}, compA_{1}, gateA_{1};Oversampler os_; // preamp-waveshaper anti-aliasingint32_t maxFrames_ = 4096;diff --git a/tests/Nota.SmokeTest/Program.cs b/tests/Nota.SmokeTest/Program.csindex 845d227c..cc5f6c09 100644--- a/tests/Nota.SmokeTest/Program.cs+++ b/tests/Nota.SmokeTest/Program.cs@@ -3075,7 +3075,7 @@ Check(utilDev >= 0 && engine.DeviceName(fxT, utilDev) == "Nota Utility" && enginengine.DeviceSetParam(fxT, delDev, 12, 0.5f); // Delay Dry/Wet (index 12)Check(Math.Abs(engine.DeviceGetParam(fxT, delDev, 12) - 0.5f) < 0.001f, "Delay param round-trips");int ampDev = engine.AddBuiltinDevice(fxT, 6);-Check(ampDev >= 0 && engine.DeviceName(fxT, ampDev) == "Nota Valve" && engine.DeviceParamCount(fxT, ampDev) == 14, "add built-in Nota Valve (14 params)");+Check(ampDev >= 0 && engine.DeviceName(fxT, ampDev) == "Nota Valve" && engine.DeviceParamCount(fxT, ampDev) == 23, "add built-in Nota Valve (23 params)");Check(Math.Abs(engine.DeviceGetParam(fxT, ampDev, 0) - 2f) < 0.001f, $"Nota Valve defaults to Blues model (Model={engine.DeviceGetParam(fxT, ampDev, 0)})");Check(engine.DeviceParamName(fxT, ampDev, 8) == "Cab On" && engine.DeviceParamName(fxT, ampDev, 9) == "Cabinet"&& engine.DeviceParamName(fxT, ampDev, 11) == "Axis" && engine.DeviceParamName(fxT, ampDev, 12) == "Gate", "mockup-2m params present (Cab On/Cabinet/Axis/Gate)");@@ -6904,6 +6904,185 @@ Console.WriteLine("-- Auto Filter (effect kind 7) --");}}+// ===================== Nota Valve (effect kind 6) ==========================+Console.WriteLine("-- Nota Valve (effect kind 6) --");+{+ using var aveng = new NotaEngine();+ int avt = aveng.AddAudioTrack();+ aveng.AddAudioClip(avt, wav, 0.0);+ int avd = aveng.AddBuiltinDevice(avt, 6);+ Check(avd >= 0 && aveng.DeviceName(avt, avd) == "Nota Valve" && aveng.TrackDeviceBuiltinKind(avt, avd) == 6, "add Nota Valve (kind 6)");+ int avpc = aveng.DeviceParamCount(avt, avd);+ Check(avpc == 23, $"Nota Valve exposes 23 params ({avpc})");+ const int AModel = 0, AGain = 1, AMiddle = 3, AOutput = 6, AMix = 7, ACabOn = 8, ACab = 9, AMic = 10, AAxis = 11, AGate = 12, AOs = 13,+ AMidFreq = 14, ADist = 15, APos = 16, ALowCut = 17, AHighCut = 18, AEven = 19, AComp = 20, ABright = 21, ADeep = 22;+ Check(aveng.DeviceParamName(avt, avd, AMidFreq) == "Mid Freq" && aveng.DeviceParamName(avt, avd, ADist) == "Mic Distance"+ && aveng.DeviceParamName(avt, avd, APos) == "Mic Position" && aveng.DeviceParamName(avt, avd, ALowCut) == "Low Cut"+ && aveng.DeviceParamName(avt, avd, AHighCut) == "High Cut" && aveng.DeviceParamName(avt, avd, AEven) == "Even Only"+ && aveng.DeviceParamName(avt, avd, AComp) == "Auto Comp" && aveng.DeviceParamName(avt, avd, ABright) == "Bright"+ && aveng.DeviceParamName(avt, avd, ADeep) == "Deep",+ "appended params: Mid Freq · Mic Distance / Position · Low / High Cut · Even Only · Auto Comp · Bright · Deep");+ // The first 14 keep their raw units; the appended ones are 0..1 and default to the old sound.+ Check(Math.Abs(aveng.DeviceParamMax(avt, avd, AGain) - 10f) < 1e-6f && Math.Abs(aveng.DeviceParamMax(avt, avd, AModel) - 6f) < 1e-6f+ && Math.Abs(aveng.DeviceParamMax(avt, avd, AMidFreq) - 1f) < 1e-6f, "old params keep raw ranges, new ones are 0..1");+ Check(Math.Abs(aveng.DeviceParamDefault(avt, avd, AMidFreq) - 0.5119f) < 1e-3f && aveng.DeviceParamDefault(avt, avd, ALowCut) < 0.01f+ && aveng.DeviceParamDefault(avt, avd, AHighCut) > 0.99f && aveng.DeviceParamDefault(avt, avd, APos) < 0.5f+ && aveng.DeviceParamDefault(avt, avd, AEven) < 0.5f && aveng.DeviceParamDefault(avt, avd, AComp) < 0.5f+ && aveng.DeviceParamDefault(avt, avd, ABright) < 0.5f && aveng.DeviceParamDefault(avt, avd, ADeep) < 0.5f,+ "appended params default to the old sound (650 Hz mid, no cuts, cap, no even / comp / bright / deep)");+ aveng.DeviceSetParam(avt, avd, AGain, 7.5f);+ Check(Math.Abs(aveng.DeviceGetParam(avt, avd, AGain) - 7.5f) < 1e-3f, "device param set/get round-trips (raw units)");+ aveng.DeviceSetParam(avt, avd, AGain, 3f);++ var abuf = new float[4096 * 2];+ void ARender(int n = 4096) { aveng.SetBpm(120); aveng.Seek(0); aveng.Play(); for (int k = 0; k < n; k += 4096) aveng.RenderOffline(abuf, 4096); aveng.StopTransport(); }+ bool AFinite(float[] b) { foreach (var x in b) if (!float.IsFinite(x) || Math.Abs(x) > 8f) return false; return true; }++ // Every model × cabinet × mic renders audible + finite.+ int aBad = 0;+ for (int m = 0; m < 7; m++)+ for (int c = 0; c < 5; c++)+ {+ aveng.DeviceSetParam(avt, avd, AModel, m); aveng.DeviceSetParam(avt, avd, ACab, c); aveng.DeviceSetParam(avt, avd, AMic, c % 3);+ ARender();+ if (!(Rms(abuf, 4096) > 1e-4f && AFinite(abuf))) aBad++;+ }+ Check(aBad == 0, $"every model / cabinet / mic renders audible + stable ({aBad} failed)");+ aveng.DeviceSetParam(avt, avd, AModel, 3f); aveng.DeviceSetParam(avt, avd, ACab, 3f); aveng.DeviceSetParam(avt, avd, AMic, 0f);++ // Every new switch and range end renders audible + finite.+ int aSw = 0;+ foreach (var (p, v) in new[] { (AMidFreq, 0f), (AMidFreq, 1f), (ADist, 0f), (ADist, 1f), (APos, 1f), (ALowCut, 1f), (AHighCut, 0f),+ (AEven, 1f), (AComp, 1f), (ABright, 1f), (ADeep, 1f), (AOs, 1f), (ACabOn, 0f), (AAxis, 1f), (AGate, 0.3f) })+ {+ aveng.DeviceSetParam(avt, avd, p, v);+ ARender();+ if (!(Rms(abuf, 4096) > 1e-4f && AFinite(abuf))) aSw++;+ aveng.DeviceSetParam(avt, avd, p, aveng.DeviceParamDefault(avt, avd, p));+ }+ Check(aSw == 0, $"every mid / mic / cut / switch setting renders stable ({aSw} failed)");++ // Scope: telemetry + the four responses.+ const int aTele = 32, aResp = 96;+ var asc = new float[aTele + 4 * aResp];+ ARender(16384);+ int an = aveng.DeviceScope(avt, avd, asc, asc.Length);+ Check(an == asc.Length && asc[3] > 1000 && (int)asc[26] == aResp, $"Valve scope carries telemetry + responses ({an} values, sr {asc[3]:0})");+ Check(asc[0] > 0.01f && asc[1] > 0.01f, $"input / output peaks are metered ({asc[0]:0.00} → {asc[1]:0.00})");+ Check(asc[4] > 0.01f && asc[5] == 0f && asc[6] < 0f, $"THD and harmonics are measured (THD {asc[4] * 100:0.0} %, 2nd {asc[6]:0} dB)");+ float At(int at, double hz) { double t = Math.Log(hz / asc[24]) / Math.Log(asc[25] / asc[24]) * (aResp - 1); return asc[at + (int)Math.Round(Math.Clamp(t, 0, aResp - 1))]; }+ // Middle +: the tone response peaks near Mid Freq; the flat reference stays put.+ aveng.DeviceSetParam(avt, avd, AMiddle, 10f); aveng.DeviceSetParam(avt, avd, AMidFreq, 0.699f); // 1 kHz+ aveng.DeviceScope(avt, avd, asc, asc.Length);+ double boost = At(aTele, 1000) - At(aTele + aResp, 1000);+ Check(boost > 8 && Math.Abs(asc[20] - 1000) < 5, $"Middle boosts the tone stack at Mid Freq (+{boost:0.0} dB at {asc[20]:0} Hz)");+ aveng.DeviceSetParam(avt, avd, AMiddle, 5f); aveng.DeviceSetParam(avt, avd, AMidFreq, aveng.DeviceParamDefault(avt, avd, AMidFreq));+ // Off-axis darkens the cab against its on-axis reference; on-axis there is no loss.+ aveng.DeviceScope(avt, avd, asc, asc.Length);+ float loss0 = asc[19];+ aveng.DeviceSetParam(avt, avd, AAxis, 0.6f); aveng.DeviceScope(avt, avd, asc, asc.Length);+ Check(Math.Abs(loss0) < 0.05f && asc[19] < -3f && At(aTele + 2 * aResp, 6000) < At(aTele + 3 * aResp, 6000),+ $"off-axis darkens the cabinet ({loss0:0.0} → {asc[19]:0.0} dB at 4 kHz)");+ aveng.DeviceSetParam(avt, avd, AAxis, 0f);+ // Closer mic = more proximity bass.+ aveng.DeviceSetParam(avt, avd, ADist, 0f); aveng.DeviceScope(avt, avd, asc, asc.Length);+ Check(At(aTele + 2 * aResp, 150) - At(aTele + 3 * aResp, 150) > 2, "a close mic lifts the lows (proximity)");+ aveng.DeviceSetParam(avt, avd, ADist, aveng.DeviceParamDefault(avt, avd, ADist));+ // Oversampling lowers the aliasing estimate.+ aveng.DeviceSetParam(avt, avd, AGain, 9f); aveng.DeviceScope(avt, avd, asc, asc.Length);+ float alias1 = asc[15];+ aveng.DeviceSetParam(avt, avd, AOs, 1f); aveng.DeviceScope(avt, avd, asc, asc.Length);+ Check(asc[15] < alias1 - 10 && (int)asc[18] == 8, $"oversampling lowers the aliasing estimate ({alias1:0} → {asc[15]:0} dB at 8×)");+ aveng.DeviceSetParam(avt, avd, AOs, 0f);++ // Even Only: the 3rd harmonic falls away, the 2nd stays.+ float odd3 = asc[7];+ aveng.DeviceSetParam(avt, avd, AEven, 1f); aveng.DeviceScope(avt, avd, asc, asc.Length);+ Check(asc[7] < -80f && asc[6] > -60f && odd3 > -60f, $"Even Only drops the odd harmonics (3rd {odd3:0} → {asc[7]:0} dB, 2nd {asc[6]:0} dB)");+ aveng.DeviceSetParam(avt, avd, AEven, 0f);++ // Auto Comp pulls a hot / quiet amp toward the input level; Mix 0 = the dry signal.+ aveng.SetDeviceBypassed(avt, avd, true); ARender(); float aDry = Rms(abuf, 4096); aveng.SetDeviceBypassed(avt, avd, false);+ aveng.DeviceSetParam(avt, avd, AOutput, 10f);+ ARender(); float aHot = Rms(abuf, 4096);+ aveng.DeviceSetParam(avt, avd, AOutput, 5f); aveng.DeviceSetParam(avt, avd, AComp, 1f);+ ARender(16384); float aComped = Rms(abuf, 4096);+ Check(Math.Abs(20 * Math.Log10(aComped / aDry)) < 2.5 && Math.Abs(20 * Math.Log10(aHot / aDry)) > 3,+ $"Auto Comp matches the dry level ({20 * Math.Log10(aHot / aDry):+0.0;-0.0;0.0} dB at +12 → {20 * Math.Log10(aComped / aDry):+0.0;-0.0;0.0} dB)");+ aveng.DeviceSetParam(avt, avd, AComp, 0f);+ aveng.DeviceSetParam(avt, avd, AMix, 0f);+ ARender(); float aMix0 = Rms(abuf, 4096);+ Check(Math.Abs(aMix0 - aDry) < aDry * 0.02f, $"Mix 0 passes the dry signal ({aMix0:0.000} vs {aDry:0.000})");+ aveng.DeviceSetParam(avt, avd, AMix, 1f);++ // Texts + the reset action.+ aveng.DeviceSetParam(avt, avd, AGate, 0.4f);+ string atext = aveng.DeviceText(avt, avd, 0);+ Check(atext.StartsWith("Rock") && atext.Contains("4x12 Closed") && atext.Contains("gate"), $"status text names the model, cab and gate (got '{atext}')");+ Check(aveng.DeviceText(avt, avd, 1).Contains("THD") && aveng.DeviceText(avt, avd, 2).Contains("Mic Distance"), "live reading and parameter guide texts");+ aveng.DeviceAction(avt, avd, 0, 0, 0);+ ARender(); Check(AFinite(abuf) && Rms(abuf, 4096) > 1e-4f, "the reset action keeps the output audible and finite");++ // MCP: the amp reading.+ var atools = new Nota.Mcp.Tools.DeviceTools(aveng, new Nota.SmokeTest.SyncDispatch(), new Nota.SmokeTest.NoRefresh());+ ARender(16384);+ var ar = atools.ReadValve(avt, avd).Result;+ Check(ar.Model == "Rock" && ar.SampleRate > 1000 && ar.HarmonicsDb.Length == 6 && ar.ToneStack.Length == 8 && ar.Cabinet.Length == 8+ && ar.Summary.StartsWith("Rock") && ar.GateThresholdDb < -40 && ar.ThdPercent > 0,+ $"MCP read_valve reports the model, THD, responses and gate ({ar.Model}, THD {ar.ThdPercent:0.0} %, alias {ar.AliasingDb:0} dB)");+ aveng.DeviceSetParam(avt, avd, AGate, 0f);++ // Duplicate the track → cloneDevice(kind 6) must carry the params, appended ones too.+ aveng.DeviceSetParam(avt, avd, ADeep, 1f); aveng.DeviceSetParam(avt, avd, ALowCut, 0.5f);+ int acopy = aveng.DuplicateTrack(avt);+ Check(acopy > 0 && Math.Abs(aveng.DeviceGetParam(acopy, avd, AModel) - 3f) < 1e-3f && aveng.DeviceGetParam(acopy, avd, ADeep) > 0.9f+ && Math.Abs(aveng.DeviceGetParam(acopy, avd, ALowCut) - 0.5f) < 1e-3f, "duplicate track clones Valve params (appended ones too)");+ aveng.RemoveTrack(acopy);+ aveng.DeviceSetParam(avt, avd, ADeep, 0f); aveng.DeviceSetParam(avt, avd, ALowCut, 0f);++ // Automation drives an appended param and a raw-unit one.+ int alane = aveng.AddAutomationLane(avt, AutomationTarget.DeviceParam, avd, AMidFreq);+ aveng.SetAutomationPoints(avt, alane, new[] { new AutomationPoint(0, 0.9f), new AutomationPoint(16, 0.9f) });+ int alane2 = aveng.AddAutomationLane(avt, AutomationTarget.DeviceParam, avd, AGain);+ aveng.SetAutomationPoints(avt, alane2, new[] { new AutomationPoint(0, 0.8f), new AutomationPoint(16, 0.8f) });+ ARender();+ Check(Math.Abs(aveng.DeviceGetParam(avt, avd, AMidFreq) - 0.9f) < 0.01f, $"automation drives Mid Freq ({aveng.DeviceGetParam(avt, avd, AMidFreq):0.00})");+ Check(aveng.DeviceGetParam(avt, avd, AGain) > 0.5f, $"automation drives Gain ({aveng.DeviceGetParam(avt, avd, AGain):0.00})");+ aveng.RemoveAutomationLane(avt, alane2);+ aveng.RemoveAutomationLane(avt, alane);++ // Factory presets: ≥ 25, every named param exists, each applies in place, renders and sits near the dry level.+ {+ var names = new HashSet<string>();+ for (int k = 0; k < avpc; k++) names.Add(aveng.DeviceParamName(avt, avd, k));+ var cat = new FactoryPresetCatalog();+ var mine = cat.All().Where(p => !p.IsInstrument && !p.IsMidiEffect && p.BuiltinKind == 6).ToList();+ Check(mine.Count >= 25, $"Nota Valve 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 Valve preset param name exists{(bad.Count > 0 ? " — bad: " + string.Join(", ", bad) : "")}");+ aveng.SetDeviceBypassed(avt, avd, true); ARender(16384); float dryRef = Rms(abuf, 4096); aveng.SetDeviceBypassed(avt, avd, false);+ int pf = 0; var loud = new List<string>();+ foreach (var p in mine)+ {+ if (cat.ApplyInPlace(aveng, p.Id, avt, avd).Length != 0) { pf++; continue; }+ ARender(16384);+ float r = Rms(abuf, 4096);+ if (!AFinite(abuf) || r < 1e-4f) pf++;+ double db = 20 * Math.Log10(r / dryRef);+ if (Environment.GetEnvironmentVariable("NOTA_VALVE_LEVELS") == "1") Console.WriteLine($" level {p.DisplayName,-20} {db:+0.0;-0.0;0.0} dB (out {aveng.DeviceGetParam(avt, avd, AOutput):0.00})");+ if (Math.Abs(db) > 4) loud.Add($"{p.DisplayName} {db:+0.0;-0.0;0.0} dB");+ }+ Check(pf == 0, $"every Valve preset applies and renders ({pf} failed)");+ Check(loud.Count == 0, $"every Valve preset sits within ±4 dB of the dry level{(loud.Count > 0 ? " — " + string.Join(", ", loud) : "")}");+ cat.ApplyInPlace(aveng, "amp/Modern Metal", avt, avd);+ Check(Math.Abs(aveng.DeviceGetParam(avt, avd, AModel) - 5f) < 1e-3f && aveng.DeviceGetParam(avt, avd, ADeep) > 0.5f && aveng.DeviceGetParam(avt, avd, AGate) > 0.4f,+ "Modern Metal preset: Heavy + Deep + gate");+ cat.ApplyInPlace(aveng, "amp/Clean Combo", avt, avd);+ Check(aveng.DeviceGetParam(avt, avd, ADeep) < 0.5f && aveng.DeviceGetParam(avt, avd, AGate) < 0.001f && aveng.DeviceGetParam(avt, avd, AHighCut) > 0.99f,+ "unnamed params reset to defaults between presets");+ }+}+// ===================== Nota Vintage (effect kind 8) ========================Console.WriteLine("-- Nota Vintage (effect kind 8) --");{