Nota — a free DAW for macOS, Windows and Linux. No subscription, no account — just open it and make music.
C# audioaudio-unitavaloniacpp20cross-platformdawdigital-audio-workstationdspjucelinux-audiomcp-servermidimusicmusic-productionpiano-rollplugin-hostsequencersynthesizervstvst3
Redesign of Delay
Egor Khindikaynenf6c715d95745
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex a74b6ee9..92394e92 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -288,6 +288,28 @@ Entry categories: `Added`, `Changed`, `Fixed`, `Removed`.restart — and the choice is remembered.### Changed+- **Nota Delay is a full delay, not a time-and-feedback box.** The card moves onto the same+ frame as Nota Chamber — a LOOP column (feedback · spread), a centre panel with **Time**+ and **Loop · Wow** tabs over a live repeat window, a **Levels / Output** panel and a+ status strip — and the engine grows the parts that were missing:+ - **A tone stage inside the loop:** a low cut and a high cut you drag on the FILTER+ graph, allpass **Diffuse** that smears the repeats towards reverb, and **Tape mode**,+ which adds head loss and soft saturation and doubles the WOW depth.+ - **Changing the delay time is a choice.** *Fade on change* crossfades to the new tap, so+ dragging a time knob or picking another division stays clean; switched off, the read+ head glides to it and bends the pitch like a tape machine.+ - **An output stage:** a separate **dry level**, stereo **width** and **bass mono** on the+ repeats, **Wet only** for a return track, and **latency compensation** that pulls the+ read pointer back by the diffuser's group delay so each repeat still lands on the beat.+ - **Freeze** now truly holds — the loop bypasses its filters and saturation while it is+ on, so a held loop neither dulls nor grows — and **Clear loop** empties the buffer.+ **Tap tempo** sets the time by ear.+ - The repeat window draws the two channels on a dB scale, lights the repeat that is+ sounding, and reads the same in Ember Paper. **29 factory presets**, up from three.+ - The ten new parameters are appended, so older projects open unchanged and every one of+ them automates, MIDI-learns, saves in a preset and is reachable over MCP;+ `get_device_text` returns the delay's status line, and the new `device_action` tool+ clears the loop.- **Nota Aurora's unison dials now do what they say.** **Detune** is in cents (0–50) andno longer scales with the voice count, and **spread**, which the engine used to ignore,now pans the stack across the stereo field. Patches that use unison, including thediff --git a/FEATURES.md b/FEATURES.mdindex a163e167..ea9d4771 100644--- a/FEATURES.md+++ b/FEATURES.md@@ -327,8 +327,12 @@ and user presets, automation, persistence and cloning.- **Nota Reverb** (2) — Hall/Room/Plate/Chamber, RT60, HF damp, pre-delay, size,diffusion, low/high cut, width, tail modulation, Freeze; an interactive tail graph.- **Nota Delay** (3) — independent L/R times (ms or tempo-synced 1/16…1/2 with triplets- and dotted values), Link, feedback, spread, ping-pong, tape WOW modulation, Freeze; an- echo-tap graph.+ and dotted values), Link, feedback, spread, ping-pong; a tone stage in the loop (low cut,+ high cut, allpass diffusion, tape saturation) with tape WOW modulation; Freeze (loop held,+ input muted) and Clear loop; a time change either crossfades (Fade on change) or glides,+ bending the pitch tape-style; output stage with dry level, width, bass mono, wet only and+ latency compensation for the diffuser. Tabs: Time / Loop · Wow and Levels / Output, over a+ live repeat window that lights the repeat sounding now. Tap tempo. 29 factory presets.- **Nota Utility** (4) — gain, L/R balance, stereo width (mid/side 0–400%), channel mode(Stereo/Left/Right/Swap), bass mono, mute, phase invert; goniometer/vectorscope,correlation meter, meters, Gain match.diff --git a/src/managed/Nota.App/Controls/DelayTaps.cs b/src/managed/Nota.App/Controls/DelayTaps.csdeleted file mode 100644index a347f554..00000000--- a/src/managed/Nota.App/Controls/DelayTaps.cs+++ /dev/null@@ -1,72 +0,0 @@-// SPDX-License-Identifier: AGPL-3.0-only-// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.-//-// Delay taps visualization (mockup 2h): the echo train drawn per channel — L above the-// centre axis, R below — with height = level (feedback decay) and spacing = actual-// timing. Ping-pong and dotted offsets read at a glance. The body feeds it tap fractions-// (0..1 of the graph), feedback and a ruler; this control just draws.--using System;-using System.Globalization;-using Avalonia;-using Avalonia.Controls;-using Avalonia.Media;--namespace Nota.App;--internal sealed class DelayTaps : Control-{- private static readonly IBrush Sunken = NotaPalette.BgSunken;- private static readonly IBrush BorderDef = NotaPalette.BorderDefault;- private static readonly IBrush Accent = NotaPalette.Accent;- private static readonly IBrush AccentBright = NotaPalette.AccentBright;- private static readonly IBrush GridB = NotaGraph.Grid;- private static readonly IBrush Axis = NotaPalette.TextAxis;- private static readonly Typeface Face = NotaFonts.Mono;-- private double _fracL = 0.25, _fracR = 0.25;- private float _fb = 0.4f;- private bool _ping;- private string _label = "";- private string[] _ruler = { "0", "1 bar", "2 bars" };-- public void Set(double fracL, double fracR, float feedback, bool ping, string label, string[] ruler)- { _fracL = Math.Max(0.02, fracL); _fracR = Math.Max(0.02, fracR); _fb = feedback; _ping = ping; _label = label; _ruler = ruler; InvalidateVisual(); }-- private void Txt(DrawingContext c, string t, double x, double y, IBrush b, bool center = false)- {- var ft = new FormattedText(t, CultureInfo.InvariantCulture, FlowDirection.LeftToRight, Face, 8, b);- c.DrawText(ft, new Point(center ? x - ft.Width / 2 : x, y));- }-- public override void Render(DrawingContext ctx)- {- double w = Bounds.Width, h = Bounds.Height; if (w <= 0) return;- NotaGraph.Window(ctx, new Rect(0, 0, w, h));- double x0 = 8, x1 = w - 8, mid = h * 0.5, half = (h - 30) * 0.5;-- // Ruler ticks (0 / mid / end) + centre axis.- for (int i = 0; i <= 2; i++) { double x = x0 + (x1 - x0) * i / 2.0; ctx.DrawLine(new Pen(GridB, 1), new Point(x, 14), new Point(x, h - 12)); Txt(ctx, _ruler[Math.Min(i, _ruler.Length - 1)], x, h - 10, Axis, i > 0); }- ctx.DrawLine(new Pen(GridB, 1.2), new Point(x0, mid), new Point(x1, mid));- Txt(ctx, _label, x0 + 2, 3, Axis);- Txt(ctx, "L", x0 + 2, mid - half - 2, Accent);- Txt(ctx, "R", x0 + 2, mid + half - 6, Accent);-- void Train(double frac, bool up)- {- for (int n = 1; n <= 16; n++)- {- double x = x0 + n * frac * (x1 - x0);- if (x > x1) break;- double lvl = Math.Pow(Math.Max(0.05f, _fb), n - 1);- double len = Math.Max(2, lvl * half);- var top = up ? new Point(x, mid - len) : new Point(x, mid + len);- bool bright = _ping && ((n % 2 == 1) == up); // ping-pong: alternate emphasis- ctx.DrawLine(new Pen(bright ? AccentBright : Accent, 2), new Point(x, mid), top);- ctx.DrawEllipse(bright ? AccentBright : Accent, null, top, 2, 2);- }- }- Train(_fracL, true);- Train(_fracR, false);- }-}diff --git a/src/managed/Nota.App/Controls/DelayViews.cs b/src/managed/Nota.App/Controls/DelayViews.csnew file mode 100644index 00000000..e996aefa--- /dev/null+++ b/src/managed/Nota.App/Controls/DelayViews.cs@@ -0,0 +1,294 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.+//+// The custom-drawn views of the Nota Delay card: the repeat window (the echo train per+// channel, L in brass above the axis and R in rose below, the sounding repeat lit), the+// LOOP column's vertical faders, and the feedback tone graph (low cut / high cut, dragged+// by its handles). They draw what the card hands them and own no engine state.++using System;+using System.Globalization;+using Avalonia;+using Avalonia.Controls;+using Avalonia.Input;+using Avalonia.Media;++namespace Nota.App;++// The repeat window: the echo train per channel — L above the centre axis, R below — with+// height = level (feedback decay) and spacing = actual timing. Ping-pong and dotted offsets+// read at a glance. Frozen, every repeat stands at full height and the window is brass-lined.+// The repeat that is sounding now is lit (colour only — nothing moves).+internal sealed class DelayTaps : Control+{+ private const int MaxTaps = 24;++ private double _fracL = 0.25, _fracR = 0.25;+ private float _fb = 0.4f;+ private bool _ping, _freeze;+ private string _title = "", _sub = "", _ruler = "", _window = "";+ private int _litL = -1, _litR = -1;++ public DelayTaps() => ClipToBounds = true;++ /// <summary>Feed the window: tap spacing as a fraction of its width per channel, the+ /// feedback, the ping-pong and freeze states, and the four corner labels.</summary>+ public void Set(double fracL, double fracR, float feedback, bool ping, bool freeze,+ string title, string sub, string ruler, string window)+ {+ _fracL = Math.Clamp(fracL, 0.02, 1.0);+ _fracR = Math.Clamp(fracR, 0.02, 1.0);+ _fb = feedback; _ping = ping; _freeze = freeze;+ _title = title; _sub = sub; _ruler = ruler; _window = window;+ InvalidateVisual();+ }++ /// <summary>Which repeat is sounding now per channel (−1 = none): the card counts them+ /// off the transport clock, this only lights them.</summary>+ public void SetLit(int litL, int litR)+ {+ if (litL == _litL && litR == _litR) return;+ _litL = litL; _litR = litR;+ InvalidateVisual();+ }++ private static FormattedText Text(string t, IBrush ink, double size = 8)+ => new(t, CultureInfo.InvariantCulture, FlowDirection.LeftToRight, NotaFonts.Mono, size, ink);++ public override void Render(DrawingContext ctx)+ {+ double w = Bounds.Width, h = Bounds.Height;+ if (w < 8 || h < 8) return;+ var rect = new Rect(0, 0, w, h);+ NotaGraph.Window(ctx, rect);+ if (_freeze)+ ctx.DrawRectangle(null, new Pen(NotaPalette.Accent, 1), new RoundedRect(rect.Deflate(0.5), NotaGraph.Radius));++ double x0 = 8, x1 = w - 8, mid = h * 0.5, half = (h - 34) * 0.5;+ if (x1 <= x0 || half <= 2) return;++ // Quarter grid + the centre axis the two channels hang from.+ for (int i = 1; i < 4; i++)+ {+ double x = x0 + (x1 - x0) * i / 4.0;+ ctx.DrawLine(NotaGraph.GridPen, new Point(x, 5), new Point(x, h - 5));+ }+ ctx.DrawLine(new Pen(NotaPalette.GridBeat, 1.2), new Point(x0, mid), new Point(x1, mid));++ void Train(double frac, bool up, int lit)+ {+ var ink = up ? NotaPalette.Accent : NotaPalette.Rose;+ var litInk = up ? NotaPalette.AccentBright : NotaPalette.RoseBright;+ for (int n = 1; n <= MaxTaps; n++)+ {+ double x = x0 + n * frac * (x1 - x0);+ if (x > x1) break;+ // Height is the repeat's level on a −60 dB scale, the way the ear hears it+ // fade — a linear scale buries everything past the third repeat.+ double lvl = _freeze ? 1.0 : Math.Pow(Math.Clamp(_fb, 0.02f, 0.999f), n - 1);+ double len = Math.Max(2, Math.Clamp((20 * Math.Log10(Math.Max(lvl, 1e-9)) + 60) / 60, 0, 1) * half);+ var head = new Point(x, up ? mid - len : mid + len);+ // Ping-pong bounces the repeat across the channels, so every other one leads.+ bool lead = _ping && ((n % 2 == 1) == up);+ bool sounding = n - 1 == lit;+ var pen = sounding ? litInk : lead ? (up ? NotaPalette.AccentBright : NotaPalette.RoseBright) : ink;+ ctx.DrawLine(new Pen(pen, sounding ? 2.4 : 2), new Point(x, mid), head);+ ctx.DrawEllipse(pen, null, head, sounding ? 3 : 2.4, sounding ? 3 : 2.4);+ }+ }+ Train(_fracL, true, _litL);+ Train(_fracR, false, _litR);++ if (_title.Length > 0) ctx.DrawText(Text(_title, _freeze ? NotaPalette.AccentBright : NotaGraph.AxisInk), new Point(x0 - 2, 4));+ if (_sub.Length > 0) { var ft = Text(_sub, NotaGraph.AxisInk); ctx.DrawText(ft, new Point(x0 - 2, h - 4 - ft.Height)); }+ if (_ruler.Length > 0) { var ft = Text(_ruler, NotaGraph.AxisInk); ctx.DrawText(ft, new Point(x1 + 2 - ft.Width, 4)); }+ if (_window.Length > 0) { var ft = Text(_window, NotaGraph.AxisInk); ctx.DrawText(ft, new Point(x1 + 2 - ft.Width, h - 4 - ft.Height)); }+ }+}++// A vertical fader in the LOOP column: a groove, a wash fill in the parameter's own chroma+// and a bright handle. Drag up to raise, double-click restores the default.+internal sealed class DelayFader : Control+{+ private double _v;+ private bool _drag;++ /// <summary>The fill chroma — brass for feedback, rose for spread.</summary>+ public IBrush Ink { get; init; } = NotaPalette.Accent;+ public IBrush Handle { get; init; } = NotaPalette.AccentBright;+ public double Default { get; set; } = double.NaN;+ public bool Dragging => _drag;++ public event Action<double>? Changed;+ public event Action? GestureBegin;+ public event Action? GestureEnd;++ public DelayFader() { Width = 16; Cursor = new Cursor(StandardCursorType.SizeNorthSouth); }++ public void Set(double v)+ {+ if (_drag) return;+ double n = Math.Clamp(v, 0, 1);+ if (Math.Abs(n - _v) < 1e-4) return;+ _v = n; InvalidateVisual();+ }++ private void Apply(PointerEventArgs e)+ {+ double h = Bounds.Height; if (h <= 2) return;+ _v = Math.Clamp(1 - e.GetPosition(this).Y / h, 0, 1);+ Changed?.Invoke(_v); InvalidateVisual();+ }+ protected override void OnPointerPressed(PointerPressedEventArgs e)+ {+ base.OnPointerPressed(e);+ if (!e.GetCurrentPoint(this).Properties.IsLeftButtonPressed) return;+ if (e.ClickCount == 2 && !double.IsNaN(Default))+ {+ GestureBegin?.Invoke(); _v = Default; Changed?.Invoke(_v); GestureEnd?.Invoke();+ InvalidateVisual(); e.Handled = true; return;+ }+ _drag = true; GestureBegin?.Invoke(); e.Pointer.Capture(this); Apply(e); e.Handled = true;+ }+ protected override void OnPointerMoved(PointerEventArgs e) { base.OnPointerMoved(e); if (_drag) Apply(e); }+ protected override void OnPointerReleased(PointerReleasedEventArgs e)+ {+ base.OnPointerReleased(e);+ if (!_drag) return;+ _drag = false; e.Pointer.Capture(null); GestureEnd?.Invoke();+ }++ public override void Render(DrawingContext ctx)+ {+ double w = Bounds.Width, h = Bounds.Height;+ if (w < 2 || h < 4) return;+ var rect = new Rect(0.5, 0.5, w - 1, h - 1);+ double r = Math.Min(8, w / 2);+ ctx.DrawRectangle(NotaPalette.BgSunken, null, rect, r, r);+ double y = (1 - _v) * h;+ using (ctx.PushClip(new RoundedRect(rect, r)))+ ctx.FillRectangle(NotaPalette.Wash((SolidColorBrush)Ink, 0x48), new Rect(0, y, w, h - y));+ ctx.DrawRectangle(null, new Pen(NotaPalette.BorderDefault, 1), rect, r, r);+ double hy = Math.Clamp(y, 1.5, h - 2.5);+ ctx.DrawRectangle(Handle, null, new Rect(1.5, hy - 1, w - 3, 2), 1, 1);+ }+}++// The feedback tone: the band the repeats live in, between the low cut and the high cut.+// Drag either handle horizontally to move its corner; double-click opens the band wide again.+internal sealed class DelayFilterCurve : Control+{+ private const double FMin = 20, FMax = 20000;++ private double _low, _high = 1;+ private double _lowHz = 20, _highHz = 20000;+ private int _drag; // 0 none, 1 low cut, 2 high cut+ private int _hover;++ public event Action<int, double>? Changed; // handle (0 low / 1 high), new normalised value+ public event Action<int>? GestureBegin;+ public event Action<int>? GestureEnd;+ public event Action<int>? Reset;++ public bool Dragging => _drag != 0;++ public DelayFilterCurve()+ {+ ClipToBounds = true;+ Cursor = new Cursor(StandardCursorType.SizeWestEast);+ }++ public void Set(double lowNorm, double highNorm, double lowHz, double highHz)+ {+ _low = Math.Clamp(lowNorm, 0, 1); _high = Math.Clamp(highNorm, 0, 1);+ _lowHz = lowHz; _highHz = highHz;+ InvalidateVisual();+ }++ private static double XOf(double hz, double w) => Math.Log(Math.Clamp(hz, FMin, FMax) / FMin) / Math.Log(FMax / FMin) * w;++ private int NearestHandle(double x, double w)+ => Math.Abs(x - XOf(_lowHz, w)) <= Math.Abs(x - XOf(_highHz, w)) ? 1 : 2;++ private void Apply(PointerEventArgs e)+ {+ double w = Bounds.Width; if (w <= 4 || _drag == 0) return;+ double x = Math.Clamp(e.GetPosition(this).X, 0, w);+ double hz = FMin * Math.Pow(FMax / FMin, x / w);+ // Each handle spans its own parameter range: 20 Hz … 2 kHz, and 200 Hz … 20 kHz.+ double norm = _drag == 1+ ? Math.Log(Math.Clamp(hz, 20, 2000) / 20) / Math.Log(2000.0 / 20)+ : Math.Log(Math.Clamp(hz, 200, 20000) / 200) / Math.Log(20000.0 / 200);+ Changed?.Invoke(_drag - 1, Math.Clamp(norm, 0, 1));+ }++ protected override void OnPointerPressed(PointerPressedEventArgs e)+ {+ base.OnPointerPressed(e);+ if (!e.GetCurrentPoint(this).Properties.IsLeftButtonPressed) return;+ int h = NearestHandle(e.GetPosition(this).X, Bounds.Width);+ if (e.ClickCount == 2) { Reset?.Invoke(h - 1); e.Handled = true; return; }+ _drag = h; GestureBegin?.Invoke(h - 1); e.Pointer.Capture(this); Apply(e); e.Handled = true;+ }+ protected override void OnPointerMoved(PointerEventArgs e)+ {+ base.OnPointerMoved(e);+ if (_drag != 0) { Apply(e); return; }+ int h = NearestHandle(e.GetPosition(this).X, Bounds.Width);+ if (h != _hover) { _hover = h; InvalidateVisual(); }+ }+ protected override void OnPointerExited(PointerEventArgs e)+ { base.OnPointerExited(e); if (_hover != 0) { _hover = 0; InvalidateVisual(); } }+ protected override void OnPointerReleased(PointerReleasedEventArgs e)+ {+ base.OnPointerReleased(e);+ if (_drag == 0) return;+ GestureEnd?.Invoke(_drag - 1); _drag = 0; e.Pointer.Capture(null);+ }++ public override void Render(DrawingContext ctx)+ {+ double w = Bounds.Width, h = Bounds.Height;+ if (w < 12 || h < 12) return;+ var rect = new Rect(0, 0, w, h);+ NotaGraph.Window(ctx, rect);++ double top = 12, bottom = h - 5, span = bottom - top;+ if (span < 4) return;++ // One-pole high-pass × one-pole low-pass magnitude, −24 dB floor.+ var geo = new StreamGeometry();+ using (var g = geo.Open())+ {+ bool first = true;+ for (int i = 0; i <= 56; i++)+ {+ double x = w * i / 56.0;+ double f = FMin * Math.Pow(FMax / FMin, i / 56.0);+ double rl = f / _lowHz, rh = f / _highHz;+ double mag = rl / Math.Sqrt(1 + rl * rl) * (1 / Math.Sqrt(1 + rh * rh));+ double db = 20 * Math.Log10(Math.Max(mag, 1e-4));+ double y = top + span * Math.Clamp(-db / 24.0, 0, 1);+ if (first) { g.BeginFigure(new Point(x, y), false); first = false; }+ else g.LineTo(new Point(x, y));+ }+ }+ ctx.DrawGeometry(null, NotaGraph.PrimaryPen, geo);++ // Corner handles on the two cut frequencies.+ foreach (var (hz, idx) in new[] { (_lowHz, 1), (_highHz, 2) })+ {+ double x = Math.Clamp(XOf(hz, w), 2, w - 2);+ bool hot = _drag == idx || (_drag == 0 && _hover == idx);+ // Stop the stem above the corner readout so the two never cross.+ ctx.DrawLine(new Pen(hot ? NotaPalette.AccentBright : NotaPalette.BorderStrong, 1),+ new Point(x, top - 4), new Point(x, bottom - 9));+ ctx.DrawEllipse(hot ? NotaPalette.AccentBright : NotaPalette.TextSecondary, null, new Point(x, top + span * 0.5), 2.8, 2.8);+ }++ NotaGraph.Title(ctx, rect, "Filter");+ NotaGraph.Axis(ctx, rect, NotaGraph.Corner.BottomRight, NotaNum.F($"{Hz(_lowHz)} – {Hz(_highHz)}"));+ }++ private static string Hz(double hz) => hz >= 1000 ? NotaNum.F($"{hz / 1000:0.#}k") : NotaNum.F($"{hz:0}");+}diff --git a/src/managed/Nota.App/DeviceCards/Bodies/DelayDeviceBody.cs b/src/managed/Nota.App/DeviceCards/Bodies/DelayDeviceBody.csindex 14f3f199..2f999af1 100644--- a/src/managed/Nota.App/DeviceCards/Bodies/DelayDeviceBody.cs+++ b/src/managed/Nota.App/DeviceCards/Bodies/DelayDeviceBody.cs@@ -1,14 +1,20 @@// SPDX-License-Identifier: AGPL-3.0-only// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.//-// Detail · Devices — built-in Delay body (kind 3), mockup 2h on the shared shell-// (700×260): a LIVE strip (Feedback · Spread · Freeze · Taps readout · Mix) over the-// per-channel TAPS graph (flex) | TIME panel (Sync/ms · division buttons · Link · Ping ·-// WOW) | OUTPUT rail (dry/wet · out). Divisions are a row of buttons, not a dropdown.+// Detail · Devices — built-in Delay body (device kind 3), a build of the "Nota Delay"+// mockup (700 × 260) on the Chamber frame: an always-visible LOOP column (Feedback ·+// Spread), a centre tabbed panel (Time / Loop · Wow) over the live repeat window, a right+// tabbed panel (Levels / Output) and a status strip. The repeat window and the feedback+// filter are controls, not decoration. Every control is a device param, so automation /+// MIDI learn / presets / A-B / persistence come for free; Tap tempo and Clear loop are the+// two actions that are not (the first writes Time L/R, the second wipes the loop).+// 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;@@ -19,136 +25,572 @@ namespace Nota.App;internal sealed class DelayDeviceBody : IDeviceBody{+ // ── Parameter indices (must match Delay.h) ───────────────────────────────private const int SyncMode = 0, TimeL = 1, TimeR = 2, DivL = 3, DivR = 4, LinkLR = 5, Feedback = 6,- Spread = 7, PingPong = 8, WowRate = 9, WowDepth = 10, Freeze = 11, DryWet = 12, Output = 13;+ Spread = 7, PingPong = 8, WowRate = 9, WowDepth = 10, Freeze = 11, DryWet = 12, Output = 13,+ DryLevel = 14, Diffuse = 15, LowCut = 16, HighCut = 17, TapeMode = 18, FadeChange = 19,+ WidthP = 20, BassMono = 21, WetOnly = 22, LatencyComp = 23;+ // Scope telemetry layout (Delay::S_*).+ private const int S_WetPk = 0, S_OutL = 1, S_OutR = 2, S_Cpu = 3, S_SampleRate = 4, S_Bpm = 5,+ S_DiffuseSmp = 6, S_Frozen = 7, S_MsL = 8, S_MsR = 9, S_Latency = 10, kScope = 11;+ private const int A_ClearLoop = 0;+private static readonly string[] DivNames = { "1/16", "1/8T", "1/8", "1/8.", "1/4T", "1/4", "1/4.", "1/2" };private static readonly double[] DivBeats = { 0.25, 1.0 / 3, 0.5, 0.75, 2.0 / 3, 1.0, 1.5, 2.0 };+ private const double SyncWindowBeats = 8.0; // the repeat window spans two 4/4 bars+ private static readonly double[] WindowRanges = { 0.25, 0.4, 0.6, 0.8, 1.2, 1.6, 2.4, 3.2, 4.8, 6.4, 9.6 };public double Width => 700;-- public string? Subtitle => "DELAY"; // the processing type, shown as the header badgepublic bool FullBleed => true;+ public string? Subtitle => "DELAY";public Control Build(DeviceCardContext ctx, int index){- var engine = ctx.Engine; int track = ctx.TrackId, di = index;+ var engine = ctx.Engine;+ int track = ctx.TrackId, di = index;float P(int p) => engine.DeviceGetParam(track, di, p);- void SetP(int p, float v) => engine.DeviceSetParam(track, di, p, v);- static double Exp(double v, double lo, double hi) => lo * Math.Pow(hi / lo, Math.Clamp(v, 0, 1));+ void Begin(int p) => engine.BeginAutomationWrite(track, AutomationTarget.DeviceParam, di, p, "");+ void End(int p) => engine.EndAutomationWrite(track, AutomationTarget.DeviceParam, di, p, "");+ void Raw(int p, float v) => engine.DeviceSetParam(track, di, p, Math.Clamp(v, 0f, 1f));+ // A discrete edit (a click) is one automation gesture, so it records while the transport does.+ void SetP(int p, float v) { Begin(p); Raw(p, v); End(p); }+ void Reset(int p) { Begin(p); Raw(p, engine.DeviceParamDefault(track, di, p)); End(p); }+ bool On(int p) => P(p) >= 0.5f;int Sel(int p, int n) => Math.Clamp((int)Math.Round(P(p) * (n - 1)), 0, n - 1);- var taps = new DelayTaps { VerticalAlignment = VerticalAlignment.Stretch };- var tapsLbl = new TextBlock { FontSize = 9, Foreground = TextPrimary, VerticalAlignment = VerticalAlignment.Center };- tapsLbl.BindResource(TextBlock.FontFamilyProperty, "Font.Mono");- void SyncGraph()+ var readouts = new List<Action>();+ var scope = new float[kScope];+ int scN = 0;+ double Sc(int i) => scN > i ? scope[i] : 0;++ // ---- formatters -------------------------------------------------------------+ static double Exp(double v, double lo, double hi) => lo * Math.Pow(hi / lo, Math.Clamp(v, 0, 1));+ static string Pct(double v) => NotaNum.F($"{v * 100:0} %");+ static string Ms(double ms) => ms >= 100 ? NotaNum.F($"{ms:0} ms") : NotaNum.F($"{ms:0.0} ms");+ static string Hz(double hz) => hz >= 1000 ? NotaNum.F($"{hz / 1000:0.0} k") : NotaNum.F($"{hz:0} Hz");+ static string ShortDb(double db) => db <= -99 ? "−∞" : NotaNum.F($"{db:0.0;−0.0;0.0}");+ static string Db(double db) => db <= -99 ? "−∞" : NotaNum.F($"{db:+0.0;−0.0;0.0} dB");+ static string Secs(double s) => s >= 1 ? NotaNum.F($"{s:0.0} s") : NotaNum.F($"{s * 1000:0} ms");+ static double OutDb(double v) => v <= 0.0005 ? -100 : 20 * Math.Log10(v * 2);+ static double DryDb(double v) { double g = 2 * v * v; return g <= 1e-5 ? -100 : 20 * Math.Log10(g); }+ static double LowHz(double v) => Exp(v, 20, 2000);+ static double HighHz(double v) => Exp(v, 200, 20000);+ string LowCutF(double v) => v <= 0.001 ? "off" : Hz(LowHz(v));+ string HighCutF(double v) => v >= 0.999 ? "off" : Hz(HighHz(v));+ static string Window(double s) => s >= 1 ? NotaNum.F($"{s:0.#} s") : NotaNum.F($"{s * 1000:0} ms");+ static double NiceWindow(double seconds){- bool sync = P(SyncMode) > 0.5f, link = P(LinkLR) > 0.5f;- int dL = Sel(DivL, 8), dR = link ? dL : Sel(DivR, 8);- double fracL, fracR; string label; string[] ruler;- if (sync) { fracL = DivBeats[dL] / 8; fracR = DivBeats[dR] / 8; label = $"L {DivNames[dL]} · R {DivNames[dR]}"; ruler = new[] { "0", "1 bar", "2 bars" }; }- else { double msL = P(TimeL) * 2000, msR = link ? msL : P(TimeR) * 2000; fracL = msL / 2000; fracR = msR / 2000; label = $"L {msL:0} · R {msR:0}\u2009ms"; ruler = new[] { "0", "1\u2009s", "2\u2009s" }; }- taps.Set(fracL, fracR, P(Feedback), P(PingPong) > 0.5f, label, ruler);- tapsLbl.Text = label;+ foreach (double r in WindowRanges) if (r >= seconds) return r;+ return WindowRanges[^1];}- ctx.AddDeviceRefresher(SyncGraph);- string Pct(double v) => $"{v * 100:0}\u2009%";- string SpreadF(double v) => $"{v * 50:0}\u2009ms";- string RateF(double v) => $"{Exp(v, 0.05, 8):0.00}\u2009Hz";- string DbF(double v) => v <= 0.001 ? "−∞" : $"{20 * Math.Log10(v * 2):+0.0;−0.0;0.0}";- string MsF(double v) => $"{v * 2000:0}\u2009ms";+ // The engine's tempo only reaches the scope once audio has rolled, so fall back to 120.+ double Bpm() => Sc(S_Bpm) > 1 ? Sc(S_Bpm) : 120;+ double BeatMs() => 60000.0 / Bpm();+ // The set times, as the knobs read them. The engine's own figures (smoothed, and+ // shortened by the diffuser compensation) reach the card through S_MsL / S_MsR.+ double MsL() => On(SyncMode) ? DivBeats[Sel(DivL, 8)] * BeatMs() : P(TimeL) * 2000;+ double MsR() => On(LinkLR) ? MsL() : On(SyncMode) ? DivBeats[Sel(DivR, 8)] * BeatMs() : P(TimeR) * 2000;+ double SpreadMs() => P(Spread) * 50;- Control Cell(string name, int p, Func<double, string> fmt, IBrush? arc = null, double size = 34)+ // ---- small builders ---------------------------------------------------------+ static TextBlock Caps(string t, IBrush? c = null, double fs = 7) => new()+ { Text = t, FontSize = fs, FontWeight = FontWeight.Bold, Foreground = c ?? TextTertiary, LetterSpacing = 0.8, VerticalAlignment = VerticalAlignment.Center };+ static TextBlock Mono(string t, double fs, IBrush c)+ { var tb = new TextBlock { Text = t, FontSize = fs, Foreground = c, VerticalAlignment = VerticalAlignment.Center }; tb.BindResource(TextBlock.FontFamilyProperty, "Font.Mono"); return tb; }+ static StackPanel Row(double sp, params Control[] cs)+ { var s = new StackPanel { Orientation = Orientation.Horizontal, Spacing = sp, VerticalAlignment = VerticalAlignment.Center }; foreach (var c in cs) s.Children.Add(c); return s; }+ static T Docked<T>(T c, Dock d) where T : Control { DockPanel.SetDock(c, d); return c; }+ static T Col<T>(T c, int col) where T : Control { Grid.SetColumn(c, col); return c; }+ static T GRow<T>(T c, int row) where T : Control { Grid.SetRow(c, row); return c; }+ static Border Divider(Control child, double top = 5) => new()+ { BorderBrush = NotaPalette.GraphBorder, BorderThickness = new Thickness(0, 1, 0, 0), Padding = new Thickness(0, top, 0, 0), Child = child };++ // Gauge knob bound to a device param (automation gesture + MIDI learn + live follow).+ Control K(int p, string name, Func<double, string> fmt, double size = 34, double cellW = 50, IBrush? arc = null, Action? onChange = null){- var val = new TextBlock { Text = fmt(P(p)), FontSize = 8, Foreground = TextPrimary };- val.BindResource(TextBlock.FontFamilyProperty, "Font.Mono");+ var val = Mono(fmt(P(p)), 7, TextPrimary);var knob = new Knob(P(p), 1.0) { Accent = true, ArcColor = arc, Default = engine.DeviceParamDefault(track, di, p), Width = size, Height = size };- knob.ValueChanged += v => { SetP(p, (float)v); val.Text = fmt(v); SyncGraph(); };- knob.GestureBegin += () => engine.BeginAutomationWrite(track, AutomationTarget.DeviceParam, di, p, "");- knob.GestureEnd += () => engine.EndAutomationWrite(track, AutomationTarget.DeviceParam, di, p, "");- MidiLearn.Bind(knob, MidiTarget.DeviceParam(track, di, p), name);- ctx.AddDeviceRefresher(() => { if (!knob.Dragging) { float c = P(p); if (Math.Abs(c - knob.Value) > 1e-3) { knob.Value = c; val.Text = fmt(c); } } });- return KnobCell(name, knob, val, size + 16);- }- Control Row(params Control[] cs) { var sp = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 2, HorizontalAlignment = HorizontalAlignment.Center }; foreach (var c in cs) sp.Children.Add(c); return sp; }-- Control Slider(int p, string name, Func<double, string> fmt, double w)- {- var row = DeviceCardKit.SliderRow(name, () => P(p), n => { SetP(p, (float)n); SyncGraph(); }, () => fmt(P(p)), out var sync,- begin: () => engine.BeginAutomationWrite(track, AutomationTarget.DeviceParam, di, p, ""),- end: () => engine.EndAutomationWrite(track, AutomationTarget.DeviceParam, di, p, ""),- trackWidth: w, valueWidth: 44);- ctx.AddDeviceRefresher(sync);- MidiLearn.Bind(row, MidiTarget.DeviceParam(track, di, p), name);- return row;+ knob.ValueChanged += v => { Raw(p, (float)v); val.Text = fmt(v); onChange?.Invoke(); };+ knob.GestureBegin += () => Begin(p);+ knob.GestureEnd += () => End(p);+ MidiLearn.Bind(knob, MidiTarget.DeviceParam(track, di, p), engine.DeviceParamName(track, di, p));+ readouts.Add(() => { if (knob.Dragging) return; float c = P(p); if (Math.Abs(c - knob.Value) > 1e-4) knob.Value = c; val.Text = fmt(c); });+ return KnobCell(name, knob, val, cellW);}- Control Toggle(int p, string label)++ // On/off switch bound to a param (> 0.5 = on).+ Control Toggle(int p, string label, Func<bool>? dim = null){- var b = new Border { CornerRadius = NotaRadius.Control, BorderThickness = new Thickness(1), Padding = new Thickness(8, 2), Cursor = new Cursor(StandardCursorType.Hand), VerticalAlignment = VerticalAlignment.Center, Child = new TextBlock { Text = label, FontSize = 9, FontWeight = FontWeight.SemiBold } };- void Hi() { bool on = P(p) > 0.5f; b.Background = on ? NotaPalette.AccentSubtle : Sunken; b.BorderBrush = on ? NotaPalette.BorderBrass : BorderDef; ((TextBlock)b.Child!).Foreground = on ? NotaPalette.AccentHover : TextTertiary; }- b.PointerPressed += (_, _) => { SetP(p, P(p) > 0.5f ? 0f : 1f); Hi(); SyncGraph(); };- ctx.AddDeviceRefresher(Hi); Hi();- MidiLearn.Bind(b, MidiTarget.DeviceParam(track, di, p), engine.DeviceParamName(track, di, p));- return b;+ var wrap = Switch(label, () => On(p), () => SetP(p, On(p) ? 0f : 1f), out var sync, dim);+ readouts.Add(sync);+ MidiLearn.Bind(wrap, MidiTarget.DeviceParam(track, di, p), engine.DeviceParamName(track, di, p));+ return wrap;}- // Division chip row over a param (8 steps).- Control DivChips(int p)++ // Segmented chips over a discrete param (n options spread over 0..1).+ Control Seg(int p, string[] names, bool fill = false, Action? onPick = null){- // Eight divisions: past the almanac's four-choice limit for segments — an accepted exception, see DESIGN.md § Accepted departures.- var seg = DeviceCardKit.Segments(DivNames, () => Sel(p, 8), i => { SetP(p, i / 7f); SyncGraph(); }, out var sync);- ctx.AddDeviceRefresher(sync);+ int n = names.Length;+ var seg = DeviceCardKit.Segments(names, () => Sel(p, n), iv => { SetP(p, n > 1 ? iv / (float)(n - 1) : 0f); onPick?.Invoke(); }, out var sync, fill: fill, padX: fill ? 2 : 6);+ readouts.Add(sync);MidiLearn.Bind(seg, MidiTarget.DeviceParam(track, di, p), engine.DeviceParamName(track, di, p));return seg;}- Control Seg(int p, string[] opts)++ // A latching chip over a toggle param (Link · Ping · Fade · Freeze).+ Border Latch(int p, string text, string tip){- int n = opts.Length;- var seg = DeviceCardKit.Segments(opts, () => Sel(p, n), iv => { SetP(p, n > 1 ? iv / (float)(n - 1) : 0f); SyncGraph(); RebuildTime(); }, out var sync);- ctx.AddDeviceRefresher(sync);- MidiLearn.Bind(seg, MidiTarget.DeviceParam(track, di, p), engine.DeviceParamName(track, di, p));- return seg;+ var tb = new TextBlock { Text = text, FontSize = 9, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center };+ var b = new Border { Height = 18, Padding = new Thickness(8, 0), CornerRadius = NotaRadius.Control, BorderThickness = new Thickness(1), Cursor = new Cursor(StandardCursorType.Hand), VerticalAlignment = VerticalAlignment.Center, Child = tb };+ void Hi()+ {+ bool on = On(p);+ b.Background = on ? NotaPalette.AccentSubtle : Sunken;+ b.BorderBrush = on ? NotaPalette.BorderBrass : BorderDef;+ tb.Foreground = on ? NotaPalette.AccentHover : TextTertiary;+ tb.FontWeight = on ? FontWeight.SemiBold : FontWeight.Normal;+ }+ b.PointerPressed += (_, e) => { if (!e.GetCurrentPoint(b).Properties.IsLeftButtonPressed) return; SetP(p, On(p) ? 0f : 1f); Hi(); e.Handled = true; };+ ToolTip.SetTip(b, tip);+ MidiLearn.Bind(b, MidiTarget.DeviceParam(track, di, p), engine.DeviceParamName(track, di, p));+ readouts.Add(Hi); Hi();+ return b;+ }++ // A small text button (an action, not a parameter).+ Border Btn(string text, Action click, string? tip = null)+ {+ var tb = new TextBlock { Text = text, FontSize = 8, Foreground = TextPrimary, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center };+ var b = new Border { Height = 16, Padding = new Thickness(6, 0), CornerRadius = NotaRadius.Badge, Background = Raised, Cursor = new Cursor(StandardCursorType.Hand), VerticalAlignment = VerticalAlignment.Center, Child = tb };+ b.PointerPressed += (_, e) => { if (!e.GetCurrentPoint(b).Properties.IsLeftButtonPressed) return; click(); e.Handled = true; };+ if (tip != null) ToolTip.SetTip(b, tip);+ return b;+ }++ // Horizontal bar slider over a param.+ Control Bar(int p, Func<double, string> fmt, Func<bool>? dim = null, double valW = 30)+ {+ var row = DeviceCardKit.SliderRow("", () => P(p), v => Raw(p, (float)v), () => fmt(P(p)), out var sync,+ begin: () => Begin(p), end: () => End(p), reset: () => Reset(p), dim: dim, valueWidth: valW);+ readouts.Add(sync);+ MidiLearn.Bind(row, MidiTarget.DeviceParam(track, di, p), engine.DeviceParamName(track, di, p));+ return row;+ }+ Control SliderRow(string label, int p, Func<double, string> fmt, double labW = 52, Func<bool>? dim = null, double valW = 30)+ {+ var g = new Grid { ColumnDefinitions = new ColumnDefinitions(NotaNum.F($"{labW},*")), VerticalAlignment = VerticalAlignment.Center };+ g.Children.Add(Caps(label));+ g.Children.Add(Col(Bar(p, fmt, dim, valW), 1));+ return g;+ }++ // ======================================================================+ // The repeat window — shared by both centre tabs+ // ======================================================================+ // One view per centre tab — a control has one parent, and both tabs show the window.+ var tapViews = new List<DelayTaps>();+ double windowSec = 0;+ var start = DateTime.UtcNow;+ DelayTaps NewTaps()+ {+ var t = new DelayTaps();+ ToolTip.SetTip(t, "The repeat train — L above the axis, R below. Height is the level left after each pass; the repeat sounding now is lit.");+ tapViews.Add(t);+ return t;+ }+ void SyncTaps()+ {+ if (tapViews.Count == 0) return;+ bool sync = On(SyncMode), link = On(LinkLR), freeze = On(Freeze);+ double msl = MsL(), msr = link ? msl : MsR();+ double fracL, fracR; string title, sub, ruler, win;+ if (sync)+ {+ int dl = Sel(DivL, 8), dr = link ? dl : Sel(DivR, 8);+ windowSec = SyncWindowBeats * BeatMs() / 1000.0;+ fracL = DivBeats[dl] / SyncWindowBeats;+ fracR = (DivBeats[dr] * BeatMs() + SpreadMs()) / (windowSec * 1000.0);+ title = NotaNum.F($"L {DivNames[dl]}");+ sub = NotaNum.F($"R {DivNames[dr]}");+ ruler = "0 · 1 bar · 2 bars";+ win = "";+ }+ else+ {+ windowSec = NiceWindow(Math.Max(msl, msr + SpreadMs()) * 3.2 / 1000.0);+ double winMs = windowSec * 1000.0;+ fracL = msl / winMs; fracR = (msr + SpreadMs()) / winMs;+ title = NotaNum.F($"L {Ms(msl)}");+ sub = NotaNum.F($"R {Ms(msr)}");+ ruler = "";+ win = Window(windowSec);+ }+ if (freeze) { title = "LOOP HELD · no decay"; sub = NotaNum.F($"R {Ms(msr)}"); }+ foreach (var t in tapViews) t.Set(fracL, fracR, P(Feedback), On(PingPong), freeze, title, sub, ruler, win);++ // Light the repeat that is sounding: the card counts them off the wall clock at the+ // repeat period, and only while the wet path is actually making sound.+ int litL = -1, litR = -1;+ if (Sc(S_WetPk) > 5e-4 && msl > 1 && msr > 1)+ {+ double ms = (DateTime.UtcNow - start).TotalMilliseconds;+ int nL = Math.Max(1, (int)(1.0 / Math.Max(fracL, 1e-3)));+ int nR = Math.Max(1, (int)(1.0 / Math.Max(fracR, 1e-3)));+ litL = (int)(ms / msl) % nL; litR = (int)(ms / msr) % nR;+ }+ foreach (var t in tapViews) t.SetLit(litL, litR);+ }+ readouts.Add(SyncTaps);++ // ======================================================================+ // LEFT — LOOP column (Feedback · Spread)+ // ======================================================================+ Control LoopFader(int p, string label, IBrush ink, IBrush handle, Func<string> value, string tip)+ {+ var f = new DelayFader { Ink = ink, Handle = handle, Width = 18, VerticalAlignment = VerticalAlignment.Stretch, Default = engine.DeviceParamDefault(track, di, p) };+ f.Changed += v => Raw(p, (float)v);+ f.GestureBegin += () => Begin(p);+ f.GestureEnd += () => End(p);+ MidiLearn.Bind(f, MidiTarget.DeviceParam(track, di, p), engine.DeviceParamName(track, di, p));+ ToolTip.SetTip(f, tip);+ var lb = Caps(label); lb.HorizontalAlignment = HorizontalAlignment.Center;+ var val = Mono("", 7, TextPrimary); val.HorizontalAlignment = HorizontalAlignment.Center;+ readouts.Add(() =>+ {+ f.Set(P(p));+ val.Text = value();+ bool hot = On(Freeze) && p == Feedback;+ val.Foreground = hot || P(p) > 0.9f ? AccentBright : TextPrimary;+ lb.Foreground = hot ? AccentBright : TextTertiary;+ });+ return new DockPanel { Width = 44, Children = { Docked(val, Dock.Bottom), Docked(lb, Dock.Bottom), f } };}+ var loopTitle = Caps("LOOP"); loopTitle.HorizontalAlignment = HorizontalAlignment.Center;+ var faders = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,Auto"), ColumnSpacing = 4, HorizontalAlignment = HorizontalAlignment.Center, Margin = new Thickness(0, 4, 0, 2) };+ faders.Children.Add(LoopFader(Feedback, "FEEDBACK", NotaPalette.Accent, NotaPalette.AccentBright,+ () => On(Freeze) ? "HOLD" : Pct(P(Feedback)),+ "Feedback — how much of each repeat goes round again; Freeze pins it at 100 %. Double-click resets."));+ faders.Children.Add(Col(LoopFader(Spread, "SPREAD", NotaPalette.Rose, NotaPalette.RoseBright,+ () => NotaNum.F($"{P(Spread) * 50:0} ms"),+ "Spread — pushes the right channel later, up to 50 ms. Double-click resets."), 1));+ var loopCol = new Border+ {+ Width = 96, Background = Card2, BorderBrush = BorderDef, BorderThickness = new Thickness(1), CornerRadius = NotaRadius.Tile, Padding = new Thickness(0, 5, 0, 4),+ Child = new DockPanel { Children = { Docked(loopTitle, Dock.Top), faders } },+ };+ DockPanel.SetDock(loopCol, Dock.Left);- // TIME panel: sync/ms + link/ping, then L/R rows (chips in sync, knobs in ms).- var timeHost = new ContentControl();- void RebuildTime()+ // ======================================================================+ // CENTRE — Time+ // ======================================================================+ Control TimeTab(){- bool sync = P(SyncMode) > 0.5f;- Control LR(string ch, int divP, int timeP) => new StackPanel { Orientation = Orientation.Horizontal, Spacing = 6, VerticalAlignment = VerticalAlignment.Center, Children = {- new TextBlock { Text = ch, FontSize = 9, FontWeight = FontWeight.Bold, Foreground = TextSecondary, Width = 12, VerticalAlignment = VerticalAlignment.Center },- sync ? DivChips(divP) : Cell("", timeP, MsF, null, 30) } };- timeHost.Content = new StackPanel { Spacing = 5, Children = { LR("L", DivL, TimeL), LR("R", DivR, TimeR) } };+ var host = new ContentControl();+ // The bottom half changes with the mode: divisions in Sync, free times in ms.+ Control SyncRows()+ {+ Control LR(string ch, int p, Func<bool>? dim)+ {+ var g = new Grid { ColumnDefinitions = new ColumnDefinitions("12,*"), ColumnSpacing = 5, Height = 20 };+ var lbl = Caps(ch); g.Children.Add(lbl);+ // Eight divisions: past the almanac's four-choice limit for segments — an+ // accepted exception, see DESIGN.md § Accepted departures.+ g.Children.Add(Col(Seg(p, DivNames, fill: true, onPick: SyncTaps), 1));+ if (dim is not null) readouts.Add(() => lbl.Foreground = dim() ? TextDisabled : TextTertiary);+ return g;+ }+ return new StackPanel { Spacing = 4, Children = { LR("L", DivL, null), LR("R", DivR, () => On(LinkLR)) } };+ }+ Control MsRow()+ {+ var g = new Grid { ColumnDefinitions = new ColumnDefinitions("*,*,*,*,Auto"), Height = 56 };+ g.Children.Add(K(TimeL, "L TIME", v => Ms(v * 2000), 34, 50, null, SyncTaps));+ g.Children.Add(Col(K(TimeR, "R TIME", v => On(LinkLR) ? Ms(P(TimeL) * 2000) : Ms(v * 2000), 34, 50, null, SyncTaps), 1));+ g.Children.Add(Col(K(Feedback, "FEEDBACK", Pct, 34, 50, null, SyncTaps), 2));+ g.Children.Add(Col(K(Spread, "SPREAD", v => NotaNum.F($"{v * 50:0} ms"), 34, 50, null, SyncTaps), 3));+ var toggles = new StackPanel { Spacing = 5, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(8, 0, 0, 0), Children = {+ Toggle(LinkLR, "Link L/R"), Toggle(FadeChange, "Fade on change") } };+ g.Children.Add(Col(toggles, 4));+ return g;+ }+ Control? syncRows = null, msRow = null;+ void Refill() => host.Content = On(SyncMode) ? syncRows ??= SyncRows() : msRow ??= MsRow();+ Refill();++ var modeSeg = Seg(SyncMode, new[] { "ms", "Sync" }, onPick: () => { Refill(); SyncTaps(); });+ var hint = Mono("", 7, TextTertiary); hint.HorizontalAlignment = HorizontalAlignment.Right;+ readouts.Add(() => hint.Text = On(SyncMode)+ ? NotaNum.F($"L {DivNames[Sel(DivL, 8)]} · R {DivNames[On(LinkLR) ? Sel(DivL, 8) : Sel(DivR, 8)]}")+ : On(LinkLR) ? "channels linked" : "channels independent");++ var head = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,Auto,Auto,Auto,Auto,*"), ColumnSpacing = 5, Height = 20 };+ head.Children.Add(Caps("MODE"));+ head.Children.Add(Col(modeSeg, 1));+ head.Children.Add(Col(Latch(LinkLR, "Link", "Link L/R — the right channel follows the left's time"), 2));+ head.Children.Add(Col(Latch(PingPong, "Ping", "Ping-pong — each repeat crosses to the other channel"), 3));+ head.Children.Add(Col(Latch(FadeChange, "Fade", "Fade on change — crossfade to a new delay time instead of gliding to it (which bends the pitch, tape style)"), 4));+ head.Children.Add(Col(hint, 5));++ var bottom = new Border { Child = host };+ // Automation or a preset can flip Sync under us — follow it.+ readouts.Add(() => { if (On(SyncMode) != ReferenceEquals(host.Content, syncRows)) Refill(); });+ return new DockPanel { LastChildFill = true, Margin = new Thickness(8, 5, 8, 4), Children = {+ Docked(head, Dock.Top),+ Docked(bottom, Dock.Bottom),+ new Border { Margin = new Thickness(0, 4, 0, 4), Child = NewTaps() } } };}- RebuildTime();- Control Band(string title, Control body)+ // ======================================================================+ // CENTRE — Loop · Wow+ // ======================================================================+ Control LoopTab(){- var head = new TextBlock { Text = title, FontSize = 8, FontWeight = FontWeight.Bold, Foreground = TextTertiary, Margin = new Thickness(0, 0, 0, 3) };- return new Border { Background = Card2, BorderBrush = BorderDef, BorderThickness = new Thickness(1), CornerRadius = NotaRadius.Panel, Padding = new Thickness(7, 5), Child = new StackPanel { Children = { head, body } } };+ var filter = new DelayFilterCurve { MinWidth = 78 };+ filter.Changed += (h, v) => Raw(h == 0 ? LowCut : HighCut, (float)v);+ filter.GestureBegin += h => Begin(h == 0 ? LowCut : HighCut);+ filter.GestureEnd += h => End(h == 0 ? LowCut : HighCut);+ filter.Reset += h => Reset(h == 0 ? LowCut : HighCut);+ ToolTip.SetTip(filter, "The band the repeats live in — drag the left handle for the low cut, the right one for the high cut. Double-click a handle to open it.");+ MidiLearn.Bind(filter, MidiTarget.DeviceParam(track, di, LowCut), "Low Cut");+ readouts.Add(() => { if (!filter.Dragging) filter.Set(P(LowCut), P(HighCut), LowHz(P(LowCut)), HighHz(P(HighCut))); });++ var g = new Grid { ColumnDefinitions = new ColumnDefinitions("48,48,*,60,60,Auto"), ColumnSpacing = 4, Height = 58 };+ g.Children.Add(K(Feedback, "FEEDBACK", v => On(Freeze) ? "HOLD" : Pct(v), 34, 48, null, SyncTaps));+ g.Children.Add(Col(K(Diffuse, "DIFFUSE", Pct, 34, 48), 1));+ g.Children.Add(Col(new Border { Margin = new Thickness(2, 2, 2, 6), Child = filter }, 2));+ g.Children.Add(Col(K(WowRate, "WOW RATE", v => { double hz = Exp(v, 0.05, 8); return hz >= 1 ? NotaNum.F($"{hz:0.0} Hz") : NotaNum.F($"{hz:0.00} Hz"); }, 34, 60, Teal), 3));+ g.Children.Add(Col(K(WowDepth, "WOW DEPTH", Pct, 34, 60, Teal), 4));+ var toggles = new StackPanel { Spacing = 5, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(6, 0, 0, 0), Children = {+ Toggle(Freeze, "Freeze"), Toggle(TapeMode, "Tape mode") } };+ g.Children.Add(Col(toggles, 5));++ return new DockPanel { LastChildFill = true, Margin = new Thickness(8, 5, 8, 4), Children = {+ Docked(g, Dock.Bottom),+ new Border { Margin = new Thickness(0, 0, 0, 4), Child = NewTaps() } } };}- var timePanel = Band("TIME", new StackPanel { Spacing = 6, Children = {- new StackPanel { Orientation = Orientation.Horizontal, Spacing = 5, Children = { Seg(SyncMode, new[] { "ms", "Sync" }), Toggle(LinkLR, "Link"), Toggle(PingPong, "Ping") } },- timeHost } });- var wowBand = Band("WOW", Row(Cell("Rate", WowRate, RateF, Teal), Cell("Depth", WowDepth, Pct, Teal)));- var bands = new StackPanel { Width = 288, Spacing = 6, VerticalAlignment = VerticalAlignment.Center, Children = { timePanel, wowBand } };- var rail = new Border { Width = 96, Background = NotaPalette.SurfaceInset, BorderBrush = BorderDef, BorderThickness = new Thickness(1, 0, 0, 0), Padding = new Thickness(6, 8),- Child = new StackPanel { Spacing = 10, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Children = {- Cell("Dry/Wet", DryWet, Pct, Teal, 40), Cell("Out", Output, DbF, null, 38) } } };- DockPanel.SetDock(rail, Dock.Right);+ // ======================================================================+ // RIGHT — Levels / Output+ // ======================================================================+ double lastTap = 0; int tapCount = 0; double tapSum = 0;+ void TapTempo()+ {+ double now = (DateTime.UtcNow - start).TotalMilliseconds;+ double gap = now - lastTap;+ lastTap = now;+ if (gap < 80 || gap > 2000) { tapCount = 0; tapSum = 0; return; } // a new series+ tapSum += gap; tapCount++;+ double ms = tapSum / tapCount;+ SetP(SyncMode, 0f); // tapping a time means free time+ SetP(TimeL, (float)(ms / 2000.0));+ if (!On(LinkLR)) SetP(TimeR, (float)(ms / 2000.0));+ SyncTaps();+ }++ Control LevelsTab()+ {+ var wetBar = new PentadLevelBar { Height = 4, VerticalAlignment = VerticalAlignment.Center };+ var wetDb = Mono("", 8, TextPrimary); wetDb.Width = 30; wetDb.TextAlignment = TextAlignment.Right;+ readouts.Add(() =>+ {+ double pk = Sc(S_WetPk);+ wetBar.SetLinear(pk);+ double db = pk > 1e-5 ? 20 * Math.Log10(pk) : -100;+ wetDb.Text = ShortDb(db);+ wetDb.Foreground = db > -6 ? NotaPalette.Warning : TextPrimary;+ });+ var wet = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,*,Auto"), ColumnSpacing = 6, VerticalAlignment = VerticalAlignment.Center };+ wet.Children.Add(Caps("WET")); wet.Children.Add(Col(wetBar, 1)); wet.Children.Add(Col(wetDb, 2));++ var btns = new Grid { ColumnDefinitions = new ColumnDefinitions("*,*"), ColumnSpacing = 6, VerticalAlignment = VerticalAlignment.Center };+ var freezeBtn = Btn("Freeze", () => { SetP(Freeze, On(Freeze) ? 0f : 1f); SyncTaps(); }, "Freeze — hold the loop forever; the input is muted and the repeats stop decaying");+ var freezeTxt = (TextBlock)freezeBtn.Child!;+ freezeBtn.BorderThickness = new Thickness(1);+ readouts.Add(() =>+ {+ bool on = On(Freeze);+ freezeBtn.Background = on ? NotaPalette.AccentSubtle : Raised;+ freezeBtn.BorderBrush = on ? NotaPalette.BorderBrass : Brushes.Transparent;+ freezeTxt.Foreground = on ? NotaPalette.AccentHover : TextPrimary;+ freezeTxt.FontWeight = on ? FontWeight.SemiBold : FontWeight.Normal;+ });+ btns.Children.Add(freezeBtn);+ btns.Children.Add(Col(Btn("Tap tempo", TapTempo, "Tap four times to set the delay time by ear (switches to free ms)"), 1));- var live = new Border { Height = 34, Background = NotaPalette.SurfaceCard, BorderBrush = BorderDef, BorderThickness = new Thickness(0, 0, 0, 1),- Child = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 12, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(9, 0), Children = {- Slider(Feedback, "FEEDBACK", Pct, 64), Slider(Spread, "SPREAD", SpreadF, 52), Toggle(Freeze, "Freeze"),- new TextBlock { Text = "TAPS", FontSize = 8, FontWeight = FontWeight.Bold, Foreground = TextTertiary, VerticalAlignment = VerticalAlignment.Center }, tapsLbl,- Slider(DryWet, "MIX", Pct, 52) } } };+ var clear = new Grid { ColumnDefinitions = new ColumnDefinitions("*,*"), ColumnSpacing = 6, VerticalAlignment = VerticalAlignment.Center };+ clear.Children.Add(Btn("Clear loop", () => engine.DeviceAction(track, di, A_ClearLoop, 0, 0), "Empty the delay buffer — silences what is still circulating"));+ clear.Children.Add(Col(Toggle(WetOnly, "Wet only"), 1));++ var rows = new Control[]+ {+ SliderRow("MIX", DryWet, Pct, 52, () => On(WetOnly)),+ SliderRow("DRY", DryLevel, v => ShortDb(DryDb(v)), 52, () => On(WetOnly)),+ SliderRow("OUT", Output, v => ShortDb(OutDb(v))),+ new Border { Height = 1, Background = NotaPalette.GraphBorder, Margin = new Thickness(0, 2) },+ SliderRow("FEEDBACK", Feedback, v => On(Freeze) ? "HOLD" : Pct(v), 52),+ SliderRow("SPREAD", Spread, v => NotaNum.F($"{v * 50:0}"), 52),+ new Border { Height = 1, Background = NotaPalette.GraphBorder, Margin = new Thickness(0, 2) },+ btns, clear, wet,+ };+ var grid = new Grid { RowDefinitions = new RowDefinitions("*,*,*,Auto,*,*,Auto,*,*,*") };+ for (int r = 0; r < rows.Length; r++) grid.Children.Add(GRow(rows[r], r));+ return new Border { Padding = new Thickness(8, 4), Child = grid };+ }++ Control OutputTab()+ {+ var meterL = new PentadLevelBar { Vertical = true, Width = 11, Height = 56 };+ var meterR = new PentadLevelBar { Vertical = true, Width = 11, Height = 56 };+ readouts.Add(() => { meterL.SetLinear(Sc(S_OutL)); meterR.SetLinear(Sc(S_OutR)); });+ static Control Centre(Control c) { c.HorizontalAlignment = HorizontalAlignment.Center; return c; }+ var scale = new Grid { RowDefinitions = new RowDefinitions("*,*,*"), Height = 56, Children = { Mono("0", 7, TextDisabled), GRow(Mono("−12", 7, TextDisabled), 1), GRow(Mono("−48", 7, TextDisabled), 2) } };+ var meters = Row(4,+ new StackPanel { Spacing = 2, Children = { meterL, Centre(Caps("L")) } },+ new StackPanel { Spacing = 2, Children = { meterR, Centre(Caps("R")) } },+ scale);+ meters.VerticalAlignment = VerticalAlignment.Top;+ var top = Row(8, K(Output, "OUT", v => Db(OutDb(v)), 40, 54), meters);- var content = new Grid { ColumnDefinitions = new ColumnDefinitions("*,Auto"), ColumnSpacing = 8, Margin = new Thickness(9, 8) };- content.Children.Add(taps); Grid.SetColumn(bands, 1); content.Children.Add(bands);- var contentDock = new DockPanel { LastChildFill = true, Children = { rail, content } };+ var mid = new StackPanel { Spacing = 6, Children = {+ SliderRow("MIX", DryWet, Pct, 52, () => On(WetOnly)),+ SliderRow("WIDTH", WidthP, v => NotaNum.F($"{v * 200:0}"), 52),+ SliderRow("MONO f", BassMono, v => v <= 0.001 ? "off" : NotaNum.F($"{Exp(v, 30, 500):0}"), 52) } };- DockPanel.SetDock(live, Dock.Top);- SyncGraph();- return new DockPanel { LastChildFill = true, Children = { live, contentDock } };+ var wetOnly = Toggle(WetOnly, "Wet only (send)");+ ToolTip.SetTip(wetOnly, "Wet only — repeats with no dry, for a return / send track");+ var comp = Toggle(LatencyComp, "Latency comp.");+ ToolTip.SetTip(comp, "The diffuser lengthens the loop by a fixed group delay; on, the read pointer is pulled back by exactly that so each repeat lands on the set time.");+ var bottom = new StackPanel { Spacing = 5, Children = { wetOnly, comp } };++ var body = new DockPanel { LastChildFill = false, Children = {+ Docked(top, Dock.Top), Docked(Divider(mid), Dock.Top), Docked(Divider(bottom), Dock.Bottom) } };+ ((Control)body.Children[1]).Margin = new Thickness(0, 5, 0, 0);+ return new Border { Padding = new Thickness(8, 5), Child = body };+ }++ // ======================================================================+ // Tab frames+ // ======================================================================+ var centreHost = new ContentControl();+ var rightHost = new ContentControl();+ var centreBodies = new Control?[2];+ var rightBodies = new Control?[2];+ int centreTab = 0;+ var extras = Mono("", 7, TextTertiary);+ readouts.Add(() =>+ {+ if (centreTab == 0)+ {+ extras.Text = On(SyncMode)+ ? NotaNum.F($"{DivNames[Sel(DivL, 8)]} = {Ms(MsL())} · {(On(PingPong) ? "ping-pong" : "parallel")}")+ : NotaNum.F($"L {Ms(MsL())} · R {Ms(On(LinkLR) ? MsL() : MsR())} · window {Window(windowSec)}");+ extras.Foreground = TextTertiary;+ }+ else+ {+ extras.Text = On(Freeze)+ ? NotaNum.F($"input muted · loop {Secs(MsL() / 1000)}")+ : NotaNum.F($"filter {LowCutF(P(LowCut))} — {HighCutF(P(HighCut))}");+ extras.Foreground = On(Freeze) ? AccentBright : TextTertiary;+ }+ });+ Control CentreBody(int t) => centreBodies[t] ??= t == 1 ? LoopTab() : TimeTab();+ Control RightBody(int t) => rightBodies[t] ??= t == 1 ? OutputTab() : LevelsTab();++ var centre = TabFrame(new[] { "Time", "Loop · Wow" }, centreHost, CentreBody, false, t => { centreTab = t; foreach (var a in readouts) a(); }, extras);+ var rightFrame = TabFrame(new[] { "Levels", "Output" }, rightHost, RightBody, true, _ => { foreach (var a in readouts) a(); }, null);+ var right = new Border { Width = 186, Background = Card2, BorderBrush = BorderDef, BorderThickness = new Thickness(1), CornerRadius = NotaRadius.Tile, ClipToBounds = true, Child = rightFrame };+ DockPanel.SetDock(right, Dock.Right);+ var centreBox = new Border { Background = Card2, BorderBrush = BorderDef, BorderThickness = new Thickness(1), CornerRadius = NotaRadius.Tile, Margin = new Thickness(5, 0), ClipToBounds = true, Child = centre };++ // ======================================================================+ // Status strip+ // ======================================================================+ var statusLeft = new TextBlock { FontSize = 8, Foreground = TextSecondary, VerticalAlignment = VerticalAlignment.Center, TextTrimming = TextTrimming.CharacterEllipsis };+ var statusRight = Mono("", 8, TextSecondary);+ string StatusText()+ {+ if (On(Freeze))+ return NotaNum.F($"Freeze: loop held, input muted · filter {LowCutF(P(LowCut))} — {HighCutF(P(HighCut))}");+ string time = On(SyncMode)+ ? NotaNum.F($"Sync {DivNames[Sel(DivL, 8)]}{(On(LinkLR) ? "" : NotaNum.F($" / {DivNames[Sel(DivR, 8)]}"))}")+ : NotaNum.F($"ms · L {MsL():0} / R {(On(LinkLR) ? MsL() : MsR()):0}");+ string mode = On(PingPong) ? " · ping-pong" : "";+ string tape = On(TapeMode) ? " · tape" : "";+ // How many repeats stay above −60 dB — the honest answer to "how long does it ring".+ float fb = Math.Clamp(P(Feedback), 0.001f, 0.98f);+ int audible = (int)Math.Floor(Math.Log(0.001) / Math.Log(fb));+ return NotaNum.F($"{time}{mode}{tape} · feedback {Pct(P(Feedback))} · {audible} audible repeats");+ }+ readouts.Add(() =>+ {+ statusLeft.Text = StatusText();+ statusLeft.Foreground = On(Freeze) ? AccentBright : TextSecondary;+ double sr = Sc(S_SampleRate), diff = Sc(S_DiffuseSmp);+ string comp = P(Diffuse) <= 0.001f || diff < 1 ? "" : On(LatencyComp)+ ? NotaNum.F($" · diffuser −{diff:0}\u2009smp compensated")+ : NotaNum.F($" · diffuser +{diff:0}\u2009smp");+ statusRight.Text = sr > 0 ? NotaNum.F($"{sr / 1000:0.#} kHz · latency {Sc(S_Latency):0} smp{comp} · CPU {Sc(S_Cpu) * 100:0.0} %") : "";+ });+ var statusGrid = new Grid { ColumnDefinitions = new ColumnDefinitions("*,Auto"), ColumnSpacing = 8 };+ statusGrid.Children.Add(statusLeft);+ statusGrid.Children.Add(Col(statusRight, 1));+ var status = new Border { Height = 18, Background = Sunken, BorderBrush = BorderDef, BorderThickness = new Thickness(0, 1, 0, 0), Padding = new Thickness(8, 0), Child = statusGrid };+ DockPanel.SetDock(status, Dock.Bottom);++ // ---- assemble ---------------------------------------------------------------+ var bodyRow = new DockPanel { LastChildFill = true, Margin = new Thickness(5), Children = { loopCol, right, centreBox } };+ var root = new DockPanel { LastChildFill = true, Background = NotaPalette.SurfaceInset, Children = { status, bodyRow } };++ void Refresh()+ {+ scN = engine.DeviceScope(track, di, scope, kScope);+ foreach (var a in readouts) a();+ }+ ctx.AddDeviceRefresher(Refresh);+ Refresh();+ return root;++ // local: a tab frame (bar + swapping body), optional extras on the right of the bar.+ Control TabFrame(string[] tabs, ContentControl host, Func<int, Control> body, bool centered, Action<int>? changed, Control? extrasCtl)+ {+ int sel = 0;+ var btns = new Border[tabs.Length];+ void Hi()+ {+ for (int i = 0; i < tabs.Length; i++)+ {+ bool on = i == sel;+ btns[i].Background = on ? Card2 : Brushes.Transparent;+ btns[i].BorderBrush = on ? Brass : Brushes.Transparent;+ var tb = (TextBlock)btns[i].Child!;+ tb.Foreground = on ? AccentBright : TextTertiary;+ tb.FontWeight = on ? FontWeight.SemiBold : FontWeight.Normal;+ }+ }+ var bar = centered ? (Avalonia.Controls.Panel)new UniformGrid { Rows = 1 } : new StackPanel { Orientation = Orientation.Horizontal };+ for (int i = 0; i < tabs.Length; i++)+ {+ int iv = i;+ var b = new Border+ {+ Padding = new Thickness(9, 0), BorderThickness = new Thickness(0, 0, 0, 2), BorderBrush = Brushes.Transparent, Cursor = new Cursor(StandardCursorType.Hand),+ Child = new TextBlock { Text = tabs[i], FontSize = 9, Foreground = TextTertiary, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center },+ };+ b.PointerPressed += (_, _) => { sel = iv; Hi(); host.Content = body(iv); changed?.Invoke(iv); };+ btns[i] = b;+ bar.Children.Add(b);+ }+ var barDock = new DockPanel { Height = 20, LastChildFill = centered };+ if (extrasCtl != null) { var ex = new Border { Padding = new Thickness(0, 0, 8, 0), Child = extrasCtl }; DockPanel.SetDock(ex, Dock.Right); barDock.Children.Add(ex); }+ if (!centered) DockPanel.SetDock(bar, Dock.Left);+ barDock.Children.Add(bar);+ var barBorder = new Border { BorderBrush = BorderDef, BorderThickness = new Thickness(0, 0, 0, 1), Child = barDock };+ DockPanel.SetDock(barBorder, Dock.Top);+ Hi();+ host.Content = body(sel);+ return new DockPanel { LastChildFill = true, Children = { barBorder, host } };+ }}}diff --git a/src/managed/Nota.Infrastructure/Persistence/FactoryPresetCatalog.cs b/src/managed/Nota.Infrastructure/Persistence/FactoryPresetCatalog.csindex 834a6ea1..68e59e87 100644--- a/src/managed/Nota.Infrastructure/Persistence/FactoryPresetCatalog.cs+++ b/src/managed/Nota.Infrastructure/Persistence/FactoryPresetCatalog.cs@@ -1081,10 +1081,46 @@ public sealed class FactoryPresetCatalog : IFactoryPresetsFx("reverb", 2, "Bright Plate",("Algorithm", 0.66f), ("Decay", 0.5f), ("HF Damp", 0.15f), ("High Cut", 1.0f), ("Diffusion", 0.8f), ("Dry/Wet", 0.3f));Fx("reverb", 2, "Shimmer Freeze",("Algorithm", 0.0f), ("Freeze", 1.0f), ("Mod Rate", 0.4f), ("Mod Depth", 0.6f), ("Width", 1.0f), ("Dry/Wet", 0.5f));- // ---- Delay (kind 3) — all params normalized 0..1. Div: 1/16 0 … 1/8 .29 … 1/4 .71 … 1/2 1.- Fx("delay", 3, "Slapback", ("Sync", 0.0f), ("Time L", 0.06f), ("Time R", 0.06f), ("Feedback", 0.12f), ("Dry/Wet", 0.25f));- Fx("delay", 3, "Dub Eighths", ("Sync", 1.0f), ("Div L", 0.286f), ("Div R", 0.286f), ("Feedback", 0.58f), ("Ping-Pong", 1.0f), ("Wow Depth", 0.3f), ("Dry/Wet", 0.35f));- Fx("delay", 3, "Ping Quarter",("Sync", 1.0f), ("Div L", 0.714f), ("Div R", 0.714f), ("Feedback", 0.45f), ("Ping-Pong", 1.0f), ("Spread", 0.3f), ("Dry/Wet", 0.3f));+ // ---- Delay (kind 3) — 29 presets, all params normalized 0..1. Div: 1/16 0 · 1/8T .143 ·+ // 1/8 .286 · 1/8. .429 · 1/4T .571 · 1/4 .714 · 1/4. .857 · 1/2 1. Time L/R = ms / 2000.+ // Low Cut = log(Hz / 20) / log(100) · High Cut = log(Hz / 200) / log(100) (1 = off) ·+ // Bass Mono = log(Hz / 30) / log(16.7) (0 = off) · Wow Rate = log(Hz / .05) / log(160) ·+ // Dry Level and Output are 0 dB at .707 and .5 · Width is 100 % at .5 · Spread = ms / 50.+ // Short and classic+ Fx("delay", 3, "Slapback", ("Sync", 0f), ("Time L", 0.060f), ("Time R", 0.060f), ("Link L/R", 1f), ("Feedback", 0.10f), ("High Cut", 0.80f), ("Dry/Wet", 0.25f));+ Fx("delay", 3, "Doubler", ("Sync", 0f), ("Time L", 0.014f), ("Time R", 0.019f), ("Feedback", 0f), ("Width", 0.70f), ("Dry/Wet", 0.35f));+ Fx("delay", 3, "Rockabilly Slap", ("Sync", 0f), ("Time L", 0.055f), ("Link L/R", 1f), ("Feedback", 0.22f), ("Tape Mode", 1f), ("High Cut", 0.70f), ("Dry/Wet", 0.28f));+ Fx("delay", 3, "Haas Widener", ("Sync", 0f), ("Time L", 0.008f), ("Time R", 0.013f), ("Feedback", 0f), ("Width", 0.85f), ("Dry/Wet", 0.50f));+ Fx("delay", 3, "Vocal Throw", ("Sync", 1f), ("Div L", 0.714f), ("Link L/R", 1f), ("Feedback", 0.30f), ("Low Cut", 0.42f), ("High Cut", 0.70f), ("Dry/Wet", 0.22f));+ // Tempo-synced+ Fx("delay", 3, "Eighth Bounce", ("Sync", 1f), ("Div L", 0.286f), ("Div R", 0.286f), ("Ping-Pong", 1f), ("Feedback", 0.38f), ("Spread", 0.48f), ("Dry/Wet", 0.30f));+ Fx("delay", 3, "Dub Eighths", ("Sync", 1f), ("Div L", 0.286f), ("Div R", 0.286f), ("Ping-Pong", 1f), ("Feedback", 0.62f), ("Low Cut", 0.48f), ("High Cut", 0.75f), ("Wow Depth", 0.30f), ("Dry/Wet", 0.35f));+ Fx("delay", 3, "Ping Quarter", ("Sync", 1f), ("Div L", 0.714f), ("Div R", 0.714f), ("Ping-Pong", 1f), ("Feedback", 0.45f), ("Spread", 0.30f), ("Dry/Wet", 0.30f));+ Fx("delay", 3, "Dotted Eighth", ("Sync", 1f), ("Div L", 0.429f), ("Link L/R", 1f), ("Feedback", 0.40f), ("High Cut", 0.78f), ("Dry/Wet", 0.28f));+ Fx("delay", 3, "Triplet Roll", ("Sync", 1f), ("Div L", 0.143f), ("Link L/R", 1f), ("Feedback", 0.48f), ("Dry/Wet", 0.30f));+ Fx("delay", 3, "Sixteenth Stutter",("Sync", 1f), ("Div L", 0f), ("Link L/R", 1f), ("Feedback", 0.55f), ("High Cut", 0.72f), ("Dry/Wet", 0.35f));+ Fx("delay", 3, "Half-Note Wash", ("Sync", 1f), ("Div L", 1f), ("Link L/R", 1f), ("Feedback", 0.55f), ("Diffuse", 0.45f), ("Dry/Wet", 0.35f));+ Fx("delay", 3, "Cross Rhythm", ("Sync", 1f), ("Div L", 0.286f), ("Div R", 0.429f), ("Ping-Pong", 1f), ("Feedback", 0.44f), ("Dry/Wet", 0.32f));+ Fx("delay", 3, "Polyrhythm 3:4", ("Sync", 1f), ("Div L", 0.571f), ("Div R", 0.714f), ("Feedback", 0.40f), ("Width", 0.65f), ("Dry/Wet", 0.30f));+ Fx("delay", 3, "Wide Quarters", ("Sync", 1f), ("Div L", 0.714f), ("Div R", 0.714f), ("Ping-Pong", 1f), ("Spread", 0.60f), ("Width", 0.80f), ("Feedback", 0.42f), ("Dry/Wet", 0.30f));+ Fx("delay", 3, "Trance Gate Echo",("Sync", 1f), ("Div L", 0f), ("Div R", 0.143f), ("Ping-Pong", 1f), ("Feedback", 0.62f), ("Low Cut", 0.50f), ("High Cut", 0.82f), ("Dry/Wet", 0.34f));+ // Tape and character+ Fx("delay", 3, "Tape Echo", ("Sync", 0f), ("Time L", 0.140f), ("Link L/R", 1f), ("Feedback", 0.45f), ("Tape Mode", 1f), ("Fade on Change", 0f), ("Wow Rate", 0.30f), ("Wow Depth", 0.25f), ("Low Cut", 0.35f), ("High Cut", 0.60f), ("Dry/Wet", 0.32f));+ Fx("delay", 3, "Space Echo", ("Sync", 0f), ("Time L", 0.185f), ("Link L/R", 1f), ("Feedback", 0.55f), ("Tape Mode", 1f), ("Diffuse", 0.35f), ("Wow Depth", 0.30f), ("Low Cut", 0.42f), ("High Cut", 0.55f), ("Dry/Wet", 0.36f));+ Fx("delay", 3, "Warped Tape", ("Sync", 0f), ("Time L", 0.220f), ("Link L/R", 1f), ("Feedback", 0.50f), ("Tape Mode", 1f), ("Fade on Change", 0f), ("Wow Rate", 0.45f), ("Wow Depth", 0.70f), ("Dry/Wet", 0.34f));+ Fx("delay", 3, "Bucket Brigade", ("Sync", 0f), ("Time L", 0.090f), ("Link L/R", 1f), ("Feedback", 0.42f), ("Tape Mode", 1f), ("Low Cut", 0.30f), ("High Cut", 0.45f), ("Dry/Wet", 0.30f));+ Fx("delay", 3, "Slap Wide", ("Sync", 0f), ("Time L", 0.156f), ("Time R", 0.187f), ("Feedback", 0.18f), ("Spread", 0.44f), ("Width", 0.67f), ("Dry/Wet", 0.44f));+ Fx("delay", 3, "Repitch Riser", ("Sync", 0f), ("Time L", 0.300f), ("Link L/R", 1f), ("Feedback", 0.60f), ("Tape Mode", 1f), ("Fade on Change", 0f), ("Wow Depth", 0.35f), ("Dry/Wet", 0.40f));+ Fx("delay", 3, "Telephone Echo", ("Sync", 1f), ("Div L", 0.286f), ("Link L/R", 1f), ("Feedback", 0.50f), ("Low Cut", 0.70f), ("High Cut", 0.50f), ("Dry/Wet", 0.32f));+ // Ambient and frozen+ Fx("delay", 3, "Diffuse Cloud", ("Sync", 1f), ("Div L", 0.857f), ("Link L/R", 1f), ("Feedback", 0.70f), ("Diffuse", 0.85f), ("Low Cut", 0.44f), ("High Cut", 0.66f), ("Width", 0.75f), ("Dry/Wet", 0.42f));+ Fx("delay", 3, "Ambient Wash", ("Sync", 1f), ("Div L", 1f), ("Div R", 1f), ("Ping-Pong", 1f), ("Feedback", 0.72f), ("Diffuse", 0.75f), ("Low Cut", 0.50f), ("High Cut", 0.65f), ("Width", 0.80f), ("Dry/Wet", 0.45f));+ Fx("delay", 3, "Dark Cavern", ("Sync", 0f), ("Time L", 0.350f), ("Link L/R", 1f), ("Feedback", 0.68f), ("Diffuse", 0.60f), ("Low Cut", 0.30f), ("High Cut", 0.40f), ("Dry/Wet", 0.40f));+ Fx("delay", 3, "Tape Hold", ("Sync", 1f), ("Div L", 0.286f), ("Link L/R", 1f), ("Freeze", 1f), ("Feedback", 1f), ("Diffuse", 0.56f), ("Low Cut", 0.477f), ("High Cut", 0.753f), ("Wow Rate", 0.30f), ("Wow Depth", 0.15f), ("Spread", 0.88f), ("Dry Level", 0f), ("Dry/Wet", 1f), ("Output", 0.38f));+ Fx("delay", 3, "Frozen Bed", ("Sync", 1f), ("Div L", 1f), ("Link L/R", 1f), ("Freeze", 1f), ("Diffuse", 1f), ("High Cut", 0.60f), ("Width", 0.80f), ("Dry/Wet", 0.70f), ("Output", 0.42f));+ // Sends (wet only, for a return track)+ Fx("delay", 3, "Send · Eighth", ("Wet Only", 1f), ("Sync", 1f), ("Div L", 0.286f), ("Div R", 0.286f), ("Ping-Pong", 1f), ("Feedback", 0.40f), ("Low Cut", 0.42f), ("High Cut", 0.78f), ("Bass Mono", 0.49f), ("Dry/Wet", 1f));+ Fx("delay", 3, "Send · Quarter", ("Wet Only", 1f), ("Sync", 1f), ("Div L", 0.714f), ("Div R", 0.714f), ("Ping-Pong", 1f), ("Feedback", 0.45f), ("Spread", 0.55f), ("Width", 0.80f), ("Low Cut", 0.45f), ("Dry/Wet", 1f));// ---- Utility (kind 4) — Gain -24..24 dB · Balance -1..1 · Width 0..400% ·// Channel Mode 0..3 (Stereo/Left/Right/Swap) · Mono Freq 20..2000 Hz · toggles 0/1diff --git a/src/managed/Nota.Mcp/Tools/DeviceTools.cs b/src/managed/Nota.Mcp/Tools/DeviceTools.csindex 433d75b7..35f5c092 100644--- a/src/managed/Nota.Mcp/Tools/DeviceTools.cs+++ b/src/managed/Nota.Mcp/Tools/DeviceTools.cs@@ -67,9 +67,13 @@ 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.")]+ [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).")]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). 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));+public sealed record AnalyzerBand(double Hz, double Db);public sealed record AnalyzerPeak(double Hz, double Db, string Note);public sealed record AnalyzerReading(string Summary, string Scope, string Cursors, AnalyzerBand[] Bands, AnalyzerPeak[] Peaks);diff --git a/src/native/nota.engine/src/Delay.h b/src/native/nota.engine/src/Delay.hindex 31a174cb..4a5c2073 100644--- a/src/native/nota.engine/src/Delay.h+++ b/src/native/nota.engine/src/Delay.h@@ -1,14 +1,22 @@// SPDX-License-Identifier: AGPL-3.0-only// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.//-// Built-in stereo delay (mockup 2h) — independent L/R times (free ms or tempo-synced-// divisions 1/16…1/2 incl. triplet/dotted), Link L/R, feedback, ping-pong cross-feed,-// stereo spread, tape-style WOW modulation (rate · depth), Freeze (infinite loop) and-// dry/wet + output trim. Tempo comes from Device::setTransport.+// Built-in stereo delay ("Nota Delay" — almanac update) on the Chamber frame: independent+// L/R times (free ms or tempo-synced divisions 1/16…1/2 incl. triplet/dotted), Link L/R,+// feedback, ping-pong cross-feed, stereo spread, a tone shaper in the loop (low cut · high+// cut · allpass diffusion · tape saturation), tape-style WOW modulation (rate · depth),+// Freeze (infinite loop, input muted) and an output stage (dry level · dry/wet · width ·+// bass mono · wet only · output trim). Tempo comes from Device::setTransport.+//+// Changing the delay time either crossfades to the new tap (Fade on Change — no pitch+// artefact) or glides to it at a limited rate (tape repitch). The diffuser sits in the loop+// and lengthens it by a fixed group delay; Latency Comp pulls the read pointer back by that+// much so the echo lands exactly on the set time.//// All params are normalized 0..1 (denormalized in process()); persist/clone/automation-// are generic through the base Device. The ring buffers are allocated on the message-// thread in setSampleRate, so process() never allocates. A core Device (JUCE-free).+// are generic through the base Device. Param order is the persisted layout — APPEND ONLY.+// The ring buffers are allocated on the message thread in setSampleRate, so process()+// never allocates. A core Device (JUCE-free).#pragma once@@ -16,8 +24,11 @@#include <algorithm>#include <atomic>+#include <chrono>#include <cmath>#include <cstdint>+#include <cstdio>+#include <string>#include <vector>namespace nota {@@ -26,8 +37,19 @@ class Delay : public Device {public:enum {SyncMode = 0, TimeL, TimeR, DivL, DivR, LinkLR, Feedback, Spread,- PingPong, WowRate, WowDepth, Freeze, DryWet, Output, kNumParams+ PingPong, WowRate, WowDepth, Freeze, DryWet, Output,+ // ---- appended for the almanac update — keep the order, append only ----+ DryLevel, Diffuse, LowCut, HighCut, TapeMode, FadeChange,+ Width, BassMono, WetOnly, LatencyComp, kNumParams+ };+ // Scope telemetry layout (read by the card).+ enum {+ S_WetPk = 0, S_OutL, S_OutR, S_Cpu, S_SampleRate, S_Bpm,+ S_DiffuseSmp, S_Frozen, S_MsL, S_MsR, S_Latency, kScope};+ // deviceAction ids.+ enum { A_ClearLoop = 0 };+static constexpr float kMaxTimeMs = 2000.0f;static constexpr int kNumDiv = 8;// Division lengths in beats (quarter = 1): 1/16, 1/8T, 1/8, 1/8·, 1/4T, 1/4, 1/4·, 1/2.@@ -35,91 +57,288 @@ public:void setSampleRate(double sr, int32_t /*maxBlock*/) override {sr_ = sr > 0 ? sr : 44100.0;- size_ = static_cast<int>(sr_ * (kMaxTimeMs / 1000.0)) + static_cast<int>(sr_ * 0.06) + 4;+ size_ = static_cast<int>(sr_ * (kMaxTimeMs / 1000.0)) + static_cast<int>(sr_ * 0.12) + 4;bufL_.assign(size_, 0.0f); bufR_.assign(size_, 0.0f);write_ = 0;+ // Diffusion allpasses: two mutually prime lengths per channel, R slightly offset so+ // the pair decorrelates. Lengths scale with the sample rate; the loop is longer by+ // their sum, which Latency Comp subtracts from the read pointer.+ ap_[0].resize(static_cast<int>(sr_ * 0.00201));+ ap_[1].resize(static_cast<int>(sr_ * 0.00343));+ ap_[2].resize(static_cast<int>(sr_ * 0.00229));+ ap_[3].resize(static_cast<int>(sr_ * 0.00387));+ fadeLen_ = std::max(64, static_cast<int>(sr_ * 0.030));+ fadePos_ = fadeLen_;+ curL_ = curR_ = oldL_ = oldR_ = 0.0;+ hpL_ = hpR_ = lpL_ = lpR_ = tapeL_ = tapeR_ = monoL_ = monoR_ = 0.0f;+ wowPhase_ = 0.0;+ srA_.store(static_cast<float>(sr_), std::memory_order_relaxed);}void setTransport(double, double samplesPerBeat, bool) override {if (samplesPerBeat > 0.0) spb_ = samplesPerBeat;}void process(float* buf, int32_t frames) override {- if (size_ <= 4) return;- const bool sync = p_[SyncMode].load(std::memory_order_relaxed) > 0.5f && spb_ > 0.0;- const bool link = p_[LinkLR].load(std::memory_order_relaxed) > 0.5f;- const bool ping = p_[PingPong].load(std::memory_order_relaxed) > 0.5f;- const bool freeze = p_[Freeze].load(std::memory_order_relaxed) > 0.5f;- const float fb = freeze ? 1.0f : std::clamp(p_[Feedback].load(std::memory_order_relaxed), 0.0f, 0.95f);+ if (size_ <= 4 || frames <= 0) return;+ const auto t0 = std::chrono::steady_clock::now();+ if (clear_.exchange(false, std::memory_order_relaxed)) wipe();++ const bool sync = on(SyncMode) && spb_ > 0.0;+ const bool link = on(LinkLR);+ const bool ping = on(PingPong);+ const bool freeze = on(Freeze);+ const bool tape = on(TapeMode);+ const bool fade = on(FadeChange);+ const bool wetOnly = on(WetOnly);++ const float fb = freeze ? 1.0f : std::clamp(get(Feedback), 0.0f, 0.98f);const float inGain = freeze ? 0.0f : 1.0f;- const float mix = clamp01(p_[DryWet]); const float wet = mix, dry = 1.0f - mix;- const float outG = clamp01(p_[Output]) * 2.0f;- const float spreadMs = clamp01(p_[Spread]) * 50.0f;+ const float mix = wetOnly ? 1.0f : clamp01(DryWet);+ const float dryG = wetOnly ? 0.0f : (1.0f - mix) * dryGain(clamp01(DryLevel));+ const float wetG = mix;+ const float outG = clamp01(Output) * 2.0f;+ const float width = clamp01(Width) * 2.0f;- float dL = delaySamples(TimeL, DivL, sync);- float dR = link ? dL : delaySamples(TimeR, DivR, sync);- dR += spreadMs * 0.001f * (float)sr_;- dL = std::clamp(dL, 1.0f, (float)size_ - 3.0f);- dR = std::clamp(dR, 1.0f, (float)size_ - 3.0f);+ // ---- delay targets -------------------------------------------------------+ const float spreadMs = clamp01(Spread) * 50.0f;+ double tgtL = delaySamples(TimeL, DivL, sync);+ double tgtR = link ? tgtL : delaySamples(TimeR, DivR, sync);+ tgtR += spreadMs * 0.001 * sr_;+ const double diffuse = clamp01(Diffuse);+ const double apLen = static_cast<double>(ap_[0].n + ap_[1].n); // loop group delay+ if (on(LatencyComp)) { tgtL -= apLen; tgtR -= apLen; }+ const double lo = 1.0, hi = static_cast<double>(size_) - 3.0;+ tgtL = std::clamp(tgtL, lo, hi); tgtR = std::clamp(tgtR, lo, hi);+ if (curL_ <= 0.0) { curL_ = tgtL; curR_ = tgtR; oldL_ = tgtL; oldR_ = tgtR; }++ if (fade) {+ // Crossfade to the new tap; a fade already running finishes first, so dragging+ // a time knob does not restart it every block.+ if (fadePos_ >= fadeLen_ && (std::fabs(tgtL - curL_) > 0.5 || std::fabs(tgtR - curR_) > 0.5)) {+ oldL_ = curL_; oldR_ = curR_; curL_ = tgtL; curR_ = tgtR; fadePos_ = 0;+ }+ } else {+ fadePos_ = fadeLen_; // repitch: one tap, glided below+ }+ // Tape glide: the read pointer moves 0.06 samples per sample, so a time change bends+ // the pitch by at most ±6 % while it slides — the tape-delay sound.+ constexpr double glide = 0.06;- const double wowInc = expMap(clamp01(p_[WowRate]), 0.05, 8.0) / sr_;- const float wowDepth = clamp01(p_[WowDepth]) * 6.0f * (float)(sr_ / 44100.0); // samples+ const double wowInc = expMap(clamp01(WowRate), 0.05, 8.0) / sr_;+ const float wowDepth = clamp01(WowDepth) * (tape ? 12.0f : 6.0f) * static_cast<float>(sr_ / 44100.0);++ // ---- loop tone (control rate) --------------------------------------------+ const float hpC = onePole(expMap(clamp01(LowCut), 20.0, 2000.0));+ const float lpC = onePole(expMap(clamp01(HighCut), 200.0, 20000.0));+ const bool hpOn = clamp01(LowCut) > 0.001f, lpOn = clamp01(HighCut) < 0.999f;+ const float tapeC = onePole(8000.0); // tape head loss+ const float drive = tape ? 1.0f + 2.0f * clamp01(Feedback) : 0.0f;+ const float apG = static_cast<float>(0.62 * diffuse);+ const float monoC = onePole(std::max(20.0, expMap(clamp01(BassMono), 30.0, 500.0)));+ const bool monoOn = clamp01(BassMono) > 0.001f;++ float wetPk = 0.0f, outPkL = 0.0f, outPkR = 0.0f;for (int32_t i = 0; i < frames; ++i) {- const float lfo = std::sin(kTwoPi * wowPhase_); wowPhase_ += wowInc; if (wowPhase_ >= 1.0) wowPhase_ -= 1.0;- const float mod = lfo * wowDepth;- const float dl = read(bufL_, dL + mod), dr = read(bufR_, dR - mod);+ if (!fade) {+ curL_ += std::clamp(tgtL - curL_, -glide, glide);+ curR_ += std::clamp(tgtR - curR_, -glide, glide);+ } else if (fadePos_ < fadeLen_) {+ ++fadePos_;+ }+ const float lfo = std::sin(kTwoPi * wowPhase_);+ wowPhase_ += wowInc; if (wowPhase_ >= 1.0) wowPhase_ -= 1.0;+ const double mod = static_cast<double>(lfo * wowDepth);++ float rdL, rdR;+ if (fadePos_ < fadeLen_) {+ const float t = static_cast<float>(fadePos_) / static_cast<float>(fadeLen_);+ const float a = 1.0f - t;+ rdL = read(bufL_, oldL_ + mod) * a + read(bufL_, curL_ + mod) * t;+ rdR = read(bufR_, oldR_ - mod) * a + read(bufR_, curR_ - mod) * t;+ } else {+ rdL = read(bufL_, curL_ + mod);+ rdR = read(bufR_, curR_ - mod);+ }+const float l = buf[i * 2], r = buf[i * 2 + 1];- const float fbL = ping ? dr : dl, fbR = ping ? dl : dr;- bufL_[write_] = l * inGain + fbL * fb;- bufR_[write_] = r * inGain + fbR * fb;- buf[i * 2] = (dry * l + wet * dl) * outG;- buf[i * 2 + 1] = (dry * r + wet * dr) * outG;+ float wl = ping ? rdR : rdL, wr = ping ? rdL : rdR;+ float inpL = l * inGain + wl * fb;+ float inpR = r * inGain + wr * fb;+ if (!freeze) {+ // The loop's tone: cuts, tape head loss + saturation. Frozen, the loop is+ // left untouched so it holds instead of slowly dulling.+ if (hpOn) { hpL_ += hpC * (inpL - hpL_); inpL -= hpL_; hpR_ += hpC * (inpR - hpR_); inpR -= hpR_; }+ if (lpOn) { lpL_ += lpC * (inpL - lpL_); inpL = lpL_; lpR_ += lpC * (inpR - lpR_); inpR = lpR_; }+ if (tape) {+ tapeL_ += tapeC * (inpL - tapeL_); inpL = std::tanh(tapeL_ * drive) / std::tanh(drive);+ tapeR_ += tapeC * (inpR - tapeR_); inpR = std::tanh(tapeR_ * drive) / std::tanh(drive);+ }+ }+ inpL = ap_[1].tick(ap_[0].tick(inpL, apG), apG);+ inpR = ap_[3].tick(ap_[2].tick(inpR, apG), apG);+ bufL_[write_] = inpL; bufR_[write_] = inpR;if (++write_ >= size_) write_ = 0;++ // ---- output stage: width, bass mono, mix, trim ----+ float outWetL = rdL, outWetR = rdR;+ if (width != 1.0f || monoOn) {+ float mid = (outWetL + outWetR) * 0.5f, side = (outWetL - outWetR) * 0.5f * width;+ if (monoOn) { monoL_ += monoC * (side - monoL_); side -= monoL_; }+ outWetL = mid + side; outWetR = mid - side;+ }+ const float oL = (dryG * l + wetG * outWetL) * outG;+ const float oR = (dryG * r + wetG * outWetR) * outG;+ buf[i * 2] = oL; buf[i * 2 + 1] = oR;++ wetPk = std::max(wetPk, std::fabs(outWetL * wetG));+ outPkL = std::max(outPkL, std::fabs(oL)); outPkR = std::max(outPkR, std::fabs(oR));}++ // ---- telemetry -----------------------------------------------------------+ mWet_.store(decayPeak(mWet_.load(std::memory_order_relaxed), wetPk), std::memory_order_relaxed);+ mOutL_.store(decayPeak(mOutL_.load(std::memory_order_relaxed), outPkL), std::memory_order_relaxed);+ mOutR_.store(decayPeak(mOutR_.load(std::memory_order_relaxed), outPkR), std::memory_order_relaxed);+ msL_.store(static_cast<float>(curL_ * 1000.0 / sr_), std::memory_order_relaxed);+ msR_.store(static_cast<float>(curR_ * 1000.0 / sr_), std::memory_order_relaxed);+ diffA_.store(static_cast<float>(apLen), std::memory_order_relaxed);+ bpmA_.store(spb_ > 0.0 ? static_cast<float>(60.0 * sr_ / spb_) : 0.0f, std::memory_order_relaxed);+ srA_.store(static_cast<float>(sr_), std::memory_order_relaxed);+ const double el = std::chrono::duration<double>(std::chrono::steady_clock::now() - t0).count();+ cpuS_ = cpuS_ * 0.9 + (el / (frames / sr_)) * 0.1;+ cpuA_.store(static_cast<float>(cpuS_), std::memory_order_relaxed);}+ // ---- identity / params -------------------------------------------------------const char* displayName() const override { return "Nota Delay"; }int32_t builtinKind() const override { return 3; }int32_t paramCount() const override { return kNumParams; }const char* paramName(int32_t i) const override {static const char* nm[] = { "Sync", "Time L", "Time R", "Div L", "Div R", "Link L/R", "Feedback",- "Spread", "Ping-Pong", "Wow Rate", "Wow Depth", "Freeze", "Dry/Wet", "Output" };+ "Spread", "Ping-Pong", "Wow Rate", "Wow Depth", "Freeze", "Dry/Wet", "Output",+ "Dry Level", "Diffuse", "Low Cut", "High Cut", "Tape Mode", "Fade on Change",+ "Width", "Bass Mono", "Wet Only", "Latency Comp" };return (i >= 0 && i < kNumParams) ? nm[i] : "";}float paramMin(int32_t) const override { return 0.0f; }float paramMax(int32_t) const override { return 1.0f; }float getParam(int32_t i) const override { return (i >= 0 && i < kNumParams) ? p_[i].load(std::memory_order_relaxed) : 0.0f; }- void setParam(int32_t i, float v) override { if (i >= 0 && i < kNumParams) p_[i].store(v, std::memory_order_relaxed); }+ void setParam(int32_t i, float v) override { if (i >= 0 && i < kNumParams) p_[i].store(std::clamp(v, 0.0f, 1.0f), std::memory_order_relaxed); }++ // Nothing is added to the dry path — the wet is the effect itself.+ int32_t latencySamples() const override { return 0; }++ void deviceAction(int32_t id, int32_t, float) override {+ if (id == A_ClearLoop) clear_.store(true, std::memory_order_relaxed);+ }++ int32_t scopeRead(float* out, int32_t maxSamples) const override {+ if (!out || maxSamples < kScope) return 0;+ out[S_WetPk] = mWet_.load(std::memory_order_relaxed);+ out[S_OutL] = mOutL_.load(std::memory_order_relaxed);+ out[S_OutR] = mOutR_.load(std::memory_order_relaxed);+ out[S_Cpu] = cpuA_.load(std::memory_order_relaxed);+ out[S_SampleRate] = srA_.load(std::memory_order_relaxed);+ out[S_Bpm] = bpmA_.load(std::memory_order_relaxed);+ out[S_DiffuseSmp] = diffA_.load(std::memory_order_relaxed);+ out[S_Frozen] = getParam(Freeze) >= 0.5f ? 1.0f : 0.0f;+ out[S_MsL] = msL_.load(std::memory_order_relaxed);+ out[S_MsR] = msR_.load(std::memory_order_relaxed);+ out[S_Latency] = static_cast<float>(latencySamples());+ return kScope;+ }++ // id 0 — a one-line summary of what the delay is doing now (the card's status strip,+ // and get_device_text over MCP).+ std::string deviceText(int32_t id) const override {+ if (id != 0) return {};+ char b[256];+ const bool sync = getParam(SyncMode) >= 0.5f && spb_ > 0.0;+ const bool link = getParam(LinkLR) >= 0.5f;+ const float msl = msL_.load(std::memory_order_relaxed), msr = msR_.load(std::memory_order_relaxed);+ if (getParam(Freeze) >= 0.5f) {+ std::snprintf(b, sizeof b, "Freeze: loop held, input muted - %.0f ms / %.0f ms - mix %.0f %%",+ msl, msr, getParam(DryWet) * 100.0f);+ } else if (sync) {+ const int dl = divIndex(DivL), dr = link ? dl : divIndex(DivR);+ static const char* nm[kNumDiv] = { "1/16", "1/8T", "1/8", "1/8.", "1/4T", "1/4", "1/4.", "1/2" };+ std::snprintf(b, sizeof b, "Sync %s / %s%s - feedback %.0f %% - mix %.0f %%",+ nm[dl], nm[dr], getParam(PingPong) >= 0.5f ? " - ping-pong" : "",+ getParam(Feedback) * 100.0f, getParam(DryWet) * 100.0f);+ } else {+ std::snprintf(b, sizeof b, "Free %.0f ms / %.0f ms%s - feedback %.0f %% - mix %.0f %%",+ msl, msr, getParam(PingPong) >= 0.5f ? " - ping-pong" : "",+ getParam(Feedback) * 100.0f, getParam(DryWet) * 100.0f);+ }+ return std::string(b);+ }Delay() {set(SyncMode, 1.0f); set(TimeL, 0.35f); set(TimeR, 0.35f); set(DivL, 2.0f / 7.0f); set(DivR, 2.0f / 7.0f);set(LinkLR, 0.0f); set(Feedback, 0.38f); set(Spread, 0.0f); set(PingPong, 0.0f);set(WowRate, 0.3f); set(WowDepth, 0.15f); set(Freeze, 0.0f); set(DryWet, 0.3f); set(Output, 0.5f);+ set(DryLevel, 0.70711f); set(Diffuse, 0.0f); set(LowCut, 0.0f); set(HighCut, 1.0f);+ set(TapeMode, 0.0f); set(FadeChange, 1.0f); set(Width, 0.5f); set(BassMono, 0.0f);+ set(WetOnly, 0.0f); set(LatencyComp, 1.0f);}private:static constexpr double kTwoPi = 6.283185307179586;- static float clamp01(const std::atomic<float>& a) { return std::clamp(a.load(std::memory_order_relaxed), 0.0f, 1.0f); }++ // A Schroeder allpass: lossless, so a frozen loop neither grows nor decays.+ struct AllPass {+ std::vector<float> z; int n = 0, w = 0;+ void resize(int len) { n = std::max(1, len); z.assign(n, 0.0f); w = 0; }+ void wipe() { std::fill(z.begin(), z.end(), 0.0f); }+ float tick(float x, float g) {+ const float d = z[w];+ const float v = x + g * d;+ z[w] = v; if (++w >= n) w = 0;+ return d - g * v;+ }+ };++ float get(int i) const { return p_[i].load(std::memory_order_relaxed); }+ bool on(int i) const { return get(i) >= 0.5f; }+ float clamp01(int i) const { return std::clamp(get(i), 0.0f, 1.0f); }void set(int i, float v) { p_[i].store(v, std::memory_order_relaxed); }static double expMap(double v, double lo, double hi) { return lo * std::pow(hi / lo, std::clamp(v, 0.0, 1.0)); }+ // Dry trim: 0 dB at 1/√2, up to +6 dB at the top, silent at 0.+ static float dryGain(float v) { return 2.0f * v * v; }+ static float decayPeak(float held, float now) { return now > held ? now : held * 0.82f; }+ float onePole(double hz) const { return static_cast<float>(1.0 - std::exp(-kTwoPi * std::clamp(hz, 5.0, sr_ * 0.45) / sr_)); }- float delaySamples(int timeParam, int divParam, bool sync) const {- if (sync) {- int d = std::clamp((int)std::lround(clamp01(p_[divParam]) * (kNumDiv - 1)), 0, kNumDiv - 1);- return (float)(kDivBeats[d] * spb_);- }- float ms = std::clamp(clamp01(p_[timeParam]) * kMaxTimeMs, 1.0f, kMaxTimeMs);- return ms * 0.001f * (float)sr_;+ int divIndex(int p) const { return std::clamp(static_cast<int>(std::lround(std::clamp(getParam(p), 0.0f, 1.0f) * (kNumDiv - 1))), 0, kNumDiv - 1); }++ double delaySamples(int timeParam, int divParam, bool sync) const {+ if (sync) return kDivBeats[divIndex(divParam)] * spb_;+ const double ms = std::clamp(static_cast<double>(clamp01(timeParam)) * kMaxTimeMs, 1.0, static_cast<double>(kMaxTimeMs));+ return ms * 0.001 * sr_;}- float read(const std::vector<float>& b, float delay) const {- float rp = write_ - delay; while (rp < 0) rp += size_;- int i0 = (int)rp; float frac = rp - i0; int i1 = i0 + 1; if (i1 >= size_) i1 -= size_;+ float read(const std::vector<float>& b, double delay) const {+ double rp = write_ - std::clamp(delay, 1.0, static_cast<double>(size_) - 3.0);+ while (rp < 0) rp += size_;+ const int i0 = static_cast<int>(rp); const float frac = static_cast<float>(rp - i0);+ int i1 = i0 + 1; if (i1 >= size_) i1 -= size_;return b[i0] + (b[i1] - b[i0]) * frac;}+ void wipe() {+ std::fill(bufL_.begin(), bufL_.end(), 0.0f);+ std::fill(bufR_.begin(), bufR_.end(), 0.0f);+ for (auto& a : ap_) a.wipe();+ hpL_ = hpR_ = lpL_ = lpR_ = tapeL_ = tapeR_ = monoL_ = monoR_ = 0.0f;+ }double sr_ = 44100.0, spb_ = 0.0, wowPhase_ = 0.0;+ double curL_ = 0.0, curR_ = 0.0, oldL_ = 0.0, oldR_ = 0.0;+ int fadeLen_ = 1024, fadePos_ = 1024;int size_ = 0, write_ = 0;std::vector<float> bufL_, bufR_;+ AllPass ap_[4];+ float hpL_ = 0, hpR_ = 0, lpL_ = 0, lpR_ = 0, tapeL_ = 0, tapeR_ = 0, monoL_ = 0, monoR_ = 0;+ double cpuS_ = 0.0;+ std::atomic<bool> clear_{false};+ std::atomic<float> mWet_{0}, mOutL_{0}, mOutR_{0}, cpuA_{0}, srA_{44100.0f}, bpmA_{0}, diffA_{0}, msL_{0}, msR_{0};std::atomic<float> p_[kNumParams] = {};};diff --git a/tests/Nota.SmokeTest/Program.cs b/tests/Nota.SmokeTest/Program.csindex 401ad38a..009a1ed7 100644--- a/tests/Nota.SmokeTest/Program.cs+++ b/tests/Nota.SmokeTest/Program.cs@@ -3069,7 +3069,7 @@ Check(Rms(buf, frames) > 1e-4f, $"audio flows through EQ + Compressor chain (rmsint revDev = engine.AddBuiltinDevice(fxT, 2);Check(revDev >= 0 && engine.DeviceName(fxT, revDev) == "Nota Reverb" && engine.DeviceParamCount(fxT, revDev) == 14, "add built-in Reverb (14 params)");int delDev = engine.AddBuiltinDevice(fxT, 3);-Check(delDev >= 0 && engine.DeviceName(fxT, delDev) == "Nota Delay" && engine.DeviceParamCount(fxT, delDev) == 14, "add built-in Delay (14 params)");+Check(delDev >= 0 && engine.DeviceName(fxT, delDev) == "Nota Delay" && engine.DeviceParamCount(fxT, delDev) == 24, "add built-in Delay (24 params)");int utilDev = engine.AddBuiltinDevice(fxT, 4);Check(utilDev >= 0 && engine.DeviceName(fxT, utilDev) == "Nota Utility" && engine.DeviceParamCount(fxT, utilDev) == 9, "add built-in Utility (9 params)");engine.DeviceSetParam(fxT, delDev, 12, 0.5f); // Delay Dry/Wet (index 12)@@ -3105,6 +3105,132 @@ engine.RenderOffline(buf, frames);Check(Rms(buf, frames) > 1e-4f, $"audio flows through EQ+Comp+Reverb+Delay+Utility chain (rms={Rms(buf, frames):0.0000})");engine.StopTransport();+// ============================ Nota Delay ====================================+Console.WriteLine("-- Nota Delay --");+{+ using var de = new NotaEngine();+ de.SetBpm(120); de.SetTimeSignature(4, 4);+ int dt = de.AddInstrumentTrack();+ de.AddMidiClip(dt, 0.0, 4.0);+ de.SetClipNotes(dt, 0, new[] { new NotaNote(60, 0.0, 0.25, 1.0f) });+ int dd = de.AddBuiltinDevice(dt, 3);+ const int Sync = 0, TimeL = 1, TimeR = 2, DivL = 3, LinkLR = 5, Feedback = 6, PingPong = 8,+ Freeze = 11, DryWet = 12, Output = 13, DryLevel = 14, Diffuse = 15, LowCut = 16,+ HighCut = 17, TapeMode = 18, FadeChange = 19, WidthP = 20, BassMono = 21,+ WetOnly = 22, LatencyComp = 23;+ Check(dd >= 0 && de.TrackDeviceBuiltinKind(dt, dd) == 3, "add built-in Nota Delay (kind 3)");+ Check(de.DeviceParamName(dt, dd, DryLevel) == "Dry Level" && de.DeviceParamName(dt, dd, Diffuse) == "Diffuse"+ && de.DeviceParamName(dt, dd, LowCut) == "Low Cut" && de.DeviceParamName(dt, dd, HighCut) == "High Cut"+ && de.DeviceParamName(dt, dd, TapeMode) == "Tape Mode" && de.DeviceParamName(dt, dd, FadeChange) == "Fade on Change"+ && de.DeviceParamName(dt, dd, WidthP) == "Width" && de.DeviceParamName(dt, dd, BassMono) == "Bass Mono"+ && de.DeviceParamName(dt, dd, WetOnly) == "Wet Only" && de.DeviceParamName(dt, dd, LatencyComp) == "Latency Comp",+ "Delay names its appended params");+ de.DeviceSetParam(dt, dd, Diffuse, 0.62f);+ Check(Math.Abs(de.DeviceGetParam(dt, dd, Diffuse) - 0.62f) < 1e-4, "Delay param set/get round-trips");++ float[] Render(int frames = 40000)+ {+ var b = new float[frames * 2];+ de.Seek(0); de.Play(); de.RenderOffline(b, frames); de.StopTransport();+ return b;+ }+ static bool Finite(float[] b) { foreach (var s in b) if (!float.IsFinite(s) || Math.Abs(s) > 8f) return false; return true; }+ // Energy in the tail, well after the 0.25-beat note has ended — that is the repeats.+ static double TailRms(float[] b, int fromFrame)+ {+ double sum = 0; int n = 0;+ for (int i = fromFrame * 2; i < b.Length; i++) { sum += b[i] * b[i]; n++; }+ return n > 0 ? Math.Sqrt(sum / n) : 0;+ }++ // Free ms, wet only: the repeats are all that is left, and they keep coming.+ de.DeviceSetParam(dt, dd, Sync, 0f);+ de.DeviceSetParam(dt, dd, TimeL, 0.1f); // 200 ms+ de.DeviceSetParam(dt, dd, TimeR, 0.1f);+ de.DeviceSetParam(dt, dd, LinkLR, 1f);+ de.DeviceSetParam(dt, dd, Feedback, 0.6f);+ de.DeviceSetParam(dt, dd, WetOnly, 1f);+ var wet = Render();+ Check(Finite(wet) && TailRms(wet, 24000) > 1e-4, $"Delay repeats ring on after the note (tail rms {TailRms(wet, 24000):F4})");++ // The loop filters bite: a narrow band leaves less in the tail than the open band.+ de.DeviceSetParam(dt, dd, LowCut, 0.75f); // ~630 Hz+ de.DeviceSetParam(dt, dd, HighCut, 0.35f); // ~1 kHz+ var narrow = Render();+ Check(Finite(narrow) && TailRms(narrow, 24000) < TailRms(wet, 24000),+ $"Low/High Cut thin the repeats ({TailRms(narrow, 24000):F4} < {TailRms(wet, 24000):F4})");+ de.DeviceSetParam(dt, dd, LowCut, 0f); de.DeviceSetParam(dt, dd, HighCut, 1f);++ // Every character switch renders finite and audible.+ foreach (var (p, v, what) in new[] { (PingPong, 1f, "ping-pong"), (TapeMode, 1f, "tape mode"),+ (FadeChange, 0f, "repitch"), (Diffuse, 1f, "diffusion"),+ (WidthP, 1f, "width 200 %"), (BassMono, 0.6f, "bass mono") })+ {+ float was = de.DeviceGetParam(dt, dd, p);+ de.DeviceSetParam(dt, dd, p, v);+ var b = Render();+ Check(Finite(b) && TailRms(b, 24000) > 1e-5, $"Delay {what} renders finite + audible (tail rms {TailRms(b, 24000):F4})");+ de.DeviceSetParam(dt, dd, p, was);+ }++ // Freeze holds the loop instead of letting it decay, and Clear loop empties it.+ de.DeviceSetParam(dt, dd, Feedback, 0.3f);+ de.DeviceSetParam(dt, dd, Freeze, 1f);+ var held = Render(60000);+ double early = TailRms(held[..(30000 * 2)], 20000), late = TailRms(held, 50000);+ Check(Finite(held) && late > early * 0.5, $"Freeze holds the loop instead of decaying (late {late:F4} vs early {early:F4})");+ de.DeviceAction(dt, dd, 0, 0, 0); // Clear loop+ var cleared = new float[8000 * 2];+ de.RenderOffline(cleared, 8000); // transport stopped: nothing new goes in+ Check(Rms(cleared, 8000) < 1e-4, $"Clear loop empties the delay buffer (rms {Rms(cleared, 8000):F5})");+ de.DeviceSetParam(dt, dd, Freeze, 0f);+ de.DeviceSetParam(dt, dd, WetOnly, 0f);++ // Dry Level and Output are real trims on the dry path.+ de.DeviceSetParam(dt, dd, DryWet, 0f);+ de.DeviceSetParam(dt, dd, Output, 0.5f);+ de.DeviceSetParam(dt, dd, DryLevel, 0.70711f);+ float unity = Rms(Render(8000), 8000);+ de.DeviceSetParam(dt, dd, DryLevel, 0f);+ float silent = Rms(Render(8000), 8000);+ Check(unity > 1e-3 && silent < unity * 0.05f, $"Dry Level trims the dry path ({silent:F4} vs {unity:F4})");+ de.DeviceSetParam(dt, dd, DryLevel, 0.70711f);++ // Latency Comp shortens the loop by the diffuser's group delay — a different signal.+ de.DeviceSetParam(dt, dd, DryWet, 1f);+ de.DeviceSetParam(dt, dd, Diffuse, 0.8f);+ de.DeviceSetParam(dt, dd, LatencyComp, 1f);+ var comped = Render(20000);+ de.DeviceSetParam(dt, dd, LatencyComp, 0f);+ var raw = Render(20000);+ double diff = 0; for (int i = 0; i < raw.Length; i++) { double d = comped[i] - raw[i]; diff += d * d; }+ Check(Finite(comped) && Finite(raw) && Math.Sqrt(diff / raw.Length) > 1e-5, "Latency Comp moves the repeats");+ de.DeviceSetParam(dt, dd, LatencyComp, 1f);++ // Telemetry + the MCP status line.+ var sc = new float[11];+ de.DeviceSetParam(dt, dd, Sync, 1f); de.DeviceSetParam(dt, dd, DivL, 2f / 7f);+ Render(20000);+ int scn = de.DeviceScope(dt, dd, sc, sc.Length);+ Check(scn == 11 && sc[4] > 1000 && sc[5] > 1, $"Delay scope reports sample rate + tempo ({sc[4]:0} Hz, {sc[5]:0.0} BPM)");+ string text = de.DeviceText(dt, dd, 0);+ Check(text.Contains("1/8"), $"Delay status text names the division (got '{text}')");++ // Clone: duplicating the track keeps the appended params.+ de.DeviceSetParam(dt, dd, Diffuse, 0.44f);+ int t2 = de.DuplicateTrack(dt);+ int dd2 = de.TrackDeviceCount(t2) - 1;+ Check(t2 > 0 && Math.Abs(de.DeviceGetParam(t2, dd2, Diffuse) - 0.44f) < 1e-4, "duplicate track clones the Delay's params");++ // Automation: a device-param lane drives Feedback.+ int lane = de.AddAutomationLane(dt, AutomationTarget.DeviceParam, dd, Feedback);+ Check(lane >= 0, "add Delay Feedback automation lane");+ de.SetAutomationPoints(dt, lane, new[] { new AutomationPoint(0.0, 0.1f), new AutomationPoint(2.0, 0.85f) });+ var ab = new float[4096 * 2];+ de.Seek(1.99); de.Play(); de.RenderOffline(ab, 4096); de.StopTransport();+ Check(de.DeviceGetParam(dt, dd, Feedback) > 0.7f, $"automation drives Delay Feedback ({de.DeviceGetParam(dt, dd, Feedback):F2})");+}+// ============================ Nota Crush ====================================Console.WriteLine("-- Nota Crush --");{