Skip to content

armgit / nota

Public Imported from GitHub
0

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

Add Nota Prism, a three-band multiband dynamics effect

Egor Khindikaynen69b608ca17fc
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1e12178b..49db7e5b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,6 +19,18 @@ Entry categories: `Added`, `Changed`, `Fixed`, `Removed`.
## [Unreleased]
### Added
+- **Nota Prism — multiband dynamics.** A new built-in audio effect (kind 21) that splits the
+ signal into Low / Mid / High with phase-coherent crossovers — or two bands, or one — and gives
+ each band a compressor above a threshold and an expander (or an upward compressor, which lifts
+ quiet detail) below a second one, with their own attack and release. Drag the crossovers on
+ the live input/output spectrum, drag the threshold dots on the transfer curve, watch each
+ band's detector against its threshold on the *Time* tab, and solo a band to hear it alone.
+ Amount scales all the dynamics at once; there is Peak / RMS detection, auto release, lookahead
+ (latency-compensated), an external sidechain split into the same bands (with Listen), auto
+ makeup, Mix for parallel compression, output gain and a soft clip at −0.3 dBFS. The card
+ follows the design mockup (Global column, Bands / Band detail / Time and Meters / Output tabs,
+ a status line with CPU). 12 factory presets (Bus Glue, Upward Squash, Vocal Control, De-Esser
+ and more); every control can be automated, MIDI learned and A/B compared.
- **Nota Chamber — a hybrid reverb.** A new built-in audio effect (kind 20) that runs a
convolution reverb and an algorithmic reverb side by side, as in Ableton's Hybrid Reverb.
**Blend** mixes the two — in parallel, or in **Serial** with the convolution feeding the
diff --git a/FEATURES.md b/FEATURES.md
index 745d2332..31ff654a 100644
--- a/FEATURES.md
+++ b/FEATURES.md
@@ -277,6 +277,13 @@ and user presets, automation, persistence and cloning.
shifter; Blend (parallel or serial), separate free/synced pre-delays, a 4-band EQ at the
input / tail / output, ducking, width + bass mono, Dry/Wet, wet-only send mode. IR edits
morph the tail without clicks; user IRs persist in the project.
+- **Nota Prism** (21) — three-band dynamics (multiband compressor / expander): Linkwitz-Riley
+ crossovers dragged on a live input/output spectrum, 3 / 2 / 1-band modes; per band a
+ compressor above one threshold (ratio to ∞:1, knee) and an expander or upward compressor
+ below another (limited by Floor), each with its own attack/release (auto release above), plus
+ band gain and solo. Amount scales every ratio; Peak/RMS detection, lookahead (PDC), a
+ band-split external sidechain with Listen, auto makeup, Mix, output gain and a −0.3 dBFS soft
+ clip. Transfer curve with drag handles, detector-envelope trace, per-band GR meters.
- **Nota Chorus** — modulation (chorus) effect.
- **Forge**, **Valve** and **Vintage** each carry an **OVERSAMPLE** selector
(Off/2×/4×/8×) to suppress aliasing under heavy drive.
diff --git a/src/managed/Nota.App/ArrangementView.Automation.cs b/src/managed/Nota.App/ArrangementView.Automation.cs
index 4406b73d..5ae7e4cb 100644
--- a/src/managed/Nota.App/ArrangementView.Automation.cs
+++ b/src/managed/Nota.App/ArrangementView.Automation.cs
@@ -398,9 +398,10 @@ public sealed partial class ArrangementView
{
if (!sepAdded) { flyout.Items.Add(new Separator()); sepAdded = true; }
var devMenu = new MenuItem { Header = dn };
- // Nota Chamber (45 params) groups by its section prefix ("IR", "Algo", "EQ" …):
- // a word shared by two or more params becomes a submenu.
- bool grouped = e.TrackDeviceBuiltinKind(t.Id, d) == 20;
+ // Nota Chamber (45 params) groups by its section prefix ("IR", "Algo", "EQ" …),
+ // Nota Prism (52) by band ("Low", "Mid", "High", "Crossover"): a word shared
+ // by two or more params becomes a submenu.
+ bool grouped = e.TrackDeviceBuiltinKind(t.Id, d) is 20 or 21;
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/PrismViews.cs b/src/managed/Nota.App/Controls/PrismViews.cs
new file mode 100644
index 00000000..adc55ef0
--- /dev/null
+++ b/src/managed/Nota.App/Controls/PrismViews.cs
@@ -0,0 +1,473 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.
+//
+// Custom-drawn views for the Nota Prism card (multiband dynamics, device kind 21):
+// PrismSpectrum — the input spectrum (fill) and output spectrum (line) under the three band
+// tints; the crossover lines are drag handles (X = frequency).
+// PrismTransfer — the selected band's static curve (compression above + expansion / upward
+// compression below, knee, floor) with the live detector level riding on it;
+// drag a threshold dot ← → for the threshold, ↑ ↓ for the ratio.
+// PrismEnvTrace — the band's input peaks and its detector envelope against the threshold.
+// PrismGrMeter — a gain-reduction bar that grows down from the top (boost grows up), with
+// an optional peak-hold line.
+// Band colours follow the mockup: Low = mauve, Mid = brass, High = teal.
+
+using System;
+using System.Diagnostics;
+using System.Globalization;
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Input;
+using Avalonia.Media;
+using Nota.Application;
+
+namespace Nota.App;
+
+internal static class PrismInk
+{
+ public static readonly Color[] BandColor = { NotaPalette.TrackColors[7], NotaPalette.AccentColor, NotaPalette.TrackColors[4] };
+ public static readonly IBrush[] Band = { new SolidColorBrush(BandColor[0]), NotaPalette.Accent, NotaPalette.Teal };
+ // Text / handle tint for the selected band (the brass band lights up to AccentBright).
+ public static readonly IBrush[] BandLit = { Band[0], NotaPalette.AccentBright, Band[2] };
+ public static readonly string[] Names = { "Low", "Mid", "High" };
+ public static readonly IBrush InnerBorder = new SolidColorBrush(Color.Parse("#221F1A"));
+ public static readonly IPen InnerPen = new Pen(InnerBorder, 1);
+ private static readonly Typeface Mono = new("ui-monospace, Menlo, monospace");
+ private static readonly Typeface Sans = new("Inter, system-ui, sans-serif", FontStyle.Normal, FontWeight.Bold);
+
+ public static IBrush Alpha(Color c, byte a) => new SolidColorBrush(Color.FromArgb(a, c.R, c.G, c.B));
+ public static FormattedText Text(string s, double size, IBrush b) => new(s, CultureInfo.InvariantCulture, FlowDirection.LeftToRight, Mono, size, b);
+ public static FormattedText Caps(string s, double size, IBrush b) => new(s, CultureInfo.InvariantCulture, FlowDirection.LeftToRight, Sans, size, b);
+ public static double Db(double lin) => lin > 1e-6 ? 20 * Math.Log10(lin) : -120;
+ public static string HzShort(double hz) => hz >= 1000 ? (hz >= 10000 ? FormattableString.Invariant($"{hz / 1000:0}k") : FormattableString.Invariant($"{hz / 1000:0.0}k")) : FormattableString.Invariant($"{hz:0}");
+}
+
+// ---------------------------------------------------------------------------------------------
+// Spectrum + crossovers
+// ---------------------------------------------------------------------------------------------
+internal sealed class PrismSpectrum : Control
+{
+ private const int FftN = 2048, Bins = FftN / 2;
+ private const double TopDb = -6, BottomDb = -96;
+ private const double MinGap = 0.0335; // ⅓ octave in normalized crossover units (log 20 Hz … 20 kHz)
+ private static readonly IBrush InFill = PrismInk.Alpha(((ISolidColorBrush)NotaPalette.TextPrimary).Color, 0x12);
+ private readonly IAudioEngine _engine;
+ private readonly int _track, _device;
+ private readonly float[] _buf = new float[FftN];
+ private readonly double[] _re = new double[FftN], _im = new double[FftN], _hann = new double[FftN];
+ private readonly double[] _inDb = new double[Bins], _outDb = new double[Bins];
+ private double _sr = 48000, _xl = 0.318, _xh = 0.693;
+ private int _bands = 3, _sel = 1, _drag = -1, _hover = -1;
+
+ public double DefaultLow { get; set; } = 0.318;
+ public double DefaultHigh { get; set; } = 0.693;
+ public event Action<int, double>? CrossoverChanged; // (0 low / 1 high, normalized)
+ public event Action<int>? DragStarted;
+ public event Action<int>? DragEnded;
+ public event Action<int>? BandClicked;
+
+ public PrismSpectrum(IAudioEngine engine, int track, int device)
+ {
+ _engine = engine; _track = track; _device = device;
+ for (int i = 0; i < FftN; i++) _hann[i] = 0.5 - 0.5 * Math.Cos(2 * Math.PI * i / (FftN - 1));
+ Array.Fill(_inDb, -120); Array.Fill(_outDb, -120);
+ ClipToBounds = true;
+ }
+
+ public void Set(double xl, double xh, int bands, int sel, double sr)
+ {
+ if (sr > 0) _sr = sr;
+ if (_drag < 0) { _xl = xl; _xh = xh; }
+ _bands = bands; _sel = sel;
+ }
+
+ public void Tick()
+ {
+ if (!IsEffectivelyVisible) return;
+ Analyze(0, _inDb); Analyze(1, _outDb);
+ InvalidateVisual();
+ }
+
+ private void Analyze(int layer, double[] db)
+ {
+ int n = _engine.DeviceLayerWave(_track, _device, layer, _buf, FftN);
+ if (n < FftN) { for (int k = 1; k < Bins; k++) db[k] = Math.Max(-120, db[k] - 2.5); return; }
+ for (int i = 0; i < FftN; i++) { _re[i] = _buf[i] * _hann[i]; _im[i] = 0; }
+ Fft(_re, _im);
+ const double refMag = FftN / 4.0;
+ for (int k = 1; k < Bins; k++)
+ {
+ double mag = Math.Sqrt(_re[k] * _re[k] + _im[k] * _im[k]);
+ double d = 20 * Math.Log10(mag / refMag + 1e-9);
+ db[k] = d > db[k] ? d : Math.Max(d, db[k] - 2.5);
+ }
+ }
+
+ private double X(double v) => v * Bounds.Width;
+ private int HitLine(Point p)
+ {
+ if (_bands >= 2 && Math.Abs(p.X - X(_xl)) <= 6) return 0;
+ if (_bands >= 3 && Math.Abs(p.X - X(_xh)) <= 6) return 1;
+ return -1;
+ }
+
+ protected override void OnPointerMoved(PointerEventArgs e)
+ {
+ base.OnPointerMoved(e);
+ var p = e.GetPosition(this);
+ if (_drag >= 0)
+ {
+ double v = Math.Clamp(p.X / Math.Max(1, Bounds.Width), 0, 1);
+ if (_drag == 0) { v = Math.Min(v, _bands >= 3 ? _xh - MinGap : 0.97); _xl = v; }
+ else { v = Math.Max(v, _xl + MinGap); _xh = v; }
+ CrossoverChanged?.Invoke(_drag, v);
+ InvalidateVisual();
+ return;
+ }
+ int h = HitLine(p);
+ if (h != _hover) { _hover = h; Cursor = h >= 0 ? new Cursor(StandardCursorType.SizeWestEast) : new Cursor(StandardCursorType.Hand); InvalidateVisual(); }
+ }
+ protected override void OnPointerExited(PointerEventArgs e) { base.OnPointerExited(e); if (_hover >= 0) { _hover = -1; InvalidateVisual(); } }
+ protected override void OnPointerPressed(PointerPressedEventArgs e)
+ {
+ base.OnPointerPressed(e);
+ if (!e.GetCurrentPoint(this).Properties.IsLeftButtonPressed) return;
+ var p = e.GetPosition(this);
+ int h = HitLine(p);
+ if (h >= 0)
+ {
+ if (e.ClickCount == 2)
+ {
+ DragStarted?.Invoke(h);
+ double v = h == 0 ? DefaultLow : DefaultHigh;
+ if (h == 0) _xl = v; else _xh = v;
+ CrossoverChanged?.Invoke(h, v);
+ DragEnded?.Invoke(h);
+ }
+ else { _drag = h; DragStarted?.Invoke(h); e.Pointer.Capture(this); }
+ e.Handled = true; InvalidateVisual();
+ return;
+ }
+ double f = p.X / Math.Max(1, Bounds.Width);
+ int band = _bands == 1 ? 1 : f < _xl ? 0 : (_bands == 2 || f < _xh) ? 1 : 2;
+ BandClicked?.Invoke(band);
+ e.Handled = true;
+ }
+ protected override void OnPointerReleased(PointerReleasedEventArgs e)
+ {
+ base.OnPointerReleased(e);
+ if (_drag < 0) return;
+ int d = _drag; _drag = -1; e.Pointer.Capture(null); DragEnded?.Invoke(d); InvalidateVisual();
+ }
+
+ public override void Render(DrawingContext ctx)
+ {
+ double w = Bounds.Width, h = Bounds.Height;
+ if (w < 8 || h < 8) return;
+ var rect = new Rect(0, 0, w, h);
+ ctx.DrawRectangle(NotaPalette.BgSunken, null, rect, 4, 4);
+
+ // Band tints (the selected band a little stronger).
+ double[] edges = _bands switch { 1 => new[] { 0.0, 1.0 }, 2 => new[] { 0.0, _xl, 1.0 }, _ => new[] { 0.0, _xl, _xh, 1.0 } };
+ int[] ids = _bands switch { 1 => new[] { 1 }, 2 => new[] { 0, 1 }, _ => new[] { 0, 1, 2 } };
+ for (int i = 0; i < ids.Length; i++)
+ ctx.FillRectangle(PrismInk.Alpha(PrismInk.BandColor[ids[i]], ids[i] == _sel ? (byte)0x22 : (byte)0x14), new Rect(X(edges[i]), 0, X(edges[i + 1]) - X(edges[i]), h));
+ var grid = new Pen(NotaPalette.SurfaceCard, 1);
+ foreach (double gf in new[] { 100.0, 1000.0, 10000.0 }) { double gx = X(Math.Log(gf / 20) / Math.Log(1000)); ctx.DrawLine(grid, new Point(gx, 0), new Point(gx, h)); }
+
+ // Spectra: input filled, output as a line.
+ double Y(double db) => Math.Clamp((TopDb - db) / (TopDb - BottomDb), 0, 1) * h;
+ double DbAt(double[] a, double fx)
+ {
+ double f0 = 20 * Math.Pow(1000, fx), f1 = 20 * Math.Pow(1000, fx + 2 / w);
+ double k0 = f0 * FftN / _sr, k1 = f1 * FftN / _sr;
+ if (k1 - k0 < 1)
+ {
+ int i = Math.Clamp((int)k0, 1, Bins - 2); double t = Math.Clamp(k0 - i, 0, 1);
+ return a[i] * (1 - t) + a[i + 1] * t;
+ }
+ double m = -120;
+ for (int k = Math.Max(1, (int)k0); k <= Math.Min(Bins - 1, (int)k1); k++) m = Math.Max(m, a[k]);
+ return m;
+ }
+ var fill = new StreamGeometry();
+ using (var g = fill.Open())
+ {
+ g.BeginFigure(new Point(0, h), true);
+ for (double x = 0; x <= w; x += 2) g.LineTo(new Point(x, Y(DbAt(_inDb, x / w))));
+ g.LineTo(new Point(w, h));
+ g.EndFigure(true);
+ }
+ ctx.DrawGeometry(InFill, new Pen(NotaPalette.BorderStrong, 1), fill);
+ var line = new StreamGeometry();
+ using (var g = line.Open())
+ {
+ g.BeginFigure(new Point(0, Y(DbAt(_outDb, 0))), false);
+ for (double x = 2; x <= w; x += 2) g.LineTo(new Point(x, Y(DbAt(_outDb, x / w))));
+ }
+ ctx.DrawGeometry(null, new Pen(NotaPalette.TextSecondary, 1.3), line);
+
+ // Crossover lines + frequency tags (the line takes the colour of the band above it).
+ void Cross(double v, int upper, int idx)
+ {
+ double x = Math.Round(X(v)) + 0.5;
+ var col = PrismInk.Band[upper];
+ bool hot = _hover == idx || _drag == idx;
+ ctx.DrawLine(new Pen(col, hot ? 2 : 1), new Point(x, 0), new Point(x, h));
+ var t = PrismInk.Text(PrismInk.HzShort(20 * Math.Pow(1000, v)), 7, upper == 1 ? NotaPalette.AccentBright : col);
+ double tw = t.Width + 8, tx = Math.Clamp(x - tw / 2, 0, w - tw);
+ var tag = new Rect(tx, 0, tw, 12);
+ ctx.DrawRectangle(hot ? NotaPalette.SurfaceRaised : NotaPalette.SurfaceCard, new Pen(col, 1), tag, 3, 3);
+ ctx.DrawText(t, new Point(tx + 4, 6 - t.Height / 2));
+ }
+ if (_bands >= 2) Cross(_xl, 1, 0);
+ if (_bands >= 3) Cross(_xh, 2, 1);
+
+ var l0 = PrismInk.Text("20", 7, NotaPalette.TextDisabled);
+ ctx.DrawText(l0, new Point(5, h - l0.Height - 1));
+ var l1 = PrismInk.Text("20k Hz", 7, NotaPalette.TextDisabled);
+ ctx.DrawText(l1, new Point(w - l1.Width - 5, h - l1.Height - 1));
+ ctx.DrawRectangle(null, PrismInk.InnerPen, rect.Deflate(0.5), 4, 4);
+ }
+
+ // In-place iterative radix-2 Cooley–Tukey FFT.
+ private static void Fft(double[] re, double[] im)
+ {
+ int n = re.Length;
+ for (int i = 1, j = 0; i < n; i++)
+ {
+ int bit = n >> 1;
+ for (; (j & bit) != 0; bit >>= 1) j ^= bit;
+ j ^= bit;
+ if (i < j) { (re[i], re[j]) = (re[j], re[i]); (im[i], im[j]) = (im[j], im[i]); }
+ }
+ for (int len = 2; len <= n; len <<= 1)
+ {
+ double ang = -2 * Math.PI / len, wr = Math.Cos(ang), wi = Math.Sin(ang);
+ for (int i = 0; i < n; i += len)
+ {
+ double cr = 1, ci = 0;
+ for (int k = 0; k < len / 2; k++)
+ {
+ int a = i + k, b = i + k + len / 2;
+ double tr = re[b] * cr - im[b] * ci, ti = re[b] * ci + im[b] * cr;
+ re[b] = re[a] - tr; im[b] = im[a] - ti;
+ re[a] += tr; im[a] += ti;
+ double ncr = cr * wr - ci * wi; ci = cr * wi + ci * wr; cr = ncr;
+ }
+ }
+ }
+ }
+}
+
+// ---------------------------------------------------------------------------------------------
+// Transfer curve
+// ---------------------------------------------------------------------------------------------
+internal sealed class PrismTransfer : Control
+{
+ private const double Lo = -72; // axes span −72 … 0 dB
+ private double _thrA = -18, _slopeA = 0.5, _thrB = -40, _slopeB = 0.4, _floor = 24, _knee = 6, _level = -120;
+ private bool _below;
+ private int _band = 1, _drag, _hover; // handle: 1 above, 2 below
+ private Point _start;
+
+ public event Action<int>? DragStarted;
+ public event Action<int, double, double>? Dragged; // (handle, dx fraction of width, dy px since press)
+ public event Action<int>? DragEnded;
+ public event Action<int>? ResetRequested;
+
+ public PrismTransfer() { ClipToBounds = true; }
+
+ public void Set(int band, double thrA, double slopeA, bool below, double thrB, double slopeB, double floor, double knee, double level)
+ {
+ _band = band; _thrA = thrA; _slopeA = slopeA; _below = below; _thrB = thrB; _slopeB = slopeB; _floor = floor; _knee = knee; _level = level;
+ InvalidateVisual();
+ }
+
+ private static double Knee(double u, double w)
+ {
+ if (w > 0.01) { if (2 * u < -w) return 0; if (2 * u <= w) { double t = u + 0.5 * w; return t * t / (2 * w); } return u; }
+ return u > 0 ? u : 0;
+ }
+ private double Out(double x)
+ {
+ double y = x - _slopeA * Knee(x - _thrA, _knee);
+ if (_below) y += Math.Clamp(-_slopeB * Knee(_thrB - x, _knee), -_floor, _floor);
+ return y;
+ }
+ private Point Pt(double inDb, double outDb)
+ {
+ double w = Bounds.Width, h = Bounds.Height;
+ return new Point((inDb - Lo) / -Lo * w, h - Math.Clamp((outDb - Lo) / -Lo, -0.2, 1.2) * h);
+ }
+ private int Hit(Point p)
+ {
+ static double D(Point a, Point b) => Math.Sqrt((a.X - b.X) * (a.X - b.X) + (a.Y - b.Y) * (a.Y - b.Y));
+ double da = D(p, Pt(_thrA, Out(_thrA))), db = D(p, Pt(_thrB, Out(_thrB)));
+ if (da <= 8 && da <= db) return 1;
+ if (db <= 8) return 2;
+ return 0;
+ }
+
+ protected override void OnPointerPressed(PointerPressedEventArgs e)
+ {
+ base.OnPointerPressed(e);
+ if (!e.GetCurrentPoint(this).Properties.IsLeftButtonPressed) return;
+ int hdl = Hit(e.GetPosition(this));
+ if (hdl == 0) return;
+ if (e.ClickCount == 2) { ResetRequested?.Invoke(hdl); e.Handled = true; return; }
+ _drag = hdl; _start = e.GetPosition(this);
+ DragStarted?.Invoke(hdl); e.Pointer.Capture(this); e.Handled = true;
+ }
+ protected override void OnPointerMoved(PointerEventArgs e)
+ {
+ base.OnPointerMoved(e);
+ var p = e.GetPosition(this);
+ if (_drag > 0) { Dragged?.Invoke(_drag, (p.X - _start.X) / Math.Max(1, Bounds.Width), p.Y - _start.Y); return; }
+ int h = Hit(p);
+ if (h != _hover) { _hover = h; Cursor = h > 0 ? new Cursor(StandardCursorType.SizeAll) : Cursor.Default; InvalidateVisual(); }
+ }
+ protected override void OnPointerReleased(PointerReleasedEventArgs e)
+ {
+ base.OnPointerReleased(e);
+ if (_drag == 0) return;
+ int d = _drag; _drag = 0; e.Pointer.Capture(null); DragEnded?.Invoke(d);
+ }
+
+ public override void Render(DrawingContext ctx)
+ {
+ double w = Bounds.Width, h = Bounds.Height;
+ if (w < 8 || h < 8) return;
+ var rect = new Rect(0, 0, w, h);
+ ctx.DrawRectangle(NotaPalette.BgSunken, null, rect, 4, 4);
+ var grid = new Pen(NotaPalette.SurfaceCard, 1);
+ ctx.DrawLine(grid, new Point(0, h / 2), new Point(w, h / 2));
+ ctx.DrawLine(grid, new Point(w / 2, 0), new Point(w / 2, h));
+ ctx.DrawLine(new Pen(NotaPalette.SurfaceRaised, 1, new DashStyle(new double[] { 3, 3 }, 0)), new Point(0, h), new Point(w, 0));
+
+ var col = PrismInk.Band[_band];
+ var curve = new StreamGeometry();
+ using (var g = curve.Open())
+ {
+ g.BeginFigure(Pt(Lo, Out(Lo)), false);
+ for (double x = Lo + 0.5; x <= 0; x += 0.5) g.LineTo(Pt(x, Out(x)));
+ }
+ using (ctx.PushClip(rect))
+ ctx.DrawGeometry(null, new Pen(col, 2), curve);
+
+ // Live detector level riding the curve.
+ if (_level > Lo) ctx.DrawEllipse(NotaPalette.TextPrimary, null, Pt(_level, Out(_level)), 2.2, 2.2);
+ // Threshold handles.
+ var below = Pt(_thrB, Out(_thrB));
+ if (_below || _hover == 2) ctx.DrawEllipse(_below ? NotaPalette.TextSecondary : NotaPalette.TextDisabled, _hover == 2 ? new Pen(NotaPalette.TextPrimary, 1) : null, below, 3, 3);
+ ctx.DrawEllipse(PrismInk.BandLit[_band], _hover == 1 ? new Pen(NotaPalette.TextPrimary, 1) : null, Pt(_thrA, Out(_thrA)), 3.5, 3.5);
+
+ var ta = PrismInk.Text(FormattableString.Invariant($"above {_thrA:0}"), 7, PrismInk.BandLit[_band]);
+ ctx.DrawText(ta, new Point(4, 3));
+ var tb = PrismInk.Text(_below ? FormattableString.Invariant($"below {_thrB:0}") : "below off", 7, _below ? NotaPalette.TextSecondary : NotaPalette.TextDisabled);
+ ctx.DrawText(tb, new Point(4, h - tb.Height - 2));
+ ctx.DrawRectangle(null, PrismInk.InnerPen, rect.Deflate(0.5), 4, 4);
+ }
+}
+
+// ---------------------------------------------------------------------------------------------
+// Detector envelope trace
+// ---------------------------------------------------------------------------------------------
+internal sealed class PrismEnvTrace : Control
+{
+ private float[] _in = Array.Empty<float>(), _det = Array.Empty<float>();
+ private int _n, _band = 1;
+ private double _thrA = -18, _thrB = -40;
+ private bool _below;
+
+ public PrismEnvTrace() { ClipToBounds = true; }
+
+ public void Set(float[] input, float[] det, int n, int band, double thrA, bool below, double thrB)
+ {
+ _in = input; _det = det; _n = n; _band = band; _thrA = thrA; _below = below; _thrB = thrB;
+ InvalidateVisual();
+ }
+
+ public override void Render(DrawingContext ctx)
+ {
+ double w = Bounds.Width, h = Bounds.Height;
+ if (w < 8 || h < 8) return;
+ var rect = new Rect(0, 0, w, h);
+ ctx.DrawRectangle(NotaPalette.BgSunken, null, rect, 4, 4);
+ const double top = 14, range = 60; // 0 dB at `top`, −60 dB at the bottom
+ double Y(double db) => top + Math.Clamp(-db / range, 0, 1) * (h - top - 2);
+ var grid = new Pen(NotaPalette.SurfaceCard, 1);
+ foreach (int g in new[] { -12, -24, -36, -48 }) ctx.DrawLine(grid, new Point(0, Y(g)), new Point(w, Y(g)));
+ var col = PrismInk.Band[_band];
+ var dash = new DashStyle(new double[] { 3, 3 }, 0);
+ ctx.DrawLine(new Pen(PrismInk.Alpha(PrismInk.BandColor[_band], 0x90), 1, dash), new Point(0, Y(_thrA)), new Point(w, Y(_thrA)));
+ if (_below && _thrB > -range) ctx.DrawLine(new Pen(NotaPalette.BorderStrong, 1, dash), new Point(0, Y(_thrB)), new Point(w, Y(_thrB)));
+
+ void Trace(float[] a, IPen pen)
+ {
+ if (_n < 2 || a.Length < _n) return;
+ var geo = new StreamGeometry();
+ using (var g = geo.Open())
+ {
+ for (int i = 0; i < _n; i++)
+ {
+ var p = new Point(w * i / (_n - 1), Y(PrismInk.Db(a[i])));
+ if (i == 0) g.BeginFigure(p, false); else g.LineTo(p);
+ }
+ }
+ ctx.DrawGeometry(null, pen, geo);
+ }
+ Trace(_in, new Pen(NotaPalette.BorderStrong, 1.2));
+ Trace(_det, new Pen(col, 1.7));
+
+ var title = PrismInk.Caps("DETECTOR ENVELOPE · " + PrismInk.Names[_band].ToUpperInvariant(), 7, NotaPalette.TextTertiary);
+ ctx.DrawText(title, new Point(5, 3));
+ var l2 = PrismInk.Text("detector", 7, PrismInk.BandLit[_band]);
+ var l1 = PrismInk.Text("input", 7, NotaPalette.TextTertiary);
+ double x2 = w - l2.Width - 5, x1 = x2 - 14 - l1.Width - 12;
+ ctx.FillRectangle(NotaPalette.BorderStrong, new Rect(x1, 7, 8, 2)); ctx.DrawText(l1, new Point(x1 + 11, 3));
+ ctx.FillRectangle(col, new Rect(x2 - 11, 7, 8, 2)); ctx.DrawText(l2, new Point(x2, 3));
+ ctx.DrawRectangle(null, PrismInk.InnerPen, rect.Deflate(0.5), 4, 4);
+ }
+}
+
+// ---------------------------------------------------------------------------------------------
+// Gain-reduction meter
+// ---------------------------------------------------------------------------------------------
+internal sealed class PrismGrMeter : Control
+{
+ private const double Scale = 12; // full height = 12 dB
+ private static readonly Stopwatch Clock = Stopwatch.StartNew();
+ private double _gr, _boost, _hold, _holdT;
+ private bool _peakHold;
+ public int Band { get; init; }
+ public bool Soloed { get; set; }
+
+ public PrismGrMeter() { Width = 18; }
+
+ public void Set(double grDb, double boostDb, bool peakHold)
+ {
+ _gr = Math.Max(0, grDb); _boost = Math.Max(0, boostDb); _peakHold = peakHold;
+ double now = Clock.Elapsed.TotalSeconds;
+ if (_gr >= _hold) { _hold = _gr; _holdT = now; }
+ else if (now - _holdT > 1.5) _hold = Math.Max(_gr, _hold - 0.2);
+ InvalidateVisual();
+ }
+
+ public override void Render(DrawingContext ctx)
+ {
+ double w = Bounds.Width, h = Bounds.Height;
+ if (w < 4 || h < 4) return;
+ var rect = new Rect(0.5, 0.5, w - 1, h - 1);
+ ctx.DrawRectangle(NotaPalette.BgSunken, new Pen(Soloed ? NotaPalette.Accent : PrismInk.InnerBorder, 1), rect, 2, 2);
+ double ih = h - 3;
+ var col = PrismInk.BandColor[Band];
+ if (_gr > 0.01) ctx.DrawRectangle(PrismInk.Band[Band], null, new Rect(1.5, 1.5, w - 3, ih * Math.Min(1, _gr / Scale)), 2, 2);
+ if (_boost > 0.01) { double bh = ih * Math.Min(1, _boost / Scale); ctx.FillRectangle(PrismInk.Alpha(col, 0x70), new Rect(1.5, h - 1.5 - bh, w - 3, bh)); }
+ if (_peakHold && _hold > 0.05)
+ {
+ double y = 1.5 + ih * Math.Min(1, _hold / Scale);
+ ctx.FillRectangle(NotaPalette.TextPrimary, new Rect(1.5, Math.Min(h - 2.5, y), w - 3, 1));
+ }
+ }
+}
diff --git a/src/managed/Nota.App/DeviceCards/Bodies/PrismDeviceBody.cs b/src/managed/Nota.App/DeviceCards/Bodies/PrismDeviceBody.cs
new file mode 100644
index 00000000..345e0ba2
--- /dev/null
+++ b/src/managed/Nota.App/DeviceCards/Bodies/PrismDeviceBody.cs
@@ -0,0 +1,786 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.
+//
+// Detail · Devices — built-in Nota Prism body (device kind 21, three-band dynamics), a build of
+// the "Nota Prism" mockup (700 × 260) on the Chamber frame: an always-visible GLOBAL column
+// (Amount + Output), a centre tabbed panel (Bands / Band detail / Time), a right tabbed panel
+// (Meters / Output) and a status strip. Bands are colour-coded Low = mauve, Mid = brass,
+// High = teal. The spectrum's crossover lines, the transfer curve's threshold dots and every
+// slider are controls. Every control is a device param, so automation / MIDI learn / presets /
+// A-B / persistence come for free. FullBleed — the shared shell draws the header.
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+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 PrismDeviceBody : IDeviceBody
+{
+ // ── Parameter indices (must match Prism.h) ───────────────────────────────
+ private const int Amount = 0, Output = 1, BandsP = 2, XoverLow = 3, XoverHigh = 4, Detect = 5, Lookahead = 6, AutoMakeup = 7,
+ SoftClip = 8, ScListen = 9, Solo = 10, PeakHold = 11, Mix = 12, Global = 13, PerBand = 13;
+ private const int AboveThresh = 0, AboveRatio = 1, Attack = 2, Release = 3, Gain = 4, BelowOn = 5, BelowThresh = 6, BelowRatio = 7,
+ BelowAttack = 8, BelowRelease = 9, Floor = 10, Knee = 11, AutoRelease = 12;
+ private static int BP(int band, int field) => Global + band * PerBand + field;
+ // Scope telemetry layout (Prism::S_*).
+ private const int S_Gr0 = 0, S_Boost0 = 3, S_Level0 = 6, S_OutL = 9, S_OutR = 10, S_Cpu = 12, S_SampleRate = 13, S_Latency = 14,
+ S_ScActive = 15, S_ClipDb = 16, kScope = 20;
+ private const int TraceLen = 256;
+
+ private static readonly IBrush RailBg = new SolidColorBrush(Color.Parse("#1B1916"));
+ private static readonly IBrush Panel = NotaPalette.BgApp;
+ private static readonly IBrush Border2 = NotaPalette.BorderDefault;
+ private static readonly IBrush BorderIn = PrismInk.InnerBorder;
+ private static readonly IBrush Inset = NotaPalette.BgSunken;
+ private static readonly IBrush TabBg = NotaPalette.SurfaceCard;
+ private static readonly IBrush Amber = NotaPalette.Accent;
+ private static readonly IBrush AmberLit = NotaPalette.AccentBright;
+ private static readonly IBrush AmberSubtle = NotaPalette.AccentSubtle;
+ private static readonly IBrush RowSel = new SolidColorBrush(Color.FromArgb(0x10, 0xD8, 0xA0, 0x3D));
+ private static readonly IBrush TxtC = NotaPalette.TextPrimary;
+ private static readonly IBrush Txt2 = NotaPalette.TextSecondary;
+ private static readonly IBrush MutedC = NotaPalette.TextTertiary;
+ private static readonly IBrush DimC = NotaPalette.TextDisabled;
+ private static readonly IBrush OffPill = NotaPalette.SurfaceRaised;
+ private static readonly IBrush Mauve = PrismInk.Band[0];
+
+ // The selected band and tabs survive a card rebuild (keyed by track + device slot).
+ private static readonly Dictionary<(int, int), (int Band, int Centre, int Right)> ViewState = new();
+
+ public double Width => 700;
+ public bool FullBleed => true;
+ public string? Subtitle => "MULTIBAND";
+
+ public Control Build(DeviceCardContext ctx, int index)
+ {
+ var engine = ctx.Engine;
+ int track = ctx.TrackId, di = index;
+ float P(int p) => engine.DeviceGetParam(track, di, p);
+ void 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, 1f));
+ // A discrete edit (click) is one automation gesture, so Touch / Latch / Write record it.
+ void SetP(int p, float v) { Begin(p); Raw(p, v); End(p); }
+ bool On(int p) => P(p) >= 0.5f;
+ int Sel(int p, int n) => Math.Clamp((int)Math.Round(P(p) * (n - 1)), 0, n - 1);
+ float Def(int p) => engine.DeviceParamDefault(track, di, p);
+
+ var readouts = new List<Action>();
+ var scope = new float[kScope];
+ int scN = 0;
+ double Sc(int i) => scN > i ? scope[i] : 0;
+
+ var view = ViewState.TryGetValue((track, di), out var vs) ? vs : (Band: 1, Centre: 0, Right: 0);
+ int band = view.Band;
+ var bandListeners = new List<Action>();
+ void SelectBand(int b)
+ {
+ if (!BandActive(b)) return;
+ band = b; ViewState[(track, di)] = (band, view.Centre, view.Right);
+ foreach (var a in bandListeners) a();
+ foreach (var a in readouts) a();
+ }
+
+ // ---- mappings / formatters ---------------------------------------------------
+ int BandCount() => 3 - Sel(BandsP, 3);
+ bool BandActive(int b) => b == 1 || (b == 0 && BandCount() >= 2) || (b == 2 && BandCount() >= 3);
+ static double Exp(double v, double lo, double hi) => lo * Math.Pow(hi / lo, Math.Clamp(v, 0, 1));
+ static double ThrA(double v) => -60 + 60 * v;
+ static double ThrB(double v) => -80 + 80 * v;
+ static double RatioB(double v) => Math.Pow(4, (v - 0.5) * 2);
+ static double XHz(double v) => Exp(v, 20, 20000);
+ static string Inv(FormattableString f) => FormattableString.Invariant(f);
+ static string DbF(double db) => Math.Abs(db) < 0.05 ? "0.0 dB" : Inv($"{db:+0.0;−0.0} dB");
+ static string DbShort(double db) => Math.Abs(db) < 0.05 ? "0.0" : Inv($"{db:+0.0;−0.0}");
+ static string ThrF(double db) => Inv($"{db:0;−0} dB");
+ static string RatioAF(double v) { if (v >= 0.999) return "∞ : 1"; double r = 1 / (1 - v); return r < 10 ? Inv($"{r:0.0#} : 1") : Inv($"{r:0} : 1"); }
+ static string RatioAShort(double v) { if (v >= 0.999) return "∞:1"; double r = 1 / (1 - v); return r < 10 ? Inv($"{r:0.#}:1") : Inv($"{r:0}:1"); }
+ static string RatioBF(double v) { double r = RatioB(v); return Math.Abs(r - 1) < 0.01 ? "1 : 1" : r > 1 ? Inv($"{r:0.0#} : 1") : Inv($"↑ {1 / r:0.0#} : 1"); }
+ static string RatioBShort(double v) { double r = RatioB(v); return Math.Abs(r - 1) < 0.01 ? "1:1" : r > 1 ? Inv($"{r:0.0#}") : Inv($"↑{1 / r:0.0}"); }
+ static string Ms(double ms) => ms >= 1000 ? Inv($"{ms / 1000:0.00} s") : ms >= 10 ? Inv($"{ms:0} ms") : Inv($"{ms:0.0} ms");
+ static string AtkF(double v) => Ms(Exp(v, 0.1, 300));
+ static string RelF(double v) => Ms(Exp(v, 5, 3000));
+ static string GainF(double v) => DbF((v - 0.5) * 48);
+ static string HzF(double hz) => hz >= 1000 ? Inv($"{hz / 1000:0.0#} kHz") : Inv($"{hz:0} Hz");
+ static string Pct(double v) => Inv($"{v * 100:0} %");
+ string FloorF(int b) => RatioB(P(BP(b, BelowRatio))) < 1 ? Inv($"+{P(BP(b, Floor)) * 48:0} dB") : Inv($"−{P(BP(b, Floor)) * 48:0} dB");
+
+ // ---- small builders ---------------------------------------------------------
+ static TextBlock Caps(string t, IBrush? c = null, double fs = 7) => new() { Text = t, FontSize = fs, FontWeight = FontWeight.Bold, Foreground = c ?? MutedC, 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 Control Docked(Control c, Dock d) { DockPanel.SetDock(c, d); return c; }
+ static Control Col(Control c, int col) { Grid.SetColumn(c, col); return c; }
+ static Control GRow(Control c, int row) { Grid.SetRow(c, row); return c; }
+ static Border Divider(Control child, double top = 5) => new() { BorderBrush = BorderIn, BorderThickness = new Thickness(0, 1, 0, 0), Padding = new Thickness(0, top, 0, 0), Child = child };
+ Control Learn(Control c, int p) { MidiLearn.Bind(c, MidiTarget.DeviceParam(track, di, p), engine.DeviceParamName(track, di, p)); return c; }
+
+ // Gauge knob bound to a device param (automation gesture + MIDI learn + live follow).
+ Control K(int p, string name, Func<double, string> fmt, double size = 34, double cellW = 50, IBrush? arc = null)
+ {
+ var val = Mono(fmt(P(p)), 7, TxtC);
+ var knob = new Knob(P(p), 1.0) { Accent = true, ArcColor = arc, Default = Def(p), Width = size, Height = size };
+ knob.ValueChanged += v => { Raw(p, (float)v); val.Text = fmt(v); };
+ knob.GestureBegin += () => Begin(p);
+ knob.GestureEnd += () => End(p);
+ Learn(knob, p);
+ readouts.Add(() => { if (knob.Dragging || !knob.IsEffectivelyVisible) return; float c = P(p); if (Math.Abs(c - knob.Value) > 1e-4) knob.Value = c; val.Text = fmt(c); });
+ return KnobCell(name, knob, val, cellW);
+ }
+
+ // On/off pill bound to a param (> 0.5 = on).
+ Control Toggle(int p, string label, Func<string>? dynLabel = null)
+ {
+ var pill = new Border { Width = 18, Height = 10, CornerRadius = new CornerRadius(5), VerticalAlignment = VerticalAlignment.Center };
+ var dot = new Border { Width = 7, Height = 7, CornerRadius = new CornerRadius(4) };
+ var host = new Canvas { Width = 18, Height = 10 }; Canvas.SetTop(dot, 1.5); host.Children.Add(dot); pill.Child = host;
+ var txt = new TextBlock { Text = label, FontSize = 8, VerticalAlignment = VerticalAlignment.Center };
+ void Hi()
+ {
+ bool on = On(p);
+ pill.Background = on ? Amber : OffPill; dot.Background = on ? Panel : MutedC;
+ Canvas.SetLeft(dot, on ? 9.5 : 1.5); txt.Foreground = on ? TxtC : Txt2;
+ if (dynLabel != null) txt.Text = dynLabel();
+ }
+ var wrap = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 5, VerticalAlignment = VerticalAlignment.Center, Background = Brushes.Transparent, Cursor = new Cursor(StandardCursorType.Hand), Children = { pill } };
+ if (label.Length > 0 || dynLabel != null) wrap.Children.Add(txt);
+ wrap.PointerPressed += (_, e) => { if (!e.GetCurrentPoint(wrap).Properties.IsLeftButtonPressed) return; SetP(p, On(p) ? 0f : 1f); Hi(); e.Handled = true; };
+ readouts.Add(Hi); Hi();
+ Learn(wrap, p);
+ return wrap;
+ }
+
+ // Segmented chips over a discrete param (n options spread over 0..1).
+ Control Seg(int p, string[] names, Action? changed = null)
+ {
+ int n = names.Length; var cells = new Border[n];
+ void Hi()
+ {
+ int cur = Sel(p, n);
+ for (int i = 0; i < n; i++)
+ {
+ bool on = i == cur;
+ cells[i].Background = on ? Amber : Brushes.Transparent;
+ var tb = (TextBlock)cells[i].Child!; tb.Foreground = on ? Panel : MutedC; tb.FontWeight = on ? FontWeight.SemiBold : FontWeight.Normal;
+ }
+ }
+ var row = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 1 };
+ for (int i = 0; i < n; i++)
+ {
+ int iv = i;
+ var c = new Border { CornerRadius = new CornerRadius(2), Padding = new Thickness(4, 0), Cursor = new Cursor(StandardCursorType.Hand), Child = new TextBlock { Text = names[i], FontSize = 7, Foreground = MutedC } };
+ c.PointerPressed += (_, e) => { SetP(p, n > 1 ? iv / (float)(n - 1) : 0f); Hi(); changed?.Invoke(); e.Handled = true; };
+ cells[i] = c; row.Children.Add(c);
+ }
+ readouts.Add(Hi); Hi();
+ var seg = new Border { Background = Inset, BorderBrush = Border2, BorderThickness = new Thickness(1), CornerRadius = new CornerRadius(3), Padding = new Thickness(1), VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Left, Child = row };
+ Learn(seg, p);
+ return seg;
+ }
+
+ // Horizontal bar slider over a param, with a mono readout on the right.
+ Control Bar(int p, Func<double, string> fmt, Func<IBrush> fillC, Func<bool>? dim = null, double valW = 30, Func<IBrush>? valC = null)
+ {
+ var fill = new Border { Height = 3, CornerRadius = new CornerRadius(2), HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Center };
+ var handle = new Border { Width = 6, Height = 7, CornerRadius = new CornerRadius(2) };
+ var lay = new Canvas { Height = 9 };
+ lay.Children.Add(handle); Canvas.SetTop(handle, 1);
+ var canvas = new Avalonia.Controls.Panel { Height = 11, MinWidth = 20, Background = Brushes.Transparent, Cursor = new Cursor(StandardCursorType.Hand), Children = {
+ new Border { Height = 3, Background = Inset, CornerRadius = new CornerRadius(2), VerticalAlignment = VerticalAlignment.Center }, fill, lay } };
+ var val = Mono("", 8, TxtC); val.Width = valW; val.TextAlignment = TextAlignment.Right; val.TextTrimming = TextTrimming.None;
+ bool drag = false;
+ void Vis()
+ {
+ double v = Math.Clamp(P(p), 0, 1), w = canvas.Bounds.Width; if (w <= 0) w = 60;
+ fill.Width = Math.Max(0, v * w); Canvas.SetLeft(handle, v * w - 3); val.Text = fmt(v);
+ bool d = dim?.Invoke() ?? false;
+ fill.Background = d ? NotaPalette.BorderStrong : fillC(); handle.Background = d ? MutedC : Txt2;
+ val.Foreground = d ? MutedC : valC?.Invoke() ?? TxtC;
+ }
+ void From(PointerEventArgs e) { double w = canvas.Bounds.Width; Raw(p, (float)(w > 0 ? Math.Clamp(e.GetPosition(canvas).X / w, 0, 1) : 0)); Vis(); }
+ canvas.PointerPressed += (_, e) =>
+ {
+ if (!e.GetCurrentPoint(canvas).Properties.IsLeftButtonPressed) return;
+ if (e.ClickCount == 2) { SetP(p, Def(p)); Vis(); e.Handled = true; return; }
+ drag = true; Begin(p); e.Pointer.Capture(canvas); From(e); e.Handled = true;
+ };
+ canvas.PointerMoved += (_, e) => { if (drag) From(e); };
+ canvas.PointerReleased += (_, e) => { if (drag) { drag = false; End(p); e.Pointer.Capture(null); } };
+ canvas.SizeChanged += (_, _) => Vis();
+ readouts.Add(() => { if (!drag && canvas.IsEffectivelyVisible) Vis(); });
+ var grid = new Grid { ColumnDefinitions = new ColumnDefinitions("*,Auto"), ColumnSpacing = 5, VerticalAlignment = VerticalAlignment.Center };
+ grid.Children.Add(canvas); grid.Children.Add(Col(val, 1));
+ Learn(grid, p);
+ return grid;
+ }
+ Control SliderRow(string label, int p, Func<double, string> fmt, double labW = 50, double valW = 30)
+ {
+ var g = new Grid { ColumnDefinitions = new ColumnDefinitions(Inv($"{labW},*")), VerticalAlignment = VerticalAlignment.Center };
+ g.Children.Add(Caps(label)); g.Children.Add(Col(Bar(p, fmt, () => Amber, null, valW), 1));
+ return g;
+ }
+
+ // A mono readout that edits its param by vertical drag (~140 px full range); double-click resets.
+ Control DragVal(int p, Func<double, string> fmt, Func<IBrush> color)
+ {
+ var tb = Mono("", 8, TxtC); tb.TextAlignment = TextAlignment.Right; tb.HorizontalAlignment = HorizontalAlignment.Stretch;
+ var host = new Border { Background = Brushes.Transparent, Cursor = new Cursor(StandardCursorType.SizeNorthSouth), Child = tb };
+ bool drag = false; double y0 = 0, v0 = 0;
+ host.PointerPressed += (_, e) =>
+ {
+ if (!e.GetCurrentPoint(host).Properties.IsLeftButtonPressed) return;
+ if (e.ClickCount == 2) { SetP(p, Def(p)); e.Handled = true; return; }
+ drag = true; y0 = e.GetPosition(host).Y; v0 = P(p); Begin(p); e.Pointer.Capture(host); e.Handled = true;
+ };
+ host.PointerMoved += (_, e) => { if (drag) { Raw(p, (float)(v0 + (y0 - e.GetPosition(host).Y) / 140.0)); tb.Text = fmt(P(p)); } };
+ host.PointerReleased += (_, e) => { if (drag) { drag = false; End(p); e.Pointer.Capture(null); } };
+ readouts.Add(() => { tb.Text = fmt(P(p)); tb.Foreground = color(); });
+ Learn(host, p);
+ return host;
+ }
+
+ // Band name cell: colour bar + name (lit when selected).
+ Control BandName(int b, double barH)
+ {
+ var name = new TextBlock { Text = PrismInk.Names[b], FontSize = 9, VerticalAlignment = VerticalAlignment.Center };
+ readouts.Add(() => { bool s = band == b; name.Foreground = s ? PrismInk.BandLit[b] : TxtC; name.FontWeight = s ? FontWeight.SemiBold : FontWeight.Normal; });
+ return new StackPanel { Orientation = Orientation.Horizontal, Spacing = 5, VerticalAlignment = VerticalAlignment.Center, Children = {
+ new Border { Width = 3, Height = barH, CornerRadius = new CornerRadius(2), Background = PrismInk.Band[b] }, name } };
+ }
+
+ // A clickable table row for band b: selects the band; dimmed + inert when the band is off.
+ Border BandRow(int b, Grid content, double height)
+ {
+ content.Height = height;
+ var row = new Border { BorderBrush = BorderIn, BorderThickness = new Thickness(0, 1, 0, 0), Background = Brushes.Transparent, Child = content };
+ row.PointerPressed += (_, e) => { if (e.GetCurrentPoint(row).Properties.IsLeftButtonPressed) SelectBand(b); };
+ readouts.Add(() =>
+ {
+ bool act = BandActive(b);
+ row.Background = band == b && act ? RowSel : Brushes.Transparent;
+ row.Opacity = act ? 1 : 0.32; row.IsHitTestVisible = act;
+ });
+ return row;
+ }
+
+ // ======================================================================
+ // LEFT — GLOBAL column (Amount + Output)
+ // ======================================================================
+ Control Fader(int p, string label, string tip)
+ {
+ var f = new ChamberFader { VerticalAlignment = VerticalAlignment.Stretch, Default = Def(p) };
+ f.Changed += v => Raw(p, (float)v);
+ f.DragStarted += () => Begin(p);
+ f.DragEnded += () => End(p);
+ readouts.Add(() => f.Set(P(p)));
+ Learn(f, p);
+ ToolTip.SetTip(f, tip);
+ var lb = Caps(label); lb.HorizontalAlignment = HorizontalAlignment.Center;
+ return new DockPanel { Children = { Docked(lb, Dock.Bottom), f } };
+ }
+ var amtTxt = Mono("", 7, AmberLit); amtTxt.HorizontalAlignment = HorizontalAlignment.Center;
+ var outTxt = Mono("", 7, TxtC); outTxt.HorizontalAlignment = HorizontalAlignment.Center;
+ readouts.Add(() => { amtTxt.Text = Pct(P(Amount)); outTxt.Text = DbShort((P(Output) - 0.5) * 48); });
+ var globTitle = Caps("GLOBAL"); globTitle.HorizontalAlignment = HorizontalAlignment.Center;
+ var faders = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,Auto"), ColumnSpacing = 9, HorizontalAlignment = HorizontalAlignment.Center, Margin = new Thickness(0, 4, 0, 3) };
+ faders.Children.Add(Fader(Amount, "AMT", "Amount — scales every band's compression and expansion (0 % = none). Double-click: 100 %"));
+ faders.Children.Add(Col(Fader(Output, "OUT", "Output gain ±24 dB — double-click: 0 dB"), 1));
+ var globCol = new Border { Width = 56, Background = Panel, BorderBrush = Border2, BorderThickness = new Thickness(1), CornerRadius = new CornerRadius(5), Padding = new Thickness(0, 5, 0, 4),
+ Child = new DockPanel { Children = { Docked(globTitle, Dock.Top), Docked(outTxt, Dock.Bottom), Docked(amtTxt, Dock.Bottom), faders } } };
+ DockPanel.SetDock(globCol, Dock.Left);
+
+ // ======================================================================
+ // CENTRE — Bands (spectrum + per-band overview)
+ // ======================================================================
+ Control BandsTab()
+ {
+ var spec = new PrismSpectrum(engine, track, di) { DefaultLow = Def(XoverLow), DefaultHigh = Def(XoverHigh) };
+ spec.CrossoverChanged += (h, v) => Raw(h == 0 ? XoverLow : XoverHigh, (float)v);
+ spec.DragStarted += h => Begin(h == 0 ? XoverLow : XoverHigh);
+ spec.DragEnded += h => End(h == 0 ? XoverLow : XoverHigh);
+ spec.BandClicked += SelectBand;
+ ToolTip.SetTip(spec, "Input spectrum (fill) and output (line). Drag a crossover line to move it; double-click resets. Click a band to select it.");
+ readouts.Add(() => { spec.Set(P(XoverLow), P(XoverHigh), BandCount(), band, Sc(S_SampleRate)); spec.Tick(); });
+
+ const string cols = "50,*,*,40,40";
+ var head = new Grid { ColumnDefinitions = new ColumnDefinitions(cols), Height = 11 };
+ var hA = Caps("ABOVE — COMPRESS", DimC); hA.HorizontalAlignment = HorizontalAlignment.Center;
+ var hB = Caps("BELOW — EXPAND", DimC); hB.HorizontalAlignment = HorizontalAlignment.Center;
+ var hG = Caps("GAIN", DimC); hG.HorizontalAlignment = HorizontalAlignment.Right;
+ var hR = Caps("GR", DimC); hR.HorizontalAlignment = HorizontalAlignment.Right;
+ head.Children.Add(Caps("BAND", DimC)); head.Children.Add(Col(hA, 1)); head.Children.Add(Col(hB, 2)); head.Children.Add(Col(hG, 3)); head.Children.Add(Col(hR, 4));
+ var rows = new StackPanel { Children = { head } };
+ for (int b = 0; b < 3; b++)
+ {
+ int bb = b;
+ var g = new Grid { ColumnDefinitions = new ColumnDefinitions(cols) };
+ g.Children.Add(BandName(bb, 12));
+ var above = Bar(BP(bb, AboveThresh), v => Inv($"{ThrA(v):0;−0} · {RatioAShort(P(BP(bb, AboveRatio)))}"), () => PrismInk.Band[bb], null, 52,
+ () => band == bb ? PrismInk.BandLit[bb] : TxtC);
+ above.Margin = new Thickness(0, 0, 8, 0);
+ ToolTip.SetTip(above, "Compression threshold · ratio (set the ratio in Band detail)");
+ g.Children.Add(Col(above, 1));
+ bool BelowOff() => !On(BP(bb, BelowOn));
+ var below = Bar(BP(bb, BelowThresh), v => BelowOff() ? "off" : Inv($"{ThrB(v):0;−0} · {RatioBShort(P(BP(bb, BelowRatio)))}"), () => PrismInk.Band[bb], BelowOff, 52);
+ below.Margin = new Thickness(0, 0, 8, 0);
+ // The readout toggles the below section on / off.
+ var belowVal = (TextBlock)((Grid)below).Children[1];
+ belowVal.Cursor = new Cursor(StandardCursorType.Hand);
+ belowVal.PointerPressed += (_, e) => { if (!e.GetCurrentPoint(belowVal).Properties.IsLeftButtonPressed) return; SetP(BP(bb, BelowOn), BelowOff() ? 1f : 0f); e.Handled = true; };
+ ToolTip.SetTip(below, "Expansion / upward-compression threshold · ratio — click the readout to switch it on or off");
+ g.Children.Add(Col(below, 2));
+ var gain = DragVal(BP(bb, Gain), v => DbShort((v - 0.5) * 48), () => Math.Abs(P(BP(bb, Gain)) - 0.5f) < 0.001f ? Txt2 : TxtC);
+ ToolTip.SetTip(gain, "Band gain ±24 dB — drag up / down, double-click resets");
+ g.Children.Add(Col(gain, 3));
+ var grTrack = new Border { Width = 32, Height = 4, CornerRadius = new CornerRadius(2), Background = Inset, HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Center, ClipToBounds = true };
+ var grFill = new Border { Background = PrismInk.Band[bb], HorizontalAlignment = HorizontalAlignment.Right };
+ grTrack.Child = grFill;
+ readouts.Add(() => grFill.Width = 32 * Math.Clamp(Sc(S_Gr0 + bb) / 12, 0, 1));
+ g.Children.Add(Col(grTrack, 4));
+ rows.Children.Add(BandRow(bb, g, 22));
+ }
+ rows.Height = 88;
+ return new DockPanel { LastChildFill = true, Margin = new Thickness(8, 5, 8, 3), Children = {
+ Docked(rows, Dock.Bottom),
+ new Border { Margin = new Thickness(0, 0, 0, 4), Child = spec } } };
+ }
+
+ // ======================================================================
+ // CENTRE — Band detail (transfer curve + above / below knobs), one panel per band
+ // ======================================================================
+ Control DetailPanel(int b)
+ {
+ var tr = new PrismTransfer();
+ int dragThr = 0, dragRat = 0; float thr0 = 0, rat0 = 0;
+ tr.DragStarted += h =>
+ {
+ dragThr = BP(b, h == 1 ? AboveThresh : BelowThresh); dragRat = BP(b, h == 1 ? AboveRatio : BelowRatio);
+ thr0 = P(dragThr); rat0 = P(dragRat); Begin(dragThr); Begin(dragRat);
+ if (h == 2 && !On(BP(b, BelowOn))) SetP(BP(b, BelowOn), 1f); // grabbing the below dot switches it on
+ };
+ tr.Dragged += (h, dx, dy) =>
+ {
+ double spanDb = h == 1 ? 60 : 80; // param span of that threshold
+ Raw(dragThr, (float)(thr0 + dx * 72 / spanDb));
+ Raw(dragRat, (float)(rat0 + dy / (h == 1 ? 160.0 : 240.0))); // drag down = more processing
+ foreach (var a in readouts) a();
+ };
+ tr.DragEnded += _ => { End(dragThr); End(dragRat); };
+ tr.ResetRequested += h =>
+ {
+ int t = BP(b, h == 1 ? AboveThresh : BelowThresh), r = BP(b, h == 1 ? AboveRatio : BelowRatio);
+ SetP(t, Def(t)); SetP(r, Def(r));
+ };
+ ToolTip.SetTip(tr, "Drag a dot: ← → threshold, ↑ ↓ ratio (down = more). The bright dot is compression above, the grey one expansion below. Double-click a dot resets it.");
+ readouts.Add(() =>
+ {
+ if (!tr.IsEffectivelyVisible) return;
+ double amt = P(Amount);
+ tr.Set(b, ThrA(P(BP(b, AboveThresh))), P(BP(b, AboveRatio)) * amt, On(BP(b, BelowOn)), ThrB(P(BP(b, BelowThresh))),
+ (RatioB(P(BP(b, BelowRatio))) - 1) * amt, P(BP(b, Floor)) * 48, P(BP(b, Knee)) * 24, Sc(S_Level0 + b));
+ });
+ var trCap = Caps("TRANSFER · " + PrismInk.Names[b].ToUpperInvariant());
+ var kneeRow = new Grid { ColumnDefinitions = new ColumnDefinitions("32,*"), Margin = new Thickness(0, 4, 0, 0) };
+ kneeRow.Children.Add(Caps("KNEE"));
+ kneeRow.Children.Add(Col(Bar(BP(b, Knee), v => Inv($"{v * 24:0.#} dB"), () => PrismInk.Band[b], null, 32), 1));
+ var left = new Border { Width = 150, BorderBrush = BorderIn, BorderThickness = new Thickness(0, 0, 1, 0), Padding = new Thickness(7, 5),
+ Child = new DockPanel { Children = { Docked(trCap, Dock.Top), Docked(kneeRow, Dock.Bottom), new Border { Margin = new Thickness(0, 4, 0, 0), Child = tr } } } };
+
+ // ABOVE — compression
+ var aCap = Caps("ABOVE — COMPRESSION", PrismInk.BandLit[b]);
+ var aGr = Mono("", 7, Txt2); aGr.HorizontalAlignment = HorizontalAlignment.Right;
+ readouts.Add(() => { double gr = Sc(S_Gr0 + b); aGr.Text = gr > 0.05 ? Inv($"GR −{gr:0.0} dB") : "GR 0.0 dB"; });
+ var aHead = new Grid { ColumnDefinitions = new ColumnDefinitions("*,Auto"), Height = 11 };
+ aHead.Children.Add(aCap); aHead.Children.Add(Col(aGr, 1));
+ var aKnobs = new UniformGrid { Rows = 1, VerticalAlignment = VerticalAlignment.Center };
+ aKnobs.Children.Add(K(BP(b, AboveThresh), "THRESH", v => ThrF(ThrA(v)), 36, 52));
+ aKnobs.Children.Add(K(BP(b, AboveRatio), "RATIO", RatioAF, 36, 52));
+ aKnobs.Children.Add(K(BP(b, Attack), "ATTACK", AtkF, 36, 52));
+ aKnobs.Children.Add(K(BP(b, Release), "RELEASE", RelF, 36, 52));
+ aKnobs.Children.Add(K(BP(b, Gain), "GAIN", GainF, 36, 52));
+ var aSec = new DockPanel { Children = { Docked(aHead, Dock.Top), aKnobs } };
+
+ // BELOW — expansion / upward compression
+ var bCap = Caps("BELOW — EXPANSION");
+ readouts.Add(() => { bool up = RatioB(P(BP(b, BelowRatio))) < 0.99; bCap.Text = up ? "BELOW — UPWARD COMPRESSION" : "BELOW — EXPANSION"; bCap.Foreground = On(BP(b, BelowOn)) ? Txt2 : MutedC; });
+ var bToggle = Toggle(BP(b, BelowOn), "", () => On(BP(b, BelowOn)) ? "on" : "off");
+ var bHead = new Grid { ColumnDefinitions = new ColumnDefinitions("*,Auto"), Height = 11 };
+ bHead.Children.Add(bCap); bHead.Children.Add(Col(bToggle, 1));
+ var bKnobs = new UniformGrid { Rows = 1, VerticalAlignment = VerticalAlignment.Center };
+ bKnobs.Children.Add(K(BP(b, BelowThresh), "THRESH", v => ThrF(ThrB(v)), 36, 52, Mauve));
+ bKnobs.Children.Add(K(BP(b, BelowRatio), "RATIO", RatioBF, 36, 52, Mauve));
+ bKnobs.Children.Add(K(BP(b, BelowAttack), "ATTACK", AtkF, 36, 52, Mauve));
+ bKnobs.Children.Add(K(BP(b, BelowRelease), "RELEASE", RelF, 36, 52, Mauve));
+ bKnobs.Children.Add(K(BP(b, Floor), "FLOOR", _ => FloorF(b), 36, 52, Mauve));
+ readouts.Add(() => bKnobs.Opacity = On(BP(b, BelowOn)) ? 1 : 0.45);
+ ToolTip.SetTip(bKnobs, "Ratio above 1 : 1 expands (quiet parts get quieter); below 1 : 1 (↑) compresses upward (quiet parts are lifted). Floor limits either to ± that many dB.");
+ var bSec = Divider(new DockPanel { Children = { Docked(bHead, Dock.Top), bKnobs } }, 4);
+
+ var right = new Grid { RowDefinitions = new RowDefinitions("*,*"), Margin = new Thickness(7, 5, 7, 3) };
+ right.Children.Add(aSec); right.Children.Add(GRow(bSec, 1));
+ var g = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,*") };
+ g.Children.Add(left); g.Children.Add(Col(right, 1));
+ return g;
+ }
+ Control DetailTab()
+ {
+ var host = new Avalonia.Controls.Panel();
+ var panels = new Control[3];
+ for (int b = 0; b < 3; b++) { panels[b] = DetailPanel(b); host.Children.Add(panels[b]); }
+ void Show() { for (int b = 0; b < 3; b++) panels[b].IsVisible = b == band; }
+ bandListeners.Add(Show); Show();
+ return host;
+ }
+
+ // ======================================================================
+ // CENTRE — Time (detector trace + per-band attack / release / auto release)
+ // ======================================================================
+ Control TimeTab()
+ {
+ var trace = new PrismEnvTrace();
+ var tIn = new float[TraceLen]; var tDet = new float[TraceLen];
+ readouts.Add(() =>
+ {
+ if (!trace.IsEffectivelyVisible) return;
+ int n = engine.DeviceLayerWave(track, di, 2 + band * 2, tIn, TraceLen);
+ int m = engine.DeviceLayerWave(track, di, 3 + band * 2, tDet, TraceLen);
+ trace.Set(tIn, tDet, Math.Min(n, m), band, ThrA(P(BP(band, AboveThresh))), On(BP(band, BelowOn)), ThrB(P(BP(band, BelowThresh))));
+ });
+ ToolTip.SetTip(trace, "The selected band's input peaks (grey) and what its compressor's detector makes of them (the last ~1.5 s), against the threshold.");
+ const string cols = "50,*,*,40";
+ var head = new Grid { ColumnDefinitions = new ColumnDefinitions(cols), Height = 11 };
+ var hA = Caps("ATTACK", DimC); hA.HorizontalAlignment = HorizontalAlignment.Center;
+ var hR = Caps("RELEASE", DimC); hR.HorizontalAlignment = HorizontalAlignment.Center;
+ var hU = Caps("AUTO", DimC); hU.HorizontalAlignment = HorizontalAlignment.Right;
+ head.Children.Add(Caps("BAND", DimC)); head.Children.Add(Col(hA, 1)); head.Children.Add(Col(hR, 2)); head.Children.Add(Col(hU, 3));
+ var rows = new StackPanel { Children = { head } };
+ for (int b = 0; b < 3; b++)
+ {
+ int bb = b;
+ var g = new Grid { ColumnDefinitions = new ColumnDefinitions(cols) };
+ g.Children.Add(BandName(bb, 11));
+ IBrush Lit() => band == bb ? PrismInk.BandLit[bb] : TxtC;
+ var atk = Bar(BP(bb, Attack), AtkF, () => PrismInk.Band[bb], null, 38, Lit); atk.Margin = new Thickness(0, 0, 8, 0);
+ var rel = Bar(BP(bb, Release), RelF, () => PrismInk.Band[bb], null, 38, Lit); rel.Margin = new Thickness(0, 0, 8, 0);
+ g.Children.Add(Col(atk, 1)); g.Children.Add(Col(rel, 2));
+ var auto = Toggle(BP(bb, AutoRelease), ""); auto.HorizontalAlignment = HorizontalAlignment.Right;
+ ToolTip.SetTip(auto, "Auto release — short peaks recover fast, sustained compression recovers slowly");
+ g.Children.Add(Col(auto, 3));
+ rows.Children.Add(BandRow(bb, g, 18));
+ }
+ rows.Height = 74;
+ return new DockPanel { LastChildFill = true, Margin = new Thickness(8, 5, 8, 3), Children = {
+ Docked(rows, Dock.Bottom),
+ new Border { Margin = new Thickness(0, 0, 0, 4), Child = trace } } };
+ }
+
+ // ======================================================================
+ // RIGHT — Meters / Output
+ // ======================================================================
+ Control MetersTab()
+ {
+ var meters = new Grid { ColumnDefinitions = new ColumnDefinitions("*,*,*,Auto"), Margin = new Thickness(0, 4, 0, 0) };
+ for (int b = 0; b < 3; b++)
+ {
+ int bb = b;
+ var m = new PrismGrMeter { Band = bb, HorizontalAlignment = HorizontalAlignment.Center };
+ var val = Mono("", 7, PrismInk.Band[bb]); val.HorizontalAlignment = HorizontalAlignment.Center;
+ var nm = Caps(PrismInk.Names[bb].ToUpperInvariant()); nm.HorizontalAlignment = HorizontalAlignment.Center;
+ readouts.Add(() =>
+ {
+ bool act = BandActive(bb);
+ m.Soloed = act && Sel(Solo, 4) == bb + 1;
+ m.Set(act ? Sc(S_Gr0 + bb) : 0, act ? Sc(S_Boost0 + bb) : 0, On(PeakHold));
+ double gr = Sc(S_Gr0 + bb), bo = Sc(S_Boost0 + bb);
+ val.Text = !act ? "—" : bo > gr + 0.05 ? Inv($"+{bo:0.0}") : gr > 0.05 ? Inv($"−{gr:0.0}") : "0.0";
+ val.Foreground = band == bb ? PrismInk.BandLit[bb] : PrismInk.Band[bb];
+ nm.Foreground = band == bb ? PrismInk.BandLit[bb] : MutedC;
+ m.Opacity = act ? 1 : 0.3;
+ });
+ var col = new DockPanel { Background = Brushes.Transparent, Cursor = new Cursor(StandardCursorType.Hand), Children = { Docked(nm, Dock.Bottom), Docked(val, Dock.Bottom), m } };
+ ((Control)val).Margin = new Thickness(0, 3, 0, 1);
+ col.PointerPressed += (_, e) => { if (e.GetCurrentPoint(col).Properties.IsLeftButtonPressed) SelectBand(bb); };
+ meters.Children.Add(Col(col, b));
+ }
+ var scale = new Grid { RowDefinitions = new RowDefinitions("Auto,*,Auto,*,Auto,Auto"), Margin = new Thickness(2, 0, 0, 0),
+ Children = { Mono("0", 7, DimC), GRow(Mono("−6", 7, DimC), 2), GRow(Mono("−12", 7, DimC), 4), GRow(new Border { Height = 25 }, 5) } };
+ meters.Children.Add(Col(scale, 3));
+
+ // Solo L / M / H (one band at a time; click the lit one to clear).
+ var soloCells = new Border[3];
+ var soloTxt = Mono("", 7, MutedC); soloTxt.HorizontalAlignment = HorizontalAlignment.Right;
+ void HiSolo()
+ {
+ int s = Sel(Solo, 4) - 1;
+ for (int i = 0; i < 3; i++)
+ {
+ bool on = s == i, act = BandActive(i);
+ soloCells[i].Background = on ? AmberSubtle : OffPill; soloCells[i].BorderBrush = on ? Amber : Brushes.Transparent;
+ var t = (TextBlock)soloCells[i].Child!; t.Foreground = on ? AmberLit : act ? Txt2 : DimC; t.FontWeight = on ? FontWeight.SemiBold : FontWeight.Normal;
+ }
+ soloTxt.Text = s >= 0 && BandActive(s) ? PrismInk.Names[s].ToLowerInvariant() : "none"; soloTxt.Foreground = s >= 0 ? AmberLit : MutedC;
+ }
+ var soloRow = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 3 };
+ string[] sl = { "L", "M", "H" };
+ for (int i = 0; i < 3; i++)
+ {
+ int iv = i;
+ var c = new Border { Height = 15, Padding = new Thickness(6, 0), CornerRadius = new CornerRadius(3), BorderThickness = new Thickness(1), Cursor = new Cursor(StandardCursorType.Hand),
+ Child = new TextBlock { Text = sl[i], FontSize = 8, VerticalAlignment = VerticalAlignment.Center } };
+ c.PointerPressed += (_, e) =>
+ {
+ if (!e.GetCurrentPoint(c).Properties.IsLeftButtonPressed || !BandActive(iv)) return;
+ SetP(Solo, Sel(Solo, 4) == iv + 1 ? 0f : (iv + 1) / 3f); HiSolo(); e.Handled = true;
+ };
+ soloCells[i] = c; soloRow.Children.Add(c);
+ }
+ Learn(soloRow, Solo);
+ ToolTip.SetTip(soloRow, "Solo a band — hear only that band (click again to clear)");
+ readouts.Add(HiSolo); HiSolo();
+ var soloGrid = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,Auto,*"), ColumnSpacing = 6 };
+ soloGrid.Children.Add(Caps("SOLO")); soloGrid.Children.Add(Col(soloRow, 1)); soloGrid.Children.Add(Col(soloTxt, 2));
+ var bottom = Divider(new StackPanel { Spacing = 5, Children = { soloGrid, Toggle(PeakHold, "Peak hold") } });
+ bottom.Margin = new Thickness(0, 5, 0, 0);
+ return new DockPanel { Margin = new Thickness(8, 6, 8, 5), Children = { Docked(Caps("GAIN REDUCTION"), Dock.Top), Docked(bottom, Dock.Bottom), meters } };
+ }
+ Control OutputTab()
+ {
+ var meterL = new PentadLevelBar { Vertical = true, Width = 11, Height = 50 };
+ var meterR = new PentadLevelBar { Vertical = true, Width = 11, Height = 50 };
+ readouts.Add(() => { meterL.SetLinear(Sc(S_OutL)); meterR.SetLinear(Sc(S_OutR)); });
+ static Control Center(Control c) { c.HorizontalAlignment = HorizontalAlignment.Center; return c; }
+ var scale = new Grid { RowDefinitions = new RowDefinitions("*,*,*"), Height = 50, Children = { Mono("0", 7, DimC), GRow(Mono("−12", 7, DimC), 1), GRow(Mono("−48", 7, DimC), 2) } };
+ var meters = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 4, VerticalAlignment = VerticalAlignment.Top, Children = {
+ new StackPanel { Spacing = 2, Children = { meterL, Center(Caps("L")) } },
+ new StackPanel { Spacing = 2, Children = { meterR, Center(Caps("R")) } }, scale } };
+ var top = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 8, Children = { K(Output, "OUTPUT", v => DbF((v - 0.5) * 48), 38, 54), meters } };
+
+ // Sidechain source (None + every other track).
+ var scName = new TextBlock { FontSize = 8, Foreground = TxtC, VerticalAlignment = VerticalAlignment.Center, TextTrimming = TextTrimming.CharacterEllipsis };
+ bool scOk = engine.DeviceAcceptsSidechain(track, di);
+ string SrcName(int id)
+ {
+ for (int i = 0; i < engine.TrackCount; i++)
+ if (engine.TryGetTrackInfo(i, out var ti) && ti.Id == id)
+ { string n = engine.GetTrackName(id); return n.Length > 0 ? n : Inv($"Track {i + 1}"); }
+ return "None";
+ }
+ readouts.Add(() =>
+ {
+ int src = scOk ? engine.DeviceSidechainSource(track, di) : -1;
+ scName.Text = !scOk ? "n/a in a rack" : src < 0 ? "None — own input" : SrcName(src);
+ scName.Foreground = src >= 0 ? TxtC : Txt2;
+ });
+ var scBox = new Border { Height = 16, Background = Inset, BorderBrush = Border2, BorderThickness = new Thickness(1), CornerRadius = new CornerRadius(3), Padding = new Thickness(6, 0),
+ Cursor = new Cursor(StandardCursorType.Hand), IsEnabled = scOk,
+ Child = new DockPanel { Children = { Docked(new TextBlock { Text = "▾", FontSize = 8, Foreground = MutedC, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(5, 0, 0, 0) }, Dock.Right), scName } } };
+ ToolTip.SetTip(scBox, "Sidechain — key every band's detector from another track (split into the same bands)");
+ scBox.PointerPressed += (_, e) =>
+ {
+ if (!e.GetCurrentPoint(scBox).Properties.IsLeftButtonPressed || !scOk) return;
+ var fly = new MenuFlyout();
+ int cur = engine.DeviceSidechainSource(track, di);
+ void Item(string name, int id)
+ {
+ var mi = new MenuItem { Header = name };
+ if (id == cur) mi.Icon = new Avalonia.Controls.Shapes.Ellipse { Width = 6, Height = 6, Fill = Amber };
+ mi.Click += (_, _) => { engine.SetDeviceSidechainSource(track, di, id); ctx.NotifyChanged(); foreach (var a in readouts) a(); };
+ fly.Items.Add(mi);
+ }
+ Item("None — own input", -1);
+ fly.Items.Add(new Separator());
+ for (int i = 0; i < engine.TrackCount; i++)
+ if (engine.TryGetTrackInfo(i, out var ti) && ti.Id != track) Item(SrcName(ti.Id), ti.Id);
+ fly.ShowAt(scBox);
+ e.Handled = true;
+ };
+ var scRow = new Grid { ColumnDefinitions = new ColumnDefinitions("50,*"), VerticalAlignment = VerticalAlignment.Center };
+ scRow.Children.Add(Caps("SIDECHAIN")); scRow.Children.Add(Col(scBox, 1));
+ var listen = Toggle(ScListen, "Listen");
+ ToolTip.SetTip(listen, "Listen — hear the detector's key signal (the sidechain, or the input), per solo band");
+ var mk = Toggle(AutoMakeup, "Auto makeup");
+ ToolTip.SetTip(mk, "Auto makeup — each band gets back about half of its compression at 0 dBFS");
+ var toggles = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,*"), ColumnSpacing = 10 };
+ toggles.Children.Add(listen); toggles.Children.Add(Col(mk, 1));
+ var mid = new StackPanel { Spacing = 5, Children = {
+ SliderRow("LOOKAHEAD", Lookahead, v => Inv($"{v * 10:0.0} ms")),
+ SliderRow("MIX", Mix, Pct), scRow, toggles } };
+
+ var clipTxt = Mono("", 7, TxtC); clipTxt.HorizontalAlignment = HorizontalAlignment.Right;
+ readouts.Add(() =>
+ {
+ double c = Sc(S_ClipDb);
+ clipTxt.Text = On(SoftClip) && c > 0.05 ? Inv($"−0.3 dBFS · {c:0.0}") : "−0.3 dBFS";
+ clipTxt.Foreground = On(SoftClip) ? (c > 0.05 ? NotaPalette.Warning : TxtC) : MutedC;
+ });
+ var clipRow = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,Auto,*"), ColumnSpacing = 6 };
+ var clipSeg = Seg(SoftClip, new[] { "Off", "On" });
+ ToolTip.SetTip(clipSeg, "Soft clip — a smooth ceiling at −0.3 dBFS after the output gain");
+ clipRow.Children.Add(Caps("SOFT CLIP")); clipRow.Children.Add(Col(clipSeg, 1)); clipRow.Children.Add(Col(clipTxt, 2));
+ var midB = Divider(mid); midB.Margin = new Thickness(0, 4, 0, 0);
+ return new DockPanel { LastChildFill = false, Margin = new Thickness(8, 5, 8, 5), Children = {
+ Docked(top, Dock.Top), Docked(midB, Dock.Top), Docked(Divider(clipRow), Dock.Bottom) } };
+ }
+
+ // ======================================================================
+ // Tab frames
+ // ======================================================================
+ var centreHost = new ContentControl(); var rightHost = new ContentControl();
+ var centreBodies = new Control?[3]; var rightBodies = new Control?[2];
+ int centreTab = view.Centre;
+ var extras = new ContentControl { VerticalAlignment = VerticalAlignment.Center };
+ Control ModeExtras()
+ {
+ var seg = Seg(BandsP, new[] { "3", "2", "1" }, () => { if (!BandActive(band)) SelectBand(1); foreach (var a in readouts) a(); });
+ ToolTip.SetTip(seg, "Bands — 3: Low / Mid / High · 2: Low + Mid (Mid runs to 20 kHz) · 1: Mid, full band");
+ return new StackPanel { Orientation = Orientation.Horizontal, Spacing = 5, Children = { Caps("MODE"), seg } };
+ }
+ Control BandChips()
+ {
+ var chips = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 4 };
+ var cells = new Border[3];
+ void Hi()
+ {
+ for (int i = 0; i < 3; i++)
+ {
+ bool on = i == band, act = BandActive(i);
+ cells[i].BorderBrush = on ? PrismInk.Band[i] : NotaPalette.BorderStrong;
+ cells[i].Background = on ? PrismInk.Alpha(PrismInk.BandColor[i], 0x29) : Brushes.Transparent;
+ var t = (TextBlock)cells[i].Child!; t.Foreground = on ? PrismInk.BandLit[i] : act ? Txt2 : DimC; t.FontWeight = on ? FontWeight.SemiBold : FontWeight.Normal;
+ }
+ }
+ for (int i = 0; i < 3; i++)
+ {
+ int iv = i;
+ var c = new Border { Height = 15, Padding = new Thickness(6, 0), CornerRadius = new CornerRadius(3), BorderThickness = new Thickness(1), Cursor = new Cursor(StandardCursorType.Hand),
+ Child = new TextBlock { Text = PrismInk.Names[i], FontSize = 8, VerticalAlignment = VerticalAlignment.Center } };
+ c.PointerPressed += (_, e) => { SelectBand(iv); e.Handled = true; };
+ cells[i] = c; chips.Children.Add(c);
+ }
+ readouts.Add(Hi); Hi();
+ return chips;
+ }
+ Control DetectExtras()
+ {
+ var seg = Seg(Detect, new[] { "Peak", "RMS" });
+ ToolTip.SetTip(seg, "Detector — Peak follows every transient; RMS (10 ms) follows loudness, smoother");
+ return new StackPanel { Orientation = Orientation.Horizontal, Spacing = 5, Children = { Caps("DETECT"), seg } };
+ }
+ var extrasBodies = new Control?[3];
+ void SetExtras(int t) => extras.Content = extrasBodies[t] ??= t switch { 1 => BandChips(), 2 => DetectExtras(), _ => ModeExtras() };
+ Control CentreBody(int t) => centreBodies[t] ??= t switch { 1 => DetailTab(), 2 => TimeTab(), _ => BandsTab() };
+ Control RightBody(int t) => rightBodies[t] ??= t == 1 ? OutputTab() : MetersTab();
+ SetExtras(centreTab);
+ var centre = TabFrame(new[] { "Bands", "Band detail", "Time" }, centreTab, centreHost, CentreBody, false, t =>
+ {
+ centreTab = t; view = (band, t, view.Right); ViewState[(track, di)] = view; SetExtras(t); foreach (var a in readouts) a();
+ }, extras);
+ var rightFrame = TabFrame(new[] { "Meters", "Output" }, view.Right, rightHost, RightBody, true, t =>
+ {
+ view = (band, view.Centre, t); ViewState[(track, di)] = view; foreach (var a in readouts) a();
+ }, null);
+ var right = new Border { Width = 186, Background = Panel, BorderBrush = Border2, BorderThickness = new Thickness(1), CornerRadius = new CornerRadius(5), ClipToBounds = true, Child = rightFrame };
+ DockPanel.SetDock(right, Dock.Right);
+ var centreBox = new Border { Background = Panel, BorderBrush = Border2, BorderThickness = new Thickness(1), CornerRadius = new CornerRadius(5), Margin = new Thickness(5, 0), ClipToBounds = true, Child = centre };
+
+ // ======================================================================
+ // Status strip
+ // ======================================================================
+ var statusLeft = new TextBlock { FontSize = 8, Foreground = Txt2, VerticalAlignment = VerticalAlignment.Center, TextTrimming = TextTrimming.CharacterEllipsis };
+ var statusRight = Mono("", 8, Txt2);
+ string StatusText()
+ {
+ int nb = BandCount();
+ int solo = Sel(Solo, 4) - 1;
+ if (On(ScListen)) return "Listening to the detector key" + (solo >= 0 ? Inv($" · {PrismInk.Names[solo]} band") : "");
+ switch (centreTab)
+ {
+ case 1:
+ {
+ int b = band;
+ string head = solo == b ? Inv($"{PrismInk.Names[b]} solo") : PrismInk.Names[b];
+ string below = On(BP(b, BelowOn)) ? Inv($"below {ThrB(P(BP(b, BelowThresh))):0;−0} dB {RatioBF(P(BP(b, BelowRatio))).Replace(" ", "")}") : "below off";
+ return Inv($"{head} · above {ThrA(P(BP(b, AboveThresh))):0;−0} dB {RatioAF(P(BP(b, AboveRatio))).Replace(" ", "")} · {below} · knee {P(BP(b, Knee)) * 24:0.#} dB");
+ }
+ case 2:
+ {
+ var autos = Enumerable.Range(0, 3).Where(b => BandActive(b) && On(BP(b, AutoRelease))).Select(b => PrismInk.Names[b]).ToList();
+ int src = engine.DeviceAcceptsSidechain(track, di) ? engine.DeviceSidechainSource(track, di) : -1;
+ string sc = src >= 0 ? "sidechain: " + engine.GetTrackName(src) : "own input";
+ return Inv($"{(On(Detect) ? "RMS" : "Peak")} detector · {(autos.Count > 0 ? "auto release on " + string.Join(", ", autos) : "fixed release")} · {sc}");
+ }
+ default:
+ string xo = nb == 3 ? Inv($"crossovers {HzF(XHz(P(XoverLow)))} / {HzF(XHz(P(XoverHigh)))}") : nb == 2 ? Inv($"crossover {HzF(XHz(P(XoverLow)))}") : "full band";
+ return Inv($"{nb} {(nb == 1 ? "band" : "bands")} · {xo} · amount {P(Amount) * 100:0} %{(solo >= 0 && BandActive(solo) ? " · " + PrismInk.Names[solo] + " solo" : "")}");
+ }
+ }
+ readouts.Add(() =>
+ {
+ statusLeft.Text = StatusText();
+ statusLeft.Foreground = (centreTab == 1 && Sel(Solo, 4) - 1 == band) || On(ScListen) ? AmberLit : Txt2;
+ double sr = Sc(S_SampleRate), lat = Sc(S_Latency);
+ string la = lat > 0 && sr > 0 ? Inv($"lookahead {lat * 1000 / sr:0.#} ms") : "no lookahead";
+ string sc = Sc(S_ScActive) > 0.5 ? " · SC" : "";
+ statusRight.Text = sr > 0 ? Inv($"{sr / 1000:0.#} kHz · {la}{sc} · 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 = Inset, BorderBrush = Border2, 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 = { globCol, right, centreBox } };
+ var root = new DockPanel { LastChildFill = true, Background = RailBg, Children = { status, bodyRow } };
+
+ void Refresh()
+ {
+ scN = engine.DeviceScope(track, di, scope, kScope);
+ if (!BandActive(band)) { band = 1; foreach (var a in bandListeners) a(); }
+ foreach (var a in readouts) a();
+ }
+ 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, int initial, ContentControl host, Func<int, Control> body, bool centered, Action<int>? changed, Control? extrasCtl)
+ {
+ int sel = Math.Clamp(initial, 0, tabs.Length - 1); var btns = new Border[tabs.Length];
+ void Hi()
+ {
+ for (int i = 0; i < tabs.Length; i++)
+ {
+ bool on = i == sel;
+ btns[i].Background = on ? TabBg : Brushes.Transparent; btns[i].BorderBrush = on ? Amber : Brushes.Transparent;
+ var tb = (TextBlock)btns[i].Child!; tb.Foreground = on ? AmberLit : MutedC; 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 = MutedC, 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 = Border2, 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.cs
index ed70401b..5c3048ec 100644
--- a/src/managed/Nota.App/DeviceCards/DeviceCardFactory.cs
+++ b/src/managed/Nota.App/DeviceCards/DeviceCardFactory.cs
@@ -39,6 +39,7 @@ internal sealed class DeviceCardFactory
[18] = new AutoGainDeviceBody(),
[19] = new ShutterDeviceBody(),
[20] = new ChamberDeviceBody(),
+ [21] = new PrismDeviceBody(),
};
/// <summary>Resolve the body for a device: -1 = hosted plugin, a mapped built-in kind,
diff --git a/src/managed/Nota.App/DeviceCards/Rack/RackCardView.cs b/src/managed/Nota.App/DeviceCards/Rack/RackCardView.cs
index 66bc327c..4b268205 100644
--- a/src/managed/Nota.App/DeviceCards/Rack/RackCardView.cs
+++ b/src/managed/Nota.App/DeviceCards/Rack/RackCardView.cs
@@ -25,8 +25,8 @@ namespace Nota.App;
internal sealed class RackCardView(DeviceCardContext ctx)
{
- private static readonly string[] RackDeviceNames = { "Nota EQ-3", "Nota EQ-8", "Nota Dynamic EQ-8", "Nota Compressor", "Nota Reverb", "Nota Chamber", "Nota Delay", "Nota Utility", "Nota Level", "Nota Ceiling", "Nota Shutter", "Nota Valve", "Nota Auto Filter", "Nota Vintage", "Nota Forge", "Nota Crush", "Nota Orbit", "Nota Auto Shift", "Nota Beat Repeat", "Nota Strata" };
- private static readonly int[] RackDeviceKinds = { 16, 0, 13, 1, 2, 20, 3, 4, 18, 14, 19, 6, 7, 8, 17, 12, 9, 10, 11, 15 };
+ private static readonly string[] RackDeviceNames = { "Nota EQ-3", "Nota EQ-8", "Nota Dynamic EQ-8", "Nota Compressor", "Nota Prism", "Nota Reverb", "Nota Chamber", "Nota Delay", "Nota Utility", "Nota Level", "Nota Ceiling", "Nota Shutter", "Nota Valve", "Nota Auto Filter", "Nota Vintage", "Nota Forge", "Nota Crush", "Nota Orbit", "Nota Auto Shift", "Nota Beat Repeat", "Nota Strata" };
+ private static readonly int[] RackDeviceKinds = { 16, 0, 13, 1, 21, 2, 20, 3, 4, 18, 14, 19, 6, 7, 8, 17, 12, 9, 10, 11, 15 };
private static readonly IBrush RowSel = new SolidColorBrush(Color.FromArgb(0x22, 0xD8, 0xA0, 0x3D)); // selected chain wash
private readonly DeviceCardContext _ctx = ctx;
@@ -2090,6 +2090,10 @@ internal class RackChainDeviceEngineProxy : System.Reflection.DispatchProxy
case nameof(Nota.Application.IAudioEngine.DeviceGainReduction): return 0f;
case nameof(Nota.Application.IAudioEngine.DeviceLoadFile): return false; // chain devices keep params only
case nameof(Nota.Application.IAudioEngine.DeviceText): return "";
+ // No telemetry surface for chain devices — passing through would read the
+ // track's top-level device at the same index.
+ case nameof(Nota.Application.IAudioEngine.DeviceScope): return 0;
+ case nameof(Nota.Application.IAudioEngine.DeviceLayerWave): return 0;
case nameof(Nota.Application.IAudioEngine.DeviceAcceptsSidechain): return false;
case nameof(Nota.Application.IAudioEngine.DeviceSidechainSource): return -1;
case nameof(Nota.Application.IAudioEngine.DeviceSidechainGain): return 0f;
diff --git a/src/managed/Nota.Infrastructure/Persistence/FactoryPresetCatalog.cs b/src/managed/Nota.Infrastructure/Persistence/FactoryPresetCatalog.cs
index cec68d05..47c8b619 100644
--- a/src/managed/Nota.Infrastructure/Persistence/FactoryPresetCatalog.cs
+++ b/src/managed/Nota.Infrastructure/Persistence/FactoryPresetCatalog.cs
@@ -347,6 +347,62 @@ public sealed class FactoryPresetCatalog : IFactoryPresets
Fx("chamber", 20, "Send · Big Hall", ("IR", 0f), ("Blend", 0.5f), ("Wet Only", 1f), ("Conv Predelay", 0.2f), ("Algo Decay", 0.65f), ("EQ Low Cut", 0.437f), ("EQ High Cut", 0.8f), ("Bass Mono", 0.548f));
Fx("chamber", 20, "Send · Plate", ("IR", 0.5f), ("Blend", 0.5f), ("Wet Only", 1f), ("Algo Mode", 0.333f), ("Algo Decay", 0.5f), ("Conv Predelay", 0.2f), ("Algo Predelay", 0.2f), ("EQ Low Cut", 0.5f));
+ // ---- Nota Prism (kind 21) — three-band dynamics, all params normalized 0..1 (unnamed params
+ // reset to their defaults: every band compresses −18 dB 2:1). Bands 0 = 3 / .5 = 2 / 1 = 1;
+ // Crossover 20·1000^v Hz (180 Hz .318, 2.4 kHz .693); Above Thresh −60+60·v dB; Above Ratio
+ // = 1 − 1/ratio (.5 = 2:1, .75 = 4:1, 1 = ∞:1, 0 = off); Below Thresh −80+80·v dB; Below Ratio
+ // 4^((v−.5)·2) (.5 = 1:1, .75 = 2:1 expansion, .25 = 2:1 upward); Attack 0.1·3000^v ms;
+ // Release 5·600^v ms; Gain / Output (v−.5)·48 dB; Floor v·48 dB; Knee v·24 dB; Lookahead v·10 ms.
+ Fx("prism", 21, "Bus Glue", ("Amount", 0.74f), ("Output", 0.525f), ("Soft Clip", 1f),
+ ("Low Above Thresh", 0.767f), ("Low Above Ratio", 0.667f), ("Low Gain", 0.529f),
+ ("Mid Below On", 1f), ("Mid Below Thresh", 0.475f), ("Mid Below Ratio", 0.6214f),
+ ("High Above Thresh", 0.6f), ("High Above Ratio", 0.75f), ("High Gain", 0.483f));
+ Fx("prism", 21, "Upward Squash", ("Amount", 0.8f), ("Mix", 0.65f), ("Output", 0.4375f), ("Soft Clip", 1f),
+ ("Low Above Thresh", 0.533f), ("Low Above Ratio", 0.9f), ("Low Attack", 0.4248f), ("Low Release", 0.4334f), ("Low Gain", 0.5625f),
+ ("Low Below On", 1f), ("Low Below Ratio", 0f), ("Low Below Attack", 0.4248f), ("Low Below Release", 0.4334f), ("Low Floor", 0.75f),
+ ("Mid Above Thresh", 0.533f), ("Mid Above Ratio", 0.9f), ("Mid Attack", 0.4248f), ("Mid Release", 0.4334f),
+ ("Mid Below On", 1f), ("Mid Below Ratio", 0f), ("Mid Below Attack", 0.4248f), ("Mid Below Release", 0.4334f), ("Mid Floor", 0.75f),
+ ("High Above Thresh", 0.533f), ("High Above Ratio", 0.9f), ("High Attack", 0.4248f), ("High Release", 0.4334f), ("High Gain", 0.5625f),
+ ("High Below On", 1f), ("High Below Ratio", 0f), ("High Below Attack", 0.4248f), ("High Below Release", 0.4334f), ("High Floor", 0.75f));
+ Fx("prism", 21, "Vocal Control", ("Amount", 0.8f), ("Detect", 1f), ("Lookahead", 0.3f), ("Output", 0.55f), ("Auto Makeup", 1f),
+ ("Crossover Low", 0.2917f), ("Crossover High", 0.7993f),
+ ("Low Above Thresh", 0.6f), ("Low Above Ratio", 0.75f), ("Low Attack", 0.7038f), ("Low Release", 0.6596f), ("Low Auto Release", 1f), ("Low Gain", 0.479f),
+ ("Mid Above Thresh", 0.667f), ("Mid Attack", 0.5752f), ("Mid Release", 0.6052f),
+ ("High Above Thresh", 0.5f), ("High Above Ratio", 0.667f), ("High Attack", 0.4248f), ("High Release", 0.4968f), ("High Auto Release", 1f));
+ Fx("prism", 21, "De-Esser", ("Crossover Low", 0.534f), ("Crossover High", 0.8257f), ("Lookahead", 0.2f),
+ ("Low Above Ratio", 0f), ("Mid Above Ratio", 0f),
+ ("High Above Thresh", 0.5f), ("High Above Ratio", 0.833f), ("High Attack", 0.2876f), ("High Release", 0.36f), ("High Knee", 0.125f));
+ Fx("prism", 21, "Low-End Tamer", ("Crossover Low", 0.2594f), ("Crossover High", 0.699f),
+ ("Low Above Thresh", 0.6f), ("Low Above Ratio", 0.75f), ("Low Attack", 0.6618f), ("Low Release", 0.5317f),
+ ("Mid Above Ratio", 0f), ("High Above Ratio", 0f));
+ Fx("prism", 21, "Drum Punch", ("Crossover Low", 0.3333f), ("Crossover High", 0.7253f), ("Output", 0.52f),
+ ("Low Above Thresh", 0.8f), ("Low Attack", 0.7124f), ("Low Release", 0.4683f), ("Low Gain", 0.5417f),
+ ("Low Below On", 1f), ("Low Below Thresh", 0.5625f), ("Low Below Ratio", 0.75f), ("Low Floor", 0.25f),
+ ("Mid Above Thresh", 0.8f), ("Mid Attack", 0.6618f), ("Mid Release", 0.4334f),
+ ("Mid Below On", 1f), ("Mid Below Thresh", 0.5625f), ("Mid Below Ratio", 0.75f), ("Mid Floor", 0.25f),
+ ("High Above Thresh", 0.8f), ("High Attack", 0.5752f), ("High Release", 0.36f),
+ ("High Below On", 1f), ("High Below Thresh", 0.5f), ("High Below Ratio", 0.75f), ("High Floor", 0.25f));
+ Fx("prism", 21, "Gentle Master", ("Lookahead", 0.5f), ("Soft Clip", 1f), ("Crossover Low", 0.3333f), ("Crossover High", 0.7253f),
+ ("Low Above Thresh", 0.667f), ("Low Above Ratio", 0.333f), ("Low Attack", 0.7124f), ("Low Release", 0.6401f), ("Low Knee", 0.5f), ("Low Auto Release", 1f),
+ ("Mid Above Thresh", 0.667f), ("Mid Above Ratio", 0.333f), ("Mid Attack", 0.7124f), ("Mid Release", 0.6401f), ("Mid Knee", 0.5f), ("Mid Auto Release", 1f),
+ ("High Above Thresh", 0.667f), ("High Above Ratio", 0.333f), ("High Attack", 0.6618f), ("High Release", 0.5767f), ("High Knee", 0.5f), ("High Auto Release", 1f));
+ Fx("prism", 21, "Noise Floor Cleanup",("Low Above Ratio", 0f), ("Mid Above Ratio", 0f), ("High Above Ratio", 0f),
+ ("Low Below On", 1f), ("Low Below Thresh", 0.375f), ("Low Below Ratio", 0.8962f),
+ ("Mid Below On", 1f), ("Mid Below Thresh", 0.375f), ("Mid Below Ratio", 0.8962f),
+ ("High Below On", 1f), ("High Below Thresh", 0.4375f), ("High Below Ratio", 0.8962f), ("High Floor", 0.625f));
+ Fx("prism", 21, "Air Lift", ("Crossover High", 0.8257f), ("Low Above Ratio", 0f), ("Mid Above Ratio", 0f),
+ ("High Above Thresh", 0.6f), ("High Above Ratio", 0.5f), ("High Gain", 0.5417f),
+ ("High Below On", 1f), ("High Below Thresh", 0.4375f), ("High Below Ratio", 0.25f), ("High Floor", 0.25f));
+ Fx("prism", 21, "Two-Band Bass", ("Bands", 0.5f), ("Crossover Low", 0.3333f), ("Detect", 1f),
+ ("Low Above Thresh", 0.667f), ("Low Above Ratio", 0.75f), ("Low Attack", 0.6618f), ("Low Release", 0.5767f),
+ ("Mid Above Thresh", 0.6f), ("Mid Attack", 0.4886f), ("Mid Release", 0.4683f));
+ Fx("prism", 21, "Single-Band Leveler",("Bands", 1f), ("Detect", 1f), ("Auto Makeup", 1f),
+ ("Mid Above Thresh", 0.6f), ("Mid Above Ratio", 0.667f), ("Mid Attack", 0.7124f), ("Mid Release", 0.6401f), ("Mid Auto Release", 1f), ("Mid Knee", 0.5f));
+ Fx("prism", 21, "Parallel Crush", ("Mix", 0.4f), ("Output", 0.54f),
+ ("Low Above Thresh", 0.5f), ("Low Above Ratio", 0.9f), ("Low Attack", 0.4248f), ("Low Release", 0.4334f), ("Low Gain", 0.625f),
+ ("Mid Above Thresh", 0.5f), ("Mid Above Ratio", 0.9f), ("Mid Attack", 0.4248f), ("Mid Release", 0.4334f), ("Mid Gain", 0.625f),
+ ("High Above Thresh", 0.5f), ("High Above Ratio", 0.9f), ("High Attack", 0.4248f), ("High Release", 0.4334f), ("High Gain", 0.625f));
+
// ---- Compressor (kind 1) — Thresh -60..0, Ratio 1..20, Attack .1..100 ms, Release 5..1000 ms, Makeup 0..24 dB
// Character: Clean 0 / Glue 1 / Punch 2 / Opto 3 / FET 4.
Fx("comp", 1, "Drum Glue", ("Character", 1f), ("Thresh", -18f), ("Ratio", 3f), ("Attack", 30f), ("Release", 200f), ("Knee", 8f), ("AutoGain", 1f), ("Mix", 100f));
diff --git a/src/managed/Nota.Mcp/Tools/DeviceTools.cs b/src/managed/Nota.Mcp/Tools/DeviceTools.cs
index 8bc74294..dfb31163 100644
--- a/src/managed/Nota.Mcp/Tools/DeviceTools.cs
+++ b/src/managed/Nota.Mcp/Tools/DeviceTools.cs
@@ -19,7 +19,7 @@ public sealed class DeviceTools(IAudioEngine engine, IEngineDispatch dispatch, I
(0, "EQ-8"), (1, "Compressor"), (2, "Reverb"), (3, "Delay"), (4, "Utility"), (5, "Effect Rack"),
(6, "Nota Valve"), (7, "Auto Filter"), (8, "Nota Vintage"), (9, "Nota Orbit"), (10, "Auto Shift"),
(11, "Beat Repeat"), (12, "Crush"), (13, "Dynamic EQ-8"), (14, "Ceiling"), (15, "Strata"),
- (16, "EQ-3"), (17, "Forge"), (18, "Nota Level"), (19, "Nota Shutter"), (20, "Nota Chamber"),
+ (16, "EQ-3"), (17, "Forge"), (18, "Nota Level"), (19, "Nota Shutter"), (20, "Nota Chamber"), (21, "Nota Prism"),
};
public sealed record DeviceKind(int Kind, string Name);
diff --git a/src/managed/Nota.Presentation/ViewModels/BrowserViewModel.cs b/src/managed/Nota.Presentation/ViewModels/BrowserViewModel.cs
index 9b380bae..a74e64cc 100644
--- a/src/managed/Nota.Presentation/ViewModels/BrowserViewModel.cs
+++ b/src/managed/Nota.Presentation/ViewModels/BrowserViewModel.cs
@@ -201,6 +201,7 @@ public sealed partial class BrowserViewModel : ObservableObject
new() { Name = "Nota EQ-3", Kind = BrowserItemKind.BuiltinEffect, BuiltinKind = 16, Sub = "3-band EQ" },
new() { Name = "Nota EQ-8", Kind = BrowserItemKind.BuiltinEffect, BuiltinKind = 0, Sub = "8-band EQ" },
new() { Name = "Nota Compressor", Kind = BrowserItemKind.BuiltinEffect, BuiltinKind = 1, Sub = "built-in" },
+ new() { Name = "Nota Prism", Kind = BrowserItemKind.BuiltinEffect, BuiltinKind = 21, Sub = "multiband dynamics" },
new() { Name = "Nota Reverb", Kind = BrowserItemKind.BuiltinEffect, BuiltinKind = 2, Sub = "built-in" },
new() { Name = "Nota Chamber", Kind = BrowserItemKind.BuiltinEffect, BuiltinKind = 20, Sub = "hybrid reverb" },
new() { Name = "Nota Delay", Kind = BrowserItemKind.BuiltinEffect, BuiltinKind = 3, Sub = "built-in" },
diff --git a/src/native/nota.engine/src/Engine_Devices.cpp b/src/native/nota.engine/src/Engine_Devices.cpp
index c94c79aa..7ae18a59 100644
--- a/src/native/nota.engine/src/Engine_Devices.cpp
+++ b/src/native/nota.engine/src/Engine_Devices.cpp
@@ -21,6 +21,7 @@
#include "AutoGain.h"
#include "Shutter.h"
#include "Chamber.h"
+#include "Prism.h"
#include "Ceiling.h"
#include "Strata.h"
#include "Vintage.h"
@@ -429,6 +430,7 @@ int32_t Engine::addTrackBuiltinDevice(int32_t trackId, int32_t kind) {
else if (kind == 18) dev = std::make_shared<AutoGain>();
else if (kind == 19) dev = std::make_shared<Shutter>();
else if (kind == 20) dev = std::make_shared<Chamber>();
+ else if (kind == 21) dev = std::make_shared<Prism>();
else return -1;
dev->setSampleRate(transport_.sampleRate() > 0 ? transport_.sampleRate() : 44100.0, kMaxBlock);
if (kind == 5) if (auto* rk = dynamic_cast<RackDevice*>(dev.get())) rk->addChain(-1); // one pass-through chain
@@ -491,6 +493,7 @@ std::shared_ptr<Device> Engine::cloneDevice(const Device& src) const {
case 18: d = std::make_shared<AutoGain>(); break;
case 19: d = std::make_shared<Shutter>(); break;
case 20: d = std::make_shared<Chamber>(); break;
+ case 21: d = std::make_shared<Prism>(); break;
default: d = src.clone(); break; // hosted plugin
}
if (!d) return nullptr;
@@ -566,6 +569,7 @@ static std::shared_ptr<Device> makeBuiltinDevice(int32_t kind) {
case 18: return std::make_shared<AutoGain>();
case 19: return std::make_shared<Shutter>();
case 20: return std::make_shared<Chamber>();
+ case 21: return std::make_shared<Prism>();
default: return nullptr; // Rack / plugin: no simple per-param default
}
}
diff --git a/src/native/nota.engine/src/Prism.h b/src/native/nota.engine/src/Prism.h
new file mode 100644
index 00000000..1b0e6598
--- /dev/null
+++ b/src/native/nota.engine/src/Prism.h
@@ -0,0 +1,472 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.
+//
+// Nota Prism — three-band dynamics (in the spirit of Ableton's Multiband Dynamics). The
+// input is split by two Linkwitz-Riley 4th-order crossovers (TPT state-variable filters,
+// the low band allpass-corrected so the bands sum flat) into Low / Mid / High — or two
+// bands (Low + Mid, the Mid running to 20 kHz) or one (Mid, full band). Each band has two
+// independent processors driven by its own level detector (peak or RMS, stereo-linked):
+// ABOVE — downward compression over a threshold (ratio 1:1 … ∞:1, soft knee), and
+// BELOW — downward expansion (ratio > 1) or upward compression (ratio < 1) under a
+// second threshold, limited to ±Floor dB,
+// each with its own attack / release (optional program-dependent auto release on ABOVE),
+// then a per-band gain. Amount scales every ratio (0 % = no dynamics). Around them: an
+// external sidechain (band-split through its own crossovers, so each band keys off the
+// matching band of the key), lookahead (reported as latency for PDC), auto makeup, band
+// solo, sidechain listen, a phase-coherent Mix (the dry path is the unprocessed band sum),
+// output gain and a soft clipper at −0.3 dBFS.
+//
+// All params are normalized 0..1 (APPEND ONLY — the order is the persisted layout); persist /
+// clone / automation are generic through the base Device. Telemetry for the card:
+// scopeRead packs meters (S_*); layerWave 0/1 = recent input/output mono samples (the
+// spectrum), 2 + 2b / 3 + 2b = band b's input-peak / detector-level trace (~6 ms per point).
+
+#pragma once
+
+#include "Device.h"
+
+#include <algorithm>
+#include <atomic>
+#include <chrono>
+#include <cmath>
+#include <cstdint>
+#include <vector>
+
+namespace nota {
+
+namespace prism {
+
+constexpr double kPi = 3.14159265358979323846;
+constexpr float kSqrt2 = 1.41421356f;
+
+inline double expMap(double v, double lo, double hi) { return lo * std::pow(hi / lo, std::clamp(v, 0.0, 1.0)); }
+
+// Butterworth-Q (k = √2) TPT state-variable filter (Cytomic). LR4 = two cascaded stages.
+struct Coef { float a1 = 1, a2 = 0, a3 = 0; };
+inline Coef coef(double hz, double sr) {
+ const double g = std::tan(kPi * std::clamp(hz, 10.0, sr * 0.45) / sr);
+ Coef c;
+ c.a1 = static_cast<float>(1.0 / (1.0 + g * (g + kSqrt2)));
+ c.a2 = static_cast<float>(g * c.a1);
+ c.a3 = static_cast<float>(g * c.a2);
+ return c;
+}
+struct Svf {
+ float ic1 = 0, ic2 = 0;
+ void reset() { ic1 = ic2 = 0; }
+ // bp = v1, lp = v2; hp = x − √2·bp − lp; allpass = x − 2√2·bp.
+ inline void tick(float x, const Coef& c, float& bp, float& lp) {
+ const float v3 = x - ic2;
+ const float v1 = c.a1 * ic1 + c.a2 * v3;
+ const float v2 = ic2 + c.a2 * ic1 + c.a3 * v3;
+ ic1 = 2.0f * v1 - ic1; ic2 = 2.0f * v2 - ic2;
+ bp = v1; lp = v2;
+ }
+ inline float lp(float x, const Coef& c) { float b, l; tick(x, c, b, l); return l; }
+ inline float hp(float x, const Coef& c) { float b, l; tick(x, c, b, l); return x - kSqrt2 * b - l; }
+ inline float ap(float x, const Coef& c) { float b, l; tick(x, c, b, l); return x - 2.0f * kSqrt2 * b; }
+};
+
+// One channel's band splitter. LR4 low/high share their first stage (its lp feeds the
+// low LR4, its hp the high LR4); in 3-band mode the low band passes the second
+// crossover's allpass so Low + Mid + High sums to a flat-magnitude allpass.
+struct Splitter {
+ Svf a1, b1, c1, ap2, a2, b2, c2;
+ void reset() { for (Svf* s : { &a1, &b1, &c1, &ap2, &a2, &b2, &c2 }) s->reset(); }
+ inline void run(float x, int nb, const Coef& k1, const Coef& k2, float out[3]) {
+ if (nb <= 1) { out[0] = 0.0f; out[1] = x; out[2] = 0.0f; return; }
+ float bp, lp;
+ a1.tick(x, k1, bp, lp);
+ const float hp = x - kSqrt2 * bp - lp;
+ const float low = b1.lp(lp, k1);
+ const float rest = c1.hp(hp, k1);
+ if (nb == 2) { out[0] = low; out[1] = rest; out[2] = 0.0f; return; }
+ out[0] = ap2.ap(low, k2);
+ float bp2, lp2;
+ a2.tick(rest, k2, bp2, lp2);
+ const float hp2 = rest - kSqrt2 * bp2 - lp2;
+ out[1] = b2.lp(lp2, k2);
+ out[2] = c2.hp(hp2, k2);
+ }
+};
+
+// Soft-knee static curve: 0 below −W/2, quadratic across the knee, linear (= u) above.
+inline float knee(float u, float w) {
+ if (w > 0.01f) {
+ if (2.0f * u < -w) return 0.0f;
+ if (2.0f * u <= w) { const float t = u + 0.5f * w; return t * t / (2.0f * w); }
+ return u;
+ }
+ return u > 0.0f ? u : 0.0f;
+}
+
+} // namespace prism
+
+class Prism final : public Device {
+public:
+ static constexpr int kBands = 3;
+ // Global params.
+ enum { Amount = 0, Output, Bands, XoverLow, XoverHigh, Detect, Lookahead, AutoMakeup, SoftClip,
+ ScListen, Solo, PeakHold, Mix, kGlobal };
+ // Per-band fields (band b's field f lives at kGlobal + b * kPerBand + f).
+ enum { AboveThresh = 0, AboveRatio, Attack, Release, Gain, BelowOn, BelowThresh, BelowRatio,
+ BelowAttack, BelowRelease, Floor, Knee, AutoRelease, kPerBand };
+ static constexpr int kNumParams = kGlobal + kBands * kPerBand; // 52
+ static constexpr int P(int band, int field) { return kGlobal + band * kPerBand + field; }
+
+ // Packed scope telemetry (lock-free, UI-polled).
+ enum { S_Gr0 = 0, S_Gr1, S_Gr2, S_Boost0, S_Boost1, S_Boost2, S_Level0, S_Level1, S_Level2,
+ S_OutL, S_OutR, S_InPeak, S_Cpu, S_SampleRate, S_Latency, S_ScActive, S_ClipDb, S_Bands,
+ S_XoverLow, S_XoverHigh, kScope };
+
+ static constexpr int kSpecLen = 2048; // spectrum rings (power of two)
+ static constexpr int kTraceLen = 256; // detector traces
+
+ // Musical mappings (shared with the card / presets via the comments in FactoryPresetCatalog).
+ static double threshAboveDb(float v) { return -60.0 + 60.0 * v; }
+ static double threshBelowDb(float v) { return -80.0 + 80.0 * v; }
+ static double ratioBelow(float v) { return std::pow(4.0, (v - 0.5) * 2.0); } // 0.25 … 4
+ static double timeMs(float v, bool release) { return release ? prism::expMap(v, 5.0, 3000.0) : prism::expMap(v, 0.1, 300.0); }
+ static double xoverHz(float v) { return prism::expMap(v, 20.0, 20000.0); }
+
+ Prism() {
+ static const float glob[kGlobal] = {
+ 1.0f, 0.5f, 0.0f, 0.318f, 0.693f, // amount 100 % · output 0 dB · 3 bands · 180 Hz · 2.4 kHz
+ 0.0f, 0.0f, 0.0f, 0.0f, // peak · lookahead 0 · auto makeup off · soft clip off
+ 0.0f, 0.0f, 0.0f, 1.0f }; // listen off · no solo · peak hold off · mix 100 %
+ for (int i = 0; i < kGlobal; ++i) p_[i].store(glob[i], std::memory_order_relaxed);
+ // Attack / release per band: Low 20 / 200 ms, Mid 10 / 150 ms, High 5 / 100 ms.
+ static const float atk[kBands] = { 0.6618f, 0.5752f, 0.4886f };
+ static const float rel[kBands] = { 0.5767f, 0.5317f, 0.4683f };
+ for (int b = 0; b < kBands; ++b) {
+ const float def[kPerBand] = {
+ 0.7f, 0.5f, atk[b], rel[b], 0.5f, // above −18 dB · 2:1 · attack · release · gain 0 dB
+ 0.0f, 0.5f, 0.6214f, // below off · −40 dB · 1.4:1
+ 0.7124f, 0.6401f, // below attack 30 ms · release 300 ms
+ 0.5f, 0.25f, 0.0f }; // floor 24 dB · knee 6 dB · auto release off
+ for (int f = 0; f < kPerBand; ++f) p_[P(b, f)].store(def[f], std::memory_order_relaxed);
+ }
+ setSampleRate(44100.0, 0);
+ }
+
+ // ---- lifecycle ---------------------------------------------------------------
+ void setSampleRate(double sr, int32_t /*maxBlock*/) override {
+ sr_ = sr > 0 ? sr : 44100.0;
+ srA_.store(static_cast<float>(sr_), std::memory_order_relaxed);
+ laSize_ = static_cast<int>(sr_ * 0.0105) + 2; // up to 10 ms lookahead
+ for (auto& d : delay_) d.assign(static_cast<size_t>(laSize_) * 2, 0.0f);
+ laW_ = 0;
+ traceDiv_ = std::max(1, static_cast<int>(std::lround(sr_ * 0.006)));
+ traceCount_ = 0;
+ for (auto& s : split_) s.reset();
+ scSplit_.reset();
+ for (int b = 0; b < kBands; ++b) {
+ BandState& s = st_[b];
+ s = BandState{};
+ s.thrA = static_cast<float>(threshAboveDb(get(P(b, AboveThresh))));
+ s.thrB = static_cast<float>(threshBelowDb(get(P(b, BelowThresh))));
+ s.gain = static_cast<float>((get(P(b, Gain)) - 0.5f) * 48.0f);
+ }
+ xl_ = static_cast<float>(std::log(xoverHz(get(XoverLow))));
+ xh_ = static_cast<float>(std::log(xoverHz(get(XoverHigh))));
+ outS_ = 1.0f; mixS_ = get(Mix);
+ }
+
+ int32_t latencySamples() const override {
+ return std::clamp(static_cast<int>(std::lround(get(Lookahead) * 10.0 * 0.001 * sr_)), 0, laSize_ - 1);
+ }
+
+ // ---- sidechain ------------------------------------------------------------------
+ int32_t sidechainSourceTrackId() const override { return scTrackId_.load(std::memory_order_relaxed); }
+ void setSidechainSourceTrackId(int32_t id) override { scTrackId_.store(id, std::memory_order_relaxed); }
+ void setSidechain(const float* interleaved, int32_t frames) override { scBuf_ = interleaved; scFrames_ = frames; }
+ bool acceptsSidechain() const override { return true; }
+
+ // ---- DSP ---------------------------------------------------------------------
+ void process(float* buf, int32_t frames) override {
+ if (frames <= 0) return;
+ const auto t0 = std::chrono::steady_clock::now();
+ const double sr = sr_;
+
+ // ---- block parameters ----
+ const float amount = get(Amount);
+ const float outTarget = std::pow(10.0f, (get(Output) - 0.5f) * 48.0f / 20.0f);
+ const int nb = 3 - std::clamp(static_cast<int>(std::lround(get(Bands) * 2.0f)), 0, 2);
+ const bool rms = get(Detect) >= 0.5f;
+ const int la = latencySamples();
+ const bool autoMk = get(AutoMakeup) >= 0.5f;
+ const bool clip = get(SoftClip) >= 0.5f;
+ const bool listen = get(ScListen) >= 0.5f;
+ int solo = std::clamp(static_cast<int>(std::lround(get(Solo) * 3.0f)), 0, 3) - 1;
+ const float mixTarget = get(Mix);
+ bool active[kBands] = { nb >= 2, true, nb >= 3 };
+ if (solo >= 0 && !active[solo]) solo = -1;
+
+ const float* sc = (scBuf_ && scFrames_ >= frames) ? scBuf_ : nullptr;
+ const float scGain = std::pow(10.0f, sidechainGainDb() / 20.0f);
+
+ struct BandCfg { float thrA, slopeA, atkA, relA, relFast, relSlow, slowAtk, gain, thrB, slopeB, atkB, relB, floor, knee; bool below, autoRel; };
+ BandCfg cfg[kBands];
+ auto coefMs = [sr](double ms) { return static_cast<float>(std::exp(-1.0 / (std::max(0.01, ms) * 0.001 * sr))); };
+ for (int b = 0; b < kBands; ++b) {
+ BandCfg& c = cfg[b];
+ c.thrA = static_cast<float>(threshAboveDb(get(P(b, AboveThresh))));
+ c.slopeA = std::clamp(get(P(b, AboveRatio)), 0.0f, 1.0f) * amount; // 1 − 1/ratio
+ const double atk = timeMs(get(P(b, Attack)), false), rel = timeMs(get(P(b, Release)), true);
+ c.atkA = coefMs(atk); c.relA = coefMs(rel);
+ c.relFast = coefMs(rel * 0.4); c.relSlow = coefMs(rel * 2.5); c.slowAtk = coefMs(std::max(atk * 4.0, 60.0));
+ c.autoRel = get(P(b, AutoRelease)) >= 0.5f;
+ const float mk = autoMk ? 0.5f * c.slopeA * -c.thrA : 0.0f;
+ c.gain = (get(P(b, Gain)) - 0.5f) * 48.0f + mk;
+ c.below = get(P(b, BelowOn)) >= 0.5f;
+ c.thrB = static_cast<float>(threshBelowDb(get(P(b, BelowThresh))));
+ c.slopeB = c.below ? static_cast<float>(ratioBelow(get(P(b, BelowRatio))) - 1.0) * amount : 0.0f;
+ c.atkB = coefMs(timeMs(get(P(b, BelowAttack)), false));
+ c.relB = coefMs(timeMs(get(P(b, BelowRelease)), true));
+ c.floor = get(P(b, Floor)) * 48.0f;
+ c.knee = get(P(b, Knee)) * 24.0f;
+ }
+
+ // Crossover targets (log Hz), kept ≥ 1/3 octave apart.
+ float fl = static_cast<float>(xoverHz(get(XoverLow))), fh = static_cast<float>(xoverHz(get(XoverHigh)));
+ fl = std::clamp(fl, 30.0f, 12000.0f); fh = std::clamp(fh, 40.0f, 16000.0f);
+ if (fh < fl * 1.26f) { fh = std::min(16000.0f, fl * 1.26f); fl = std::min(fl, fh / 1.26f); }
+ const float tl = std::log(fl), th = std::log(fh);
+ const float xs = static_cast<float>(1.0 - std::exp(-static_cast<double>(kCtrl) / (0.02 * sr)));
+ const float sm = static_cast<float>(1.0 - std::exp(-1.0 / (0.015 * sr)));
+ const float rmsC = static_cast<float>(std::exp(-1.0 / (0.010 * sr)));
+ constexpr float kDbPerLn = 8.68588964f, kLnPerDb = 0.115129255f;
+ const float clipC = 0.96605088f, clipT = 0.75f * clipC; // −0.3 dBFS ceiling, soft from −2.8 dBFS
+
+ prism::Coef k1 = prism::coef(std::exp(xl_), sr), k2 = prism::coef(std::exp(xh_), sr);
+ int ctrl = 0;
+ float grMax[kBands] = {}, boostMax[kBands] = {};
+ float outPk[2] = { 0.0f, 0.0f }, inPk = 0.0f, clipDb = 0.0f;
+ const int laSize = laSize_;
+
+ for (int32_t i = 0; i < frames; ++i) {
+ if (--ctrl <= 0) {
+ ctrl = kCtrl;
+ xl_ += xs * (tl - xl_); xh_ += xs * (th - xh_);
+ k1 = prism::coef(std::exp(xl_), sr); k2 = prism::coef(std::exp(xh_), sr);
+ }
+ const float l = buf[i * 2], r = buf[i * 2 + 1];
+ inPk = std::max(inPk, std::max(std::fabs(l), std::fabs(r)));
+ float bl[3], br[3], kb[3];
+ split_[0].run(l, nb, k1, k2, bl);
+ split_[1].run(r, nb, k1, k2, br);
+ if (sc) scSplit_.run((sc[i * 2] + sc[i * 2 + 1]) * 0.5f * scGain, nb, k1, k2, kb);
+
+ float wetL = 0, wetR = 0, dryL = 0, dryR = 0, lisL = 0, lisR = 0;
+ for (int b = 0; b < kBands; ++b) {
+ if (!active[b]) continue;
+ const BandCfg& c = cfg[b];
+ BandState& s = st_[b];
+ // --- detector (stereo-linked) ---
+ const float kl = sc ? kb[b] : bl[b], kr = sc ? kb[b] : br[b];
+ float rect;
+ if (rms) { s.ms = rmsC * s.ms + (1.0f - rmsC) * 0.5f * (kl * kl + kr * kr); rect = std::sqrt(s.ms); }
+ else rect = std::max(std::fabs(kl), std::fabs(kr));
+ if (c.autoRel) {
+ s.envA = rect + (rect > s.envA ? c.atkA : c.relFast) * (s.envA - rect);
+ s.envS = rect + (rect > s.envS ? c.slowAtk : c.relSlow) * (s.envS - rect);
+ } else {
+ s.envA = rect + (rect > s.envA ? c.atkA : c.relA) * (s.envA - rect);
+ s.envS = s.envA;
+ }
+ s.envB = rect + (rect > s.envB ? c.atkB : c.relB) * (s.envB - rect);
+ // --- gain computer (dB; thresholds / slopes / gain glide against zipper) ---
+ s.thrA += sm * (c.thrA - s.thrA); s.slopeA += sm * (c.slopeA - s.slopeA);
+ s.thrB += sm * (c.thrB - s.thrB); s.slopeB += sm * (c.slopeB - s.slopeB);
+ s.gain += sm * (c.gain - s.gain);
+ const float lvA = kDbPerLn * std::log(std::max(1e-6f, std::max(s.envA, s.envS)));
+ float dyn = -s.slopeA * prism::knee(lvA - s.thrA, c.knee);
+ if (c.below || std::fabs(s.slopeB) > 1e-5f) {
+ const float lvB = kDbPerLn * std::log(std::max(1e-6f, s.envB));
+ dyn += std::clamp(-s.slopeB * prism::knee(s.thrB - lvB, c.knee), -c.floor, c.floor);
+ }
+ s.level = lvA; s.dyn = dyn;
+ if (dyn < 0.0f) grMax[b] = std::max(grMax[b], -dyn); else boostMax[b] = std::max(boostMax[b], dyn);
+ const float g = std::exp((dyn + s.gain) * kLnPerDb);
+ // --- lookahead: gain from now, audio from la samples ago ---
+ // (always written, so switching lookahead on picks up recent audio)
+ float dl = bl[b], dr = br[b];
+ float* d = delay_[b].data();
+ d[laW_ * 2] = dl; d[laW_ * 2 + 1] = dr;
+ if (la > 0) {
+ int rp = laW_ - la; if (rp < 0) rp += laSize;
+ dl = d[rp * 2]; dr = d[rp * 2 + 1];
+ }
+ if (solo < 0 || b == solo) {
+ wetL += dl * g; wetR += dr * g; dryL += dl; dryR += dr;
+ lisL += kl; lisR += kr;
+ }
+ // --- trace ---
+ s.trPk = std::max(s.trPk, std::max(std::fabs(bl[b]), std::fabs(br[b])));
+ }
+ if (++laW_ >= laSize) laW_ = 0;
+
+ float yl, yr;
+ if (listen) { yl = lisL; yr = lisR; }
+ else {
+ mixS_ += sm * (mixTarget - mixS_);
+ yl = dryL + mixS_ * (wetL - dryL); yr = dryR + mixS_ * (wetR - dryR);
+ }
+ outS_ += sm * (outTarget - outS_);
+ yl *= outS_; yr *= outS_;
+ if (clip) {
+ const float al = std::fabs(yl), ar = std::fabs(yr);
+ auto sat = [clipC, clipT](float a) { return a <= clipT ? a : clipT + (clipC - clipT) * std::tanh((a - clipT) / (clipC - clipT)); };
+ if (al > clipT) { const float c2 = sat(al); clipDb = std::max(clipDb, kDbPerLn * std::log(al / c2)); yl = std::copysign(c2, yl); }
+ if (ar > clipT) { const float c2 = sat(ar); clipDb = std::max(clipDb, kDbPerLn * std::log(ar / c2)); yr = std::copysign(c2, yr); }
+ }
+ buf[i * 2] = yl; buf[i * 2 + 1] = yr;
+ outPk[0] = std::max(outPk[0], std::fabs(yl)); outPk[1] = std::max(outPk[1], std::fabs(yr));
+
+ // spectrum rings (mono, pre / post)
+ const uint32_t w = specW_;
+ inRing_[w & (kSpecLen - 1)] = 0.5f * (l + r);
+ outRing_[w & (kSpecLen - 1)] = 0.5f * (yl + yr);
+ specW_ = w + 1;
+ if (++traceCount_ >= traceDiv_) {
+ traceCount_ = 0;
+ const uint32_t tw = traceW_;
+ for (int b = 0; b < kBands; ++b) {
+ trIn_[b][tw & (kTraceLen - 1)] = active[b] ? st_[b].trPk : 0.0f;
+ trDet_[b][tw & (kTraceLen - 1)] = active[b] ? std::max(st_[b].envA, st_[b].envS) : 0.0f;
+ st_[b].trPk = 0.0f;
+ }
+ traceW_ = tw + 1;
+ }
+ }
+ specWA_.store(specW_, std::memory_order_release);
+ traceWA_.store(traceW_, std::memory_order_release);
+ scBuf_ = nullptr;
+ // Inactive bands forget their state so re-enabling starts clean.
+ for (int b = 0; b < kBands; ++b) if (!active[b]) { st_[b].envA = st_[b].envS = st_[b].envB = st_[b].ms = 0.0f; st_[b].dyn = 0.0f; st_[b].level = -120.0f; }
+
+ // ---- meters + CPU ----
+ const float dec = static_cast<float>(std::exp(-frames / (0.3 * sr)));
+ auto hold = [dec](std::atomic<float>& a, float v) { a.store(std::max(v, a.load(std::memory_order_relaxed) * dec), std::memory_order_relaxed); };
+ for (int b = 0; b < kBands; ++b) {
+ gr_[b].store(grMax[b], std::memory_order_relaxed);
+ boost_[b].store(boostMax[b], std::memory_order_relaxed);
+ level_[b].store(st_[b].level, std::memory_order_relaxed);
+ }
+ hold(mOutL_, outPk[0]); hold(mOutR_, outPk[1]); hold(mIn_, inPk);
+ clipA_.store(clipDb, std::memory_order_relaxed);
+ bandsA_.store(nb, std::memory_order_relaxed);
+ scActA_.store(sc != nullptr, std::memory_order_relaxed);
+ xlA_.store(std::exp(xl_), std::memory_order_relaxed); xhA_.store(std::exp(xh_), 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(static_cast<float>(cpuS_), std::memory_order_relaxed);
+ }
+
+ // ---- identity / params ---------------------------------------------------------
+ const char* displayName() const override { return "Nota Prism"; }
+ int32_t builtinKind() const override { return 21; }
+ int32_t paramCount() const override { return kNumParams; }
+ const char* paramName(int32_t i) const override {
+ static const char* nm[kNumParams] = {
+ "Amount", "Output", "Bands", "Crossover Low", "Crossover High", "Detect", "Lookahead", "Auto Makeup",
+ "Soft Clip", "SC Listen", "Solo", "Peak Hold", "Mix",
+ "Low Above Thresh", "Low Above Ratio", "Low Attack", "Low Release", "Low Gain", "Low Below On", "Low Below Thresh",
+ "Low Below Ratio", "Low Below Attack", "Low Below Release", "Low Floor", "Low Knee", "Low Auto Release",
+ "Mid Above Thresh", "Mid Above Ratio", "Mid Attack", "Mid Release", "Mid Gain", "Mid Below On", "Mid Below Thresh",
+ "Mid Below Ratio", "Mid Below Attack", "Mid Below Release", "Mid Floor", "Mid Knee", "Mid Auto Release",
+ "High Above Thresh", "High Above Ratio", "High Attack", "High Release", "High Gain", "High Below On", "High Below Thresh",
+ "High Below Ratio", "High Below Attack", "High Below Release", "High Floor", "High Knee", "High Auto Release" };
+ return (i >= 0 && i < kNumParams) ? nm[i] : "";
+ }
+ float paramMin(int32_t) const override { return 0.0f; }
+ float paramMax(int32_t) const override { 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(std::clamp(v, 0.0f, 1.0f), std::memory_order_relaxed);
+ }
+
+ // ---- telemetry ---------------------------------------------------------------
+ // Summary for the shell meter: the deepest reduction across the bands.
+ float gainReductionDb() const override {
+ float g = 0.0f;
+ for (int b = 0; b < kBands; ++b) g = std::max(g, gr_[b].load(std::memory_order_relaxed));
+ return g;
+ }
+ int32_t scopeRead(float* out, int32_t maxSamples) const override {
+ if (!out || maxSamples < kScope) return 0;
+ for (int b = 0; b < kBands; ++b) {
+ out[S_Gr0 + b] = gr_[b].load(std::memory_order_relaxed);
+ out[S_Boost0 + b] = boost_[b].load(std::memory_order_relaxed);
+ out[S_Level0 + b] = level_[b].load(std::memory_order_relaxed);
+ }
+ out[S_OutL] = mOutL_.load(std::memory_order_relaxed);
+ out[S_OutR] = mOutR_.load(std::memory_order_relaxed);
+ out[S_InPeak] = mIn_.load(std::memory_order_relaxed);
+ out[S_Cpu] = cpuA_.load(std::memory_order_relaxed);
+ out[S_SampleRate] = srA_.load(std::memory_order_relaxed);
+ out[S_Latency] = static_cast<float>(latencySamples());
+ out[S_ScActive] = scActA_.load(std::memory_order_relaxed) ? 1.0f : 0.0f;
+ out[S_ClipDb] = clipA_.load(std::memory_order_relaxed);
+ out[S_Bands] = static_cast<float>(bandsA_.load(std::memory_order_relaxed));
+ out[S_XoverLow] = xlA_.load(std::memory_order_relaxed);
+ out[S_XoverHigh] = xhA_.load(std::memory_order_relaxed);
+ return kScope;
+ }
+ // Rings, oldest → newest (torn reads are fine for a visualizer): 0 input / 1 output mono
+ // samples (≤ 2048), 2 + 2b band b's input peak, 3 + 2b its detector level (linear, ≤ 256).
+ int32_t layerWave(int32_t layer, float* out, int32_t maxSamples) const override {
+ if (!out || maxSamples <= 0) return 0;
+ if (layer == 0 || layer == 1) {
+ const float* ring = layer == 0 ? inRing_ : outRing_;
+ const uint32_t w = specWA_.load(std::memory_order_acquire);
+ const int32_t n = std::min<int32_t>(maxSamples, kSpecLen);
+ const uint32_t start = w - static_cast<uint32_t>(n);
+ for (int32_t k = 0; k < n; ++k) out[k] = ring[(start + static_cast<uint32_t>(k)) & (kSpecLen - 1)];
+ return n;
+ }
+ const int b = (layer - 2) / 2;
+ if (b < 0 || b >= kBands) return 0;
+ const float* ring = ((layer - 2) & 1) ? trDet_[b] : trIn_[b];
+ const uint32_t w = traceWA_.load(std::memory_order_acquire);
+ const int32_t n = std::min<int32_t>(maxSamples, kTraceLen);
+ const uint32_t start = w - static_cast<uint32_t>(n);
+ for (int32_t k = 0; k < n; ++k) out[k] = ring[(start + static_cast<uint32_t>(k)) & (kTraceLen - 1)];
+ return n;
+ }
+
+private:
+ static constexpr int kCtrl = 16; // crossover coefficient refresh (samples)
+
+ struct BandState {
+ float ms = 0, envA = 0, envS = 0, envB = 0;
+ float thrA = -18, slopeA = 0, thrB = -40, slopeB = 0, gain = 0;
+ float level = -120, dyn = 0, trPk = 0;
+ };
+
+ float get(int i) const { return p_[i].load(std::memory_order_relaxed); }
+
+ double sr_ = 44100.0;
+ std::atomic<float> p_[kNumParams] = {};
+ prism::Splitter split_[2], scSplit_;
+ BandState st_[kBands];
+ std::vector<float> delay_[kBands];
+ int laSize_ = 2, laW_ = 0;
+ float xl_ = 5.2f, xh_ = 7.8f, outS_ = 1.0f, mixS_ = 1.0f;
+ const float* scBuf_ = nullptr; int32_t scFrames_ = 0;
+ std::atomic<int32_t> scTrackId_{-1};
+
+ // telemetry
+ float inRing_[kSpecLen] = {}, outRing_[kSpecLen] = {};
+ uint32_t specW_ = 0; std::atomic<uint32_t> specWA_{0};
+ float trIn_[kBands][kTraceLen] = {}, trDet_[kBands][kTraceLen] = {};
+ uint32_t traceW_ = 0; std::atomic<uint32_t> traceWA_{0};
+ int traceDiv_ = 256, traceCount_ = 0;
+ std::atomic<float> gr_[kBands] = {}, boost_[kBands] = {}, level_[kBands] = {};
+ std::atomic<float> mOutL_{0}, mOutR_{0}, mIn_{0}, cpuA_{0}, srA_{44100}, clipA_{0}, xlA_{180}, xhA_{2400};
+ std::atomic<int32_t> bandsA_{3};
+ std::atomic<bool> scActA_{false};
+ double cpuS_ = 0.0;
+};
+
+} // namespace nota
diff --git a/src/native/nota.engine/src/RackCore.h b/src/native/nota.engine/src/RackCore.h
index 282baf74..a29526ad 100644
--- a/src/native/nota.engine/src/RackCore.h
+++ b/src/native/nota.engine/src/RackCore.h
@@ -54,6 +54,7 @@
#include "AutoGain.h"
#include "Shutter.h"
#include "Chamber.h"
+#include "Prism.h"
#include <algorithm>
#include <atomic>
@@ -674,6 +675,7 @@ protected:
case 18: return std::make_shared<AutoGain>();
case 19: return std::make_shared<Shutter>();
case 20: return std::make_shared<Chamber>();
+ case 21: return std::make_shared<Prism>();
default: return nullptr; // 5 = Effect Rack (nesting) / plugin: not via this factory
}
}
diff --git a/tests/Nota.SmokeTest/Program.cs b/tests/Nota.SmokeTest/Program.cs
index 8a4f12c0..700507b1 100644
--- a/tests/Nota.SmokeTest/Program.cs
+++ b/tests/Nota.SmokeTest/Program.cs
@@ -2673,6 +2673,216 @@ Console.WriteLine("-- Nota Chamber --");
}
}
+// ============================ Nota Prism ===================================
+Console.WriteLine("-- Nota Prism --");
+{
+ // Prism = three-band dynamics (kind 21). Own engines (it changes level). The input is a
+ // deterministic clip — one steady sine per band (80 Hz / 800 Hz / 6 kHz) — so renders
+ // compare exactly; a loud copy drives compression, a quiet one expansion / upward.
+ const int Amount = 0, Bands = 2, Lookahead = 6, Solo = 10, Mix = 12, G = 13, PB = 13;
+ const int AboveThresh = 0, AboveRatio = 1, BelowOn = 5, BelowThresh = 6, BelowRatio = 7, Floor = 10;
+ string loudWav = Path.Combine(Path.GetTempPath(), "nota_prism_loud_" + Guid.NewGuid().ToString("N") + ".wav");
+ string quietWav = Path.Combine(Path.GetTempPath(), "nota_prism_quiet_" + Guid.NewGuid().ToString("N") + ".wav");
+ double[] tones = { 80, 800, 6000 };
+ Nota.SmokeTest.WavWriter.WriteTones(loudWav, 4.0, tones, 0.25, 44100);
+ Nota.SmokeTest.WavWriter.WriteTones(quietWav, 4.0, tones, 0.003, 44100);
+ (NotaEngine e, int t, int d) Make(string wav)
+ {
+ var e = new NotaEngine();
+ e.SetBpm(120); e.SetTimeSignature(4, 4);
+ int t = e.AddAudioTrack();
+ e.AddAudioClip(t, wav, startBeat: 0.0);
+ return (e, t, e.AddBuiltinDevice(t, 21));
+ }
+ var (pe, pt, pd) = Make(loudWav);
+ var (qe, qt, qd) = Make(quietWav);
+ try
+ {
+ Check(pd >= 0, "add built-in Nota Prism");
+ Check(pe.DeviceName(pt, pd) == "Nota Prism", $"name is Nota Prism (got '{pe.DeviceName(pt, pd)}')");
+ Check(pe.TrackDeviceBuiltinKind(pt, pd) == 21, $"builtin kind is 21 (got {pe.TrackDeviceBuiltinKind(pt, pd)})");
+ int ppc = pe.DeviceParamCount(pt, pd);
+ Check(ppc == 52, $"Nota Prism exposes 52 params (got {ppc})");
+ var pnames = Enumerable.Range(0, ppc).Select(i => pe.DeviceParamName(pt, pd, i)).ToList();
+ Check(pnames.Distinct().Count() == ppc && pnames.All(n => n.Length > 0), "Prism param names are unique and non-empty");
+ Check(pe.DeviceAcceptsSidechain(pt, pd), "Prism accepts a sidechain");
+ pe.DeviceSetParam(pt, pd, Amount, 0.42f);
+ Check(Math.Abs(pe.DeviceGetParam(pt, pd, Amount) - 0.42f) < 1e-4, "Prism param set/get round-trips");
+ pe.DeviceSetParam(pt, pd, Amount, 1f);
+
+ const int N = 8192;
+ var pb = new float[N * 2];
+ var psc = new float[32];
+ int P(int band, int f) => G + band * PB + f;
+ (bool fin, float rms) Render(NotaEngine e, int blocks = 4)
+ {
+ e.Seek(0); e.Play();
+ bool f = true; float r = 0;
+ for (int k = 0; k < blocks; k++)
+ {
+ e.RenderOffline(pb, N);
+ foreach (var s in pb) if (!float.IsFinite(s)) { f = false; break; }
+ r = Rms(pb, N);
+ }
+ e.StopTransport();
+ return (f, r);
+ }
+ void Neutral(NotaEngine e, int t, int d) { for (int b = 0; b < 3; b++) { e.DeviceSetParam(t, d, P(b, AboveRatio), 0f); e.DeviceSetParam(t, d, P(b, BelowOn), 0f); } }
+ void Defaults() { for (int i = 0; i < ppc; i++) pe.DeviceSetParam(pt, pd, i, pe.DeviceParamDefault(pt, pd, i)); }
+ static double DbRatio(float a, float b) => 20 * Math.Log10(a / Math.Max(1e-9f, b));
+
+ // Bypassed reference vs neutral settings: the LR4 split sums back flat.
+ pe.SetDeviceBypassed(pt, pd, true);
+ var rByp = Render(pe);
+ pe.SetDeviceBypassed(pt, pd, false);
+ Neutral(pe, pt, pd);
+ var rNeu = Render(pe);
+ Check(rNeu.fin && rByp.rms > 1e-2f && Math.Abs(DbRatio(rNeu.rms, rByp.rms)) < 0.2, $"neutral Prism sums flat ({DbRatio(rNeu.rms, rByp.rms):+0.00;-0.00} dB vs bypass)");
+
+ // Compression: a low threshold and a high ratio pull every band down; the scope reports GR.
+ for (int b = 0; b < 3; b++) { pe.DeviceSetParam(pt, pd, P(b, AboveThresh), 0.4f); pe.DeviceSetParam(pt, pd, P(b, AboveRatio), 0.8f); }
+ var rComp = Render(pe);
+ int pn = pe.DeviceScope(pt, pd, psc, psc.Length);
+ Check(pn == 20, $"Prism scope returns 20 values (got {pn})");
+ Check(rComp.fin && DbRatio(rComp.rms, rNeu.rms) < -6, $"compression lowers the level ({DbRatio(rComp.rms, rNeu.rms):0.0} dB)");
+ Check(psc[0] > 6f && psc[1] > 6f && psc[2] > 6f, $"every band reports gain reduction ({psc[0]:F1} / {psc[1]:F1} / {psc[2]:F1} dB)");
+ Check(pe.DeviceGainReduction(pt, pd) > 6f, $"shell GR meter follows ({pe.DeviceGainReduction(pt, pd):F1} dB)");
+ pe.DeviceSetParam(pt, pd, Amount, 0f);
+ var rAmt0 = Render(pe);
+ Check(Math.Abs(DbRatio(rAmt0.rms, rNeu.rms)) < 0.1, $"Amount 0 % leaves the signal unprocessed ({DbRatio(rAmt0.rms, rNeu.rms):+0.00;-0.00} dB)");
+ pe.DeviceSetParam(pt, pd, Amount, 1f);
+ pe.DeviceSetParam(pt, pd, Mix, 0f);
+ var rMix0 = Render(pe);
+ Check(Math.Abs(DbRatio(rMix0.rms, rNeu.rms)) < 0.1, $"Mix 0 % passes the dry band sum ({DbRatio(rMix0.rms, rNeu.rms):+0.00;-0.00} dB)");
+ pe.DeviceSetParam(pt, pd, Mix, 0.5f);
+ var rMix50 = Render(pe);
+ Check(rMix50.rms < rNeu.rms && rMix50.rms > rComp.rms, "Mix 50 % sits between dry and compressed");
+ pe.DeviceSetParam(pt, pd, Mix, 1f);
+
+ // Upward compression lifts a quiet signal (below −20 dB, ratio 1 : 4 upward, floor 24 dB);
+ // expansion (4 : 1) pushes it down.
+ Neutral(qe, qt, qd);
+ var rQuiet = Render(qe);
+ for (int b = 0; b < 3; b++)
+ {
+ qe.DeviceSetParam(qt, qd, P(b, BelowOn), 1f); qe.DeviceSetParam(qt, qd, P(b, BelowThresh), 0.75f);
+ qe.DeviceSetParam(qt, qd, P(b, BelowRatio), 0f); qe.DeviceSetParam(qt, qd, P(b, Floor), 0.5f);
+ }
+ var rUp = Render(qe);
+ qe.DeviceScope(qt, qd, psc, psc.Length);
+ Check(rUp.fin && DbRatio(rUp.rms, rQuiet.rms) > 12 && psc[3] > 12 && psc[4] > 12 && psc[5] > 12,
+ $"upward compression lifts a quiet signal ({DbRatio(rUp.rms, rQuiet.rms):+0.0} dB, boost {psc[3]:F1} / {psc[4]:F1} / {psc[5]:F1})");
+ for (int b = 0; b < 3; b++) qe.DeviceSetParam(qt, qd, P(b, BelowRatio), 1f);
+ var rExp = Render(qe);
+ Check(rExp.fin && DbRatio(rExp.rms, rQuiet.rms) < -12, $"downward expansion pushes a quiet signal down ({DbRatio(rExp.rms, rQuiet.rms):0.0} dB)");
+ for (int b = 0; b < 3; b++) qe.DeviceSetParam(qt, qd, P(b, Floor), 0.125f);
+ var rFloor = Render(qe);
+ Check(Math.Abs(DbRatio(rFloor.rms, rQuiet.rms) + 6) < 1, $"Floor limits the expansion (6 dB: {DbRatio(rFloor.rms, rQuiet.rms):0.0} dB)");
+ Defaults();
+
+ // Band modes; solo keeps one tone of three.
+ foreach (float mode in new[] { 0.5f, 1f, 0f })
+ {
+ pe.DeviceSetParam(pt, pd, Bands, mode);
+ var rm = Render(pe);
+ pe.DeviceScope(pt, pd, psc, psc.Length);
+ int expect = mode > 0.75f ? 1 : mode > 0.25f ? 2 : 3;
+ Check(rm.fin && rm.rms > 1e-3f && (int)psc[17] == expect, $"{expect}-band mode renders ({rm.rms:F3}, scope {psc[17]})");
+ }
+ Neutral(pe, pt, pd);
+ var solos = new float[3];
+ for (int b = 0; b < 3; b++) { pe.DeviceSetParam(pt, pd, Solo, (b + 1) / 3f); solos[b] = Render(pe).rms; }
+ pe.DeviceSetParam(pt, pd, Solo, 0f);
+ Check(solos.All(r => Math.Abs(DbRatio(r, rNeu.rms) + 4.77) < 1), $"solo keeps one band ({string.Join(" / ", solos.Select(r => DbRatio(r, rNeu.rms).ToString("0.0")))} dB, expect −4.8)");
+ Defaults();
+
+ // Lookahead is reported as latency (for PDC).
+ pe.DeviceSetParam(pt, pd, Lookahead, 0.5f);
+ Render(pe, 1);
+ pe.DeviceScope(pt, pd, psc, psc.Length);
+ Check(psc[14] > 200 && psc[14] < 240 && pe.TrackLatencySamples(pt) == (int)psc[14], $"5 ms lookahead reports its latency ({psc[14]} smp, track {pe.TrackLatencySamples(pt)})");
+ pe.DeviceSetParam(pt, pd, Lookahead, 0f);
+
+ // Telemetry rings for the card: spectrum samples + detector traces.
+ var ring = new float[2048];
+ Check(pe.DeviceLayerWave(pt, pd, 0, ring, ring.Length) == 2048 && ring.Any(v => Math.Abs(v) > 1e-3f), "Prism exposes the input spectrum ring");
+ Check(pe.DeviceLayerWave(pt, pd, 3, ring, 256) == 256 && ring.Take(256).Any(v => v > 1e-3f), "Prism exposes the detector trace");
+
+ // Sidechain: an external key source keys the detectors.
+ int pkey = pe.AddInstrumentTrack();
+ pe.AddMidiClip(pkey, 0.0, 8.0);
+ pe.SetClipNotes(pkey, 0, new[] { new NotaNote(40, 0.0, 7.5, 1.0f) });
+ pe.SetDeviceSidechainSource(pt, pd, pkey);
+ Check(pe.DeviceSidechainSource(pt, pd) == pkey, "Prism accepts an external key source");
+ var rSc = Render(pe);
+ pe.DeviceScope(pt, pd, psc, psc.Length);
+ Check(rSc.fin && psc[15] > 0.5f, "Prism with an external key renders finite and reports the key");
+ pe.SetDeviceSidechainSource(pt, pd, -1);
+ pe.RemoveTrack(pkey);
+
+ // Project round-trip keeps the params.
+ pe.DeviceSetParam(pt, pd, P(2, BelowRatio), 0.21f); pe.DeviceSetParam(pt, pd, Bands, 0.5f);
+ string pproj = Path.Combine(Path.GetTempPath(), "nota-prism-" + Guid.NewGuid().ToString("N"));
+ try
+ {
+ var pwarn = new System.Collections.Generic.List<string>();
+ ProjectService.Save(ProjectService.Capture(pe, new TransportState(120, 1, false, false), pwarn), pproj, pe);
+ using var pe2 = new NotaEngine();
+ ProjectService.Apply(ProjectService.Load(pproj), pe2, pproj);
+ int rt = -1;
+ for (int i = 0; i < pe2.TrackCount; i++) if (pe2.TryGetTrackInfo(i, out var ti) && pe2.TrackDeviceCount(ti.Id) > 0) { rt = ti.Id; break; }
+ Check(rt > 0 && pe2.TrackDeviceBuiltinKind(rt, 0) == 21 && Math.Abs(pe2.DeviceGetParam(rt, 0, P(2, BelowRatio)) - 0.21f) < 1e-3
+ && Math.Abs(pe2.DeviceGetParam(rt, 0, Bands) - 0.5f) < 1e-3, "project round-trip restores Prism params");
+ }
+ finally { try { Directory.Delete(pproj, true); } catch { } }
+ Defaults();
+
+ // Clone: duplicating the track carries Prism params.
+ pe.DeviceSetParam(pt, pd, P(1, AboveThresh), 0.33f);
+ int ptD = pe.DuplicateTrack(pt); int pdD = pe.TrackDeviceCount(ptD) - 1;
+ Check(ptD > 0 && Math.Abs(pe.DeviceGetParam(ptD, pdD, P(1, AboveThresh)) - 0.33f) < 1e-3, "duplicate track clones Prism params");
+ pe.RemoveTrack(ptD);
+
+ // Automation drives Amount.
+ int plane = pe.AddAutomationLane(pt, AutomationTarget.DeviceParam, pd, Amount);
+ Check(plane >= 0, "add Prism Amount automation lane");
+ pe.SetAutomationPoints(pt, plane, new[] { new AutomationPoint(0.0, 0.1f), new AutomationPoint(2.0, 0.9f) });
+ pe.Seek(1.99); pe.Play(); pe.RenderOffline(pb, 4096); pe.StopTransport();
+ Check(pe.DeviceGetParam(pt, pd, Amount) > 0.7f, $"automation drives Prism Amount ({pe.DeviceGetParam(pt, pd, Amount):F2})");
+ pe.RemoveAutomationLane(pt, plane);
+
+ // Factory presets: every named param exists and each applies in place + renders.
+ {
+ var cat = new FactoryPresetCatalog();
+ var mine = cat.All().Where(p => !p.IsInstrument && !p.IsMidiEffect && p.BuiltinKind == 21).ToList();
+ Check(mine.Count >= 10, $"Nota Prism ships factory presets ({mine.Count})");
+ var bad = mine.SelectMany(p => cat.Document(p.Id)!.NamedParams!.Keys.Where(k => !pnames.Contains(k)).Select(k => $"{p.DisplayName}:{k}")).ToList();
+ Check(bad.Count == 0, $"every Prism preset param name exists{(bad.Count > 0 ? " — bad: " + string.Join(", ", bad) : "")}");
+ int pf = 0;
+ foreach (var p in mine)
+ {
+ if (cat.ApplyInPlace(pe, p.Id, pt, pd).Length != 0) { pf++; continue; }
+ var rp = Render(pe, 2);
+ if (!rp.fin || rp.rms < 1e-3f || rp.rms > 1.5f) { pf++; Console.WriteLine($" preset {p.DisplayName}: rms {rp.rms}"); }
+ }
+ Check(pf == 0, $"every Prism preset applies and renders ({pf} failed)");
+ cat.ApplyInPlace(pe, "prism/Two-Band Bass", pt, pd);
+ Check(Math.Abs(pe.DeviceGetParam(pt, pd, Bands) - 0.5f) < 1e-3, "Two-Band Bass preset selects the 2-band mode");
+ cat.ApplyInPlace(pe, "prism/Bus Glue", pt, pd);
+ Check(pe.DeviceGetParam(pt, pd, Bands) < 1e-3, "unnamed params reset to defaults between presets");
+ }
+
+ // MCP lists the kind.
+ var dt = new Nota.Mcp.Tools.DeviceTools(pe, new Nota.SmokeTest.SyncDispatch(), new Nota.SmokeTest.NoRefresh());
+ Check(dt.ListDeviceKinds().Any(k => k.Kind == 21 && k.Name == "Nota Prism"), "MCP lists Nota Prism (kind 21)");
+ }
+ finally
+ {
+ pe.Dispose(); qe.Dispose();
+ try { File.Delete(loudWav); File.Delete(quietWav); } catch { }
+ }
+}
+
// ============================ Nota Level ===================================
Console.WriteLine("-- Nota Level (AutoGain) --");
{
diff --git a/tests/Nota.SmokeTest/WavWriter.cs b/tests/Nota.SmokeTest/WavWriter.cs
index bd5420b0..41e04c33 100644
--- a/tests/Nota.SmokeTest/WavWriter.cs
+++ b/tests/Nota.SmokeTest/WavWriter.cs
@@ -89,6 +89,25 @@ internal static class WavWriter
}
}
+ // A steady sum of sines (each at `amp`), mono — one tone per band for the multiband tests.
+ public static void WriteTones(string path, double seconds, double[] freqs, double amp, int sampleRate)
+ {
+ int frames = (int)(seconds * sampleRate);
+ using var fs = new FileStream(path, FileMode.Create, FileAccess.Write);
+ using var w = new BinaryWriter(fs);
+ int dataBytes = frames * 2;
+ w.Write("RIFF"u8.ToArray()); w.Write(36 + dataBytes); w.Write("WAVE"u8.ToArray());
+ w.Write("fmt "u8.ToArray()); w.Write(16); w.Write((short)1); w.Write((short)1);
+ w.Write(sampleRate); w.Write(sampleRate * 2); w.Write((short)2); w.Write((short)16);
+ w.Write("data"u8.ToArray()); w.Write(dataBytes);
+ for (int i = 0; i < frames; i++)
+ {
+ double s = 0;
+ foreach (double f in freqs) s += Math.Sin(2.0 * Math.PI * f * i / sampleRate) * amp;
+ w.Write((short)(Math.Clamp(s, -1, 1) * short.MaxValue));
+ }
+ }
+
// A stereo impulse response: `lead` seconds of silence, then decaying noise (independent
// L / R, deterministic LCG) — a stand-in for a user IR file.
public static void WriteNoiseIr(string path, double seconds, double lead, int sampleRate)