Skip to content

armgit / nota

Public Imported from GitHub
0

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

Redesign of EQ-8

Egor Khindikaynen40a2974f00ee
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 28a67cb6..3bb82cc5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -55,6 +55,35 @@ Entry categories: `Added`, `Changed`, `Fixed`, `Removed`.
level, the effective attack and release, look-ahead latency and how often it kicked in.
### Changed
+- **Nota EQ-8 is redrawn with slopes, mid/side and global controls.** The card follows the new
+ mockup on the 700 × 260 frame, laid out like Dynamic EQ-8:
+ - **Band chips and graph.** A row of eight chips (number, type, channel, frequency) sits over
+ the response graph. Drag a node for frequency and gain, use the wheel for Q. Double-click a
+ node to switch its band on or off; double-click empty space to switch on a free band there.
+ Right-click a node for its type, slope, channel and on.
+ - **Slope.** Low cut and high cut now go 12, 24 or 48 dB/oct. The steeper slopes are
+ Butterworth, and Q still sets the resonance.
+ - **Channel.** Each band works on the stereo signal, the Mid, the Side, or the left or right
+ channel alone. When any band works on the Side, the graph draws the Side curve in teal
+ next to the Mid.
+ - **Global.** Scale multiplies every shelf and bell gain (0 … 200 %). Output is ±12 dB.
+ Auto gain takes back the average lift of the shelves and bells, so you hear edits at the
+ same loudness.
+ - **Analyzer.** The spectra now come from the engine. Pre shows the input; Post shows the
+ output over a dimmer input; Off hides both.
+ - **Selected band panel.** Type, FREQ / GAIN / Q (RESO on the cuts), SLOPE, CHANNEL and the
+ GLOBAL controls. A status strip shows the summary, the output with the auto gain in
+ effect, the sample rate and CPU.
+ - **Compatibility.** Projects, racks and presets saved before this open unchanged: the new
+ params default to 12 dB/oct, stereo, 100 %, 0 dB and auto gain off.
+ - **34 factory presets.** They cover mix, vocal, drums, instruments, mid/side, left/right
+ and repair (hum removal). The four earlier presets keep their names.
+ - **MCP: `read_eq8`, `set_eq8_band` and `set_eq8`.** `read_eq8` reports the settings, every
+ band, the in / out peaks and both spectra. `set_eq8_band` edits a band, and `set_eq8` sets
+ Scale, Output, Auto gain and the analyzer. Both record like hand edits.
+ `get_device_text` gives a summary, a live reading and a parameter guide, and
+ `device_action` 0 resets the meters. In the automation menu, the params are grouped by
+ band.
- **Nota EQ-3 is redrawn as a DJ isolator.** The card follows the new mockup on the
700 × 260 frame. The crossover slider row is gone; you now drag the crossovers on the graph:
- **Band strips.** LOW, MID and HIGH each get a strip in their own colour with the band's
diff --git a/FEATURES.md b/FEATURES.md
index 70f9df21..f8f7df9d 100644
--- a/FEATURES.md
+++ b/FEATURES.md
@@ -326,7 +326,13 @@ and user presets, automation, persistence and cloning.
overlay). Cables are parameters: saved, preset-able and automatable. 28 factory presets.
### Audio effects
-- **Nota EQ-8** (kind 0) — 8-band parametric.
+- **Nota EQ-8** (kind 0) — 8-band parametric: each band on / off, Low cut / Low shelf / Bell /
+ Notch / High shelf / High cut, frequency, gain, Q (resonance on the cuts), a 12 / 24 / 48 dB/oct
+ slope for the cuts and a channel — stereo, Mid, Side, Left or Right. Scale (0–200 % of every
+ shelf and bell gain), Output ±12 dB and Auto gain. A full-width response graph (draggable
+ numbered nodes, the selected band's curve, a separate Side curve, an input / output spectrum
+ analyzer switched Pre / Post / Off), band chips, a panel for the selected band; 34 factory
+ presets; MCP `read_eq8`, `set_eq8_band`, `set_eq8`.
- **Nota Compressor** (1) — 5 character models (Clean/Glue/Punch/Opto/FET), soft knee,
look-ahead (reported as latency for PDC), Peak/RMS/Auto detection, hold, auto-release,
auto-gain, Range, MIX; a sidechain key (internal or another track, pre/post tap, External
diff --git a/src/managed/Nota.App/ArrangementView.Automation.cs b/src/managed/Nota.App/ArrangementView.Automation.cs
index c867782f..3096f070 100644
--- a/src/managed/Nota.App/ArrangementView.Automation.cs
+++ b/src/managed/Nota.App/ArrangementView.Automation.cs
@@ -394,11 +394,11 @@ public sealed partial class ArrangementView
// Nota Utility its mono, phase and true-peak params ("Mono Freq", "Invert L", "TP Ceiling" …),
// Nota Shutter its detector ("Det HP", "Det LP", "Det Filter"), Nota Auto Shift its
// scale notes, detector and MIDI target ("Note C#", "Det Low", "MIDI Glide" …) and Nota
- // Beat Repeat its repeat filter ("Filter Freq", "Filter Type", "Filter Narrow" …) and
- // Nota Dynamic EQ-8 its eight bands ("3 Freq", "3 Thr" … under "Band 3"):
+ // Beat Repeat its repeat filter ("Filter Freq", "Filter Type", "Filter Narrow" …), and
+ // Nota EQ-8 and Nota Dynamic EQ-8 their eight bands ("3 Freq", "3 Slope" … under "Band 3"):
// a word shared by two or more params becomes a submenu.
int bkind = e.TrackDeviceBuiltinKind(t.Id, d);
- bool grouped = bkind is 1 or 4 or 6 or 7 or 8 or 10 or 11 or 13 or 19 or 20 or 21 or 22;
+ bool grouped = bkind is 0 or 1 or 4 or 6 or 7 or 8 or 10 or 11 or 13 or 19 or 20 or 21 or 22;
var names = new string[builtinPc];
for (int p = 0; p < builtinPc; p++) names[p] = e.DeviceParamName(t.Id, d, p);
static string Head(string n) { int sp = n.IndexOf(' '); return sp > 0 ? n[..sp] : ""; }
@@ -413,7 +413,7 @@ public sealed partial class ArrangementView
if (!sub) { devMenu.Items.Add(leaf); continue; }
if (!groups.TryGetValue(head, out var g))
{
- g = new MenuItem { Header = bkind == 13 && int.TryParse(head, out _) ? "Band " + head : head };
+ g = new MenuItem { Header = bkind is 0 or 13 && int.TryParse(head, out _) ? "Band " + head : head };
groups[head] = g; devMenu.Items.Add(g);
}
g.Items.Add(leaf);
diff --git a/src/managed/Nota.App/Controls/Eq8Views.cs b/src/managed/Nota.App/Controls/Eq8Views.cs
new file mode 100644
index 00000000..c5e75118
--- /dev/null
+++ b/src/managed/Nota.App/Controls/Eq8Views.cs
@@ -0,0 +1,482 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.
+//
+// Nota EQ-8 (device kind 0) response graph, a build of the "Nota EQ-8" mockup. The window
+// draws the analyzer behind everything (the input spectrum dim, the output spectrum a step
+// brighter — Pre shows the input alone, Post both, Off neither), the selected band's own curve
+// as a faint brass line, the Side path as a teal line when any band works on the Side, and
+// the main response (stereo — or the Mid when the Side has its own curve) as the brass primary
+// curve. Every band is a numbered node at its effective gain (Scale applied) — selected brass,
+// a Side band teal, the rest Ink 3, an off band Ink 6; a Mid band wears a brass ring and a
+// left / right band a rose one. A tooltip beside the selected node reads the band.
+//
+// Drag a node — frequency and gain; the wheel over a node — Q (Shift for fine); double-click a
+// node turns the band on / off, double-click empty space switches on a free band there as a
+// stereo bell; right-click a node — type, slope, channel and on. The maths mirrors Eq.h.
+
+using System;
+using System.Globalization;
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Input;
+using Avalonia.Media;
+using Nota.Application;
+
+namespace Nota.App;
+
+/// <summary>The EQ-8 parameter layout (mirrors Eq.h) and the maths the card and the graph share.</summary>
+internal static class Eq8
+{
+ public const int Bands = 8, PerBand = 5;
+ public const int On = 0, TypeF = 1, FreqF = 2, GainF = 3, QF = 4;
+ public const int SlopeBase = 40, ChannelBase = 48, ScaleP = 56, OutputP = 57, AutoGainP = 58, AnalyzerP = 59, ParamCount = 60;
+ public const int LowCut = 0, LowShelf = 1, Bell = 2, Notch = 3, HighShelf = 4, HighCut = 5;
+ public const int St = 0, Mid = 1, Side = 2, Left = 3, Right = 4;
+ public const int AnaPre = 0, AnaPost = 1, AnaOff = 2;
+ // Telemetry (Eq::S_* / kTele / kSpec).
+ public const int S_InPeak = 0, S_OutPeak = 1, S_AutoGain = 2, S_SampleRate = 3, S_Cpu = 4, S_Analysed = 5, S_Latency = 6,
+ kTele = 16, kSpec = 96, PreAt = kTele, PostAt = kTele + kSpec, kScope = kTele + 2 * kSpec;
+ public const double Fmin = 20, Fmax = 20000;
+
+ public static readonly string[] TypeNames = DynEq.TypeNames;
+ public static readonly string[] TypeShort = DynEq.TypeShort;
+ public static readonly string[] TypeSeg = DynEq.TypeSeg;
+ public static readonly string[] ChannelNames = { "Stereo", "Mid", "Side", "Left", "Right" };
+ public static readonly string[] ChannelSeg = { "St", "Mid", "Side", "L", "R" };
+ public static readonly string[] ChannelShort = { "St", "M", "S", "L", "R" };
+ public static readonly string[] SlopeSeg = { "12", "24", "48\u2009dB" };
+ public static readonly string[] AnalyzerSeg = { "Pre", "Post", "Off" };
+
+ public static bool HasGain(int type) => DynEq.HasGain(type);
+ public static bool IsCut(int type) => type is LowCut or HighCut;
+ public static int P(int band, int field) => band * PerBand + field;
+ public static int SlopeDb(int slope) => 12 << Math.Clamp(slope, 0, 2);
+
+ public static double FreqToN(double f) => DynEq.FreqToN(f);
+ public static double NToFreq(double n) => DynEq.NToFreq(n);
+ public static double GainToN(double db) => DynEq.GainToN(db);
+ public static double NToGain(double n) => DynEq.NToGain(n);
+ public static string Hz(double f) => DynEq.Hz(f);
+ public static string HzShort(double f) => DynEq.HzShort(f);
+ public static string Db(double g) => DynEq.Db(g);
+
+ /// <summary>Ink of a band's channel: Mid brass, Side teal, L / R rose, stereo none.</summary>
+ public static IBrush? ChannelInk(int ch, bool bright = false) => ch switch
+ {
+ Mid => bright ? NotaPalette.AccentBright : NotaPalette.Accent,
+ Side => bright ? NotaPalette.TealBright : NotaPalette.Teal,
+ Left or Right => bright ? NotaPalette.RoseBright : NotaPalette.Rose,
+ _ => null,
+ };
+
+ private static readonly double[] Q24 = { 0.54119610, 1.30656296 };
+ private static readonly double[] Q48 = { 0.50979558, 0.60134489, 0.89997622, 2.56291545 };
+
+ /// <summary>A band's sections (Eq::cascade): one biquad, or for a 24 / 48 dB cut a
+ /// Butterworth cascade whose last section carries the resonance.</summary>
+ public static int Cascade(Span<DynEq.Bq> into, int type, int slope, double sr, double f0, double gDb, double q)
+ {
+ if (IsCut(type) && slope > 0)
+ {
+ var bq = slope == 1 ? Q24 : Q48;
+ double res = q / 0.70710678;
+ for (int k = 0; k < bq.Length; k++)
+ into[k] = DynEq.Coeffs(type, sr, f0, 0, k == bq.Length - 1 ? Math.Clamp(bq[k] * res, 0.1, 40) : bq[k]);
+ return bq.Length;
+ }
+ into[0] = DynEq.Coeffs(type, sr, f0, gDb, q);
+ return 1;
+ }
+
+ public static double MagDb(ReadOnlySpan<DynEq.Bq> secs, int n, double w)
+ {
+ double s = 0;
+ for (int k = 0; k < n; k++) s += DynEq.MagDb(secs[k], w);
+ return s;
+ }
+}
+
+public sealed class Eq8Curve : Control
+{
+ private const int Pts = 150;
+ private const double NodeD = 11, HitR = 9;
+
+ private static readonly IPen GridFaint = new Pen(NotaPalette.GridSubBeat, 1);
+ private static readonly IPen GridMid = new Pen(NotaPalette.GridBeat, 1);
+ private static readonly IPen ZeroPen = new Pen(NotaPalette.TrackOff, 1);
+ private static readonly IPen PrePen = new Pen(NotaPalette.BorderDefault, 1);
+ private static readonly IPen PreDimPen = new Pen(NotaPalette.Wash(NotaPalette.BorderDefault, 0x99), 1);
+ private static readonly IPen PostPen = new Pen(NotaPalette.TextAxis, 1);
+ private static readonly IPen SelPen = new Pen(NotaPalette.Wash(NotaPalette.AccentBright, 0x5A), 1);
+ private static readonly IPen SidePen = new Pen(NotaPalette.Wash(NotaPalette.Teal, 0xE6), NotaGraph.SecondaryWidth, lineJoin: PenLineJoin.Round);
+ private static readonly IPen RingPen = new Pen(NotaPalette.BgSunken, 2);
+
+ private readonly IAudioEngine _engine;
+ private readonly int _track, _device;
+ private int _selected, _drag = -1;
+ private bool _gestFreq, _gestGain;
+
+ private readonly float[] _pre = new float[Eq8.kSpec];
+ private readonly float[] _post = new float[Eq8.kSpec];
+ private bool _specOk;
+
+ public event Action? SelectionChanged;
+ /// <summary>Raised after a gesture on the graph wrote params (so the card repaints).</summary>
+ public event Action? Edited;
+
+ public Eq8Curve(IAudioEngine engine, int track, int device)
+ {
+ _engine = engine; _track = track; _device = device;
+ ClipToBounds = true;
+ MinHeight = 60;
+ // Open on the first band that shapes the sound (a cut, a notch or a gain), else the first on.
+ _selected = -1;
+ int firstOn = -1;
+ for (int b = 0; b < Eq8.Bands && _selected < 0; b++)
+ {
+ if (!BandOn(b)) continue;
+ if (firstOn < 0) firstOn = b;
+ if (!Eq8.HasGain(BandType(b)) || Math.Abs(P(b, Eq8.GainF)) > 0.05f) _selected = b;
+ }
+ if (_selected < 0) _selected = Math.Max(0, firstOn);
+ }
+
+ public int SelectedBand
+ {
+ get => _selected;
+ set { int v = Math.Clamp(value, 0, Eq8.Bands - 1); if (v == _selected) return; _selected = v; SelectionChanged?.Invoke(); InvalidateVisual(); }
+ }
+
+ /// <summary>Feed the telemetry read by the card (Eq scopeRead layout).</summary>
+ public void Update(float[] scope, int n)
+ {
+ _specOk = n >= Eq8.kScope && scope[Eq8.S_Analysed] > 0.5f;
+ if (_specOk)
+ {
+ Array.Copy(scope, Eq8.PreAt, _pre, 0, Eq8.kSpec);
+ Array.Copy(scope, Eq8.PostAt, _post, 0, Eq8.kSpec);
+ }
+ InvalidateVisual();
+ }
+
+ // ---- params ----
+ private float Pd(int p) => p < _engine.DeviceParamCount(_track, _device) ? _engine.DeviceGetParam(_track, _device, p) : 0f;
+ private float P(int band, int field) => _engine.DeviceGetParam(_track, _device, Eq8.P(band, field));
+ private void SetRaw(int p, double v) => _engine.DeviceSetParam(_track, _device, p, (float)v);
+ private void SetP(int band, int field, double v) => SetRaw(Eq8.P(band, field), v);
+ private void Gesture(int p, Action a)
+ {
+ _engine.BeginAutomationWrite(_track, AutomationTarget.DeviceParam, _device, p, "");
+ a();
+ _engine.EndAutomationWrite(_track, AutomationTarget.DeviceParam, _device, p, "");
+ }
+ private bool BandOn(int b) => P(b, Eq8.On) > 0.5f;
+ private int BandType(int b) => Math.Clamp((int)Math.Round(P(b, Eq8.TypeF)), 0, 5);
+ private int Slope(int b) => Math.Clamp((int)Math.Round(Pd(Eq8.SlopeBase + b)), 0, 2);
+ private int Chan(int b) => Math.Clamp((int)Math.Round(Pd(Eq8.ChannelBase + b)), 0, 4);
+ private double ScaleK => _engine.DeviceParamCount(_track, _device) > Eq8.ScaleP ? Math.Clamp(Pd(Eq8.ScaleP), 0, 200) / 100.0 : 1.0;
+ private int Analyzer => _engine.DeviceParamCount(_track, _device) > Eq8.AnalyzerP ? Math.Clamp((int)Math.Round(Pd(Eq8.AnalyzerP)), 0, 2) : Eq8.AnaPost;
+ private double Sr => _engine.SampleRate > 0 ? _engine.SampleRate : 48000;
+
+ // ---- geometry: the plot is the whole control ----
+ private double X(double f) => Eq8.FreqToN(f) * Bounds.Width;
+ private double Y(double db) => Eq8.GainToN(db) * Bounds.Height;
+ private Point NodeAt(int b) => new(X(P(b, Eq8.FreqF)), Y(Eq8.HasGain(BandType(b)) ? P(b, Eq8.GainF) * ScaleK : 0));
+
+ private int Hit(Point p)
+ {
+ int best = -1; double bestD = HitR * HitR;
+ for (int k = 0; k < Eq8.Bands; k++)
+ {
+ int b = (_selected + k) % Eq8.Bands; // the selected node wins a tie
+ var n = NodeAt(b);
+ double d = (p.X - n.X) * (p.X - n.X) + (p.Y - n.Y) * (p.Y - n.Y);
+ if (d < bestD) { bestD = d; best = b; }
+ }
+ return best;
+ }
+
+ // The node sits at gain × Scale; dragging it asks for the gain that lands it there.
+ private double GainAtY(double y)
+ {
+ double g = Eq8.NToGain(y / Math.Max(1, Bounds.Height)), s = ScaleK;
+ return s > 0.01 ? Math.Clamp(g / s, -18, 18) : 0;
+ }
+
+ // ---- interaction ----
+ protected override void OnPointerMoved(PointerEventArgs e)
+ {
+ base.OnPointerMoved(e);
+ var p = e.GetPosition(this);
+ if (_drag < 0) { Cursor = Hit(p) >= 0 ? new Cursor(StandardCursorType.Hand) : Cursor.Default; return; }
+ SetP(_drag, Eq8.FreqF, Eq8.NToFreq(p.X / Math.Max(1, Bounds.Width)));
+ if (_gestGain) SetP(_drag, Eq8.GainF, GainAtY(p.Y));
+ Edited?.Invoke();
+ InvalidateVisual();
+ }
+
+ protected override void OnPointerPressed(PointerPressedEventArgs e)
+ {
+ base.OnPointerPressed(e);
+ var p = e.GetPosition(this);
+ var props = e.GetCurrentPoint(this).Properties;
+ int hit = Hit(p);
+ if (props.IsRightButtonPressed)
+ {
+ if (hit >= 0) { SelectedBand = hit; ShowBandMenu(hit); e.Handled = true; }
+ return;
+ }
+ if (!props.IsLeftButtonPressed) return;
+ if (e.ClickCount == 2)
+ {
+ if (hit >= 0) Gesture(Eq8.P(hit, Eq8.On), () => SetP(hit, Eq8.On, BandOn(hit) ? 0 : 1));
+ else AddBandAt(p);
+ Edited?.Invoke(); InvalidateVisual(); e.Handled = true;
+ return;
+ }
+ if (hit < 0) return;
+ SelectedBand = hit;
+ _drag = hit;
+ e.Pointer.Capture(this);
+ _gestFreq = true;
+ _engine.BeginAutomationWrite(_track, AutomationTarget.DeviceParam, _device, Eq8.P(hit, Eq8.FreqF), "");
+ if (Eq8.HasGain(BandType(hit)) && ScaleK > 0.01)
+ {
+ _gestGain = true;
+ _engine.BeginAutomationWrite(_track, AutomationTarget.DeviceParam, _device, Eq8.P(hit, Eq8.GainF), "");
+ }
+ e.Handled = true;
+ }
+
+ protected override void OnPointerReleased(PointerReleasedEventArgs e)
+ {
+ base.OnPointerReleased(e);
+ EndDrag();
+ e.Pointer.Capture(null);
+ }
+
+ protected override void OnPointerCaptureLost(PointerCaptureLostEventArgs e)
+ {
+ EndDrag(); // never leave an automation session dangling
+ base.OnPointerCaptureLost(e);
+ }
+
+ private void EndDrag()
+ {
+ if (_drag >= 0)
+ {
+ if (_gestFreq) _engine.EndAutomationWrite(_track, AutomationTarget.DeviceParam, _device, Eq8.P(_drag, Eq8.FreqF), "");
+ if (_gestGain) _engine.EndAutomationWrite(_track, AutomationTarget.DeviceParam, _device, Eq8.P(_drag, Eq8.GainF), "");
+ }
+ _drag = -1; _gestFreq = _gestGain = false;
+ }
+
+ protected override void OnPointerWheelChanged(PointerWheelEventArgs e)
+ {
+ base.OnPointerWheelChanged(e);
+ int b = Hit(e.GetPosition(this));
+ if (b < 0) b = _selected;
+ SelectedBand = b;
+ bool fine = (e.KeyModifiers & (KeyModifiers.Shift | KeyModifiers.Control | KeyModifiers.Meta)) != 0;
+ double step = fine ? 1.03 : 1.15;
+ double q = Math.Clamp(P(b, Eq8.QF) * (e.Delta.Y > 0 ? step : 1 / step), 0.1, 18);
+ Gesture(Eq8.P(b, Eq8.QF), () => SetP(b, Eq8.QF, q));
+ Edited?.Invoke(); InvalidateVisual();
+ e.Handled = true;
+ }
+
+ private void AddBandAt(Point p)
+ {
+ for (int b = 0; b < Eq8.Bands; b++)
+ {
+ if (BandOn(b)) continue;
+ double f = Eq8.NToFreq(p.X / Math.Max(1, Bounds.Width)), g = GainAtY(p.Y);
+ Gesture(Eq8.P(b, Eq8.TypeF), () => SetP(b, Eq8.TypeF, Eq8.Bell));
+ Gesture(Eq8.P(b, Eq8.FreqF), () => SetP(b, Eq8.FreqF, f));
+ Gesture(Eq8.P(b, Eq8.GainF), () => SetP(b, Eq8.GainF, g));
+ Gesture(Eq8.P(b, Eq8.QF), () => SetP(b, Eq8.QF, 1.0));
+ if (_engine.DeviceParamCount(_track, _device) > Eq8.ChannelBase + b)
+ Gesture(Eq8.ChannelBase + b, () => SetRaw(Eq8.ChannelBase + b, Eq8.St));
+ Gesture(Eq8.P(b, Eq8.On), () => SetP(b, Eq8.On, 1));
+ SelectedBand = b;
+ return;
+ }
+ }
+
+ private void ShowBandMenu(int b)
+ {
+ var fly = new MenuFlyout();
+ int curT = BandType(b);
+ for (int t = 0; t < Eq8.TypeNames.Length; t++)
+ {
+ int tt = t;
+ var mi = new MenuItem { Header = Eq8.TypeNames[t], ToggleType = MenuItemToggleType.Radio, IsChecked = t == curT };
+ mi.Click += (_, _) => { Gesture(Eq8.P(b, Eq8.TypeF), () => SetP(b, Eq8.TypeF, tt)); Edited?.Invoke(); InvalidateVisual(); };
+ fly.Items.Add(mi);
+ }
+ bool extended = _engine.DeviceParamCount(_track, _device) >= Eq8.ParamCount;
+ if (extended)
+ {
+ fly.Items.Add(new Separator());
+ var slope = new MenuItem { Header = "Slope", IsEnabled = Eq8.IsCut(curT) };
+ for (int s = 0; s < 3; s++)
+ {
+ int ss = s;
+ var mi = new MenuItem { Header = NotaNum.F($"{Eq8.SlopeDb(s)}\u2009dB/oct"), ToggleType = MenuItemToggleType.Radio, IsChecked = s == Slope(b) };
+ mi.Click += (_, _) => { Gesture(Eq8.SlopeBase + b, () => SetRaw(Eq8.SlopeBase + b, ss)); Edited?.Invoke(); InvalidateVisual(); };
+ slope.Items.Add(mi);
+ }
+ fly.Items.Add(slope);
+ var chan = new MenuItem { Header = "Channel" };
+ for (int c = 0; c < Eq8.ChannelNames.Length; c++)
+ {
+ int cc = c;
+ var mi = new MenuItem { Header = Eq8.ChannelNames[c], ToggleType = MenuItemToggleType.Radio, IsChecked = c == Chan(b) };
+ mi.Click += (_, _) => { Gesture(Eq8.ChannelBase + b, () => SetRaw(Eq8.ChannelBase + b, cc)); Edited?.Invoke(); InvalidateVisual(); };
+ chan.Items.Add(mi);
+ }
+ fly.Items.Add(chan);
+ }
+ fly.Items.Add(new Separator());
+ var on = new MenuItem { Header = "Band on", ToggleType = MenuItemToggleType.CheckBox, IsChecked = BandOn(b) };
+ on.Click += (_, _) => { Gesture(Eq8.P(b, Eq8.On), () => SetP(b, Eq8.On, BandOn(b) ? 0 : 1)); Edited?.Invoke(); InvalidateVisual(); };
+ fly.Items.Add(on);
+ fly.ShowAt(this, showAtPointer: true);
+ }
+
+ // ---- render ----
+ private static FormattedText Text(string s, IBrush ink, double size, bool bold = false, bool mono = true)
+ => new(s, CultureInfo.InvariantCulture, FlowDirection.LeftToRight,
+ mono ? (bold ? NotaFonts.MonoBold : NotaFonts.Mono) : bold ? NotaFonts.SansBold : NotaFonts.Sans, size, ink);
+
+ private StreamGeometry SpecLine(float[] spec, double w, double h)
+ {
+ var sg = new StreamGeometry();
+ using var g = sg.Open();
+ for (int i = 0; i < Eq8.kSpec; i++)
+ {
+ double x = (i + 0.5) / Eq8.kSpec * w;
+ double y = Math.Clamp(-spec[i] / 80.0, 0, 1) * h; // 0 dBFS at the top … −80 at the bottom
+ if (i == 0) g.BeginFigure(new Point(x, y), false); else g.LineTo(new Point(x, y));
+ }
+ return sg;
+ }
+
+ public override void Render(DrawingContext ctx)
+ {
+ double w = Bounds.Width, h = Bounds.Height, sr = Sr;
+ if (w <= 0 || h <= 0) return;
+ var frame = new Rect(0, 0, w, h);
+ NotaGraph.Window(ctx, frame);
+ using var clip = ctx.PushClip(new RoundedRect(frame.Deflate(1), NotaGraph.Radius));
+
+ // grid: 100 Hz · 1 kHz (stronger) · 10 kHz; ±6 / ±12 dB, 0 dB stronger
+ foreach (var f in new[] { 100.0, 10000.0 }) ctx.DrawLine(GridFaint, new Point(X(f), 0), new Point(X(f), h));
+ ctx.DrawLine(GridMid, new Point(X(1000), 0), new Point(X(1000), h));
+ foreach (var db in new[] { -12.0, -6.0, 6.0, 12.0 }) ctx.DrawLine(GridFaint, new Point(0, Y(db)), new Point(w, Y(db)));
+ ctx.DrawLine(ZeroPen, new Point(0, Y(0)), new Point(w, Y(0)));
+
+ // analyzer: Pre — the input; Post — the output over a dimmer input; Off — neither
+ int ana = Analyzer;
+ if (_specOk && ana != Eq8.AnaOff)
+ {
+ ctx.DrawGeometry(null, ana == Eq8.AnaPre ? PrePen : PreDimPen, SpecLine(_pre, w, h));
+ if (ana == Eq8.AnaPost) ctx.DrawGeometry(null, PostPen, SpecLine(_post, w, h));
+ }
+
+ // band coefficients (effective gain = gain × Scale)
+ double sc = ScaleK;
+ var secs = new DynEq.Bq[Eq8.Bands * 4];
+ var nSec = new int[Eq8.Bands];
+ var ch = new int[Eq8.Bands];
+ bool anySide = false;
+ for (int b = 0; b < Eq8.Bands; b++)
+ {
+ int ty = BandType(b);
+ nSec[b] = Eq8.Cascade(secs.AsSpan(b * 4, 4), ty, Slope(b), sr, P(b, Eq8.FreqF), P(b, Eq8.GainF) * sc, P(b, Eq8.QF));
+ ch[b] = Chan(b);
+ if (BandOn(b) && ch[b] == Eq8.Side) anySide = true;
+ }
+ int sel = _selected;
+
+ // curves: main (all but Side bands), side (all but Mid bands), the selected band alone
+ var gm = new StreamGeometry(); var gs = new StreamGeometry(); var gx = new StreamGeometry();
+ using (var cm = gm.Open())
+ using (var cs = gs.Open())
+ using (var cx = gx.Open())
+ for (int i = 0; i < Pts; i++)
+ {
+ double n = i / (double)(Pts - 1), x = n * w;
+ double wv = 2 * Math.PI * Eq8.NToFreq(n) / sr;
+ double m = 0, s = 0;
+ for (int b = 0; b < Eq8.Bands; b++)
+ {
+ if (!BandOn(b)) continue;
+ double v = Eq8.MagDb(secs.AsSpan(b * 4, 4), nSec[b], wv);
+ if (ch[b] != Eq8.Side) m += v;
+ if (ch[b] != Eq8.Mid) s += v;
+ }
+ var pm = new Point(x, Math.Clamp(Y(m), -2, h + 2));
+ var ps = new Point(x, Math.Clamp(Y(s), -2, h + 2));
+ var px = new Point(x, Math.Clamp(Y(Eq8.MagDb(secs.AsSpan(sel * 4, 4), nSec[sel], wv)), -2, h + 2));
+ if (i == 0) { cm.BeginFigure(pm, false); cs.BeginFigure(ps, false); cx.BeginFigure(px, false); }
+ else { cm.LineTo(pm); cs.LineTo(ps); cx.LineTo(px); }
+ }
+ if (BandOn(sel)) ctx.DrawGeometry(null, SelPen, gx);
+ if (anySide) ctx.DrawGeometry(null, SidePen, gs);
+ ctx.DrawGeometry(null, NotaGraph.PrimaryPen, gm);
+
+ // axis labels
+ NotaGraph.Axis(ctx, frame, NotaGraph.Corner.BottomLeft, "20");
+ NotaGraph.Axis(ctx, frame, NotaGraph.Corner.BottomRight, "20k Hz");
+ var k1 = NotaGraph.AxisText("1k");
+ ctx.DrawText(k1, new Point(X(1000) + 3, h - 4 - k1.Height + 1));
+ var p12 = NotaGraph.AxisText("+12", null, 6); var m12 = NotaGraph.AxisText("−12", null, 6);
+ ctx.DrawText(p12, new Point(w - 5 - p12.Width, Y(12) - p12.Height - 1));
+ ctx.DrawText(m12, new Point(w - 5 - m12.Width, Y(-12) + 1));
+
+ // legend (the ANALYZER selector sits over the top-left corner, placed by the card)
+ if (anySide)
+ NotaGraph.Legend(ctx, w - 5, 2, ("mid", NotaPalette.AccentBright, NotaGraph.Mark.Line), ("side", NotaPalette.TealBright, NotaGraph.Mark.Line));
+ else
+ NotaGraph.Legend(ctx, w - 5, 2, ("stereo", NotaPalette.AccentBright, NotaGraph.Mark.Line));
+
+ // nodes (selected last, on top)
+ for (int k = 1; k <= Eq8.Bands; k++)
+ {
+ int b = (sel + k) % Eq8.Bands;
+ bool bOn = BandOn(b), isSel = b == sel;
+ var c = NodeAt(b);
+ IBrush fill = !bOn ? NotaPalette.BorderStrong : isSel ? NotaPalette.AccentBright : ch[b] == Eq8.Side ? NotaPalette.TealBright : NotaPalette.TextSecondary;
+ IBrush num = bOn ? NotaPalette.TextOnAccent : NotaPalette.TextTertiary;
+ double r = NodeD / 2;
+ ctx.DrawEllipse(fill, RingPen, c, r + 1, r + 1);
+ if (bOn && ch[b] != Eq8.Side && Eq8.ChannelInk(ch[b]) is { } ring) // Mid brass, L / R rose
+ ctx.DrawEllipse(null, new Pen(ring, 1), c, r + 2.5, r + 2.5);
+ var t = Text(NotaNum.F($"{b + 1}"), num, 7, bold: true);
+ ctx.DrawText(t, new Point(c.X - t.Width / 2, c.Y - t.Height / 2));
+ }
+
+ DrawTip(ctx, w, h);
+ }
+
+ // The selected band's reading beside its node, clear of the node and inside the window.
+ private void DrawTip(DrawingContext ctx, double w, double h)
+ {
+ int b = _selected, ty = BandType(b), chn = Chan(b);
+ bool bOn = BandOn(b), g = Eq8.HasGain(ty);
+ var a = Text(NotaNum.F($"B{b + 1} {Eq8.TypeNames[ty]}") + (chn != Eq8.St ? " · " + Eq8.ChannelShort[chn] : "") + (bOn ? "" : " · off"),
+ NotaPalette.AccentBright, 8, bold: true, mono: false);
+ var l2 = Text(Eq8.Hz(P(b, Eq8.FreqF)) + (g ? " · " + Eq8.Db(P(b, Eq8.GainF)) + " dB" : "") + NotaNum.F($" · Q {P(b, Eq8.QF):0.00}")
+ + (Eq8.IsCut(ty) ? NotaNum.F($" · {Eq8.SlopeDb(Slope(b))}\u2009dB/oct") : ""), NotaPalette.TextPrimary, 7);
+ double tw = Math.Max(a.Width, l2.Width) + 12, th = a.Height + l2.Height + 6;
+ var n = NodeAt(b);
+ double x = n.X > w * 0.62 ? n.X - 12 - tw : n.X + 12;
+ double y = n.Y < h * 0.34 ? n.Y + 8 : n.Y - 8 - th;
+ x = Math.Clamp(x, 3, Math.Max(3, w - tw - 3)); y = Math.Clamp(y, 3, Math.Max(3, h - th - 3));
+ var box = new Rect(x, y, tw, th);
+ ctx.DrawRectangle(NotaPalette.SurfaceCard, new Pen(NotaPalette.BorderStrong, 1), new RoundedRect(box.Deflate(0.5), 3));
+ ctx.DrawText(a, new Point(x + 6, y + 3));
+ ctx.DrawText(l2, new Point(x + 6, y + 3 + a.Height));
+ }
+}
diff --git a/src/managed/Nota.App/DeviceCards/Bodies/EqDeviceBody.cs b/src/managed/Nota.App/DeviceCards/Bodies/EqDeviceBody.cs
index 5123de63..806d50c8 100644
--- a/src/managed/Nota.App/DeviceCards/Bodies/EqDeviceBody.cs
+++ b/src/managed/Nota.App/DeviceCards/Bodies/EqDeviceBody.cs
@@ -1,22 +1,406 @@
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.
//
-// Detail · Devices — built-in EQ (kind 0) body: the interactive response curve, which
-// also runs the FFT analyzer on the UI tick.
+// Detail · Devices — built-in Nota EQ-8 body (device kind 0), a build of the "Nota EQ-8" mockup
+// (700 × 260), laid out like Dynamic EQ-8: a row of eight band chips over the response graph
+// (nodes drag right on the curve; the ANALYZER Pre / Post / Off switch sits in its corner), a
+// panel on the right edits the selected band (type, FREQ / GAIN / Q — RESO on the cuts —, the
+// cut's SLOPE, its CHANNEL: stereo, mid, side, left or right) and the device's GLOBAL controls
+// (Auto gain, SCALE, OUTPUT), and a status strip carries the summary, the output with the auto
+// gain in effect, and the engine. The live readings come from the engine (Eq.h scopeRead).
+// Every control is a device param (raw units), so automation / MIDI learn / presets / A-B /
+// persistence come for free. FullBleed — the shared shell draws the header (name · preset ·
+// badge · bypass).
+using System;
+using System.Collections.Generic;
+using Avalonia;
using Avalonia.Controls;
+using Avalonia.Controls.Primitives;
+using Avalonia.Input;
+using Avalonia.Layout;
+using Avalonia.Media;
+using Nota.Application;
+using static Nota.App.DeviceCardKit;
namespace Nota.App;
internal sealed class EqDeviceBody : IDeviceBody
{
public double Width => 700; // the almanac device format: 700 × 260
+ public bool FullBleed => true;
public string? Subtitle => "EQUALIZER"; // the processing type, shown as the header badge
- public Control Build(DeviceCardContext ctx, int deviceIndex)
+ public Control Build(DeviceCardContext ctx, int index)
{
- var eq = new EqCurve(ctx.Engine, ctx.TrackId, deviceIndex);
- ctx.AddDeviceRefresher(eq.Tick);
- return eq;
+ var engine = ctx.Engine;
+ int track = ctx.TrackId, di = index;
+ int pc = Math.Min(engine.DeviceParamCount(track, di), Eq8.ParamCount);
+ var mn = new float[Eq8.ParamCount];
+ var mx = new float[Eq8.ParamCount];
+ for (int p = 0; p < Eq8.ParamCount; p++)
+ {
+ mn[p] = p < pc ? engine.DeviceParamMin(track, di, p) : 0;
+ mx[p] = p < pc ? engine.DeviceParamMax(track, di, p) : 1;
+ if (mx[p] <= mn[p]) mx[p] = mn[p] + 1;
+ }
+ // Defaults of the appended params, for a device that somehow lacks them.
+ float P(int p) => p < pc ? engine.DeviceGetParam(track, di, p) : p == Eq8.ScaleP ? 100f : p == Eq8.AnalyzerP ? Eq8.AnaPost : 0f;
+ float B(int b, int f) => P(Eq8.P(b, f));
+ 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) { if (p < pc) engine.DeviceSetParam(track, di, p, Math.Clamp(v, mn[p], mx[p])); }
+ // A discrete edit (a click) is one automation gesture, so it records while the transport does.
+ void SetP(int p, float v) { Begin(p); Raw(p, v); End(p); }
+ void Learn(Control c, int p) { if (p < pc) MidiLearn.Bind(c, MidiTarget.DeviceParam(track, di, p), engine.DeviceParamName(track, di, p)); }
+
+ var readouts = new List<Action>();
+ var bandReadouts = new List<Action>();
+ var scope = new float[Eq8.kScope];
+ int scN = 0;
+ double Sc(int i) => scN > i ? scope[i] : 0;
+
+ var curve = new Eq8Curve(engine, track, di);
+ void RefreshAll()
+ {
+ for (int i = 0; i < readouts.Count; i++) readouts[i]();
+ for (int i = 0; i < bandReadouts.Count; i++) bandReadouts[i]();
+ curve.InvalidateVisual();
+ }
+ int Sel() => curve.SelectedBand;
+ bool BandOn(int b) => B(b, Eq8.On) > 0.5f;
+ int TypeOf(int b) => Math.Clamp((int)Math.Round(B(b, Eq8.TypeF)), 0, 5);
+ int SlopeOf(int b) => Math.Clamp((int)Math.Round(P(Eq8.SlopeBase + b)), 0, 2);
+ int ChanOf(int b) => Math.Clamp((int)Math.Round(P(Eq8.ChannelBase + b)), 0, 4);
+ bool Capable(int b) => Eq8.HasGain(TypeOf(b));
+ bool Cut(int b) => Eq8.IsCut(TypeOf(b));
+ bool AutoOn() => P(Eq8.AutoGainP) >= 0.5f;
+
+ // ---- small builders ---------------------------------------------------------
+ static TextBlock Caps(string t, IBrush? c = null, double fs = 7) => new()
+ { Text = t, FontSize = fs, FontWeight = FontWeight.Bold, Foreground = c ?? TextTertiary, LetterSpacing = 0.8, VerticalAlignment = VerticalAlignment.Center };
+ static TextBlock Mono(string t, double fs, IBrush c)
+ { var tb = new TextBlock { Text = t, FontSize = fs, Foreground = c, VerticalAlignment = VerticalAlignment.Center }; tb.BindResource(TextBlock.FontFamilyProperty, "Font.Mono"); return tb; }
+ static T Docked<T>(T c, Dock d) where T : Control { DockPanel.SetDock(c, d); return c; }
+ static T Col<T>(T c, int col) where T : Control { Grid.SetColumn(c, col); return c; }
+
+ // ======================================================================
+ // LEFT — band chips over the response graph
+ // ======================================================================
+ var chipRow = new UniformGrid { Rows = 1, Margin = new Thickness(3, 0), VerticalAlignment = VerticalAlignment.Center };
+ for (int b = 0; b < Eq8.Bands; b++)
+ {
+ int bb = b;
+ var num = Mono((b + 1).ToString(), 8, Brass); num.FontWeight = FontWeight.Bold;
+ var type = new TextBlock { FontSize = 7, FontWeight = FontWeight.SemiBold, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(3, 0, 0, 0) };
+ var chn = new TextBlock { FontSize = 7, FontWeight = FontWeight.Bold, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(3, 0, 0, 0) };
+ var hz = Mono("", 7, TextPrimary); hz.HorizontalAlignment = HorizontalAlignment.Right;
+ var inner = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,Auto,Auto,*"), Margin = new Thickness(4, 0) };
+ inner.Children.Add(num); inner.Children.Add(Col(type, 1)); inner.Children.Add(Col(chn, 2)); inner.Children.Add(Col(hz, 3));
+ var chip = new Border
+ {
+ Height = 15, Margin = new Thickness(1, 0), CornerRadius = NotaRadius.Badge, BorderThickness = new Thickness(1), ClipToBounds = true,
+ Cursor = new Cursor(StandardCursorType.Hand), Child = inner,
+ };
+ ToolTip.SetTip(chip, NotaNum.F($"Band {b + 1} — click to edit it, double-click to switch it on / off"));
+ chip.PointerPressed += (_, e) =>
+ {
+ if (!e.GetCurrentPoint(chip).Properties.IsLeftButtonPressed) return;
+ if (e.ClickCount == 2) SetP(Eq8.P(bb, Eq8.On), BandOn(bb) ? 0 : 1);
+ curve.SelectedBand = bb; RefreshAll(); e.Handled = true;
+ };
+ Learn(chip, Eq8.P(bb, Eq8.On));
+ readouts.Add(() =>
+ {
+ bool on = BandOn(bb), sel = bb == Sel();
+ int c = ChanOf(bb);
+ num.Foreground = !on ? TextDisabled : sel ? AccentBright : Brass;
+ type.Text = Eq8.TypeShort[TypeOf(bb)];
+ type.Foreground = on ? TextSecondary : TextDisabled;
+ chn.Text = c == Eq8.St ? "" : Eq8.ChannelShort[c];
+ chn.IsVisible = c != Eq8.St;
+ chn.Foreground = on ? Eq8.ChannelInk(c, bright: true) ?? TextSecondary : TextDisabled;
+ hz.Text = Eq8.HzShort(B(bb, Eq8.FreqF));
+ hz.Foreground = on ? TextPrimary : TextDisabled;
+ chip.BorderBrush = sel ? Brass : Brushes.Transparent;
+ chip.Background = sel ? Raised : Sunken;
+ });
+ chipRow.Children.Add(chip);
+ }
+ var chipStrip = new Border { Height = 20, BorderBrush = BorderDef, BorderThickness = new Thickness(0, 0, 0, 1), Child = chipRow };
+ DockPanel.SetDock(chipStrip, Dock.Top);
+ ToolTip.SetTip(curve, "Drag a node — frequency and gain · wheel over a node — Q · double-click a node — band on / off · "
+ + "double-click empty space — a new bell there · right-click a node — type, slope, channel");
+
+ // ANALYZER Pre / Post / Off over the graph's top-left corner.
+ var anaSeg = Segments(Eq8.AnalyzerSeg, () => Math.Clamp((int)Math.Round(P(Eq8.AnalyzerP)), 0, 2),
+ i => { SetP(Eq8.AnalyzerP, i); RefreshAll(); }, out var anaSync, padX: 4);
+ Learn(anaSeg, Eq8.AnalyzerP);
+ ToolTip.SetTip(anaSeg, "Analyzer — Pre: the input spectrum · Post: the output over a dimmer input · Off");
+ readouts.Add(anaSync);
+ var anaBar = new StackPanel
+ {
+ Orientation = Orientation.Horizontal, Spacing = 5, Margin = new Thickness(5, 3), HorizontalAlignment = HorizontalAlignment.Left,
+ VerticalAlignment = VerticalAlignment.Top, Children = { Caps("ANALYZER"), anaSeg },
+ };
+ anaBar.RenderTransform = new ScaleTransform(0.85, 0.85);
+ anaBar.RenderTransformOrigin = new RelativePoint(0, 0, RelativeUnit.Relative);
+ var graphPanel = new Border
+ {
+ Background = Card2, BorderBrush = BorderDef, BorderThickness = new Thickness(1), CornerRadius = NotaRadius.Tile,
+ ClipToBounds = true, Margin = new Thickness(0, 0, 5, 0),
+ Child = new DockPanel { LastChildFill = true, Children = { chipStrip, new Border { Padding = new Thickness(5), Child = new Panel { Children = { curve, anaBar } } } } },
+ };
+
+ // ======================================================================
+ // RIGHT — the selected band + the device's global controls (rebuilt when the selection
+ // moves, so MIDI learn and automation bind to that band's own params)
+ // ======================================================================
+ var bandHost = new ContentControl();
+
+ Control BandPanel(int b)
+ {
+ bandReadouts.Clear();
+ int pOn = Eq8.P(b, Eq8.On), pType = Eq8.P(b, Eq8.TypeF), pF = Eq8.P(b, Eq8.FreqF), pG = Eq8.P(b, Eq8.GainF),
+ pQ = Eq8.P(b, Eq8.QF), pSlope = Eq8.SlopeBase + b, pChan = Eq8.ChannelBase + b;
+
+ // 0..1 mappings (frequency and Q are log)
+ bool IsLog(int p) => p == pF || p == pQ;
+ double ToN(int p, double v) => IsLog(p)
+ ? Math.Log(Math.Clamp(v, mn[p], mx[p]) / mn[p]) / Math.Log(mx[p] / mn[p])
+ : (Math.Clamp(v, mn[p], mx[p]) - mn[p]) / (mx[p] - mn[p]);
+ double FromN(int p, double n) { n = Math.Clamp(n, 0, 1); return IsLog(p) ? mn[p] * Math.Pow(mx[p] / mn[p], n) : mn[p] + n * (mx[p] - mn[p]); }
+ double DefOf(int p) => p == pF ? 1000 : p == pG ? 0 : p == pQ ? 0.71 : engine.DeviceParamDefault(track, di, p);
+
+ // ---- header: badge · name · ON ----
+ var badgeTxt = Mono((b + 1).ToString(), 8, OnAccent); badgeTxt.FontWeight = FontWeight.Bold; badgeTxt.HorizontalAlignment = HorizontalAlignment.Center;
+ var badge = new Border { Width = 13, Height = 13, CornerRadius = NotaRadius.Pill, VerticalAlignment = VerticalAlignment.Center, Child = badgeTxt };
+ var name = new TextBlock { FontSize = 9, FontWeight = FontWeight.SemiBold, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(6, 0, 0, 0) };
+ var onSw = Switch("On", () => BandOn(b), () => { SetP(pOn, BandOn(b) ? 0 : 1); RefreshAll(); }, out var onSync);
+ Learn(onSw, pOn);
+ ToolTip.SetTip(onSw, "Band on — off leaves the band out of the signal (double-click its node does the same)");
+ bandReadouts.Add(onSync);
+ bandReadouts.Add(() =>
+ {
+ bool on = BandOn(b);
+ badge.Background = on ? AccentBright : NotaPalette.TextAxis;
+ badgeTxt.Foreground = on ? OnAccent : TextTertiary;
+ name.Text = Eq8.TypeNames[TypeOf(b)].ToUpperInvariant();
+ name.Foreground = on ? AccentBright : TextTertiary;
+ });
+ var head = new DockPanel { Height = 20, Margin = new Thickness(8, 0), Children = { Docked(onSw, Dock.Right), badge, name } };
+ var headBorder = new Border { BorderBrush = BorderDef, BorderThickness = new Thickness(0, 0, 0, 1), Child = head };
+
+ // ---- type ----
+ var typeSeg = Segments(Eq8.TypeSeg, () => TypeOf(b), i => { SetP(pType, i); RefreshAll(); }, out var typeSync, fill: true, padX: 0);
+ Learn(typeSeg, pType);
+ ToolTip.SetTip(typeSeg, "Type — high-pass, low shelf, bell, notch, high shelf, low-pass; only shelves and bells take gain");
+ bandReadouts.Add(typeSync);
+
+ // ---- knobs ----
+ Control K(int p, string label, Func<string> fmt, string tip, Func<string>? liveLabel = null, Func<bool>? inactive = null)
+ {
+ var val = Mono(fmt(), 7, TextPrimary);
+ var knob = new Knob(ToN(p, P(p)), 1.0) { Accent = true, Default = ToN(p, DefOf(p)), Width = 32, Height = 32 };
+ knob.ValueChanged += v => { Raw(p, (float)FromN(p, v)); val.Text = fmt(); RefreshAll(); };
+ knob.GestureBegin += () => Begin(p);
+ knob.GestureEnd += () => End(p);
+ Learn(knob, p);
+ ToolTip.SetTip(knob, tip);
+ var cell = KnobCell(label, knob, val, 54);
+ TextBlock? lbl = null;
+ if (cell is Panel pl) foreach (var c in pl.Children) if (c is TextBlock tb && tb != val) { lbl = tb; break; }
+ bool? wasInactive = null;
+ bandReadouts.Add(() =>
+ {
+ if (!knob.Dragging) { double c = ToN(p, P(p)); if (Math.Abs(c - knob.Value) > 1e-4) knob.Value = c; }
+ val.Text = fmt();
+ if (lbl is not null && liveLabel is not null) lbl.Text = liveLabel();
+ bool ina = inactive?.Invoke() ?? false;
+ if (wasInactive != ina) { Inactive.Set(cell, ina); wasInactive = ina; }
+ });
+ return cell;
+ }
+ var knobs = new Grid { ColumnDefinitions = new ColumnDefinitions("*,*,*"), Children =
+ {
+ K(pF, "FREQ", () => Eq8.HzShort(B(b, Eq8.FreqF)) + (B(b, Eq8.FreqF) < 1000 ? " Hz" : ""), "Frequency — or drag the node left / right"),
+ Col(K(pG, "GAIN", () => Capable(b) ? Eq8.Db(B(b, Eq8.GainF)) + " dB" : "—", "Gain — or drag the node up / down (Scale multiplies it)",
+ inactive: () => !Capable(b)), 1),
+ Col(K(pQ, "Q", () => NotaNum.F($"{B(b, Eq8.QF):0.00}"), "Q — the width (the resonance on the cuts); or the wheel over the node",
+ liveLabel: () => Cut(b) ? "RESO" : "Q"), 2),
+ } };
+
+ // ---- slope + channel ----
+ Control SegRow(string label, Control seg, Func<bool>? dim = null, bool rule = false)
+ {
+ var lbl = new Border { Width = 40, Child = Caps(label) };
+ var row = new DockPanel { Children = { Docked(lbl, Dock.Left), seg } };
+ if (dim is not null)
+ {
+ bool? was = null;
+ bandReadouts.Add(() => { bool d = dim(); if (was != d) { row.Opacity = d ? 0.4 : 1; was = d; } });
+ }
+ return rule
+ ? new Border { BorderBrush = NotaPalette.GraphBorder, BorderThickness = new Thickness(0, 1, 0, 0), Padding = new Thickness(0, 5, 0, 0), Child = row }
+ : row;
+ }
+ var slopeSeg = Segments(Eq8.SlopeSeg, () => SlopeOf(b), i => { if (Cut(b)) { SetP(pSlope, i); RefreshAll(); } },
+ out var slopeSync, fill: true, padX: 0, dim: () => !Cut(b));
+ Learn(slopeSeg, pSlope);
+ ToolTip.SetTip(slopeSeg, "Slope — how steep the high-pass / low-pass falls: 12, 24 or 48\u2009dB per octave");
+ bandReadouts.Add(slopeSync);
+ var chanSeg = Segments(Eq8.ChannelSeg, () => ChanOf(b), i => { SetP(pChan, i); RefreshAll(); }, out var chanSync, fill: true, padX: 0);
+ Learn(chanSeg, pChan);
+ ToolTip.SetTip(chanSeg, "Channel — St: both channels · Mid: the centre · Side: the edges · L / R: one channel alone");
+ bandReadouts.Add(chanSync);
+
+ // ---- global: Auto gain, Scale, Output ----
+ var autoSw = Switch("Auto gain", AutoOn, () => { SetP(Eq8.AutoGainP, AutoOn() ? 0 : 1); RefreshAll(); }, out var autoSync);
+ Learn(autoSw, Eq8.AutoGainP);
+ ToolTip.SetTip(autoSw, "Auto gain — adds the opposite of the shelves' and bells' average level, so edits are judged at the same loudness");
+ bandReadouts.Add(autoSync);
+ var globalRow = new Border
+ {
+ BorderBrush = NotaPalette.GraphBorder, BorderThickness = new Thickness(0, 1, 0, 0), Padding = new Thickness(0, 5, 0, 0),
+ Child = new DockPanel { Children = { Docked(autoSw, Dock.Right), Caps("GLOBAL") } },
+ };
+ Control SliderRow(string label, int p, Func<string> fmt, string tip, double def)
+ {
+ var trk = new SliderTrack { Bipolar = true, Ink = Teal, Reset = () => { SetP(p, (float)def); RefreshAll(); } };
+ trk.Changed += v => { Raw(p, (float)(mn[p] + v * (mx[p] - mn[p]))); RefreshAll(); };
+ trk.GestureBegin += () => Begin(p);
+ trk.GestureEnd += () => End(p);
+ Learn(trk, p);
+ ToolTip.SetTip(trk, tip);
+ var val = Mono(fmt(), 8, TextPrimary); val.TextAlignment = TextAlignment.Right; val.HorizontalAlignment = HorizontalAlignment.Right;
+ bandReadouts.Add(() =>
+ {
+ if (!trk.Dragging) trk.Norm = (P(p) - mn[p]) / (mx[p] - mn[p]);
+ val.Text = fmt();
+ val.Foreground = Math.Abs(P(p) - def) > 0.05 ? AccentBright : TextPrimary;
+ });
+ var g = new Grid { ColumnDefinitions = new ColumnDefinitions("40,*,40"), ColumnSpacing = 6, Height = 11 };
+ g.Children.Add(Caps(label));
+ g.Children.Add(Col(trk, 1));
+ g.Children.Add(Col(val, 2));
+ return g;
+ }
+ var sliders = new StackPanel
+ {
+ Spacing = 5, Children =
+ {
+ SliderRow("SCALE", Eq8.ScaleP, () => NotaNum.F($"{P(Eq8.ScaleP):0}\u2009%"),
+ "Scale — multiplies every shelf and bell gain: 100\u2009% as set, 0\u2009% flat, 200\u2009% twice as much", 100),
+ SliderRow("OUTPUT", Eq8.OutputP, () => Eq8.Db(P(Eq8.OutputP)) + " dB", "Output — the level after the EQ, ±12\u2009dB", 0),
+ },
+ };
+
+ var body = new Grid
+ {
+ RowDefinitions = new RowDefinitions("Auto,*,Auto,*,Auto,4,Auto,*,Auto,5,Auto"), Margin = new Thickness(8, 6, 8, 6),
+ };
+ void Row(Control c, int r) { Grid.SetRow(c, r); body.Children.Add(c); }
+ Row(typeSeg, 0); Row(knobs, 2);
+ Row(SegRow("SLOPE", slopeSeg, () => !Cut(b), rule: true), 4);
+ Row(SegRow("CHANNEL", chanSeg), 6);
+ Row(globalRow, 8); Row(sliders, 10);
+ var panel = new DockPanel { LastChildFill = true, Children = { Docked(headBorder, Dock.Top), body } };
+ for (int i = 0; i < bandReadouts.Count; i++) bandReadouts[i]();
+ return panel;
+ }
+
+ var right = new Border
+ {
+ Width = 186, Background = Card2, BorderBrush = BorderDef, BorderThickness = new Thickness(1), CornerRadius = NotaRadius.Tile,
+ ClipToBounds = true, Child = bandHost,
+ };
+ DockPanel.SetDock(right, Dock.Right);
+ bandHost.Content = BandPanel(Sel());
+ curve.SelectionChanged += () => { bandHost.Content = BandPanel(Sel()); RefreshAll(); };
+ curve.Edited += RefreshAll;
+
+ // ======================================================================
+ // Status strip: summary · output · engine
+ // ======================================================================
+ var statusLeft = new TextBlock { FontSize = 8, Foreground = TextSecondary, VerticalAlignment = VerticalAlignment.Center, TextTrimming = TextTrimming.CharacterEllipsis };
+ string StatusText()
+ {
+ int s = Sel(), nOn = 0, nMs = 0;
+ for (int b = 0; b < Eq8.Bands; b++)
+ {
+ if (!BandOn(b)) continue;
+ nOn++;
+ if (ChanOf(b) is Eq8.Mid or Eq8.Side) nMs++;
+ }
+ var parts = new List<string> { NotaNum.F($"{nOn} bands") };
+ if (nMs > 0) parts.Add(NotaNum.F($"M/S {nMs}"));
+ parts.Add(NotaNum.F($"scale {P(Eq8.ScaleP):0}\u2009%"));
+ string band = NotaNum.F($"B{s + 1} {Eq8.TypeNames[TypeOf(s)]} {Eq8.Hz(B(s, Eq8.FreqF))}");
+ if (Capable(s)) band += " " + Eq8.Db(B(s, Eq8.GainF)) + " dB";
+ if (Cut(s)) band += NotaNum.F($" · {Eq8.SlopeDb(SlopeOf(s))}\u2009dB/oct");
+ if (ChanOf(s) != Eq8.St) band += " · " + Eq8.ChannelNames[ChanOf(s)].ToLowerInvariant();
+ parts.Add(band);
+ return string.Join(" · ", parts);
+ }
+
+ // OUT: a mono readout that drags vertically (±12 dB), double-click resets to 0; it shows the
+ // auto gain on top when that is on.
+ var outTb = Mono("", 8, TextSecondary);
+ var outBox = new Border { Background = Brushes.Transparent, Cursor = new Cursor(StandardCursorType.SizeNorthSouth), VerticalAlignment = VerticalAlignment.Center, Child = outTb };
+ bool outDrag = false; double outY = 0;
+ outBox.PointerPressed += (_, e) =>
+ {
+ if (!e.GetCurrentPoint(outBox).Properties.IsLeftButtonPressed) return;
+ if (e.ClickCount == 2) { SetP(Eq8.OutputP, 0); RefreshAll(); e.Handled = true; return; }
+ outDrag = true; outY = e.GetPosition(outBox).Y; e.Pointer.Capture(outBox); Begin(Eq8.OutputP); e.Handled = true;
+ };
+ outBox.PointerMoved += (_, e) =>
+ {
+ if (!outDrag) return;
+ double y = e.GetPosition(outBox).Y, dy = outY - y; outY = y;
+ bool fine = (e.KeyModifiers & (KeyModifiers.Shift | KeyModifiers.Control | KeyModifiers.Meta)) != 0;
+ Raw(Eq8.OutputP, P(Eq8.OutputP) + (float)(dy * 24.0 / (fine ? 1400.0 : 140.0)));
+ RefreshAll();
+ };
+ void OutEnd() { if (!outDrag) return; outDrag = false; End(Eq8.OutputP); }
+ outBox.PointerReleased += (_, e) => { OutEnd(); e.Pointer.Capture(null); };
+ outBox.PointerCaptureLost += (_, _) => OutEnd();
+ Learn(outBox, Eq8.OutputP);
+ ToolTip.SetTip(outBox, "Output (plus the auto gain in effect) — drag up / down (Shift for fine), double-click for 0\u2009dB");
+ readouts.Add(() =>
+ {
+ float o = P(Eq8.OutputP);
+ double total = o + (AutoOn() ? Sc(Eq8.S_AutoGain) : 0);
+ outTb.Text = "OUT " + Eq8.Db(total) + " dB" + (AutoOn() ? " auto" : "");
+ outTb.Foreground = Math.Abs(total) > 0.05 ? AccentBright : TextSecondary;
+ });
+ var engineRead = Mono("", 8, TextTertiary);
+ readouts.Add(() =>
+ {
+ statusLeft.Text = StatusText();
+ double sr = Sc(Eq8.S_SampleRate);
+ engineRead.Text = sr > 0 ? NotaNum.F($"{sr / 1000:0.#}\u2009kHz · latency 0 smp · CPU {Sc(Eq8.S_Cpu) * 100:0.0}\u2009%") : "";
+ });
+ var statusRight = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 10, VerticalAlignment = VerticalAlignment.Center, Children = { outBox, engineRead } };
+ var statusGrid = new Grid { ColumnDefinitions = new ColumnDefinitions("*,Auto"), ColumnSpacing = 10 };
+ statusGrid.Children.Add(statusLeft);
+ statusGrid.Children.Add(Col(statusRight, 1));
+ var status = new Border { Height = 18, Background = Sunken, BorderBrush = BorderDef, BorderThickness = new Thickness(0, 1, 0, 0), Padding = new Thickness(8, 0), Child = statusGrid };
+ DockPanel.SetDock(status, Dock.Bottom);
+
+ // ---- assemble ---------------------------------------------------------------
+ var bodyRow = new DockPanel { LastChildFill = true, Margin = new Thickness(5), Children = { right, graphPanel } };
+ var root = new DockPanel { LastChildFill = true, Background = NotaPalette.SurfaceInset, Children = { status, bodyRow } };
+
+ void Refresh()
+ {
+ scN = engine.DeviceScope(track, di, scope, Eq8.kScope);
+ curve.Update(scope, scN);
+ for (int i = 0; i < readouts.Count; i++) readouts[i]();
+ for (int i = 0; i < bandReadouts.Count; i++) bandReadouts[i]();
+ }
+ ctx.AddDeviceRefresher(Refresh);
+ Refresh();
+ return root;
}
}
diff --git a/src/managed/Nota.App/EqCurve.cs b/src/managed/Nota.App/EqCurve.cs
deleted file mode 100644
index d5f45e8f..00000000
--- a/src/managed/Nota.App/EqCurve.cs
+++ /dev/null
@@ -1,393 +0,0 @@
-// SPDX-License-Identifier: AGPL-3.0-only
-// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.
-//
-// EQ-8 editor (eight-band mixing-console style). Draws the combined magnitude response over
-// a log-frequency / dB grid with a real-time spectrum analyzer behind it, and one
-// numbered draggable dot per enabled band. Drag = freq (+gain for shelves/bells);
-// mouse wheel = Q; double-click empty space enables a new band; right-click a dot
-// picks its filter type or removes it. Dots + curve are wired straight to the
-// device params (8 bands × 5: On/Type/Freq/Gain/Q). The engine owns the DSP; the
-// drawn curve mirrors its RBJ biquads, and the analyzer reads a pre-EQ scope ring.
-
-using System;
-using System.Globalization;
-using Avalonia;
-using Avalonia.Controls;
-using Avalonia.Input;
-using Avalonia.Media;
-using Nota.Application;
-
-namespace Nota.App;
-
-public sealed class EqCurve : Control
-{
- private const int Bands = 8, PerBand = 5;
- private const int On = 0, TypeF = 1, FreqF = 2, GainF = 3, QF = 4;
- // Filter types (mirror Eq.h).
- private const int LowCut = 0, LowShelf = 1, Bell = 2, Notch = 3, HighShelf = 4, HighCut = 5;
- private static readonly string[] TypeNames = { "Low cut", "Low shelf", "Bell", "Notch", "High shelf", "High cut" };
-
- private const double Fmin = 20, Fmax = 20000, GMax = 18;
- private const int FftN = 2048, Bins = FftN / 2;
-
- private static readonly IBrush Bg = NotaPalette.BgSunken;
- private static readonly IPen GridPen = NotaGraph.GridPen;
- private static readonly IPen GridPenFaint = new Pen(NotaPalette.Wash(NotaPalette.WellGrid, 0x60), 1);
- private static readonly IPen ZeroPen = new Pen(NotaPalette.BorderStrong, 1);
- private static readonly IPen CurvePen = new Pen(NotaPalette.Accent, NotaGraph.PrimaryWidth);
- private static readonly IBrush CurveFill = NotaPalette.Wash(NotaPalette.Accent, 0x1E);
- private static readonly IBrush SpecFill = NotaPalette.Wash(NotaPalette.Ink("#8AA6C0"), 0x30);
- private static readonly IPen SpecPen = new Pen(NotaPalette.Wash(NotaPalette.Ink("#9CB4CC"), 0x70), 1);
- private static readonly IBrush DotOn = NotaPalette.AccentBright;
- private static readonly IBrush DotSel = NotaPalette.HandleSel;
- private static readonly IBrush DotRing = NotaPalette.BgSunken;
- private static readonly IBrush LabelDim = NotaPalette.TextTertiary;
- private static readonly IBrush LabelBright = NotaPalette.TextSecondary;
- private static readonly IBrush OnAccentText = NotaPalette.TextOnAccent;
- private static readonly Typeface Mono = NotaFonts.Mono;
- private static readonly Typeface DotFont = NotaFonts.SansBold;
-
- private readonly IAudioEngine _engine;
- private readonly int _track, _device;
- private int _drag = -1, _selected = -1;
-
- // Analyzer state: pre-EQ scope → FFT → smoothed magnitude (dBFS) per bin.
- private readonly float[] _scope = new float[FftN];
- private readonly double[] _re = new double[FftN], _im = new double[FftN];
- private readonly double[] _specDb = new double[Bins];
- private readonly double[] _hann = new double[FftN];
-
- public EqCurve(IAudioEngine engine, int track, int device)
- {
- _engine = engine;
- _track = track;
- _device = device;
- MinHeight = 150;
- for (int i = 0; i < FftN; i++) _hann[i] = 0.5 - 0.5 * Math.Cos(2 * Math.PI * i / (FftN - 1));
- for (int i = 0; i < Bins; i++) _specDb[i] = -120;
- }
-
- // ---- param helpers ----------------------------------------------------
- private float P(int band, int field) => _engine.DeviceGetParam(_track, _device, band * PerBand + field);
- private void SetP(int band, int field, double v) => _engine.DeviceSetParam(_track, _device, band * PerBand + field, (float)v);
- private bool BandOn(int b) => P(b, On) > 0.5f;
- private int BandType(int b) => Math.Clamp((int)Math.Round(P(b, TypeF)), 0, 5);
- private static bool HasGain(int type) => type is LowShelf or Bell or HighShelf;
-
- // ---- coordinate mapping ----------------------------------------------
- private double FreqToX(double f, double w) => w * Math.Log(f / Fmin) / Math.Log(Fmax / Fmin);
- private double XToFreq(double x, double w) => Fmin * Math.Pow(Fmax / Fmin, Math.Clamp(x / w, 0, 1));
- private double GainToY(double g, double h) => h * (0.5 - g / (2 * GMax));
- private double YToGain(double y, double h) => Math.Clamp(GMax * (1 - 2 * y / h), -GMax, GMax);
-
- // ---- magnitude response (mirrors Eq.h RBJ biquads) --------------------
- private (double b0, double b1, double b2, double a1, double a2) Coeffs(int type, double sr, double f0, double gDb, double q)
- {
- double w0 = 2 * Math.PI * Math.Clamp(f0, 20, sr * 0.49) / sr, cw = Math.Cos(w0), sw = Math.Sin(w0);
- double a = sw / (2 * Math.Max(q, 0.1));
- (double, double, double, double, double) N(double b0, double b1, double b2, double a0, double a1, double a2)
- => (b0 / a0, b1 / a0, b2 / a0, a1 / a0, a2 / a0);
- switch (type)
- {
- case LowCut: return N((1 + cw) / 2, -(1 + cw), (1 + cw) / 2, 1 + a, -2 * cw, 1 - a);
- case HighCut: return N((1 - cw) / 2, 1 - cw, (1 - cw) / 2, 1 + a, -2 * cw, 1 - a);
- case Notch: return N(1, -2 * cw, 1, 1 + a, -2 * cw, 1 - a);
- case LowShelf:
- {
- double A = Math.Pow(10, gDb / 40), al = sw / 2 * Math.Sqrt(2), t = 2 * Math.Sqrt(A) * al;
- return N(A * ((A + 1) - (A - 1) * cw + t), 2 * A * ((A - 1) - (A + 1) * cw), A * ((A + 1) - (A - 1) * cw - t),
- (A + 1) + (A - 1) * cw + t, -2 * ((A - 1) + (A + 1) * cw), (A + 1) + (A - 1) * cw - t);
- }
- case HighShelf:
- {
- double A = Math.Pow(10, gDb / 40), al = sw / 2 * Math.Sqrt(2), t = 2 * Math.Sqrt(A) * al;
- return N(A * ((A + 1) + (A - 1) * cw + t), -2 * A * ((A - 1) + (A + 1) * cw), A * ((A + 1) + (A - 1) * cw - t),
- (A + 1) - (A - 1) * cw + t, 2 * ((A - 1) - (A + 1) * cw), (A + 1) - (A - 1) * cw - t);
- }
- default:
- {
- double A = Math.Pow(10, gDb / 40);
- return N(1 + a * A, -2 * cw, 1 - a * A, 1 + a / A, -2 * cw, 1 - a / A);
- }
- }
- }
-
- // Combined response in dB at frequency f (sum of enabled bands).
- private double MagnitudeDb(double f, double sr)
- {
- double total = 0;
- double w = 2 * Math.PI * f / sr, cw = Math.Cos(w), sw = Math.Sin(w);
- double cos2 = Math.Cos(2 * w), sin2 = Math.Sin(2 * w);
- for (int b = 0; b < Bands; b++)
- {
- if (!BandOn(b)) continue;
- var (b0, b1, b2, a1, a2) = Coeffs(BandType(b), sr, P(b, FreqF), P(b, GainF), P(b, QF));
- double numR = b0 + b1 * cw + b2 * cos2, numI = -(b1 * sw + b2 * sin2);
- double denR = 1 + a1 * cw + a2 * cos2, denI = -(a1 * sw + a2 * sin2);
- double mag2 = (numR * numR + numI * numI) / Math.Max(1e-12, denR * denR + denI * denI);
- total += 10 * Math.Log10(Math.Max(1e-12, mag2));
- }
- return total;
- }
-
- // ---- analyzer: pull scope, window, FFT, smooth ------------------------
- public void Tick()
- {
- int n = _engine.DeviceScope(_track, _device, _scope, FftN);
- if (n < FftN) { Decay(); InvalidateVisual(); return; }
- for (int i = 0; i < FftN; i++) { _re[i] = _scope[i] * _hann[i]; _im[i] = 0; }
- Fft(_re, _im);
- double sr = _engine.SampleRate > 0 ? _engine.SampleRate : 48000;
- double refMag = FftN / 4.0; // Hann-windowed full-scale sine → ~0 dB
- for (int k = 1; k < Bins; k++)
- {
- double mag = Math.Sqrt(_re[k] * _re[k] + _im[k] * _im[k]);
- double db = 20 * Math.Log10(mag / refMag + 1e-9);
- _specDb[k] = db; // no release ballistics: the spectrum shows this frame (almanac § no meter animation)
- }
- _sr = sr;
- InvalidateVisual();
- }
- private double _sr = 48000;
- private void Decay() { for (int k = 1; k < Bins; k++) _specDb[k] = -120; }
-
- // 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;
- double 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;
- }
- }
- }
- }
-
- // ---- interaction ------------------------------------------------------
- private int HitDot(Point p, double w, double h)
- {
- int best = -1; double bestD = 16 * 16;
- for (int b = 0; b < Bands; b++)
- {
- if (!BandOn(b)) continue;
- double dx = p.X - FreqToX(P(b, FreqF), w);
- double dy = p.Y - GainToY(HasGain(BandType(b)) ? P(b, GainF) : 0, h);
- double d = dx * dx + dy * dy;
- if (d < bestD) { bestD = d; best = b; }
- }
- return best;
- }
-
- protected override void OnPointerPressed(PointerPressedEventArgs e)
- {
- double w = Bounds.Width, h = Bounds.Height;
- var pt = e.GetPosition(this);
- var props = e.GetCurrentPoint(this).Properties;
-
- if (props.IsRightButtonPressed)
- {
- int b = HitDot(pt, w, h);
- if (b >= 0) { _selected = b; ShowBandMenu(b); e.Handled = true; InvalidateVisual(); }
- return;
- }
-
- if (e.ClickCount == 2) // double-click empty space → enable a new band here
- {
- if (HitDot(pt, w, h) < 0) { AddBandAt(XToFreq(pt.X, w)); e.Handled = true; }
- return;
- }
-
- int hit = HitDot(pt, w, h);
- _selected = hit;
- if (hit >= 0) { _drag = hit; e.Pointer.Capture(this); Apply(pt, w, h); }
- e.Handled = true;
- InvalidateVisual();
- }
-
- protected override void OnPointerMoved(PointerEventArgs e)
- {
- if (_drag < 0) return;
- Apply(e.GetPosition(this), Bounds.Width, Bounds.Height);
- }
-
- protected override void OnPointerReleased(PointerReleasedEventArgs e)
- {
- _drag = -1;
- e.Pointer.Capture(null);
- }
-
- protected override void OnPointerWheelChanged(PointerWheelEventArgs e)
- {
- int b = _selected >= 0 ? _selected : HitDot(e.GetPosition(this), Bounds.Width, Bounds.Height);
- if (b < 0) return;
- double q = Math.Clamp(P(b, QF) * (e.Delta.Y > 0 ? 1.15 : 1 / 1.15), 0.1, 18);
- SetP(b, QF, q);
- e.Handled = true;
- InvalidateVisual();
- }
-
- private void Apply(Point p, double w, double h)
- {
- if (_drag < 0) return;
- SetP(_drag, FreqF, Math.Clamp(XToFreq(p.X, w), Fmin, Fmax));
- if (HasGain(BandType(_drag))) SetP(_drag, GainF, YToGain(p.Y, h));
- InvalidateVisual();
- }
-
- private void AddBandAt(double freq)
- {
- for (int b = 0; b < Bands; b++)
- {
- if (BandOn(b)) continue;
- SetP(b, On, 1);
- SetP(b, TypeF, Bell);
- SetP(b, FreqF, Math.Clamp(freq, Fmin, Fmax));
- SetP(b, GainF, 0);
- SetP(b, QF, 0.7);
- _selected = b;
- InvalidateVisual();
- return;
- }
- }
-
- private void ShowBandMenu(int b)
- {
- var flyout = new MenuFlyout();
- int cur = BandType(b);
- for (int t = 0; t < TypeNames.Length; t++)
- {
- int tt = t;
- var mi = new MenuItem { Header = TypeNames[t], ToggleType = MenuItemToggleType.Radio, IsChecked = t == cur };
- mi.Click += (_, _) => { SetP(b, TypeF, tt); InvalidateVisual(); };
- flyout.Items.Add(mi);
- }
- flyout.Items.Add(new Separator());
- var rm = new MenuItem { Header = "Remove band" };
- rm.Click += (_, _) => { SetP(b, On, 0); if (_selected == b) _selected = -1; InvalidateVisual(); };
- flyout.Items.Add(rm);
- flyout.ShowAt(this, showAtPointer: true);
- }
-
- // ---- render -----------------------------------------------------------
- private void Label(DrawingContext ctx, string s, double x, double y, IBrush brush, double size = 8)
- => ctx.DrawText(new FormattedText(s, CultureInfo.InvariantCulture, FlowDirection.LeftToRight, Mono, size, brush), new Point(x, y));
-
- // Bold digit centred on (cx, cy) using the text's own metrics.
- private void DotLabel(DrawingContext ctx, string s, double cx, double cy, IBrush brush, double size)
- {
- var ft = new FormattedText(s, CultureInfo.InvariantCulture, FlowDirection.LeftToRight, DotFont, size, brush);
- ctx.DrawText(ft, new Point(cx - ft.Width / 2, cy - ft.Height / 2));
- }
-
- public override void Render(DrawingContext ctx)
- {
- double w = Bounds.Width, h = Bounds.Height;
- if (w <= 0 || h <= 0) return;
- double sr = _sr;
- NotaGraph.Window(ctx, new Rect(0, 0, w, h));
-
- // --- grid: vertical decade lines + minor ticks, horizontal dB lines ---
- double[] majors = { 100, 1000, 10000 };
- double[] minors = { 30, 50, 70, 200, 300, 500, 700, 2000, 3000, 5000, 7000, 20000 };
- foreach (var f in minors) { double x = FreqToX(f, w); ctx.DrawLine(GridPenFaint, new Point(x, 0), new Point(x, h)); }
- foreach (var f in majors)
- {
- double x = FreqToX(f, w);
- ctx.DrawLine(GridPen, new Point(x, 0), new Point(x, h));
- }
- for (int db = -12; db <= 12; db += 6)
- {
- double y = GainToY(db, h);
- ctx.DrawLine(db == 0 ? ZeroPen : GridPen, new Point(0, y), new Point(w, y));
- }
- // The range is labelled in the bottom corners and nowhere else — no full axes.
- NotaGraph.Axis(ctx, new Rect(0, 0, w, h), NotaGraph.Corner.BottomLeft, "20");
- NotaGraph.Axis(ctx, new Rect(0, 0, w, h), NotaGraph.Corner.BottomRight, "20k Hz");
-
- // --- spectrum analyzer (behind the curve) ---
- var spec = new StreamGeometry();
- using (var g = spec.Open())
- {
- g.BeginFigure(new Point(0, h), true);
- for (int k = 1; k < Bins; k++)
- {
- double f = k * sr / FftN;
- if (f < Fmin || f > Fmax) continue;
- double x = FreqToX(f, w);
- double norm = Math.Clamp((_specDb[k] + 84) / 84, 0, 1); // -84..0 dBFS → 0..1
- g.LineTo(new Point(x, h - norm * h));
- }
- g.LineTo(new Point(w, h));
- g.EndFigure(true);
- }
- ctx.DrawGeometry(null, SpecPen, spec);
-
- // --- combined EQ magnitude curve + fill ---
- const int n = 128;
- var curve = new StreamGeometry();
- var fill = new StreamGeometry();
- using (var gc = curve.Open())
- using (var gf = fill.Open())
- {
- gf.BeginFigure(new Point(0, h / 2), true);
- for (int i = 0; i <= n; i++)
- {
- double x = w * i / n;
- double y = Math.Clamp(GainToY(MagnitudeDb(XToFreq(x, w), sr), h), -2, h + 2);
- var pt = new Point(x, y);
- if (i == 0) gc.BeginFigure(pt, false); else gc.LineTo(pt);
- gf.LineTo(pt);
- }
- gf.LineTo(new Point(w, h / 2));
- gf.EndFigure(true);
- }
- ctx.DrawGeometry(null, CurvePen, curve);
-
- // --- band dots (numbered) ---
- for (int b = 0; b < Bands; b++)
- {
- if (!BandOn(b)) continue;
- int type = BandType(b);
- double x = FreqToX(P(b, FreqF), w);
- double y = GainToY(HasGain(type) ? P(b, GainF) : 0, h);
- // Almanac node: 7px, ringed in the ground; the selected band brass, the rest Ink 3.
- // The band number lives in the readout below, not on the node.
- NotaGraph.Node(ctx, new Point(x, y), b == _selected);
- }
-
- // --- readout: selected band (or a hint) ---
- string txt;
- if (_selected >= 0 && BandOn(_selected))
- {
- int b = _selected, type = BandType(b);
- txt = string.Format(NotaNum.Culture, "B{0} {1} {2:0} Hz{3} Q {4:0.00}",
- b + 1, TypeNames[type], P(b, FreqF),
- HasGain(type) ? string.Format(NotaNum.Culture, " {0:+0.0;−0.0}\u2009dB", P(b, GainF)) : "",
- P(b, QF));
- }
- else
- {
- int active = 0; for (int b = 0; b < Bands; b++) if (BandOn(b)) active++;
- txt = $"{active}/8 bands · double-click to add · right-click a dot for type · wheel = Q";
- }
- Label(ctx, txt, 6, 4, LabelBright); // readout at the top: the bottom corners carry the range
- }
-}
diff --git a/src/managed/Nota.Application/Engine/IAudioEngine.cs b/src/managed/Nota.Application/Engine/IAudioEngine.cs
index 2593f9d8..ee71acc4 100644
--- a/src/managed/Nota.Application/Engine/IAudioEngine.cs
+++ b/src/managed/Nota.Application/Engine/IAudioEngine.cs
@@ -357,9 +357,10 @@ public interface IAudioEngine : IDisposable
int MidiEffectCcDestDevice(int trackId, int index);
int MidiEffectCcDestParam(int trackId, int index);
float MidiEffectCcDepth(int trackId, int index);
- /// <summary>Copies up to maxSamples of the device's recent mono signal into
- /// outSamples (oldest→newest); returns the count written. Non-zero only for the
- /// built-in EQ-8 (real-time spectrum). Lock-free.</summary>
+ /// <summary>Copies up to maxSamples of the device's live readings into outSamples; returns
+ /// the count written. Each device defines its own layout (the analysers: a telemetry block,
+ /// then spectra — e.g. Nota EQ-8's in / out peaks, auto gain, then its pre and post
+ /// spectra); zero for devices without one. Lock-free.</summary>
int DeviceScope(int trackId, int deviceIndex, float[] outSamples, int maxSamples);
/// <summary>Interactive-device command channel (the looper's transport + per-layer mute/gain).
/// Applied at the next quantize boundary by the engine.</summary>
diff --git a/src/managed/Nota.Infrastructure/Persistence/FactoryPresetCatalog.cs b/src/managed/Nota.Infrastructure/Persistence/FactoryPresetCatalog.cs
index 41c93997..cc0c5d9c 100644
--- a/src/managed/Nota.Infrastructure/Persistence/FactoryPresetCatalog.cs
+++ b/src/managed/Nota.Infrastructure/Persistence/FactoryPresetCatalog.cs
@@ -895,13 +895,60 @@ public sealed class FactoryPresetCatalog : IFactoryPresets
("fdecay", 0.5f), ("fsustain", 0.15f), ("adecay", 0.55f), ("asustain", 0.3f)),
Cab(1, 1, 16, 0.4f)));
- // ---- EQ-8 (kind 0) — 8 bands × (On/Type/Freq/Gain/Q), param names "<band> <field>",
- // band 1 = low shelf, 2/3 = bells, 4 = high shelf (defaults). Type: 0 LowCut,
- // 1 LowShelf, 2 Bell, 3 Notch, 4 HighShelf, 5 HighCut.
- Fx("eq", 0, "Bass Boost", ("1 Type", 1f), ("1 Freq", 110f), ("1 Gain", 5f));
- Fx("eq", 0, "Air & Presence", ("3 Freq", 3000f), ("3 Gain", 2.5f), ("4 Type", 4f), ("4 Freq", 9000f), ("4 Gain", 5f));
- Fx("eq", 0, "Telephone", ("1 Type", 0f), ("1 Freq", 450f), ("2 Freq", 1200f), ("2 Gain", 6f), ("2 Q", 1.2f), ("4 Type", 5f), ("4 Freq", 3000f));
- Fx("eq", 0, "Low Cut", ("1 Type", 0f), ("1 Freq", 80f), ("1 Q", 0.7f));
+ // ---- Nota EQ-8 (kind 0) — raw units. Eq8(…) spells out every band it uses with B(band, type,
+ // Hz, dB, Q, slope, channel); a band it does not name is switched off. Type: 0 Low cut,
+ // 1 Low shelf, 2 Bell, 3 Notch, 4 High shelf, 5 High cut. Slope (cuts): 0 = 12, 1 = 24,
+ // 2 = 48 dB/oct. Channel: 0 St, 1 Mid, 2 Side, 3 L, 4 R. Globals: Scale %, Output dB,
+ // Auto Gain. The first four keep the names of the original EQ-8 presets.
+ const int HP = 0, LS = 1, BL = 2, NT = 3, HS = 4, LP = 5, S12 = 0, S24 = 1, S48 = 2, M = 1, SD = 2, L = 3, R = 4;
+ // Start + tone
+ Eq8("Init", B(1, LS, 100, 0, 0.7f), B(2, BL, 300, 0, 0.7f), B(3, BL, 2000, 0, 0.7f), B(4, HS, 8000, 0, 0.7f));
+ Eq8("Bass Boost", B(1, LS, 110, 5, 0.7f));
+ Eq8("Air & Presence", B(3, BL, 3000, 2.5f, 0.7f), B(4, HS, 9000, 5, 0.7f));
+ Eq8("Telephone", B(1, HP, 450, 0, 0.7f), B(2, BL, 1200, 6, 1.2f), B(4, LP, 3000, 0, 0.7f));
+ Eq8("Low Cut", B(1, HP, 80, 0, 0.7f));
+ Eq8("Sub Rumble Filter", B(1, HP, 25, 0, 0.71f, S48));
+ Eq8("Smile Curve", B(1, LS, 90, 3, 0.71f), B(3, BL, 800, -2, 0.7f), B(7, HS, 9000, 3, 0.71f));
+ Eq8("Loudness Contour", [("Auto Gain", 1f)], B(1, LS, 100, 4, 0.71f), B(7, HS, 10000, 3, 0.71f));
+ // Mix
+ Eq8("Mix", B(1, LS, 110, -4, 0.6f), B(3, BL, 1300, 3, 0.9f), B(6, BL, 4172, -4.5f, 0.7f));
+ Eq8("Clean Mix Bus", B(1, HP, 30, 0, 0.71f, S24), B(2, BL, 250, -1.5f, 0.9f), B(7, HS, 12000, 1.5f, 0.71f));
+ Eq8("Mud Cut", B(1, HP, 60, 0, 0.71f), B(2, BL, 300, -3.5f, 1.2f));
+ Eq8("Pad Tuck", [("Output", -1f)], B(1, HP, 200, 0, 0.71f, S24), B(4, BL, 1000, -2, 0.6f), B(8, LP, 10000, 0, 0.71f, S24));
+ // Vocal
+ Eq8("Vocal Wide", [("Output", -1f), ("Auto Gain", 1f)],
+ B(1, HP, 100, 0, 0.71f, S24), B(2, BL, 300, -3, 1.6f, ch: M), B(3, BL, 2800, 2, 1.1f, ch: M),
+ B(4, HP, 220, 0, 0.71f, S12, SD), B(5, BL, 5000, -2, 4f, ch: M), B(7, HS, 9000, 4, 0.71f, ch: SD));
+ Eq8("Vocal Presence", B(1, HP, 90, 0, 0.71f, S24), B(2, BL, 250, -2, 1f), B(4, BL, 3500, 3, 0.9f), B(7, HS, 10000, 2, 0.71f));
+ Eq8("De-Box Vocal", B(1, HP, 80, 0, 0.71f), B(3, BL, 500, -4, 1.4f), B(5, BL, 2500, 1.5f, 1f));
+ Eq8("Sibilance Tamer", B(6, BL, 6500, -6, 4f), B(7, HS, 11000, -1.5f, 0.71f));
+ Eq8("Podcast Voice", B(1, HP, 80, 0, 0.71f, S24), B(2, BL, 200, 1.5f, 0.8f), B(3, BL, 400, -2.5f, 1.2f),
+ B(5, BL, 3000, 2, 1f), B(8, LP, 14000, 0, 0.71f));
+ // Drums
+ Eq8("Kick Punch", B(1, HP, 30, 0, 0.71f, S24), B(2, BL, 60, 4, 1.2f), B(3, BL, 350, -5, 1.5f), B(5, BL, 4000, 3, 1f));
+ Eq8("Snare Crack", B(1, HP, 80, 0, 0.71f), B(2, BL, 200, 3, 1.2f), B(4, BL, 900, -3, 1.5f), B(6, BL, 5000, 3, 1f));
+ Eq8("Overheads Air", B(1, HP, 250, 0, 0.71f, S24), B(4, BL, 1000, -1.5f, 0.8f), B(7, HS, 10000, 4, 0.71f));
+ Eq8("Hi-Hat Clean", B(1, HP, 400, 0, 0.71f, S48), B(6, BL, 8000, -2, 2f));
+ // Instruments
+ Eq8("Bass Definition", B(1, HP, 35, 0, 0.71f, S24), B(2, BL, 100, 2.5f, 1f), B(3, BL, 250, -3, 1.3f),
+ B(4, BL, 800, 2, 1.2f), B(8, LP, 8000, 0, 0.71f));
+ Eq8("Acoustic Guitar", B(1, HP, 80, 0, 0.71f, S24), B(2, BL, 200, -3, 1f), B(5, BL, 5000, 2, 1f), B(7, HS, 12000, 2, 0.71f));
+ Eq8("Electric Guitar Cab", B(1, HP, 90, 0, 0.71f, S24), B(3, BL, 400, -2, 1f), B(5, BL, 2500, 2, 1.2f), B(8, LP, 7000, 0, 0.71f, S24));
+ Eq8("Piano Clarity", B(1, HP, 40, 0, 0.71f), B(3, BL, 300, -2, 0.8f), B(5, BL, 3000, 2, 0.8f), B(7, HS, 10000, 1.5f, 0.71f));
+ // Mid / Side, left / right
+ Eq8("Master Tilt", [("Scale", 60f)],
+ B(1, HP, 28, 0, 0.71f, S48), B(2, LS, 80, 2, 0.71f), B(3, BL, 250, -1.5f, 0.8f), B(4, BL, 2500, -1, 0.7f),
+ B(5, HS, 10000, 2.5f, 0.6f), B(8, LP, 20000, 0, 0.71f, S24));
+ Eq8("Mono Low End", B(1, HP, 20, 0, 0.71f), B(2, HP, 120, 0, 0.71f, S24, SD));
+ Eq8("Wide Air", B(6, BL, 3000, -1, 0.8f, ch: SD), B(7, HS, 8000, 3, 0.71f, ch: SD));
+ Eq8("Focus Center", B(3, BL, 2000, 2, 1f, ch: M), B(4, BL, 2000, -1.5f, 0.8f, ch: SD), B(5, LS, 250, -2, 0.71f, ch: SD));
+ Eq8("Double-Track Split", B(3, BL, 800, 2, 1.2f, ch: L), B(4, BL, 1600, 2, 1.2f, ch: R),
+ B(5, BL, 1600, -1.5f, 1.2f, ch: L), B(6, BL, 800, -1.5f, 1.2f, ch: R));
+ // Repair + character
+ Eq8("Hum Removal 50 Hz", B(1, NT, 50, 0, 8f), B(2, NT, 100, 0, 8f), B(3, NT, 150, 0, 8f), B(4, NT, 200, 0, 8f));
+ Eq8("Hum Removal 60 Hz", B(1, NT, 60, 0, 8f), B(2, NT, 120, 0, 8f), B(3, NT, 180, 0, 8f), B(4, NT, 240, 0, 8f));
+ Eq8("Lo-Fi Radio", [("Output", 2f)], B(1, HP, 300, 0, 0.71f, S48), B(4, BL, 1500, 4, 1f), B(8, LP, 4000, 0, 0.71f, S48));
+ Eq8("Band Pass", B(1, HP, 500, 0, 1.5f, S24), B(8, LP, 2000, 0, 1.5f, S24));
// ---- Nota EQ-3 (kind 16) — three-band isolator, all params normalized 0..1 (unnamed ones
// reset to their defaults: flat, 250 Hz / 2.5 kHz, 24 dB/oct). Eq3(…) presets are in the
@@ -1878,6 +1925,29 @@ public sealed class FactoryPresetCatalog : IFactoryPresets
private void Eq3(string name, params (string Name, float Value)[] ps)
=> Fx("eq3", 16, name, [("Range", 1f), .. ps]);
+ // A Nota EQ-8 band for Eq8(…): number 1..8, type, Hz, dB, Q, slope (cuts), channel.
+ private static (int N, int Type, float Hz, float Db, float Q, int Slope, int Ch) B(int n, int type, float hz, float db, float q,
+ int slope = 0, int ch = 0) => (n, type, hz, db, q, slope, ch);
+
+ private void Eq8(string name, params (int N, int Type, float Hz, float Db, float Q, int Slope, int Ch)[] bands)
+ => Eq8(name, [], bands);
+
+ // Every band is spelled out: the ones named are on as given, the rest are switched off — so a
+ // preset never inherits the default bands. Globals (Scale, Output, Auto Gain) are extra pairs.
+ private void Eq8(string name, (string Name, float Value)[] globals, params (int N, int Type, float Hz, float Db, float Q, int Slope, int Ch)[] bands)
+ {
+ var ps = new List<(string, float)>(globals);
+ var used = new bool[9];
+ foreach (var b in bands)
+ {
+ used[b.N] = true;
+ ps.Add(($"{b.N} On", 1f)); ps.Add(($"{b.N} Type", b.Type)); ps.Add(($"{b.N} Freq", b.Hz));
+ ps.Add(($"{b.N} Gain", b.Db)); ps.Add(($"{b.N} Q", b.Q)); ps.Add(($"{b.N} Slope", b.Slope)); ps.Add(($"{b.N} Channel", b.Ch));
+ }
+ for (int n = 1; n <= 8; n++) if (!used[n]) ps.Add(($"{n} On", 0f));
+ Fx("eq", 0, name, ps.ToArray());
+ }
+
private void Midi(string group, int kind, string name, params (string Name, float Value)[] ps)
=> Add(group, name, "builtin-midi-effect", kind, isInstrument: false, isMidi: true, ps);
diff --git a/src/managed/Nota.Mcp/Tools/DeviceTools.cs b/src/managed/Nota.Mcp/Tools/DeviceTools.cs
index 7c102e3a..21ac56c1 100644
--- a/src/managed/Nota.Mcp/Tools/DeviceTools.cs
+++ b/src/managed/Nota.Mcp/Tools/DeviceTools.cs
@@ -67,10 +67,10 @@ public sealed class DeviceTools(IAudioEngine engine, IEngineDispatch dispatch, I
[McpServerTool(Name = "load_device_file"), Description("Load an audio file into a device that takes one — Nota Chamber: a user impulse response (WAV / FLAC / MP3; mono, stereo or 4-channel true stereo), which also selects it. Returns true on success.")]
public Task<bool> LoadDeviceFile(int trackId, int deviceIndex, [Description("Absolute path to the audio file")] string path) => Mutate(() => E.DeviceLoadFile(trackId, deviceIndex, path));
- [McpServerTool(Name = "get_device_text"), Description("Read a device's resource text. Nota Chamber: id 0 = current IR name, 1 = its category, 2 = the loaded user IR's name, 10 = the built-in IR list (name, category, seconds per line; the IR param selects entry round(v × 16), 1.0 = the user IR). Nota Lens: id 0 = the analysis summary, 1 = the third-octave band table, 2 = the scope measurements, 3 = the strongest spectral peaks, 4 = the A/B cursor measurements — or use read_analyzer, which returns all of it parsed. Delay (kind 3): id 0 = a one-line summary of what it is doing now (sync division or free times, ping-pong, feedback, mix, or that it is frozen). Reverb (kind 2): id 0 = a one-line summary (algorithm, RT60, pre-delay, diffusion, mix, early reflections / vintage, or that the tail is frozen). Compressor (kind 1): id 0 = a one-line summary (character, threshold, ratio, knee, attack / release, detector, range, mix, the reduction right now, external key / unlinked / Listen) — or use read_dynamics for the numbers. Auto Filter (kind 7): id 0 = a one-line summary (type, slope, cutoff, Q, what the envelope and LFO drive and by how much, drive, mix, sidechain key), 1 = the live reading (modulated cutoff with its note, resonance, envelope level, LFO value and phase, onsets counted), 2 = a guide to what each 0..1 parameter value means — or use read_filter_motion for the numbers. Nota Vintage (kind 8): id 0 = a one-line summary (character, drive, tone model and shelves, wow / flutter with their rates, noise, crackle, wear, stage, mix, output, oversampling, auto-comp), 1 = the live reading (in / out peaks, THD with the 2nd and 3rd harmonics, asymmetry, wow and flutter in cents, band-limit, hiss level, auto-comp gain), 2 = a guide to what each 0..1 parameter value means — or use read_vintage for the numbers. Nota Valve (kind 6): id 0 = a one-line summary (model, gain, the tone stack with the middle's frequency, bright / deep, even-only, cabinet with mic, distance, axis and position, low / high cut, gate, mix, output, oversampling, auto-comp), 1 = the live reading (in / out peaks, THD with the 2nd and 3rd harmonics, estimated aliasing, drive, gate open / closed, auto-comp gain, the cab's loss at 4 kHz vs on-axis), 2 = a guide to the parameter values and units — or use read_valve for the numbers. Nota Utility (kind 4): id 0 = a one-line summary (channel mode, width and its L/R or M/S law, mono below with its slope, balance, phase, mute, gain, auto match and its reference, true-peak limit), 1 = the live reading (in / out LUFS-S, peak and RMS, true peak, the delta in the meter's unit, correlation, width, energy balance, auto-match gain, limiter reduction), 2 = a guide to the parameter values and units — or use read_utility for the numbers. Nota Shutter (kind 19): id 0 = a one-line summary (Gate / Duck, threshold, return, shape with attack / hold / release, floor, lookahead, retrigger, internal / external key, the key filter band, peak hold, Listen), 1 = the live reading (state, gain, reduction now and peak, in / out / detector levels, the share of the window it was open, openings in the last bar and since reset, key level, latency), 2 = a guide to what each 0..1 parameter value means — or use read_shutter for the numbers. Nota Auto Shift (kind 10): id 0 = a one-line summary (key and scale or the MIDI target settings, key source, amount, speed, range, human, shift and fine, formant preserve and shift, mix, detection range and sensitivity, skip sibilants, follow), 1 = the live reading (detected note and cents, frequency, clarity, target and correction, ratio, input level, MIDI note held, share sung in scale, the best and runner-up key, Learn running, latency), 2 = a guide to what each 0..1 parameter value means — or use read_auto_shift for the numbers. Nota Beat Repeat (kind 11): id 0 = a one-line summary (mode, interval, grid, offset, gate, chance, variation, pitch and pitch decay, decay, volume, the repeat filter with its type, band and narrowing, mix, Repeat held, latch), 1 = the live reading (idle / capturing / repeating, the pass of how many, the slice in ms and beats, the repeat's gain, pitch and filter, in / repeat / out levels, bar and beat, bursts and skipped intervals since reset), 2 = a guide to what each 0..1 parameter value means — or use read_beat_repeat for the numbers. Nota Dynamic EQ-8 (kind 13): id 0 = a one-line summary (bands on and dynamic, the Dynamic switch, each band on with its type, frequency, gain, Q and — for a dynamic band — mode, threshold, range, attack / release and key, solo, output, whether a key track is routed), 1 = the live reading (in / out peaks, whether a key arrives, each band's detector level and — for a dynamic band — its threshold and the gain it has now of its range, CPU), 2 = a guide to the parameter layout and units — or use read_dynamic_eq for the numbers and set_dynamic_eq_band to edit a band. Nota Ceiling (kind 14): id 0 = a one-line summary (character, gain, ceiling and whether it is true-peak, release or auto, look-ahead, stereo link, key high-pass, key track, the loudness target, Delta), 1 = the live reading (gain reduction now, its mean and deepest over the last 4 s and since reset, in / out peaks and their holds, true peak, the share of time over the ceiling, the release in use and its range, transients that reached the clip, LUFS M / S / I and the distance to the target, LRA, PLR, latency), 2 = a guide to the parameter values and units — or use read_ceiling for the numbers. Nota Crush (kind 12): id 0 = a one-line summary (mode, bits, rate with the hold, drive, wet, dither / jitter / noise, post filter, output, anti-alias, auto gain, DC filter), 1 = the live reading (in / out peak and RMS, crest, peak holds, bits with the level count and quantisation noise, the reduced rate, hold and Nyquist, THD+N, images above the Nyquist, the driven peak and folds, auto gain, CPU), 2 = a guide to what each 0..1 parameter value means — or use read_crush for the numbers. Nota EQ-3 (kind 16): id 0 = a one-line summary (slope, the two crossovers, each band's gain or kill, the fader range, output), 1 = the live reading (in / out peaks, each band's level after its gain and the gain in effect now, the crossovers in use, CPU), 2 = a guide to what each 0..1 parameter value means — or use read_eq3 for the numbers and set_eq3 to play it in dB and Hz.")]
+ [McpServerTool(Name = "get_device_text"), Description("Read a device's resource text. Nota Chamber: id 0 = current IR name, 1 = its category, 2 = the loaded user IR's name, 10 = the built-in IR list (name, category, seconds per line; the IR param selects entry round(v × 16), 1.0 = the user IR). Nota Lens: id 0 = the analysis summary, 1 = the third-octave band table, 2 = the scope measurements, 3 = the strongest spectral peaks, 4 = the A/B cursor measurements — or use read_analyzer, which returns all of it parsed. Delay (kind 3): id 0 = a one-line summary of what it is doing now (sync division or free times, ping-pong, feedback, mix, or that it is frozen). Reverb (kind 2): id 0 = a one-line summary (algorithm, RT60, pre-delay, diffusion, mix, early reflections / vintage, or that the tail is frozen). Compressor (kind 1): id 0 = a one-line summary (character, threshold, ratio, knee, attack / release, detector, range, mix, the reduction right now, external key / unlinked / Listen) — or use read_dynamics for the numbers. Auto Filter (kind 7): id 0 = a one-line summary (type, slope, cutoff, Q, what the envelope and LFO drive and by how much, drive, mix, sidechain key), 1 = the live reading (modulated cutoff with its note, resonance, envelope level, LFO value and phase, onsets counted), 2 = a guide to what each 0..1 parameter value means — or use read_filter_motion for the numbers. Nota Vintage (kind 8): id 0 = a one-line summary (character, drive, tone model and shelves, wow / flutter with their rates, noise, crackle, wear, stage, mix, output, oversampling, auto-comp), 1 = the live reading (in / out peaks, THD with the 2nd and 3rd harmonics, asymmetry, wow and flutter in cents, band-limit, hiss level, auto-comp gain), 2 = a guide to what each 0..1 parameter value means — or use read_vintage for the numbers. Nota Valve (kind 6): id 0 = a one-line summary (model, gain, the tone stack with the middle's frequency, bright / deep, even-only, cabinet with mic, distance, axis and position, low / high cut, gate, mix, output, oversampling, auto-comp), 1 = the live reading (in / out peaks, THD with the 2nd and 3rd harmonics, estimated aliasing, drive, gate open / closed, auto-comp gain, the cab's loss at 4 kHz vs on-axis), 2 = a guide to the parameter values and units — or use read_valve for the numbers. Nota Utility (kind 4): id 0 = a one-line summary (channel mode, width and its L/R or M/S law, mono below with its slope, balance, phase, mute, gain, auto match and its reference, true-peak limit), 1 = the live reading (in / out LUFS-S, peak and RMS, true peak, the delta in the meter's unit, correlation, width, energy balance, auto-match gain, limiter reduction), 2 = a guide to the parameter values and units — or use read_utility for the numbers. Nota Shutter (kind 19): id 0 = a one-line summary (Gate / Duck, threshold, return, shape with attack / hold / release, floor, lookahead, retrigger, internal / external key, the key filter band, peak hold, Listen), 1 = the live reading (state, gain, reduction now and peak, in / out / detector levels, the share of the window it was open, openings in the last bar and since reset, key level, latency), 2 = a guide to what each 0..1 parameter value means — or use read_shutter for the numbers. Nota Auto Shift (kind 10): id 0 = a one-line summary (key and scale or the MIDI target settings, key source, amount, speed, range, human, shift and fine, formant preserve and shift, mix, detection range and sensitivity, skip sibilants, follow), 1 = the live reading (detected note and cents, frequency, clarity, target and correction, ratio, input level, MIDI note held, share sung in scale, the best and runner-up key, Learn running, latency), 2 = a guide to what each 0..1 parameter value means — or use read_auto_shift for the numbers. Nota Beat Repeat (kind 11): id 0 = a one-line summary (mode, interval, grid, offset, gate, chance, variation, pitch and pitch decay, decay, volume, the repeat filter with its type, band and narrowing, mix, Repeat held, latch), 1 = the live reading (idle / capturing / repeating, the pass of how many, the slice in ms and beats, the repeat's gain, pitch and filter, in / repeat / out levels, bar and beat, bursts and skipped intervals since reset), 2 = a guide to what each 0..1 parameter value means — or use read_beat_repeat for the numbers. Nota Dynamic EQ-8 (kind 13): id 0 = a one-line summary (bands on and dynamic, the Dynamic switch, each band on with its type, frequency, gain, Q and — for a dynamic band — mode, threshold, range, attack / release and key, solo, output, whether a key track is routed), 1 = the live reading (in / out peaks, whether a key arrives, each band's detector level and — for a dynamic band — its threshold and the gain it has now of its range, CPU), 2 = a guide to the parameter layout and units — or use read_dynamic_eq for the numbers and set_dynamic_eq_band to edit a band. Nota Ceiling (kind 14): id 0 = a one-line summary (character, gain, ceiling and whether it is true-peak, release or auto, look-ahead, stereo link, key high-pass, key track, the loudness target, Delta), 1 = the live reading (gain reduction now, its mean and deepest over the last 4 s and since reset, in / out peaks and their holds, true peak, the share of time over the ceiling, the release in use and its range, transients that reached the clip, LUFS M / S / I and the distance to the target, LRA, PLR, latency), 2 = a guide to the parameter values and units — or use read_ceiling for the numbers. Nota Crush (kind 12): id 0 = a one-line summary (mode, bits, rate with the hold, drive, wet, dither / jitter / noise, post filter, output, anti-alias, auto gain, DC filter), 1 = the live reading (in / out peak and RMS, crest, peak holds, bits with the level count and quantisation noise, the reduced rate, hold and Nyquist, THD+N, images above the Nyquist, the driven peak and folds, auto gain, CPU), 2 = a guide to what each 0..1 parameter value means — or use read_crush for the numbers. Nota EQ-3 (kind 16): id 0 = a one-line summary (slope, the two crossovers, each band's gain or kill, the fader range, output), 1 = the live reading (in / out peaks, each band's level after its gain and the gain in effect now, the crossovers in use, CPU), 2 = a guide to what each 0..1 parameter value means — or use read_eq3 for the numbers and set_eq3 to play it in dB and Hz. Nota EQ-8 (kind 0): id 0 = a one-line summary (bands on, scale, each band on with its type, frequency, gain, Q, slope for the cuts and channel when not stereo, output, auto gain, analyzer), 1 = the live reading (in / out peaks, the auto gain in effect, CPU), 2 = a guide to the parameter layout and units — or use read_eq8 for the numbers, set_eq8_band to edit a band and set_eq8 for the globals.")]
public Task<string> GetDeviceText(int trackId, int deviceIndex, int id) => Read(() => E.DeviceText(trackId, deviceIndex, id));
- [McpServerTool(Name = "device_action"), Description("Run a device's own command — the few things that are actions rather than parameters. Delay (kind 3): id 0 clears the loop (empties the delay buffer, so whatever is still circulating stops; useful after Freeze). Reverb (kind 2): id 0 kills the tail (empties the reverb's buffers, so whatever is still ringing — or frozen — stops). Auto Filter (kind 7): id 0 restarts the LFO (from its start phase; in Sync the cycle is re-anchored to the current beat), id 1 resets the envelope follower (drops a held peak). Nota Vintage (kind 8): id 0 resets the wear (restarts the wow and flutter at their zero phase and silences a ringing crackle). Nota Valve (kind 6): id 0 resets the amp (clears the filters, the gate and the auto-comp). Nota Utility (kind 4): id 0 gain match — moves Gain once so the output meets the reference (the input's level, or Target when Match To = 1) over the last 3 s in the Meter's unit; id 1 resets the meters (level history, holds and the auto-match ride). Nota Shutter (kind 19): id 0 resets the meters (peak reduction, the opening count, the history); id 1 sets the history window read_shutter and the card show (intArg 0 = 250 ms, 1 = 1 s, 2 = 4 s). Nota Auto Shift (kind 10): id 0 resets the analysis (the sung-note histogram and the pitch history); id 1 is Learn — intArg 1 starts listening (clears the histogram), 0 stops and sets Key + Scale (Major / Minor) to the best match and Key Source to Manual, 2 cancels. Nota Beat Repeat (kind 11): id 0 resets (stops the repeat, clears the timeline, the meters and the burst count); id 1 fires a repeat now, as if the interval hit (ignores Chance; while the transport plays — to hold one, set the Repeat param to 1). Nota Ceiling (kind 14): id 0 resets the peaks (the peak and true-peak holds, the max reduction, the clip count and the 4 s level window); id 1 resets the loudness (integrated, LRA, the 60 s window) and the peaks. Nota Crush (kind 12): id 0 resets the meters (the peak holds and the spectrum average). Nota EQ-3 (kind 16): id 0 resets the meters (the peaks and the spectrum average). Devices without a command ignore the call.")]
+ [McpServerTool(Name = "device_action"), Description("Run a device's own command — the few things that are actions rather than parameters. Delay (kind 3): id 0 clears the loop (empties the delay buffer, so whatever is still circulating stops; useful after Freeze). Reverb (kind 2): id 0 kills the tail (empties the reverb's buffers, so whatever is still ringing — or frozen — stops). Auto Filter (kind 7): id 0 restarts the LFO (from its start phase; in Sync the cycle is re-anchored to the current beat), id 1 resets the envelope follower (drops a held peak). Nota Vintage (kind 8): id 0 resets the wear (restarts the wow and flutter at their zero phase and silences a ringing crackle). Nota Valve (kind 6): id 0 resets the amp (clears the filters, the gate and the auto-comp). Nota Utility (kind 4): id 0 gain match — moves Gain once so the output meets the reference (the input's level, or Target when Match To = 1) over the last 3 s in the Meter's unit; id 1 resets the meters (level history, holds and the auto-match ride). Nota Shutter (kind 19): id 0 resets the meters (peak reduction, the opening count, the history); id 1 sets the history window read_shutter and the card show (intArg 0 = 250 ms, 1 = 1 s, 2 = 4 s). Nota Auto Shift (kind 10): id 0 resets the analysis (the sung-note histogram and the pitch history); id 1 is Learn — intArg 1 starts listening (clears the histogram), 0 stops and sets Key + Scale (Major / Minor) to the best match and Key Source to Manual, 2 cancels. Nota Beat Repeat (kind 11): id 0 resets (stops the repeat, clears the timeline, the meters and the burst count); id 1 fires a repeat now, as if the interval hit (ignores Chance; while the transport plays — to hold one, set the Repeat param to 1). Nota Ceiling (kind 14): id 0 resets the peaks (the peak and true-peak holds, the max reduction, the clip count and the 4 s level window); id 1 resets the loudness (integrated, LRA, the 60 s window) and the peaks. Nota Crush (kind 12): id 0 resets the meters (the peak holds and the spectrum average). Nota EQ-3 (kind 16): id 0 resets the meters (the peaks and the spectrum average). Nota EQ-8 (kind 0): id 0 resets the meters (the peaks and the spectrum averages). Devices without a command ignore the call.")]
public Task DeviceAction(int trackId, int deviceIndex, [Description("Command id — see the device's list in this description")] int id,
int intArg = 0, float floatArg = 0) => Mutate(() => E.DeviceAction(trackId, deviceIndex, id, intArg, floatArg));
@@ -753,6 +753,136 @@ public sealed class DeviceTools(IAudioEngine engine, IEngineDispatch dispatch, I
return Eq3Read(trackId, deviceIndex, false);
});
+ public sealed record Eq8Band(int Band, bool On, string Type, double FreqHz, double GainDb, double EffectiveGainDb, double Q,
+ int SlopeDbPerOct, string Channel);
+ public sealed record Eq8Reading(string Summary, string Live, double ScalePercent, double OutputDb, bool AutoGain, double AutoGainNowDb,
+ string Analyzer, double InputPeakDb, double OutputPeakDb, double SampleRate, Eq8Band[] Bands,
+ bool SpectrumValid, DynEqSpectrumBand[] InputSpectrum, DynEqSpectrumBand[] OutputSpectrum);
+
+ private static readonly string[] Eq8Channels = { "Stereo", "Mid", "Side", "Left", "Right" };
+ private static readonly string[] Eq8Analyzer = { "Pre", "Post", "Off" };
+
+ private Eq8Band Eq8BandRead(int trackId, int deviceIndex, int b)
+ {
+ int pc = E.DeviceParamCount(trackId, deviceIndex);
+ float Pm(int p) => p < pc ? E.DeviceGetParam(trackId, deviceIndex, p) : p == 56 ? 100f : 0f;
+ int o = b * 5, ty = Math.Clamp((int)Math.Round(Pm(o + 1)), 0, 5);
+ bool gain = ty is 1 or 2 or 4, cut = ty is 0 or 5;
+ double scale = Math.Clamp(Pm(56), 0, 200) / 100;
+ return new Eq8Band(b + 1, Pm(o) > 0.5f, DynEqTypes[ty], Math.Round(Pm(o + 2)), gain ? Math.Round(Pm(o + 3), 1) : 0,
+ gain ? Math.Round(Pm(o + 3) * scale, 1) : 0, Math.Round(Pm(o + 4), 2),
+ cut ? 12 << Math.Clamp((int)Math.Round(Pm(40 + b)), 0, 2) : 12, Eq8Channels[Math.Clamp((int)Math.Round(Pm(48 + b)), 0, 4)]);
+ }
+
+ private Eq8Reading Eq8Read(int trackId, int deviceIndex, bool spectrum)
+ {
+ if (E.TrackDeviceBuiltinKind(trackId, deviceIndex) != 0) throw new ArgumentException("not a Nota EQ-8 (kind 0)");
+ const int tele = 16, spec = 96;
+ var sc = new float[tele + 2 * spec];
+ int n = E.DeviceScope(trackId, deviceIndex, sc, spectrum ? sc.Length : tele);
+ float V(int i) => n > i ? sc[i] : 0f;
+ float Db(int i) => n > i ? sc[i] : -120f;
+ static double R1(double v) => Math.Round(v, 1);
+ int pc = E.DeviceParamCount(trackId, deviceIndex);
+ float Pm(int p) => p < pc ? E.DeviceGetParam(trackId, deviceIndex, p) : p == 56 ? 100f : p == 59 ? 1f : 0f;
+ var bands = new Eq8Band[8];
+ for (int b = 0; b < 8; b++) bands[b] = Eq8BandRead(trackId, deviceIndex, b);
+ bool valid = spectrum && n >= sc.Length && V(5) > 0.5f;
+ DynEqSpectrumBand[] Spec(int at)
+ {
+ var sp = new List<DynEqSpectrumBand>();
+ if (valid)
+ for (int k = 0; k < 24; k++)
+ {
+ double pw = 0;
+ for (int b = 4 * k; b < 4 * k + 4; b++) pw += Math.Pow(10, sc[at + b] / 10);
+ sp.Add(new DynEqSpectrumBand(Math.Round(20 * Math.Pow(1000, (k + 0.5) / 24)), R1(Math.Max(-120, 10 * Math.Log10(Math.Max(1e-12, pw))))));
+ }
+ return sp.ToArray();
+ }
+ return new Eq8Reading(E.DeviceText(trackId, deviceIndex, 0), E.DeviceText(trackId, deviceIndex, 1), R1(Pm(56)), R1(Pm(57)),
+ Pm(58) >= 0.5f, R1(V(2)), Eq8Analyzer[Math.Clamp((int)Math.Round(Pm(59)), 0, 2)], R1(Db(0)), R1(Db(1)), V(3), bands,
+ valid, Spec(tele), Spec(tele + spec));
+ }
+
+ [McpServerTool(Name = "read_eq8"), Description(
+ "Read a Nota EQ-8 (built-in effect kind 0 — eight-band parametric EQ): Scale (% applied to every shelf and bell gain), "
+ + "output, whether Auto gain is on and the gain it adds now, the analyzer mode the card shows (Pre / Post / Off), in / out "
+ + "peaks; per band: on, type, frequency, gain, the effective gain after Scale, Q (the resonance on the cuts), slope "
+ + "(12 / 24 / 48 dB/oct, cuts only) and channel (Stereo / Mid / Side / Left / Right); plus the input and output spectra "
+ + "in 24 log bands (dB). Levels read −120 while silent; they move only while audio runs through the track. "
+ + "set_eq8_band edits a band, set_eq8 the globals.")]
+ public Task<Eq8Reading> ReadEq8(int trackId, int deviceIndex) => Read(() => Eq8Read(trackId, deviceIndex, true));
+
+ [McpServerTool(Name = "set_eq8_band"), Description(
+ "Edit one band of a Nota EQ-8 (built-in effect kind 0) in one call — only the fields you pass change; each change is "
+ + "recorded like a hand edit. type: \"Low cut\" | \"Low shelf\" | \"Bell\" | \"Notch\" | \"High shelf\" | \"High cut\" "
+ + "(only shelves and bells take gain). slope: 12, 24 or 48 dB/oct (cuts only). channel: \"Stereo\" | \"Mid\" | \"Side\" | "
+ + "\"Left\" | \"Right\". Setting any field of an off band does not switch it on — pass on true. Returns the band as read back.")]
+ public Task<Eq8Band> SetEq8Band(int trackId, int deviceIndex, [Description("Band 1..8")] int band,
+ bool? on = null, string? type = null, [Description("20..20000 Hz")] double? freqHz = null, [Description("−18..+18 dB")] double? gainDb = null,
+ [Description("0.1..18 (0.71 = flat on the cuts)")] double? q = null, [Description("12, 24 or 48")] int? slope = null,
+ string? channel = null) => Mutate(() =>
+ {
+ if (E.TrackDeviceBuiltinKind(trackId, deviceIndex) != 0) throw new ArgumentException("not a Nota EQ-8 (kind 0)");
+ if (band < 1 || band > 8) throw new ArgumentException("band is 1..8");
+ int o = (band - 1) * 5, pc = E.DeviceParamCount(trackId, deviceIndex);
+ void S(int p, double v)
+ {
+ if (p >= pc) return;
+ E.BeginAutomationWrite(trackId, AutomationTarget.DeviceParam, deviceIndex, p, "");
+ E.DeviceSetParam(trackId, deviceIndex, p, (float)v);
+ E.EndAutomationWrite(trackId, AutomationTarget.DeviceParam, deviceIndex, p, "");
+ }
+ int Idx(string[] names, string v, string what)
+ {
+ int i = Array.FindIndex(names, s => string.Equals(s, v.Trim(), StringComparison.OrdinalIgnoreCase));
+ if (i < 0) throw new ArgumentException($"{what} must be one of: {string.Join(", ", names)}");
+ return i;
+ }
+ if (type is not null) S(o + 1, Idx(DynEqTypes, type, "type"));
+ if (freqHz is { } f) S(o + 2, Math.Clamp(f, 20, 20000));
+ if (gainDb is { } g) S(o + 3, Math.Clamp(g, -18, 18));
+ if (q is { } qq) S(o + 4, Math.Clamp(qq, 0.1, 18));
+ if (slope is { } sl)
+ {
+ if (sl is not (12 or 24 or 48)) throw new ArgumentException("slope is 12, 24 or 48");
+ S(40 + band - 1, sl == 12 ? 0 : sl == 24 ? 1 : 2);
+ }
+ if (channel is not null) S(48 + band - 1, Idx(Eq8Channels, channel, "channel"));
+ if (on is { } onv) S(o, onv ? 1 : 0);
+ return Eq8BandRead(trackId, deviceIndex, band - 1);
+ });
+
+ [McpServerTool(Name = "set_eq8"), Description(
+ "Set the global controls of a Nota EQ-8 (built-in effect kind 0) — only the fields you pass change; each change is recorded "
+ + "like a hand edit. scalePercent 0..200 multiplies every shelf and bell gain (100 = as set, 0 = flat). outputDb ±12. "
+ + "autoGain adds the opposite of the average level of the shelves and bells (cuts and notches do not count; ±12 dB max). analyzer \"Pre\" | \"Post\" | \"Off\" picks the "
+ + "spectrum the card draws. Returns the device as read back (without the spectra).")]
+ public Task<Eq8Reading> SetEq8(int trackId, int deviceIndex, [Description("0..200 %")] double? scalePercent = null,
+ [Description("−12..+12 dB")] double? outputDb = null, bool? autoGain = null, string? analyzer = null) => Mutate(() =>
+ {
+ if (E.TrackDeviceBuiltinKind(trackId, deviceIndex) != 0) throw new ArgumentException("not a Nota EQ-8 (kind 0)");
+ int pc = E.DeviceParamCount(trackId, deviceIndex);
+ void S(int p, double v)
+ {
+ if (p >= pc) return;
+ E.BeginAutomationWrite(trackId, AutomationTarget.DeviceParam, deviceIndex, p, "");
+ E.DeviceSetParam(trackId, deviceIndex, p, (float)v);
+ E.EndAutomationWrite(trackId, AutomationTarget.DeviceParam, deviceIndex, p, "");
+ }
+ if (scalePercent is { } sp) S(56, Math.Clamp(sp, 0, 200));
+ if (outputDb is { } od) S(57, Math.Clamp(od, -12, 12));
+ if (autoGain is { } ag) S(58, ag ? 1 : 0);
+ if (analyzer is not null)
+ {
+ int i = Array.FindIndex(Eq8Analyzer, s => string.Equals(s, analyzer.Trim(), StringComparison.OrdinalIgnoreCase));
+ if (i < 0) throw new ArgumentException("analyzer must be Pre, Post or Off");
+ S(59, i);
+ }
+ return Eq8Read(trackId, deviceIndex, false);
+ });
+
public sealed record AnalyzerBand(double Hz, double Db);
public sealed record AnalyzerPeak(double Hz, double Db, string Note);
public sealed record AnalyzerReading(string Summary, string Scope, string Cursors, AnalyzerBand[] Bands, AnalyzerPeak[] Peaks);
diff --git a/src/native/nota.engine/include/nota/nota_engine.h b/src/native/nota.engine/include/nota/nota_engine.h
index 4504b5c5..9c5b6406 100644
--- a/src/native/nota.engine/include/nota/nota_engine.h
+++ b/src/native/nota.engine/include/nota/nota_engine.h
@@ -823,9 +823,10 @@ NOTA_API float nota_device_param_default(const NotaEngine* engine, int32_t
NOTA_API float nota_instrument_param_default(const NotaEngine* engine, int32_t track_id, int32_t param_index);
NOTA_API float nota_midi_effect_param_default(const NotaEngine* engine, int32_t track_id, int32_t index, int32_t param_index);
-/* Real-time analyzer feed: copies up to max_samples of the device's recent mono
- * signal into out (oldest->newest), returning the count written. Non-zero only for
- * the built-in EQ-8 (its pre-EQ spectrum ring). Lock-free; torn reads are fine. */
+/* Real-time analyzer feed: copies up to max_samples of the device's live readings
+ * into out, returning the count written. Each device defines its own layout (e.g.
+ * Nota EQ-8: a telemetry block, then its pre and post spectra); 0 for devices
+ * without one. Lock-free; torn reads are fine. */
NOTA_API int32_t nota_device_scope(const NotaEngine* engine, int32_t track_id, int32_t device_index, float* out, int32_t max_samples);
/* Interactive-device command channel (the looper's Record/Overdub/Play/Stop/Undo/
* Clear and per-layer mute/gain). The engine applies it at the next quantize boundary. */
diff --git a/src/native/nota.engine/src/Device.h b/src/native/nota.engine/src/Device.h
index 98051c89..3b489896 100644
--- a/src/native/nota.engine/src/Device.h
+++ b/src/native/nota.engine/src/Device.h
@@ -94,10 +94,10 @@ public:
// writes an atomic, UI reads lock-free (like the per-track level meters).
virtual float gainReductionDb() const { return 0.0f; }
- // Real-time analyzer feed: copy up to maxSamples of a recently-seen mono signal
- // into out (oldest→newest), returning the count written. Non-zero only for
- // devices with a scope (the built-in EQ-8's pre-EQ spectrum). Audio thread
- // writes a ring, UI reads lock-free; torn reads are acceptable for a visualizer.
+ // Real-time analyzer feed: copy up to maxSamples of the device's live readings into
+ // out, returning the count written. Each device defines its own layout (a telemetry
+ // block, then spectra — see Eq.h / DynamicEq.h); 0 for devices without one. Audio
+ // thread writes, UI / MCP read lock-free; torn reads are acceptable for a visualizer.
virtual int32_t scopeRead(float* /*out*/, int32_t /*maxSamples*/) const { return 0; }
// Interactive-device command channel (the looper's Record/Overdub/Play/Stop/
diff --git a/src/native/nota.engine/src/Eq.h b/src/native/nota.engine/src/Eq.h
index 93179e29..98bee3c6 100644
--- a/src/native/nota.engine/src/Eq.h
+++ b/src/native/nota.engine/src/Eq.h
@@ -1,23 +1,52 @@
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.
//
-// EQ-8 — an eight-band parametric equalizer (mixing-console style). Each band
-// has an on/off, a filter type (low cut / low shelf / bell / notch / high shelf /
-// high cut), and freq / gain / Q. Four bands are enabled by default. Stereo, in
-// place, RBJ biquads; coefficients are recomputed per block on the audio thread
-// from atomic params, so setParam stays lock-free. A pre-EQ mono ring buffer is
-// published for the UI's real-time spectrum analyzer (scopeRead, like the level
-// meters / compressor GR — audio thread writes, UI reads lock-free).
+// Nota EQ-8 (device kind 0) — an eight-band parametric equalizer (mixing-console style). Each
+// band has an on/off, a filter type (low cut / low shelf / bell / notch / high shelf / high
+// cut), freq / gain / Q, a Slope for the cuts (12 / 24 / 48 dB/oct) and a Channel: the band
+// works on the stereo pair, on the Mid or the Side of it, or on the left or right channel
+// alone. Scale multiplies every shelf and bell gain at once (0 … 200 %); Output trims the
+// result and Auto gain adds the opposite of the average level of the shelves and bells, so an
+// edit can be judged at the same loudness.
+//
+// in ─▶ band 1 ─▶ band 2 ─▶ … ─▶ band 8 ─▶ auto gain ─▶ output ─▶ out
+// a band: St (L and R) · Mid / Side (encode, filter one half, decode) · L · R
+//
+// RBJ biquads. A 12 dB/oct cut is one biquad at the band's Q (the original EQ-8); 24 and 48
+// dB/oct are Butterworth cascades of two / four sections whose last, sharpest section carries
+// the resonance (Q / 0.707). Coefficients are recomputed per block from atomic params, so
+// setParam stays lock-free; a band whose slope or channel changes starts from a clean state.
+//
+// Params are the device's raw units and APPEND ONLY: 0..39 are the original layout (8 bands ×
+// On, Type, Freq, Gain, Q), then 40..47 "n Slope" (0 = 12, 1 = 24, 2 = 48 dB/oct), 48..55 "n
+// Channel" (0 St, 1 Mid, 2 Side, 3 L, 4 R), 56 Scale (%), 57 Output (dB), 58 Auto Gain, 59
+// Analyzer (0 Pre, 1 Post, 2 Off — which spectrum the card draws). Every appended param
+// defaults to what the original EQ-8 did, so older projects, racks and presets open unchanged.
+//
+// Telemetry (scopeRead): kTele live values (in / out peaks, the auto gain in effect, sample
+// rate, CPU), then the input (pre) spectrum and the output (post) spectrum — kSpec log bands
+// 20 Hz..20 kHz each, in dB, from an FFT over the last ~85 ms, analysed on the reading thread
+// (≤ 30 Hz).
+// deviceText: 0 = status line, 1 = live reading, 2 = parameter guide.
+// deviceAction: 0 = reset the meters (peak holds and the spectrum averages).
+// Header-only, allocation-free after setSampleRate. JUCE-free.
#pragma once
#include "Device.h"
+#include "signalsmith-linear/fft.h"
+
#include <algorithm>
-#include <cstdio>
#include <atomic>
+#include <chrono>
#include <cmath>
+#include <complex>
#include <cstdint>
+#include <cstdio>
+#include <mutex>
+#include <string>
+#include <vector>
namespace nota {
@@ -28,8 +57,30 @@ public:
enum { On = 0, Type = 1, Freq = 2, Gain = 3, Q = 4 };
// Filter types (per band).
enum { LowCut = 0, LowShelf = 1, Bell = 2, Notch = 3, HighShelf = 4, HighCut = 5, kNumTypes = 6 };
+ // Channels (per band).
+ enum { ChStereo = 0, ChMid = 1, ChSide = 2, ChLeft = 3, ChRight = 4, kNumChannels = 5 };
+
+ static constexpr int kBandParams = kBands * kPerBand; // 40 — the original layout
+ enum { SlopeBase = kBandParams, ChannelBase = SlopeBase + kBands,
+ Scale = ChannelBase + kBands, Output, AutoGain, Analyzer, kNumParams }; // 60
+ enum { AnaPre = 0, AnaPost = 1, AnaOff = 2 };
- static constexpr int kNumParams = kBands * kPerBand; // 40
+ // Telemetry slots (scopeRead).
+ enum {
+ S_InPeak = 0, // input peak (300 ms fall), dBFS
+ S_OutPeak, // output peak (300 ms fall), dBFS
+ S_AutoGain, // the auto gain in effect now, dB
+ S_SampleRate,
+ S_Cpu, // share of real time spent in process()
+ S_Analysed, // 1 when the spectra are valid
+ S_Latency, // samples (always 0)
+ S_Bands, // kSpec
+ kTele = 16
+ };
+ static constexpr int kSpec = 96;
+ static constexpr double kSpecLo = 20.0, kSpecHi = 20000.0;
+ static constexpr int kPreAt = kTele, kPostAt = kTele + kSpec;
+ static constexpr int kScope = kTele + 2 * kSpec;
Eq() {
// Four musically-spread bands enabled and flat; the rest are ready but off.
@@ -41,38 +92,130 @@ public:
setBand(5, 0, Bell, 800.0f, 0.0f, 0.70f);
setBand(6, 0, Bell, 5000.0f, 0.0f, 0.70f);
setBand(7, 0, HighCut, 16000.0f, 0.0f, 0.70f);
+ for (int b = 0; b < kBands; ++b) { p_[SlopeBase + b].store(0.0f); p_[ChannelBase + b].store(0.0f); }
+ p_[Scale].store(100.0f);
+ p_[Output].store(0.0f);
+ p_[AutoGain].store(0.0f);
+ p_[Analyzer].store((float)AnaPost);
+ setSampleRate(44100.0, 0);
}
- void setSampleRate(double sr, int32_t /*maxBlock*/) override { sr_ = sr > 0 ? sr : 44100.0; }
+ void setSampleRate(double sr, int32_t /*maxBlock*/) override {
+ std::lock_guard<std::mutex> lock(mx_);
+ sr_ = sr > 0 ? sr : 44100.0;
+ srA_.store((float)sr_, std::memory_order_relaxed);
+ for (auto& ch : s_) for (auto& bd : ch) for (auto& st : bd) st = {};
+ for (auto& c : cfgKey_) c = -1;
+ autoSr_ = -1.0; autoDb_ = 0.0; autoCur_ = 1.0; outCur_ = 1.0; primed_ = false;
+ inPk_ = outPk_ = 0.0f;
+ fftN_ = sr_ > 50000.0 ? 8192 : 4096;
+ size_t ring = 1;
+ while (ring < (size_t)fftN_ * 2) ring <<= 1;
+ for (auto& r : ring_) r.assign(ring, 0.0f);
+ ringMask_ = (uint32_t)(ring - 1);
+ ringW_.store(0, std::memory_order_relaxed);
+ fft_.resize((size_t)fftN_);
+ win_.assign((size_t)fftN_, 0.0f);
+ tBuf_.assign((size_t)fftN_, 0.0f);
+ fBuf_.assign((size_t)fftN_ / 2, {});
+ for (int i = 0; i < fftN_; ++i) win_[(size_t)i] = (float)(0.5 - 0.5 * std::cos(2.0 * kPi * i / fftN_));
+ lastAnaS_ = -1.0; lastAnaW_ = 0; anaValid_ = false;
+ for (int k = 0; k < 2; ++k) for (int b = 0; b < kSpec; ++b) { aSpec_[k][b] = 0.0; spec_[k][b] = -120.0f; }
+ }
void process(float* buf, int32_t frames) override {
+ const auto t0 = std::chrono::steady_clock::now();
const double sr = sr_;
- // Recompute per-band coefficients once per block.
- Coeffs c[kBands];
- bool on[kBands];
+ const double scale = clampd(get(Scale), 0.0, 200.0) / 100.0;
+
+ // Per-band config + coefficient cascades, once per block.
+ bool on[kBands];
+ int ty[kBands], ch[kBands], nSec[kBands];
+ Coeffs c[kBands][kMaxSec];
for (int b = 0; b < kBands; ++b) {
- on[b] = p_[b * kPerBand + On].load(std::memory_order_relaxed) > 0.5f;
- if (!on[b]) continue;
- const int ty = typeOf(b);
- const double f0 = clampd(p_[b * kPerBand + Freq].load(std::memory_order_relaxed), 20.0, sr * 0.49);
- const double gDb = p_[b * kPerBand + Gain].load(std::memory_order_relaxed);
- const double q = clampd(p_[b * kPerBand + Q].load(std::memory_order_relaxed), 0.1, 18.0);
- c[b] = coeffs(ty, sr, f0, gDb, q);
+ on[b] = bandOn(b);
+ if (!on[b]) { cfgKey_[b] = -1; continue; }
+ ty[b] = typeOf(b);
+ ch[b] = channelOf(b);
+ nSec[b] = cascade(c[b], ty[b], slopeOf(b), sr, clampd(bp(b, Freq), 20.0, sr * 0.49),
+ clampd(bp(b, Gain), -18.0, 18.0) * scale, clampd(bp(b, Q), 0.1, 18.0));
+ // A band whose cascade length or channel changes starts clean (its old state means
+ // something else); a type or frequency move keeps it, as the original EQ-8 did.
+ const int key = nSec[b] * 10 + ch[b];
+ if (key != cfgKey_[b]) { for (auto& chs : s_) for (auto& st : chs[b]) st = {}; cfgKey_[b] = key; }
}
+ // Auto gain: the opposite of the average curve level, re-measured only when a param moves.
+ const bool autoOn = get(AutoGain) >= 0.5f;
+ if (autoOn) {
+ bool moved = autoSr_ != sr;
+ for (int i = 0; i < kAutoKeys && !moved; ++i) moved = autoKey_[i] != get(i);
+ if (moved) {
+ for (int i = 0; i < kAutoKeys; ++i) autoKey_[i] = get(i);
+ autoSr_ = sr;
+ autoDb_ = clampd(-averageDb(on, ty, ch, c, sr), -12.0, 12.0);
+ }
+ }
+ const double autoTarget = autoOn ? std::pow(10.0, autoDb_ / 20.0) : 1.0;
+ const double outTarget = std::pow(10.0, clampd(get(Output), -12.0, 12.0) / 20.0);
+ if (!primed_) { autoCur_ = autoTarget; outCur_ = outTarget; primed_ = true; }
+ const double glide = 1.0 - std::exp(-1.0 / (0.02 * sr)); // ~20 ms, click-free
+
+ float inPk = 0.0f, outPk = 0.0f;
+ uint32_t w = ringW_.load(std::memory_order_relaxed);
+ const bool ringOk = !ring_[0].empty();
for (int32_t i = 0; i < frames; ++i) {
- // Publish the pre-EQ mono signal for the analyzer.
- const float mono = 0.5f * (buf[i * 2] + buf[i * 2 + 1]);
- const uint32_t w = scopeW_.load(std::memory_order_relaxed);
- scope_[w & (kScope - 1)] = mono;
- scopeW_.store(w + 1, std::memory_order_relaxed);
-
- for (int ch = 0; ch < 2; ++ch) {
- float x = buf[i * 2 + ch];
- for (int b = 0; b < kBands; ++b)
- if (on[b]) x = s_[ch][b].run(c[b], x);
- buf[i * 2 + ch] = x;
+ double l = buf[i * 2], r = buf[i * 2 + 1];
+ inPk = std::max(inPk, (float)std::max(std::fabs(l), std::fabs(r)));
+ if (ringOk) ring_[0][w & ringMask_] = (float)(0.5 * (l + r));
+
+ for (int b = 0; b < kBands; ++b) {
+ if (!on[b]) continue;
+ const int n = nSec[b];
+ switch (ch[b]) {
+ case ChLeft: l = run(s_[0][b], c[b], n, l); break;
+ case ChRight: r = run(s_[1][b], c[b], n, r); break;
+ case ChMid: {
+ double m = 0.5 * (l + r); const double sd = 0.5 * (l - r);
+ m = run(s_[0][b], c[b], n, m);
+ l = m + sd; r = m - sd;
+ break;
+ }
+ case ChSide: {
+ const double m = 0.5 * (l + r); double sd = 0.5 * (l - r);
+ sd = run(s_[0][b], c[b], n, sd);
+ l = m + sd; r = m - sd;
+ break;
+ }
+ default:
+ l = run(s_[0][b], c[b], n, l);
+ r = run(s_[1][b], c[b], n, r);
+ break;
+ }
}
+ autoCur_ += (autoTarget - autoCur_) * glide;
+ outCur_ += (outTarget - outCur_) * glide;
+ const double g = autoCur_ * outCur_;
+ const float ol = (float)(l * g), orr = (float)(r * g);
+ buf[i * 2] = ol; buf[i * 2 + 1] = orr;
+ outPk = std::max(outPk, std::max(std::fabs(ol), std::fabs(orr)));
+ if (ringOk) ring_[1][w & ringMask_] = 0.5f * (ol + orr);
+ ++w;
+ }
+ ringW_.store(w, std::memory_order_release);
+
+ const double blockS = frames > 0 ? frames / sr : 0.0;
+ if (resetPk_.exchange(false, std::memory_order_acquire)) inPk_ = outPk_ = 0.0f;
+ const float fall = (float)std::exp(-blockS / 0.3);
+ inPk_ = std::max(inPk, inPk_ * fall);
+ outPk_ = std::max(outPk, outPk_ * fall);
+ inPkA_.store(db(inPk_), std::memory_order_relaxed);
+ outPkA_.store(db(outPk_), std::memory_order_relaxed);
+ autoA_.store(autoOn ? (float)autoDb_ : 0.0f, std::memory_order_relaxed);
+ if (frames > 0) {
+ const double el = std::chrono::duration<double>(std::chrono::steady_clock::now() - t0).count();
+ cpuS_ = cpuS_ * 0.9 + (el / blockS) * 0.1;
+ cpuA_.store((float)cpuS_, std::memory_order_relaxed);
}
}
@@ -81,18 +224,32 @@ public:
int32_t paramCount() const override { return kNumParams; }
const char* paramName(int32_t i) const override {
- if (i < 0 || i >= kNumParams) return "";
+ if (i == Scale) return "Scale";
+ if (i == Output) return "Output";
+ if (i == AutoGain) return "Auto Gain";
+ if (i == Analyzer) return "Analyzer";
static thread_local char buf[16];
+ if (i >= SlopeBase && i < ChannelBase) { std::snprintf(buf, sizeof(buf), "%d Slope", i - SlopeBase + 1); return buf; }
+ if (i >= ChannelBase && i < Scale) { std::snprintf(buf, sizeof(buf), "%d Channel", i - ChannelBase + 1); return buf; }
+ if (i < 0 || i >= kBandParams) return "";
const int b = i / kPerBand, f = i % kPerBand;
const char* fld = f == On ? "On" : f == Type ? "Type" : f == Freq ? "Freq" : f == Gain ? "Gain" : "Q";
std::snprintf(buf, sizeof(buf), "%d %s", b + 1, fld);
return buf;
}
float paramMin(int32_t i) const override {
+ if (i == Output) return -12.0f;
+ if (i < 0 || i >= kBandParams) return 0.0f; // Slope, Channel, Scale, Auto Gain, Analyzer
switch (i % kPerBand) { case On: return 0.0f; case Type: return 0.0f; case Freq: return 20.0f;
case Gain: return -18.0f; default: return 0.1f; }
}
float paramMax(int32_t i) const override {
+ if (i >= SlopeBase && i < ChannelBase) return 2.0f;
+ if (i >= ChannelBase && i < Scale) return kNumChannels - 1;
+ if (i == Scale) return 200.0f;
+ if (i == Output) return 12.0f;
+ if (i == AutoGain) return 1.0f;
+ if (i == Analyzer) return 2.0f;
switch (i % kPerBand) { case On: return 1.0f; case Type: return kNumTypes - 1; case Freq: return 20000.0f;
case Gain: return 18.0f; default: return 18.0f; }
}
@@ -100,41 +257,116 @@ public:
return (i >= 0 && i < kNumParams) ? p_[i].load(std::memory_order_relaxed) : 0.0f;
}
void setParam(int32_t i, float v) override {
- if (i >= 0 && i < kNumParams) p_[i].store(v, std::memory_order_relaxed);
+ if (i >= 0 && i < kNumParams && std::isfinite(v))
+ p_[i].store(std::clamp(v, paramMin(i), paramMax(i)), std::memory_order_relaxed);
}
- // Real-time analyzer feed: copy up to maxSamples of the pre-EQ mono signal into
- // out, oldest→newest. Returns the number written. Lock-free; torn reads are fine
- // for a visualizer.
+ // Telemetry block, then the pre and post spectra. Writes as much of that layout as fits
+ // in maxSamples; a read no longer than kTele skips the FFT. UI / MCP thread.
int32_t scopeRead(float* out, int32_t maxSamples) const override {
if (!out || maxSamples <= 0) return 0;
- const int32_t n = std::min(maxSamples, kScope);
- const uint32_t w = scopeW_.load(std::memory_order_relaxed);
- const uint32_t start = w - static_cast<uint32_t>(n);
- for (int32_t k = 0; k < n; ++k)
- out[k] = scope_[(start + static_cast<uint32_t>(k)) & (kScope - 1)];
+ float t[kTele] = {};
+ t[S_InPeak] = inPkA_.load(std::memory_order_relaxed);
+ t[S_OutPeak] = outPkA_.load(std::memory_order_relaxed);
+ t[S_AutoGain] = autoA_.load(std::memory_order_relaxed);
+ t[S_SampleRate] = srA_.load(std::memory_order_relaxed);
+ t[S_Cpu] = cpuA_.load(std::memory_order_relaxed);
+ t[S_Latency] = 0.0f;
+ t[S_Bands] = (float)kSpec;
+ int32_t n = 0;
+ if (maxSamples > kTele) {
+ std::lock_guard<std::mutex> lock(mx_);
+ t[S_Analysed] = analyse() ? 1.0f : 0.0f;
+ for (int k = 0; k < kTele && n < maxSamples; ++k) out[n++] = t[k];
+ for (int s = 0; s < 2; ++s)
+ for (int b = 0; b < kSpec && n < maxSamples; ++b) out[n++] = spec_[s][b];
+ return n;
+ }
+ for (int k = 0; k < kTele && n < maxSamples; ++k) out[n++] = t[k];
return n;
}
+ void deviceAction(int32_t id, int32_t /*iarg*/, float /*farg*/) override {
+ if (id != 0) return;
+ std::lock_guard<std::mutex> lock(mx_);
+ resetPk_.store(true, std::memory_order_release); // the audio thread drops its holds
+ inPkA_.store(-120.0f, std::memory_order_relaxed);
+ outPkA_.store(-120.0f, std::memory_order_relaxed);
+ lastAnaS_ = -1.0; anaValid_ = false;
+ for (int k = 0; k < 2; ++k) for (int b = 0; b < kSpec; ++b) { aSpec_[k][b] = 0.0; spec_[k][b] = -120.0f; }
+ }
+
+ // 0 — a one-line status; 1 — the live reading; 2 — a guide to the parameter values.
+ std::string deviceText(int32_t id) const override {
+ static const char* types[kNumTypes] = { "Low cut", "Low shelf", "Bell", "Notch", "High shelf", "High cut" };
+ static const char* chans[kNumChannels] = { "stereo", "mid", "side", "left", "right" };
+ static const char* anas[3] = { "pre", "post", "off" };
+ char b[256];
+ if (id == 0) {
+ int nOn = 0;
+ for (int k = 0; k < kBands; ++k) if (bandOn(k)) ++nOn;
+ std::snprintf(b, sizeof b, "%d bands on - scale %.0f %%", nOn, get(Scale));
+ std::string s = b;
+ for (int k = 0; k < kBands; ++k) {
+ if (!bandOn(k)) continue;
+ const int ty = typeOf(k);
+ std::snprintf(b, sizeof b, " | B%d %s %.0f Hz", k + 1, types[ty], bp(k, Freq)); s += b;
+ if (hasGain(ty)) { std::snprintf(b, sizeof b, " %+.1f dB", bp(k, Gain)); s += b; }
+ std::snprintf(b, sizeof b, " Q %.2f", bp(k, Q)); s += b;
+ if (ty == LowCut || ty == HighCut) { std::snprintf(b, sizeof b, " %d dB/oct", 12 << slopeOf(k)); s += b; }
+ if (channelOf(k) != ChStereo) { std::snprintf(b, sizeof b, " %s", chans[channelOf(k)]); s += b; }
+ }
+ std::snprintf(b, sizeof b, " | output %+.1f dB%s | analyzer %s", get(Output), get(AutoGain) >= 0.5f ? " + auto gain" : "",
+ anas[std::clamp((int)std::lround(get(Analyzer)), 0, 2)]);
+ s += b;
+ return s;
+ }
+ if (id == 1) {
+ float sc[kTele];
+ scopeRead(sc, kTele);
+ auto lv = [](float v) { char t[24]; if (v <= -119.0f) std::snprintf(t, sizeof t, "-inf"); else std::snprintf(t, sizeof t, "%.1f", v); return std::string(t); };
+ std::snprintf(b, sizeof b, "in %s dBFS - out %s dBFS - auto gain %+.1f dB%s - CPU %.2f %%", lv(sc[S_InPeak]).c_str(),
+ lv(sc[S_OutPeak]).c_str(), sc[S_AutoGain], get(AutoGain) >= 0.5f ? "" : " (off)", sc[S_Cpu] * 100.0f);
+ return b;
+ }
+ if (id == 2) {
+ return "Raw units. Band n (1..8) params are named \"n <field>\": at index (n-1)*5 + field On (0/1), Type (0 Low cut, "
+ "1 Low shelf, 2 Bell, 3 Notch, 4 High shelf, 5 High cut), Freq 20..20000 Hz, Gain -18..+18 dB (shelves and bells "
+ "only), Q 0.1..18 (the resonance on the cuts, 0.71 = flat); 40..47 \"n Slope\" 0 = 12, 1 = 24, 2 = 48 dB/oct "
+ "(cuts only); 48..55 \"n Channel\" 0 Stereo, 1 Mid, 2 Side, 3 Left, 4 Right. 56 Scale 0..200 % multiplies every "
+ "shelf and bell gain. 57 Output -12..+12 dB. 58 Auto Gain 0/1 adds the opposite of the average level of the "
+ "shelves and bells (cuts and notches do not count; max +-12 dB). 59 Analyzer 0 Pre, 1 Post, 2 Off (display only).";
+ }
+ return {};
+ }
+
private:
static constexpr double kPi = 3.14159265358979323846;
- static constexpr int kScope = 4096; // power of two
+ static constexpr int kMaxSec = 4;
+ static constexpr int kAutoKeys = Scale + 1; // band params, slopes, channels and Scale shape the curve
struct Coeffs { double b0 = 1, b1 = 0, b2 = 0, a1 = 0, a2 = 0; };
struct State {
double z1 = 0, z2 = 0;
- float run(const Coeffs& c, float xf) {
- double x = xf;
+ double run(const Coeffs& c, double x) {
double y = c.b0 * x + z1;
z1 = c.b1 * x - c.a1 * y + z2;
z2 = c.b2 * x - c.a2 * y;
- return static_cast<float>(y);
+ return y;
}
};
-
- int typeOf(int b) const {
- return std::clamp(static_cast<int>(std::lround(p_[b * kPerBand + Type].load(std::memory_order_relaxed))), 0, kNumTypes - 1);
+ static double run(State* st, const Coeffs* c, int n, double x) {
+ for (int k = 0; k < n; ++k) x = st[k].run(c[k], x);
+ return x;
}
+
+ float get(int i) const { return p_[i].load(std::memory_order_relaxed); }
+ float bp(int b, int f) const { return p_[b * kPerBand + f].load(std::memory_order_relaxed); }
+ bool bandOn(int b) const { return bp(b, On) > 0.5f; }
+ int typeOf(int b) const { return std::clamp(static_cast<int>(std::lround(bp(b, Type))), 0, kNumTypes - 1); }
+ int slopeOf(int b) const { return std::clamp(static_cast<int>(std::lround(get(SlopeBase + b))), 0, 2); }
+ int channelOf(int b) const { return std::clamp(static_cast<int>(std::lround(get(ChannelBase + b))), 0, kNumChannels - 1); }
+ static bool hasGain(int ty) { return ty == LowShelf || ty == Bell || ty == HighShelf; }
void setBand(int b, float on, int type, float freq, float gain, float q) {
p_[b * kPerBand + On].store(on);
p_[b * kPerBand + Type].store(static_cast<float>(type));
@@ -144,10 +376,29 @@ private:
}
static double clampd(double v, double lo, double hi) { return v < lo ? lo : (v > hi ? hi : v); }
+ static float db(float lin) { return lin > 1e-6f ? 20.0f * std::log10(lin) : -120.0f; }
static Coeffs norm(double b0, double b1, double b2, double a0, double a1, double a2) {
return {b0 / a0, b1 / a0, b2 / a0, a1 / a0, a2 / a0};
}
+ // A band's sections: one biquad, or for a 24 / 48 dB cut a Butterworth cascade whose last
+ // (sharpest) section carries the resonance. Returns the section count.
+ static int cascade(Coeffs* out, int type, int slope, double sr, double f0, double gainDb, double q) {
+ if ((type == LowCut || type == HighCut) && slope > 0) {
+ static const double q24[2] = { 0.54119610, 1.30656296 };
+ static const double q48[4] = { 0.50979558, 0.60134489, 0.89997622, 2.56291545 };
+ const int n = slope == 1 ? 2 : 4;
+ const double* bq = slope == 1 ? q24 : q48;
+ const double res = q / 0.70710678;
+ for (int k = 0; k < n; ++k) {
+ const double qk = k == n - 1 ? clampd(bq[k] * res, 0.1, 40.0) : bq[k];
+ out[k] = type == LowCut ? highpass(sr, f0, qk) : lowpass(sr, f0, qk);
+ }
+ return n;
+ }
+ out[0] = coeffs(type, sr, f0, gainDb, q);
+ return 1;
+ }
static Coeffs coeffs(int type, double sr, double f0, double gainDb, double q) {
switch (type) {
case LowCut: return highpass(sr, f0, q);
@@ -158,6 +409,33 @@ private:
default: return peaking(sr, f0, gainDb, q);
}
}
+ static double magDb(const Coeffs& k, double w) {
+ const double cw = std::cos(w), sw = std::sin(w), c2 = std::cos(2 * w), s2 = std::sin(2 * w);
+ const double nr = k.b0 + k.b1 * cw + k.b2 * c2, ni = -(k.b1 * sw + k.b2 * s2);
+ const double dr = 1 + k.a1 * cw + k.a2 * c2, di = -(k.a1 * sw + k.a2 * s2);
+ return 10.0 * std::log10(std::max(1e-12, (nr * nr + ni * ni) / std::max(1e-12, dr * dr + di * di)));
+ }
+ // The tonal lift of the curve — the average level of its shelves and bells over 20 Hz..20 kHz
+ // (log-spaced). Cuts and notches take content away rather than colour it, so they are left
+ // out (a high-pass must not make auto gain louder). Stereo and Mid bands count fully, a
+ // left or right band half, a Side band not at all (the Side is the quiet half).
+ static double averageDb(const bool* on, const int* ty, const int* ch, const Coeffs (*c)[kMaxSec], double sr) {
+ constexpr int N = 64;
+ double sum = 0.0;
+ for (int i = 0; i < N; ++i) {
+ const double f = 20.0 * std::pow(1000.0, (i + 0.5) / N);
+ if (f >= sr * 0.49) continue;
+ const double w = 2.0 * kPi * f / sr;
+ double m = 0.0;
+ for (int b = 0; b < kBands; ++b) {
+ if (!on[b] || ch[b] == ChSide || !hasGain(ty[b])) continue;
+ const double v = magDb(c[b][0], w);
+ m += (ch[b] == ChLeft || ch[b] == ChRight) ? 0.5 * v : v;
+ }
+ sum += m;
+ }
+ return sum / N;
+ }
static Coeffs peaking(double sr, double f0, double gainDb, double q) {
const double A = std::pow(10.0, gainDb / 40.0);
const double w0 = 2.0 * kPi * f0 / sr, cw = std::cos(w0), sw = std::sin(w0);
@@ -194,11 +472,74 @@ private:
(A + 1) - (A - 1) * cw + tsa, 2 * ((A - 1) - (A + 1) * cw), (A + 1) - (A - 1) * cw - tsa);
}
+ // ---- spectra (reading thread, rate-limited, under mx_) -------------------------------
+ static double nowSeconds() {
+ return std::chrono::duration<double>(std::chrono::steady_clock::now().time_since_epoch()).count();
+ }
+ bool analyse() const {
+ if (ring_[0].empty() || fftN_ <= 0) return false;
+ const double now = nowSeconds();
+ const uint32_t w = ringW_.load(std::memory_order_acquire);
+ if (lastAnaS_ >= 0 && (now - lastAnaS_ < 1.0 / 30.0 || w == lastAnaW_)) return anaValid_;
+ if (w < (uint32_t)fftN_) return anaValid_;
+ const int n = fftN_;
+ const uint32_t start = w - (uint32_t)n;
+ const int half = n / 2;
+ const double binHz = sr_ / n;
+ const double ref = 0.25 * (double)n * n * 0.25; // Hann: a full-scale sine's bin power
+ const bool stale = lastAnaS_ < 0 || now - lastAnaS_ > 1.2;
+ const double a = stale ? 1.0 : 1.0 - std::exp(-(now - lastAnaS_) / 0.2);
+ double tot = 0.0;
+ for (int s = 0; s < 2; ++s) {
+ for (int i = 0; i < n; ++i) tBuf_[(size_t)i] = ring_[s][(start + (uint32_t)i) & ringMask_] * win_[(size_t)i];
+ fft_.fft(tBuf_.data(), fBuf_.data());
+ for (int b = 0; b < kSpec; ++b) {
+ const double lo = kSpecLo * std::pow(kSpecHi / kSpecLo, (double)b / kSpec);
+ const double hi = kSpecLo * std::pow(kSpecHi / kSpecLo, (double)(b + 1) / kSpec);
+ int k0 = std::max(1, (int)std::ceil(lo / binHz)), k1 = std::min(half - 1, (int)std::ceil(hi / binHz) - 1);
+ if (k1 < k0) k0 = k1 = std::clamp((int)std::lround(std::sqrt(lo * hi) / binHz), 1, half - 1);
+ double e = 0.0;
+ for (int k = k0; k <= k1; ++k) e += std::norm(fBuf_[(size_t)k]);
+ tot += e;
+ aSpec_[s][b] += a * (e - aSpec_[s][b]);
+ spec_[s][b] = aSpec_[s][b] > ref * 1e-12 ? (float)std::max(-120.0, 10.0 * std::log10(aSpec_[s][b] / ref)) : -120.0f;
+ }
+ }
+ lastAnaS_ = now; lastAnaW_ = w;
+ anaValid_ = tot > ref * 1e-10;
+ return anaValid_;
+ }
+
double sr_ = 44100.0;
std::atomic<float> p_[kNumParams] = {};
- State s_[2][kBands] = {}; // [channel][band]
- mutable float scope_[kScope] = {}; // pre-EQ mono ring
- std::atomic<uint32_t> scopeW_{0};
+ State s_[2][kBands][kMaxSec] = {}; // [channel (or M/S half)][band][section]
+ int cfgKey_[kBands] = {}; // type / slope / channel the state belongs to
+ float autoKey_[kAutoKeys] = {}; // auto gain: the params it was measured for
+ double autoSr_ = -1.0, autoDb_ = 0.0;
+ double autoCur_ = 1.0, outCur_ = 1.0; // smoothed auto / output gains
+ bool primed_ = false;
+
+ // Meters (audio thread) and their published values.
+ float inPk_ = 0.0f, outPk_ = 0.0f;
+ double cpuS_ = 0.0;
+ std::atomic<float> inPkA_{-120.0f}, outPkA_{-120.0f}, autoA_{0.0f}, cpuA_{0.0f}, srA_{44100.0f};
+ std::atomic<bool> resetPk_{false};
+
+ // Spectra: pre / post rings written by the audio thread, the analysis state under mx_.
+ std::vector<float> ring_[2];
+ uint32_t ringMask_ = 0;
+ std::atomic<uint32_t> ringW_{0};
+ int fftN_ = 0;
+ mutable std::mutex mx_;
+ mutable signalsmith::linear::RealFFT<float> fft_;
+ std::vector<float> win_;
+ mutable std::vector<float> tBuf_;
+ mutable std::vector<std::complex<float>> fBuf_;
+ mutable double aSpec_[2][kSpec] = {};
+ mutable float spec_[2][kSpec] = {};
+ mutable double lastAnaS_ = -1.0;
+ mutable uint32_t lastAnaW_ = 0;
+ mutable bool anaValid_ = false;
};
} // namespace nota
diff --git a/tests/Nota.SmokeTest/DesignTokenCheck.cs b/tests/Nota.SmokeTest/DesignTokenCheck.cs
index 6c6a3706..c9fcae2e 100644
--- a/tests/Nota.SmokeTest/DesignTokenCheck.cs
+++ b/tests/Nota.SmokeTest/DesignTokenCheck.cs
@@ -300,7 +300,6 @@ internal static class DesignTokenCheck
if (root is null) { yield return (false, "repo root located"); yield break; }
var app = Path.Combine(root, "src/managed/Nota.App");
var views = Directory.EnumerateFiles(Path.Combine(app, "Controls"), "*.cs")
- .Append(Path.Combine(app, "EqCurve.cs"))
.Select(f => (Path: Path.GetRelativePath(app, f), Text: File.ReadAllText(f))).ToArray();
// Deliberate exceptions: MixBar is a level strip, not a graph window; RhythmWaveViz
// draws the waveform itself as a shape, which is data, not a fill under a curve.
diff --git a/tests/Nota.SmokeTest/Program.cs b/tests/Nota.SmokeTest/Program.cs
index ffba0af9..edb1918a 100644
--- a/tests/Nota.SmokeTest/Program.cs
+++ b/tests/Nota.SmokeTest/Program.cs
@@ -3195,7 +3195,7 @@ Check(m4Dry > 1e-4f, $"instrument audible (rms={m4Dry:0.0000})");
int eqDev = engine.AddBuiltinDevice(fxT, 0); // 0 = EQ-8 (flat by default = passthrough)
Check(eqDev >= 0, "add built-in EQ-8");
Check(engine.DeviceName(fxT, eqDev) == "Nota EQ-8", "EQ-8 device name");
-Check(engine.DeviceParamCount(fxT, eqDev) == 40, "EQ-8 exposes 40 params (8 bands × 5)");
+Check(engine.DeviceParamCount(fxT, eqDev) == 60, "EQ-8 exposes 60 params (8 bands × 5, slopes, channels, globals)");
engine.Seek(0);
engine.RenderOffline(buf, frames);
Check(Rms(buf, frames) > 1e-4f, $"audio flows through flat EQ-8 (rms={Rms(buf, frames):0.0000})");
@@ -5540,7 +5540,7 @@ Console.WriteLine("-- EQ-8 --");
engine.AddMidiClip(et, 0.0, 4.0);
engine.SetClipNotes(et, 0, new[] { new NotaNote(69, 0.0, 3.0, 0.9f) }); // A4 = 440 Hz + harmonics
int eq = engine.AddBuiltinDevice(et, 0);
- Check(engine.DeviceParamCount(et, eq) == 40, "EQ-8 has 40 params on a fresh track");
+ Check(engine.DeviceParamCount(et, eq) == 60, "EQ-8 has 60 params on a fresh track");
// Band 3 (index 2) is a bell; param base = 2*5. On=+0, Type=+1, Freq=+2, Gain=+3, Q=+4.
int b2 = 2 * 5;
@@ -5559,13 +5559,170 @@ Console.WriteLine("-- EQ-8 --");
float cut = Rms(eb, 8192);
Check(boosted > cut * 1.2f, $"EQ-8 bell shapes level (boost {boosted:0.000} > cut {cut:0.000})");
- // Analyzer scope: after audio has passed, the pre-EQ ring returns non-silent samples.
+ // Analyzer: after audio has passed, the scope returns the telemetry and both spectra.
engine.DeviceSetParam(et, eq, b2 + 3, 0f);
engine.Seek(0); engine.Play(); engine.RenderOffline(eb, 8192); engine.StopTransport();
- var scope = new float[2048];
- int got = engine.DeviceScope(et, eq, scope, 2048);
- float srms = Rms(scope, 1024);
- Check(got == 2048 && srms > 1e-5f, $"EQ-8 analyzer scope returns signal ({got} samples, rms {srms:0.0000})");
+ var scope = new float[16 + 2 * 96];
+ int got = engine.DeviceScope(et, eq, scope, scope.Length);
+ Check(got == scope.Length && scope[3] > 1000 && scope[5] > 0.5f, $"EQ-8 scope returns the telemetry and both spectra ({got}, sr {scope[3]})");
+}
+{
+ // Nota EQ-8 on a deterministic stereo clip — a centred 440 Hz sine (all Mid, no Side) — so
+ // gains, scale, channels, slopes, output and auto gain read in exact dB.
+ string cwav = Path.Combine(Path.GetTempPath(), "nota_smoke_eq8_centre_" + Guid.NewGuid().ToString("N") + ".wav");
+ Nota.SmokeTest.WavWriter.WriteStereo(cwav, 2.0, 44100, i => { double v = 0.3 * Math.Sin(2 * Math.PI * 440 * i / 44100.0); return (v, v); });
+ using var qe = new NotaEngine();
+ qe.SetBpm(120);
+ int qt = qe.AddAudioTrack();
+ qe.AddAudioClip(qt, cwav, 0.0);
+ int qd = qe.AddBuiltinDevice(qt, 0);
+ const int On = 0, Type = 1, Freq = 2, Gain = 3, Q = 4, SlopeB = 40, ChanB = 48, Scale = 56, Output = 57, AutoG = 58, Ana = 59;
+ float[] Render(int frames) { var b = new float[frames * 2]; qe.Seek(0); qe.Play(); qe.RenderOffline(b, frames); qe.StopTransport(); return b; }
+ (double L, double R) LevelLR()
+ {
+ var b = Render(22050); double l = 0, r = 0;
+ for (int i = 11025; i < 22050; i++) { l += b[i * 2] * b[i * 2]; r += b[i * 2 + 1] * b[i * 2 + 1]; }
+ return (10 * Math.Log10(l / 11025 + 1e-30), 10 * Math.Log10(r / 11025 + 1e-30));
+ }
+ double Level() { var (l, r) = LevelLR(); return 10 * Math.Log10((Math.Pow(10, l / 10) + Math.Pow(10, r / 10)) / 2); }
+ void Band(int b, float on, float type, float hz, float db, float q, float slope = 0, float ch = 0)
+ {
+ int o = b * 5;
+ qe.DeviceSetParam(qt, qd, o + On, on); qe.DeviceSetParam(qt, qd, o + Type, type); qe.DeviceSetParam(qt, qd, o + Freq, hz);
+ qe.DeviceSetParam(qt, qd, o + Gain, db); qe.DeviceSetParam(qt, qd, o + Q, q);
+ qe.DeviceSetParam(qt, qd, SlopeB + b, slope); qe.DeviceSetParam(qt, qd, ChanB + b, ch);
+ }
+ qe.SetDeviceBypassed(qt, qd, true);
+ double dry = Level();
+ qe.SetDeviceBypassed(qt, qd, false);
+
+ // Defaults: the appended params mean the original EQ-8, and a fresh one is transparent.
+ Check(qe.DeviceParamName(qt, qd, SlopeB) == "1 Slope" && qe.DeviceParamName(qt, qd, ChanB + 7) == "8 Channel" && qe.DeviceParamName(qt, qd, Scale) == "Scale"
+ && qe.DeviceParamName(qt, qd, Output) == "Output" && qe.DeviceParamName(qt, qd, AutoG) == "Auto Gain" && qe.DeviceParamName(qt, qd, Ana) == "Analyzer",
+ "EQ-8 appended param names");
+ Check(Math.Abs(qe.DeviceParamDefault(qt, qd, Scale) - 100) < 1e-3 && qe.DeviceParamDefault(qt, qd, SlopeB) == 0 && qe.DeviceParamDefault(qt, qd, ChanB) == 0
+ && qe.DeviceParamDefault(qt, qd, AutoG) == 0 && qe.DeviceParamDefault(qt, qd, Output) == 0 && Math.Abs(qe.DeviceParamDefault(qt, qd, Ana) - 1) < 1e-3,
+ "EQ-8 appended defaults: slope 12, stereo, scale 100 %, output 0, auto off, analyzer Post");
+ double flat = Level() - dry;
+ Check(Math.Abs(flat) < 0.1, $"a fresh EQ-8 is transparent ({flat:+0.00;-0.00} dB)");
+
+ // A +6 dB bell on the sine, then Scale.
+ for (int b = 0; b < 8; b++) qe.DeviceSetParam(qt, qd, b * 5 + On, 0f);
+ Band(2, 1, 2, 440, 6, 1);
+ double bell = Level() - dry;
+ qe.DeviceSetParam(qt, qd, Scale, 50); double half = Level() - dry;
+ qe.DeviceSetParam(qt, qd, Scale, 0); double none = Level() - dry;
+ qe.DeviceSetParam(qt, qd, Scale, 200); double twice = Level() - dry;
+ qe.DeviceSetParam(qt, qd, Scale, 100);
+ Check(Math.Abs(bell - 6) < 0.3 && Math.Abs(half - 3) < 0.3 && Math.Abs(none) < 0.1 && Math.Abs(twice - 12) < 0.4,
+ $"Scale multiplies the gain (100 % {bell:+0.0}, 50 % {half:+0.0}, 0 % {none:+0.0}, 200 % {twice:+0.0} dB)");
+
+ // Channels: the centred sine lives in the Mid — a Side band leaves it, a Mid band takes it.
+ qe.DeviceSetParam(qt, qd, ChanB + 2, 2); double side = Level() - dry;
+ qe.DeviceSetParam(qt, qd, ChanB + 2, 1); double mid = Level() - dry;
+ qe.DeviceSetParam(qt, qd, ChanB + 2, 3); var lOnly = LevelLR();
+ qe.SetDeviceBypassed(qt, qd, true); var dryLR = LevelLR(); qe.SetDeviceBypassed(qt, qd, false);
+ Check(Math.Abs(side) < 0.1 && Math.Abs(mid - 6) < 0.3 && Math.Abs(lOnly.L - dryLR.L - 6) < 0.3 && Math.Abs(lOnly.R - dryLR.R) < 0.1,
+ $"channels: Side {side:+0.0}, Mid {mid:+0.0}, Left L {lOnly.L - dryLR.L:+0.0} / R {lOnly.R - dryLR.R:+0.0} dB");
+ qe.DeviceSetParam(qt, qd, ChanB + 2, 0);
+
+ // Slopes: a high-pass an octave above the sine cuts deeper at 24 and 48 dB/oct.
+ Band(2, 1, 0, 880, 0, 0.71f, 0); double k12 = Level() - dry;
+ qe.DeviceSetParam(qt, qd, SlopeB + 2, 1); double k24 = Level() - dry;
+ qe.DeviceSetParam(qt, qd, SlopeB + 2, 2); double k48 = Level() - dry;
+ Check(k12 < -9 && k24 < k12 - 8 && k48 < k24 - 15, $"cut slopes 12 / 24 / 48 dB/oct at an octave: {k12:F1} / {k24:F1} / {k48:F1} dB");
+ bool fin = true; foreach (var v in Render(8192)) if (!float.IsFinite(v)) { fin = false; break; }
+ qe.DeviceSetParam(qt, qd, Q + 10, 12f); foreach (var v in Render(8192)) if (!float.IsFinite(v)) { fin = false; break; }
+ Check(fin, "a resonant 48 dB/oct cut renders finite");
+ Band(2, 0, 2, 440, 0, 1);
+
+ // Output and auto gain (a +6 dB low shelf lifts the average; auto takes it back).
+ qe.DeviceSetParam(qt, qd, Output, -6); double outDb = Level() - dry;
+ qe.DeviceSetParam(qt, qd, Output, 0);
+ Check(Math.Abs(outDb + 6) < 0.2, $"Output −6 dB ({outDb:F2})");
+ Band(0, 1, 1, 1000, 6, 0.71f);
+ double shelf = Level() - dry;
+ qe.DeviceSetParam(qt, qd, AutoG, 1);
+ double comp = Level() - dry;
+ var ts = new float[16];
+ qe.DeviceScope(qt, qd, ts, 16);
+ Check(comp < shelf - 1.5 && ts[2] < -1.5 && ts[2] > -6, $"auto gain takes back the shelf's average lift ({shelf:+0.0} → {comp:+0.0} dB, auto {ts[2]:+0.0;-0.0})");
+ qe.DeviceSetParam(qt, qd, AutoG, 0);
+
+ // Spectra: pre and post peak at the sine; the shelf lifts post over pre.
+ qe.DeviceAction(qt, qd, 0, 0, 0);
+ Render(8192);
+ var sc = new float[16 + 2 * 96];
+ int sn = qe.DeviceScope(qt, qd, sc, sc.Length);
+ int pkPre = 0, pkPost = 0;
+ for (int b = 1; b < 96; b++) { if (sc[16 + b] > sc[16 + pkPre]) pkPre = b; if (sc[112 + b] > sc[112 + pkPost]) pkPost = b; }
+ double hzPre = 20 * Math.Pow(1000, (pkPre + 0.5) / 96), lift = sc[112 + pkPost] - sc[16 + pkPre];
+ Check(sn == sc.Length && sc[5] > 0.5f && hzPre > 380 && hzPre < 520 && pkPre == pkPost && lift > 3 && sc[1] > sc[0] + 3,
+ $"spectra: pre / post peak at the sine (~{hzPre:0} Hz), post {lift:+0.0} dB over pre; out peak {sc[1]:F1} over in {sc[0]:F1} dBFS");
+
+ // Texts.
+ qe.DeviceSetParam(qt, qd, ChanB + 0, 1);
+ string t0 = qe.DeviceText(qt, qd, 0), t1 = qe.DeviceText(qt, qd, 1), tg = qe.DeviceText(qt, qd, 2);
+ Check(t0.Contains("bands on") && t0.Contains("Low shelf") && t0.Contains("mid") && t1.Contains("auto gain") && tg.Contains("Channel") && tg.Contains("Slope"),
+ $"device texts: status '{t0[..Math.Min(70, t0.Length)]}…', live, guide");
+
+ // Clone + automation.
+ qe.DeviceSetParam(qt, qd, SlopeB + 7, 2); qe.DeviceSetParam(qt, qd, Scale, 75);
+ int qtD = qe.DuplicateTrack(qt); int qdD = qe.TrackDeviceCount(qtD) - 1;
+ Check(qtD > 0 && qe.DeviceGetParam(qtD, qdD, SlopeB + 7) == 2 && qe.DeviceGetParam(qtD, qdD, ChanB) == 1 && Math.Abs(qe.DeviceGetParam(qtD, qdD, Scale) - 75) < 1e-3,
+ "duplicate track clones EQ-8 slope, channel and scale");
+ int lane = qe.AddAutomationLane(qt, AutomationTarget.DeviceParam, qd, Scale);
+ Check(lane >= 0, "add EQ-8 Scale automation lane");
+ qe.SetAutomationPoints(qt, lane, new[] { new AutomationPoint(0.0, 0f), new AutomationPoint(2.0, 200f) });
+ { var ab = new float[4096 * 2]; qe.Seek(1.99); qe.Play(); qe.RenderOffline(ab, 4096); qe.StopTransport(); }
+ Check(qe.DeviceGetParam(qt, qd, Scale) > 150, $"automation drives EQ-8 Scale ({qe.DeviceGetParam(qt, qd, Scale):F0} %)");
+ qe.RemoveAutomationLane(qt, lane);
+ qe.DeviceSetParam(qt, qd, Scale, 100);
+
+ // MCP: edit a band and the globals, read it all back.
+ var tools = new Nota.Mcp.Tools.DeviceTools(qe, new Nota.SmokeTest.SyncDispatch(), new Nota.SmokeTest.NoRefresh());
+ var mb = tools.SetEq8Band(qt, qd, 5, on: true, type: "High cut", freqHz: 6000, q: 0.9, slope: 48, channel: "Side").Result;
+ Check(mb.On && mb.Type == "High cut" && Math.Abs(mb.FreqHz - 6000) < 1 && mb.SlopeDbPerOct == 48 && mb.Channel == "Side" && Math.Abs(mb.Q - 0.9) < 0.01,
+ $"MCP set_eq8_band edits a band ({mb.Type} {mb.FreqHz} Hz {mb.SlopeDbPerOct} dB/oct {mb.Channel})");
+ var mg = tools.SetEq8(qt, qd, scalePercent: 50, outputDb: -2, autoGain: true, analyzer: "Pre").Result;
+ Check(Math.Abs(mg.ScalePercent - 50) < 0.05 && Math.Abs(mg.OutputDb + 2) < 0.05 && mg.AutoGain && mg.Analyzer == "Pre"
+ && Math.Abs(mg.Bands[0].EffectiveGainDb - 3) < 0.05, $"MCP set_eq8 sets the globals (scale {mg.ScalePercent} %, effective B1 {mg.Bands[0].EffectiveGainDb} dB)");
+ Render(8192);
+ var mr = tools.ReadEq8(qt, qd).Result;
+ Check(mr.SpectrumValid && mr.InputSpectrum.Length == 24 && mr.OutputSpectrum.Length == 24 && mr.Summary.Length > 0 && mr.Live.Length > 0
+ && mr.SampleRate > 1000 && mr.OutputPeakDb > -60, $"MCP read_eq8 reports settings, levels and spectra (out {mr.OutputPeakDb} dBFS)");
+ bool threw = false;
+ try { tools.SetEq8Band(qt, qd, 1, channel: "Centre").GetAwaiter().GetResult(); } catch (ArgumentException) { threw = true; }
+ Check(threw, "MCP set_eq8_band rejects an unknown channel");
+
+ // An original-EQ-8 preset (the 40 band params only) keeps the appended params at their defaults.
+ var legacy = new PresetDocument { Type = "builtin-effect", BuiltinKind = 0, NamedParams = new Dictionary<string, float> { ["1 Type"] = 1f, ["1 Freq"] = 110f, ["1 Gain"] = 5f } };
+ PresetService.ApplyInPlace(legacy, qe, qt, qd);
+ Check(qe.DeviceGetParam(qt, qd, Scale) == 100 && qe.DeviceGetParam(qt, qd, AutoG) == 0 && qe.DeviceGetParam(qt, qd, Output) == 0
+ && qe.DeviceGetParam(qt, qd, SlopeB + 4) == 0 && qe.DeviceGetParam(qt, qd, ChanB + 4) == 0, "an original EQ-8 preset loads with scale 100 %, stereo, 12 dB/oct");
+
+ // Every factory preset names only real params and renders finite.
+ var cat = new FactoryPresetCatalog();
+ int nPresets = 0; bool namesOk = true, presetsOk = true;
+ var names = new HashSet<string>();
+ for (int p = 0; p < qe.DeviceParamCount(qt, qd); p++) names.Add(qe.DeviceParamName(qt, qd, p));
+ foreach (var info in cat.All())
+ {
+ if (info.IsInstrument || info.IsMidiEffect || info.BuiltinKind != 0) continue;
+ var doc = cat.Document(info.Id);
+ if (doc is null) continue;
+ nPresets++;
+ foreach (var k in doc.NamedParams!.Keys) if (!names.Contains(k)) { namesOk = false; Console.WriteLine($" unknown param '{k}' in {info.DisplayName}"); }
+ cat.ApplyInPlace(qe, info.Id, qt, qd);
+ var pb = Render(22050);
+ bool ok = true;
+ foreach (var v in pb) if (!float.IsFinite(v) || Math.Abs(v) > 4f) { ok = false; break; }
+ if (!ok) { presetsOk = false; Console.WriteLine($" preset {info.DisplayName} not finite / over"); }
+ }
+ Check(nPresets >= 25 && namesOk && presetsOk, $"{nPresets} EQ-8 factory presets, all params known, all render finite");
+ cat.ApplyInPlace(qe, "eq/Vocal Wide", qt, qd);
+ Check(qe.DeviceGetParam(qt, qd, ChanB + 1) == 1 && qe.DeviceGetParam(qt, qd, ChanB + 6) == 2 && qe.DeviceGetParam(qt, qd, SlopeB) == 1
+ && qe.DeviceGetParam(qt, qd, 5 * 5 + On) == 0 && qe.DeviceGetParam(qt, qd, AutoG) == 1, "the Vocal Wide preset sets Mid / Side bands, a 24 dB cut and auto gain");
}
// ============================ Nota Arp (MIDI FX) ===========================