Skip to content

armgit / nota

Public Imported from GitHub
0

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

Add Nota Pentad, a 5-voice Prophet-5-style polyphonic synth

Egor Khindikaynen83ae0d720918
diff --git a/BUILD.md b/BUILD.md
index 123ad081..2a148521 100644
--- a/BUILD.md
+++ b/BUILD.md
@@ -66,6 +66,18 @@ build directory and place it next to the binary: `libnota_engine.dylib` +
On memory-constrained machines and containers, cap parallelism so the large JUCE
translation units are not OOM-killed: `export CMAKE_BUILD_PARALLEL_LEVEL=2`.
+### Nota Pentad as a standalone VST3 (optional)
+
+For checking the Pentad synth in another host, the same DSP (`src/Pentad.h`) also builds
+as a VST3 with JUCE's generic editor. It is off by default and not part of the app:
+
+```bash
+cmake -G Ninja -S src/native/nota.engine -B build-pentad -DCMAKE_BUILD_TYPE=Release \
+ -DNOTA_BUILD_PENTAD_VST3=ON
+cmake --build build-pentad --target NotaPentad_VST3
+# → build-pentad/NotaPentad_artefacts/Release/VST3/Nota Pentad.vst3
+```
+
## Building on Windows (x64)
### Requirements
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 74d10994..d7d60de3 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,6 +19,29 @@ Entry categories: `Added`, `Changed`, `Fixed`, `Removed`.
## [Unreleased]
### Added
+- **Nota Pentad — a 5-voice polyphonic synth (Prophet-5).** A new built-in instrument
+ (kind 14) modelled on the Prophet-5 Rev 3: Osc A (saw and pulse together, hard sync to
+ B) and Osc B (saw, triangle, pulse; Lo-Freq mode; keyboard tracking off), white/pink
+ noise, a mixer that overdrives the filter, a 24 dB/oct resonant low-pass that
+ self-oscillates as a clean sine and follows the keyboard (off / ½ / full or any amount),
+ and filter and amplifier envelopes with analog curves that retrigger from their current
+ level. **Poly-Mod** routes the filter envelope and Osc B — at audio rate, for FM, PWM and
+ sync sweeps — to Osc A frequency, Osc A pulse width and the cutoff; **Wheel-Mod** mixes
+ the LFO (saw/triangle/square, free or tempo-synced) with noise. 5, 10 or 16 voices with
+ round-robin or oldest-note stealing (a 4 ms fade, no clicks), Poly / Unison / Mono,
+ unison stacks with detune, glide (off / on / legato), the Release switch, velocity and
+ aftertouch amounts, pitch-bend range up to ±12. **Vintage Drift** gives every voice its
+ own pitch, cutoff and envelope spread plus slow drift, from a seed saved with the
+ project, so the same patch always renders the same way and a freeze matches playback
+ exactly. Band-limited oscillators and ×2/×4 oversampling keep aliasing below -80 dB.
+ A card editor (Wheels column, Oscillators / Filter · Amp / Poly Mod and Mixer / Output
+ tabs, a voice-activity strip, meters, a Voice setup flyout), 40 factory presets, and full
+ automation, MIDI learn, persistence and MCP support. It also builds as a standalone VST3
+ (`-DNOTA_BUILD_PENTAD_VST3=ON`) for testing in other hosts.
+- **Fine knob adjustment.** Hold ⌘ or ⇧ (Ctrl on Windows and Linux) while dragging a device
+ knob to change its value in steps ten times finer.
+- **MCP: `set_instrument_param_by_id`** sets an instrument parameter by its stable id
+ rather than by index.
- **Freeze and Live Freeze from the track's context menu.** Right-clicking a track header in
the arrangement now offers the whole freeze workflow, not just the Devices panel buttons:
**Freeze track** and **Live Freeze** on a live track; **Unfreeze track** and **Flatten to
@@ -29,6 +52,8 @@ Entry categories: `Added`, `Changed`, `Fixed`, `Removed`.
always jumps to the source, where the notes and devices live.
### Fixed
+- **Preferences: the end of long sections can be scrolled into view.** The last rows of
+ the Shortcuts list sat below the window's edge.
- **Deleting one half of a live-freeze pair no longer leaves the other half stuck.** If the
frozen track is deleted (or undone away), its source wakes up and plays again. If the
source is deleted, the frozen audio becomes an ordinary track, and if you were in the middle
diff --git a/FEATURES.md b/FEATURES.md
index 53fbfae3..d2c33462 100644
--- a/FEATURES.md
+++ b/FEATURES.md
@@ -210,6 +210,14 @@ and user presets, automation, persistence and cloning.
hats, clap, rim, tom, perc), a 16-step sequencer (locked to the transport), 4 pattern
banks (A–D), accents, per-step velocity, Swing/Humanize, and a per-voice **Sample** mode
(load your own one-shot). Six factory kits (808/909/Trap/House/Lo-Fi/Techno).
+- **Nota Pentad** — 5-voice analog poly in the Prophet-5 mould: Osc A (saw + pulse, hard
+ sync) and Osc B (saw + triangle + pulse, Lo-Freq, keyboard off), noise, a 24 dB/oct
+ resonant filter that self-oscillates and tracks the keyboard, two analog-curve ADSRs,
+ **Poly-Mod** (filter envelope and Osc B at audio rate → Osc A freq / PW / cutoff),
+ Wheel-Mod (LFO ↔ noise), 5/10/16 voices, round-robin or oldest-note stealing,
+ Poly/Unison/Mono, poly unison stacks, glide, the Release switch, and **Vintage Drift**
+ (seeded per-voice spread — a render is identical for the same seed, so freezing is
+ exact). 40 factory presets. Also builds as a standalone VST3 for other hosts.
### Audio effects
- **Nota EQ-8** (kind 0) — 8-band parametric.
@@ -396,7 +404,7 @@ Coverage:
- **Transport**: play/stop, tempo, time signature, loop, metronome.
- **Project**: `get_overview` (a full snapshot).
- **Tracks**: add and remove, volume/pan/mute/solo, groups, sends.
-- **Instruments**: add by kind, read and write parameters.
+- **Instruments**: add by kind, read and write parameters (by index or by stable id).
- **Audio effects**: add, remove, reorder, bypass, parameters.
- **MIDI clips and notes**: piano roll — add a clip, read/write/append/clear notes, move
and split.
diff --git a/src/managed/Nota.App/Controls/Knob.cs b/src/managed/Nota.App/Controls/Knob.cs
index 0597cb2f..73e6a2b6 100644
--- a/src/managed/Nota.App/Controls/Knob.cs
+++ b/src/managed/Nota.App/Controls/Knob.cs
@@ -3,7 +3,7 @@
//
// A rotary knob for device / instrument parameters (mockup style): a faint ring,
// a brass value arc over a 270° sweep, and a pointer line. Drag vertically to
-// change (up = increase). Same public API as MiniFader (Value / max / Accent /
+// change (up = increase; Ctrl/⌘/Shift = fine), double-click resets. Same public API as MiniFader (Value / max / Accent /
// ValueChanged / GestureBegin / GestureEnd) so it drops into the plugin editors.
using System;
@@ -93,7 +93,10 @@ public sealed class Knob : Control
double dy = _lastY - y; // up = increase
_lastY = y;
if (dy == 0) return;
- double v = Math.Clamp(_value + dy / 140.0 * _max, 0, _max);
+ // Fine adjust: hold Ctrl (Windows/Linux), ⌘ or Shift — 10× finer (macOS turns
+ // Ctrl+click into a right-click, so Cmd/Shift cover it there).
+ bool fine = (e.KeyModifiers & (KeyModifiers.Control | KeyModifiers.Meta | KeyModifiers.Shift)) != 0;
+ double v = Math.Clamp(_value + dy / (fine ? 1400.0 : 140.0) * _max, 0, _max);
if (Math.Abs(v - _value) < 1e-6) return;
_value = v;
InvalidateVisual();
diff --git a/src/managed/Nota.App/Controls/PentadViews.cs b/src/managed/Nota.App/Controls/PentadViews.cs
new file mode 100644
index 00000000..74b3bcab
--- /dev/null
+++ b/src/managed/Nota.App/Controls/PentadViews.cs
@@ -0,0 +1,243 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.
+//
+// Custom-drawn views for the Nota Pentad editor card: waveform glyphs (saw / pulse /
+// triangle / square), the draggable 4-pole low-pass response, the ADSR curves (analog
+// RC shapes), the voice-activity strip and the level bars. Values are pushed in by the
+// card's refresh tick; the filter curve is the only one that edits (drag X = cutoff,
+// Y = resonance).
+
+using System;
+using System.Globalization;
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Input;
+using Avalonia.Media;
+
+namespace Nota.App;
+
+// 0 saw, 1 pulse, 2 triangle, 3 square.
+internal sealed class PentadWaveIcon : Control
+{
+ private readonly int _w;
+ public IBrush Stroke { get; set; } = NotaPalette.TextTertiary;
+ public PentadWaveIcon(int wave, double w = 14, double h = 7) { _w = wave; Width = w; Height = h; }
+
+ public override void Render(DrawingContext ctx)
+ {
+ double w = Bounds.Width, h = Bounds.Height, top = 0.8, bot = h - 0.8;
+ var g = new StreamGeometry();
+ using (var c = g.Open())
+ {
+ switch (_w)
+ {
+ case 0: // two saw teeth
+ c.BeginFigure(new Point(0, bot), false);
+ c.LineTo(new Point(w * 0.45, top)); c.LineTo(new Point(w * 0.45, bot)); c.LineTo(new Point(w * 0.9, top)); c.LineTo(new Point(w * 0.9, bot));
+ break;
+ case 1: // narrow-ish pulse
+ c.BeginFigure(new Point(0, bot), false);
+ c.LineTo(new Point(0, top)); c.LineTo(new Point(w * 0.4, top)); c.LineTo(new Point(w * 0.4, bot)); c.LineTo(new Point(w, bot));
+ break;
+ case 2: // triangle
+ c.BeginFigure(new Point(0, h / 2), false);
+ c.LineTo(new Point(w * 0.25, top)); c.LineTo(new Point(w * 0.75, bot)); c.LineTo(new Point(w, h / 2));
+ break;
+ default: // square
+ c.BeginFigure(new Point(0, bot), false);
+ c.LineTo(new Point(0, top)); c.LineTo(new Point(w * 0.5, top)); c.LineTo(new Point(w * 0.5, bot)); c.LineTo(new Point(w, bot)); c.LineTo(new Point(w, top));
+ break;
+ }
+ }
+ ctx.DrawGeometry(null, new Pen(Stroke, 1.4, lineJoin: PenLineJoin.Round), g);
+ }
+}
+
+// 24 dB/oct low-pass magnitude over 20 Hz..20 kHz (log X), with the resonant peak and the
+// CEM-style passband loss at high resonance (unless bass compensation is on). Drag to edit.
+internal sealed class PentadFilterCurve : Control
+{
+ private static readonly IBrush Grid = NotaPalette.SurfaceCard;
+ private static readonly IBrush Fill = new SolidColorBrush(Color.FromArgb(0x1E, 0xD8, 0xA0, 0x3D));
+ private static readonly Typeface Mono = new("ui-monospace, monospace");
+ private double _cut = 0.5, _reso, _comp;
+ private bool _drag;
+
+ public Action<double, double>? Changed; // (cutoffNorm, resoNorm) while dragging
+ public event Action? DragStarted;
+ public event Action? DragEnded;
+
+ public PentadFilterCurve() { Cursor = new Cursor(StandardCursorType.Hand); ClipToBounds = true; }
+
+ public void Set(double cutoffNorm, double resoNorm, bool bassComp) { _cut = cutoffNorm; _reso = resoNorm; _comp = bassComp ? 1 : 0; }
+
+ private void Apply(PointerEventArgs e)
+ {
+ double w = Bounds.Width, h = Bounds.Height; if (w <= 0 || h <= 0) return;
+ var p = e.GetPosition(this);
+ _cut = Math.Clamp(p.X / w, 0, 1);
+ _reso = Math.Clamp(1 - p.Y / h, 0, 1);
+ Changed?.Invoke(_cut, _reso); InvalidateVisual();
+ }
+ protected override void OnPointerPressed(PointerPressedEventArgs e)
+ { base.OnPointerPressed(e); if (!e.GetCurrentPoint(this).Properties.IsLeftButtonPressed) return; _drag = true; DragStarted?.Invoke(); Apply(e); e.Pointer.Capture(this); 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) { _drag = false; DragEnded?.Invoke(); e.Pointer.Capture(null); } }
+
+ // dB at normalized x (0..1 across 20 Hz..20 kHz): 4 identical poles with feedback k.
+ private double Db(double x)
+ {
+ double k = 4.6 * _reso * 0.97; // stay just below the self-osc singularity
+ double wr = Math.Pow(1000, x - _cut); // ω / ωc
+ // H = G⁴ / (1 + k G⁴), G = 1 / (1 + j wr); input scaled by (1 + comp k).
+ double re = 1, im = wr; // 1 + j wr
+ // (1 + j wr)^4
+ double r2 = re * re - im * im, i2 = 2 * re * im;
+ double r4 = r2 * r2 - i2 * i2, i4 = 2 * r2 * i2;
+ double dr = r4 + k, di = i4; // (1 + j wr)^4 + k
+ double mag = (1 + _comp * k) / Math.Sqrt(dr * dr + di * di);
+ return 20 * Math.Log10(Math.Max(mag, 1e-6));
+ }
+
+ public override void Render(DrawingContext ctx)
+ {
+ double w = Bounds.Width, h = Bounds.Height;
+ if (w < 2 || h < 2) return;
+ ctx.FillRectangle(Brushes.Transparent, new Rect(0, 0, w, h));
+ var gp = new Pen(Grid, 1);
+ foreach (double hz in new[] { 100.0, 1000.0, 10000.0 }) { double gx = Math.Log10(hz / 20) / 3 * w; ctx.DrawLine(gp, new Point(gx, 0), new Point(gx, h)); }
+ double y0 = h * 0.38; // 0 dB line
+ ctx.DrawLine(gp, new Point(0, y0), new Point(w, y0));
+ double Y(double db) => Math.Clamp(y0 - db * (h * 0.018), 1, h - 1);
+
+ var line = new StreamGeometry(); var fill = new StreamGeometry();
+ using (var lc = line.Open())
+ using (var fc = fill.Open())
+ {
+ lc.BeginFigure(new Point(0, Y(Db(0))), false);
+ fc.BeginFigure(new Point(0, h), true);
+ fc.LineTo(new Point(0, Y(Db(0))));
+ for (double x = 1; x <= w; x += 1.5) { var p = new Point(x, Y(Db(x / w))); lc.LineTo(p); fc.LineTo(p); }
+ fc.LineTo(new Point(w, h));
+ }
+ ctx.DrawGeometry(Fill, null, fill);
+ ctx.DrawGeometry(null, new Pen(NotaPalette.Accent, 1.5), line);
+
+ double hz0 = 20 * Math.Pow(1000, _cut);
+ string txt = (hz0 >= 1000 ? $"{hz0 / 1000:0.00} kHz" : $"{hz0:0} Hz") + $" · Q {_reso * 10:0.0}";
+ var ft = new FormattedText(txt, CultureInfo.InvariantCulture, FlowDirection.LeftToRight, Mono, 7, NotaPalette.AccentBright);
+ ctx.DrawText(ft, new Point(w - ft.Width - 4, 3));
+
+ double hx = Math.Clamp(_cut * w, 4, w - 4), hy = Math.Clamp(Y(Db(_cut)), 4, h - 4);
+ ctx.DrawEllipse(NotaPalette.AccentBright, new Pen(NotaPalette.BgSunken, 2), new Point(hx, hy), 3.5, 3.5);
+ }
+}
+
+// ADSR with RC curves: attack charges toward an overshoot (concave), decay/release discharge.
+internal sealed class PentadEnvCurve : Control
+{
+ private double _a, _d, _s = 0.8, _r = 0.4;
+ public IBrush Accent { get; set; } = NotaPalette.Accent;
+ public PentadEnvCurve() { ClipToBounds = true; }
+
+ public void Set(double a, double d, double s, double r) { _a = a; _d = d; _s = s; _r = r; }
+
+ public override void Render(DrawingContext ctx)
+ {
+ double w = Bounds.Width, h = Bounds.Height;
+ if (w < 2 || h < 2) return;
+ double top = 3, bot = h - 2, span = bot - top;
+ double wa = w * (0.03 + 0.24 * _a), wd = w * (0.04 + 0.24 * _d), wr = w * (0.04 + 0.24 * _r);
+ double ws = Math.Max(w * 0.08, w - wa - wd - wr);
+ double xa = wa, xd = xa + wd, xs = xd + ws;
+ double Lv(double v) => bot - span * v;
+ var line = new StreamGeometry(); var fill = new StreamGeometry();
+ void Path(StreamGeometryContext c, bool closed)
+ {
+ c.BeginFigure(new Point(0, bot), closed);
+ const int n = 14;
+ for (int i = 1; i <= n; i++) { double t = i / (double)n; double v = (1 - Math.Exp(-t * 1.47)) / (1 - Math.Exp(-1.47)); c.LineTo(new Point(xa * t, Lv(v))); }
+ for (int i = 1; i <= n; i++) { double t = i / (double)n; double v = _s + (1 - _s) * Math.Exp(-t * 4); c.LineTo(new Point(xa + wd * t, Lv(v))); }
+ c.LineTo(new Point(xs, Lv(_s)));
+ for (int i = 1; i <= n; i++) { double t = i / (double)n; double v = _s * Math.Exp(-t * 4); c.LineTo(new Point(xs + wr * t, Lv(v))); }
+ c.LineTo(new Point(w, bot));
+ }
+ using (var lc = line.Open()) Path(lc, false);
+ using (var fc = fill.Open()) Path(fc, true);
+ var col = ((ISolidColorBrush)Accent).Color;
+ ctx.DrawGeometry(new SolidColorBrush(Color.FromArgb(0x1F, col.R, col.G, col.B)), null, fill);
+ ctx.DrawGeometry(null, new Pen(Accent, 1.4), line);
+ }
+}
+
+// N voice cells, lit (brass) while a voice sounds, brightness following its level.
+internal sealed class PentadVoiceStrip : Control
+{
+ private static readonly Typeface Mono = new("ui-monospace, monospace");
+ private readonly float[] _lv = new float[16];
+ private int _n = 5;
+
+ public void Set(int count, ReadOnlySpan<float> levels)
+ {
+ _n = Math.Clamp(count, 1, 16);
+ for (int i = 0; i < 16; i++) _lv[i] = i < levels.Length ? levels[i] : 0f;
+ InvalidateVisual();
+ }
+
+ public override void Render(DrawingContext ctx)
+ {
+ double w = Bounds.Width, h = Bounds.Height;
+ if (w < 2 || h < 2) return;
+ const double gap = 3;
+ double cw = Math.Min(h, (w - gap * (_n - 1)) / _n);
+ double x0 = w - (cw * _n + gap * (_n - 1)); // right-aligned
+ var off = new Pen(NotaPalette.BorderDefault, 1);
+ var on = new Pen(NotaPalette.Accent, 1);
+ var ac = NotaPalette.AccentColor;
+ for (int i = 0; i < _n; i++)
+ {
+ var r = new Rect(x0 + i * (cw + gap) + 0.5, (h - cw) / 2 + 0.5, cw - 1, cw - 1);
+ float lv = _lv[i];
+ bool lit = lv > 0.0005f;
+ byte a = (byte)(lit ? 0x22 + (int)(Math.Clamp(lv, 0f, 1f) * 0x40) : 0);
+ ctx.DrawRectangle(lit ? new SolidColorBrush(Color.FromArgb(a, ac.R, ac.G, ac.B)) : NotaPalette.BgSunken, lit ? on : off, r, 3, 3);
+ if (cw >= 12)
+ {
+ var ft = new FormattedText((i + 1).ToString(CultureInfo.InvariantCulture), CultureInfo.InvariantCulture, FlowDirection.LeftToRight, Mono, 7, lit ? NotaPalette.AccentBright : NotaPalette.TextDisabled);
+ ctx.DrawText(ft, new Point(r.X + (r.Width - ft.Width) / 2, r.Y + (r.Height - ft.Height) / 2));
+ }
+ }
+ }
+}
+
+// A level bar in dBFS (−48..+3): green, amber above −6 dB. Vertical or horizontal.
+internal sealed class PentadLevelBar : Control
+{
+ private double _db = -100;
+ public bool Vertical { get; init; }
+ public void SetLinear(double peak) { _db = peak > 1e-6 ? 20 * Math.Log10(peak) : -100; InvalidateVisual(); }
+
+ public override void Render(DrawingContext ctx)
+ {
+ double w = Bounds.Width, h = Bounds.Height;
+ if (w < 2 || h < 2) return;
+ ctx.DrawRectangle(NotaPalette.BgSunken, null, new Rect(0, 0, w, h), 2, 2);
+ static double Frac(double db) => Math.Clamp((db + 48) / 51.0, 0, 1);
+ double f = Frac(_db), fw = Frac(-6);
+ if (f <= 0) return;
+ if (Vertical)
+ {
+ double ih = h - 2;
+ double gTop = h - 1 - ih * Math.Min(f, fw);
+ ctx.FillRectangle(NotaPalette.Success, new Rect(1, gTop, w - 2, h - 1 - gTop));
+ if (f > fw) ctx.FillRectangle(NotaPalette.Warning, new Rect(1, h - 1 - ih * f, w - 2, ih * (f - fw)));
+ }
+ else
+ {
+ double iw = w;
+ ctx.FillRectangle(NotaPalette.Success, new Rect(0, 0, iw * Math.Min(f, fw), h));
+ if (f > fw) ctx.FillRectangle(NotaPalette.Warning, new Rect(iw * fw, 0, iw * (f - fw), h));
+ }
+ }
+}
diff --git a/src/managed/Nota.App/DeviceCards/IInstrumentCard.cs b/src/managed/Nota.App/DeviceCards/IInstrumentCard.cs
index ad809904..8239bbe6 100644
--- a/src/managed/Nota.App/DeviceCards/IInstrumentCard.cs
+++ b/src/managed/Nota.App/DeviceCards/IInstrumentCard.cs
@@ -24,4 +24,8 @@ internal interface IInstrumentCard
/// <summary>Card width when wrapped by the shared shell (bodies keep their natural
/// width; the chrome is what's unified). Only used when BodyOnly.</summary>
double CardWidth => 700;
+
+ /// <summary>Voice readout for the shell header (e.g. "3/5"), or null for the default
+ /// "active/16". Called on the live-refresh tick. Only used when BodyOnly.</summary>
+ string? VoiceLabel(Nota.Application.IAudioEngine engine, int trackId, int active) => null;
}
diff --git a/src/managed/Nota.App/DeviceCards/InstrumentCardFactory.cs b/src/managed/Nota.App/DeviceCards/InstrumentCardFactory.cs
index f76d3836..e959771e 100644
--- a/src/managed/Nota.App/DeviceCards/InstrumentCardFactory.cs
+++ b/src/managed/Nota.App/DeviceCards/InstrumentCardFactory.cs
@@ -26,6 +26,7 @@ internal sealed class InstrumentCardFactory
[11] = new FluxInstrumentCard(),
[12] = new RhythmInstrumentCard(),
[13] = new MonolithInstrumentCard(),
+ [14] = new PentadInstrumentCard(),
};
/// <summary>Resolve the editor for a built-in instrument kind. The Sampler (1) always
diff --git a/src/managed/Nota.App/DeviceCards/Instruments/PentadInstrumentCard.cs b/src/managed/Nota.App/DeviceCards/Instruments/PentadInstrumentCard.cs
new file mode 100644
index 00000000..287b8698
--- /dev/null
+++ b/src/managed/Nota.App/DeviceCards/Instruments/PentadInstrumentCard.cs
@@ -0,0 +1,669 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.
+//
+// Detail · Devices — built-in Nota Pentad editor (instrument kind 14), a build of the
+// "Nota Pentad" mockup (700×260) on the same frame as Monolith: an always-visible WHEELS
+// column (pitch / mod), a centre tabbed panel (Oscillators / Filter · Amp / Poly Mod), a
+// right tabbed panel (Mixer / Output) and a status strip with the Voice setup flyout
+// (polyphony, allocation, oversampling, vintage seed …). The five-voice activity strip and
+// the output meters read the instrument's scope telemetry. Every control is a plugin-param,
+// so automation / MIDI learn / presets / persistence come for free. BodyOnly — the shared
+// shell draws the header (name / preset / A-B / meter).
+
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Controls.Primitives;
+using Avalonia.Input;
+using Avalonia.Layout;
+using Avalonia.Media;
+using Avalonia.Threading;
+using Nota.Application;
+using static Nota.App.DeviceCardKit;
+
+namespace Nota.App;
+
+internal sealed class PentadInstrumentCard : IInstrumentCard
+{
+ private static readonly IBrush RailBg = new SolidColorBrush(Color.Parse("#1B1916"));
+ private static readonly IBrush Panel = NotaPalette.BgApp;
+ private static readonly IBrush Border2 = NotaPalette.BorderDefault;
+ private static readonly IBrush BorderIn = new SolidColorBrush(Color.Parse("#221F1A"));
+ private static readonly IBrush Inset = NotaPalette.BgSunken;
+ private static readonly IBrush TabBg = NotaPalette.SurfaceCard;
+ private static readonly IBrush Amber = NotaPalette.Accent;
+ private static readonly IBrush AmberLit = NotaPalette.AccentBright;
+ private static readonly IBrush TealC = NotaPalette.Teal;
+ private static readonly IBrush TxtC = NotaPalette.TextPrimary;
+ private static readonly IBrush Txt2 = NotaPalette.TextSecondary;
+ private static readonly IBrush MutedC = NotaPalette.TextTertiary;
+ private static readonly IBrush DimC = NotaPalette.TextDisabled;
+ private static readonly IBrush Handle = NotaPalette.TextSecondary;
+ private static readonly IBrush OffPill = NotaPalette.SurfaceRaised;
+ private static readonly IBrush AmberSubtle = NotaPalette.AccentSubtle;
+
+ private static readonly string[] Feet = { "32′", "16′", "8′", "4′" };
+ private static readonly string[] SyncNames = { "8 bar", "4 bar", "2 bar", "1 bar", "1/2", "1/4.", "1/4", "1/8.", "1/4T", "1/8", "1/8T", "1/16", "1/16T", "1/32" };
+
+ public bool BodyOnly => true;
+ public string Subtitle => "ANALOG POLY";
+
+ public string? VoiceLabel(IAudioEngine engine, int trackId, int active)
+ {
+ int n = engine.PluginParamCount(trackId, -1);
+ for (int i = 0; i < n; i++)
+ if (engine.PluginParamId(trackId, -1, i) == "polyphony")
+ return $"{Math.Max(0, active)}/{Poly(engine.PluginParamGet(trackId, -1, i))}";
+ return null;
+ }
+
+ private static int Poly(float v) => v < 0.25f ? 5 : v < 0.75f ? 10 : 16;
+
+ public Control Build(DeviceCardContext ctx)
+ {
+ var engine = ctx.Engine;
+ int track = ctx.TrackId;
+ int pc = engine.PluginParamCount(track, -1);
+ var idx = new Dictionary<string, int>();
+ for (int i = 0; i < pc; i++) idx[engine.PluginParamId(track, -1, i)] = i;
+ float G(string id) => idx.TryGetValue(id, out var i) ? engine.PluginParamGet(track, -1, i) : 0f;
+ int I(string id) => idx.TryGetValue(id, out var i) ? i : -1;
+ bool On(string id) => G(id) > 0.5f;
+ int Sel(string id, int n) => Math.Clamp((int)Math.Round(G(id) * (n - 1)), 0, n - 1);
+ // A discrete edit (click) is one automation gesture, so Touch/Latch/Write record it.
+ void SetP(string id, float v)
+ {
+ if (I(id) is not (var i and >= 0)) return;
+ engine.BeginAutomationWrite(track, AutomationTarget.PluginParam, -1, -1, id);
+ engine.PluginParamSet(track, -1, i, Math.Clamp(v, 0f, 1f));
+ engine.EndAutomationWrite(track, AutomationTarget.PluginParam, -1, -1, id);
+ }
+
+ var readouts = new List<Action>();
+ var scope = new float[32];
+ var filtCurve = new PentadFilterCurve();
+ var fEnvCurve = new PentadEnvCurve { Accent = Amber };
+ var aEnvCurve = new PentadEnvCurve { Accent = TealC };
+ var voiceStrips = new List<PentadVoiceStrip>();
+ var meterL = new PentadLevelBar { Vertical = true, Width = 11, Height = 56 };
+ var meterR = new PentadLevelBar { Vertical = true, Width = 11, Height = 56 };
+ var sumBar = new PentadLevelBar { Height = 4, VerticalAlignment = VerticalAlignment.Center };
+ var sumTxt = MonoText("", 8, TxtC);
+ var voiceCountTxt = MonoText("", 7, Txt2);
+ int scN = 0;
+
+ void Refresh()
+ {
+ filtCurve.Set(G("cutoff"), G("reso"), On("lowcomp")); filtCurve.InvalidateVisual();
+ fEnvCurve.Set(G("fattack"), G("fdecay"), G("fsustain"), G("frelease")); fEnvCurve.InvalidateVisual();
+ aEnvCurve.Set(G("aattack"), G("adecay"), G("asustain"), On("releaseon") ? G("arelease") : 0); aEnvCurve.InvalidateVisual();
+ scN = engine.InstrumentScope(track, scope);
+ if (scN >= 24)
+ {
+ int poly = (int)scope[0];
+ foreach (var vs in voiceStrips) vs.Set(poly, scope.AsSpan(8, 16));
+ meterL.SetLinear(scope[2]); meterR.SetLinear(scope[3]);
+ sumBar.SetLinear(scope[4] * 0.6);
+ sumTxt.Text = scope[4] > 1e-4 ? $"{20 * Math.Log10(scope[4] * 0.6):0.0}" : "−∞";
+ voiceCountTxt.Text = $"{(int)scope[1]} / {poly}";
+ }
+ foreach (var a in readouts) a();
+ }
+
+ // ---- small builders --------------------------------------------------------
+ static TextBlock Lbl(string t, double fs, IBrush c, FontWeight w = FontWeight.Bold)
+ => new() { Text = t, FontSize = fs, FontWeight = w, Foreground = c, VerticalAlignment = VerticalAlignment.Center };
+ static TextBlock Caps(string t) => new() { Text = t, FontSize = 7, FontWeight = FontWeight.Bold, Foreground = MutedC, VerticalAlignment = VerticalAlignment.Center, LetterSpacing = 0.8 };
+ static TextBlock MonoText(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 Control Docked(Control c, Dock d) { DockPanel.SetDock(c, d); return c; }
+ static Control Col(Control c, int col) { Grid.SetColumn(c, col); return c; }
+ static Border Divider(Control child, double top = 5) => new() { BorderBrush = BorderIn, BorderThickness = new Thickness(0, 1, 0, 0), Padding = new Thickness(0, top, 0, 0), Child = child };
+
+ Control K(string id, string name, Func<float, string> fmt, bool mod = false, double sz = 26, double cw = 40)
+ => InstrumentControls.InstKnob(ctx, idx, id, name, Refresh, fmt, sz, cw, mod ? TealC : null);
+
+ // On/off pill toggle backed by a param (> 0.5 = on).
+ Control Toggle(string id, string label, List<Action>? into = null)
+ {
+ var pill = new Border { Width = 18, Height = 10, CornerRadius = new CornerRadius(5), VerticalAlignment = VerticalAlignment.Center };
+ var dot = new Border { Width = 7, Height = 7, CornerRadius = new CornerRadius(4) };
+ var host = new Canvas { Width = 18, Height = 10 }; Canvas.SetTop(dot, 1.5); host.Children.Add(dot); pill.Child = host;
+ var txt = new TextBlock { Text = label, FontSize = 8, Foreground = MutedC, VerticalAlignment = VerticalAlignment.Center };
+ void Hi() { bool on = On(id); pill.Background = on ? Amber : OffPill; dot.Background = on ? Panel : MutedC; Canvas.SetLeft(dot, on ? 9.5 : 1.5); txt.Foreground = on ? TxtC : Txt2; }
+ var wrap = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 5, VerticalAlignment = VerticalAlignment.Center, Background = Brushes.Transparent, Cursor = new Cursor(StandardCursorType.Hand), Children = { pill } };
+ if (label.Length > 0) wrap.Children.Add(txt);
+ wrap.PointerPressed += (_, e) => { if (!e.GetCurrentPoint(wrap).Properties.IsLeftButtonPressed) return; SetP(id, On(id) ? 0f : 1f); Refresh(); e.Handled = true; };
+ (into ?? readouts).Add(Hi); Hi();
+ if (I(id) is var pi and >= 0) MidiLearn.Bind(wrap, MidiTarget.PluginParam(track, -1, pi), label.Length > 0 ? label : id);
+ return wrap;
+ }
+
+ // Segmented chips. values[i] is written on click; the lit chip is the nearest value.
+ Control Chips(string id, string[] names, float[]? values = null, List<Action>? into = null, double fs = 7)
+ {
+ int n = names.Length;
+ values ??= BuildValues(n);
+ var arr = new Border[n];
+ void Hi()
+ {
+ float cur = G(id); int best = 0;
+ for (int i = 1; i < n; i++) if (Math.Abs(values[i] - cur) < Math.Abs(values[best] - cur)) best = i;
+ bool exact = Math.Abs(values[best] - cur) < 0.02f;
+ for (int i = 0; i < n; i++)
+ {
+ bool on = i == best && exact;
+ arr[i].Background = on ? Amber : Brushes.Transparent;
+ var tb = (TextBlock)arr[i].Child!; tb.Foreground = on ? Panel : MutedC; tb.FontWeight = on ? FontWeight.SemiBold : FontWeight.Normal;
+ }
+ }
+ var row = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 1 };
+ for (int i = 0; i < n; i++)
+ {
+ int iv = i;
+ var c = new Border { CornerRadius = new CornerRadius(2), Padding = new Thickness(4, 0), Cursor = new Cursor(StandardCursorType.Hand), Child = new TextBlock { Text = names[i], FontSize = fs, Foreground = MutedC } };
+ c.PointerPressed += (_, e) => { SetP(id, values[iv]); Refresh(); e.Handled = true; };
+ arr[i] = c; row.Children.Add(c);
+ }
+ (into ?? readouts).Add(Hi); Hi();
+ var seg = new Border { Background = Inset, BorderBrush = Border2, BorderThickness = new Thickness(1), CornerRadius = new CornerRadius(3), Padding = new Thickness(1), VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Left, Child = row };
+ if (I(id) is var pi and >= 0) MidiLearn.Bind(seg, MidiTarget.PluginParam(track, -1, pi), id);
+ return seg;
+ }
+ static float[] BuildValues(int n) { var v = new float[n]; for (int i = 0; i < n; i++) v[i] = n > 1 ? i / (float)(n - 1) : 0f; return v; }
+
+ // Waveform on/off chip (the P5's independent, summable wave switches).
+ Control WaveChip(string id, int wave, double w = 22, double h = 16)
+ {
+ var ic = new PentadWaveIcon(wave) { HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center };
+ var b = new Border { Width = w, Height = h, BorderThickness = new Thickness(1), CornerRadius = new CornerRadius(3), Cursor = new Cursor(StandardCursorType.Hand), Child = ic };
+ void Hi() { bool on = On(id); b.Background = on ? AmberSubtle : Brushes.Transparent; b.BorderBrush = on ? Amber : NotaPalette.BorderStrong; ic.Stroke = on ? AmberLit : MutedC; ic.InvalidateVisual(); }
+ b.PointerPressed += (_, e) => { SetP(id, On(id) ? 0f : 1f); Refresh(); e.Handled = true; };
+ readouts.Add(Hi); Hi();
+ if (I(id) is var pi and >= 0) MidiLearn.Bind(b, MidiTarget.PluginParam(track, -1, pi), id);
+ return b;
+ }
+
+ // Horizontal fill slider bound to a param; `dim` greys it out (inactive route).
+ Control HSlider(string id, Func<double, string> fmt, double valW = 24, Func<bool>? dim = null, List<Action>? into = null)
+ {
+ int pi = I(id);
+ var fill = new Border { Height = 3, Background = Amber, CornerRadius = new CornerRadius(2), HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Center };
+ var handle = new Border { Width = 6, Height = 7, Background = Handle, CornerRadius = new CornerRadius(2) };
+ var lay = new Canvas { Height = 9 };
+ lay.Children.Add(handle); Canvas.SetTop(handle, 1);
+ var canvas = new Panel { Height = 11, MinWidth = 24, Background = Brushes.Transparent, Cursor = new Cursor(StandardCursorType.Hand), Children = {
+ new Border { Height = 3, Background = Inset, CornerRadius = new CornerRadius(2), VerticalAlignment = VerticalAlignment.Center }, fill, lay } };
+ var val = MonoText("", 8, TxtC); val.MinWidth = valW; val.TextAlignment = TextAlignment.Right;
+ bool drag = false;
+ void Vis(double v)
+ {
+ double w = canvas.Bounds.Width; if (w <= 0) w = 80;
+ fill.Width = Math.Max(0, v * w); Canvas.SetLeft(handle, v * w - 3); val.Text = fmt(v);
+ bool d = dim?.Invoke() ?? false;
+ fill.Background = d ? NotaPalette.BorderStrong : Amber; handle.Background = d ? MutedC : Handle; val.Foreground = d ? Txt2 : TxtC;
+ }
+ void From(PointerEventArgs e) { double w = canvas.Bounds.Width; double v = w > 0 ? Math.Clamp(e.GetPosition(canvas).X / w, 0, 1) : 0; if (pi >= 0) engine.PluginParamSet(track, -1, pi, (float)v); Vis(v); Refresh(); }
+ canvas.PointerPressed += (_, e) =>
+ {
+ if (!e.GetCurrentPoint(canvas).Properties.IsLeftButtonPressed) return;
+ if (e.ClickCount == 2 && pi >= 0) { SetP(id, engine.InstrumentParamDefault(track, pi)); Refresh(); e.Handled = true; return; }
+ drag = true; if (pi >= 0) engine.BeginAutomationWrite(track, AutomationTarget.PluginParam, -1, -1, id); e.Pointer.Capture(canvas); From(e); e.Handled = true;
+ };
+ canvas.PointerMoved += (_, e) => { if (drag) From(e); };
+ canvas.PointerReleased += (_, e) => { if (drag) { drag = false; if (pi >= 0) engine.EndAutomationWrite(track, AutomationTarget.PluginParam, -1, -1, id); e.Pointer.Capture(null); } };
+ canvas.SizeChanged += (_, _) => Vis(G(id));
+ (into ?? readouts).Add(() => { if (!drag) Vis(G(id)); });
+ var grid = new Grid { ColumnDefinitions = new ColumnDefinitions("*,Auto"), ColumnSpacing = 5, VerticalAlignment = VerticalAlignment.Center };
+ grid.Children.Add(canvas); grid.Children.Add(Col(val, 1));
+ if (pi >= 0) MidiLearn.Bind(grid, MidiTarget.PluginParam(track, -1, pi), id);
+ return grid;
+ }
+ // Label + slider on one grid row.
+ Control SliderRow(string label, string id, Func<double, string> fmt, double labW = 38, double valW = 24, Func<bool>? dim = null, List<Action>? into = null)
+ {
+ var g = new Grid { ColumnDefinitions = new ColumnDefinitions($"{labW},*"), VerticalAlignment = VerticalAlignment.Center };
+ g.Children.Add(Caps(label)); g.Children.Add(Col(HSlider(id, fmt, valW, dim, into), 1));
+ return g;
+ }
+
+ // Vertical wheel bound to a param (pitch springs back to centre).
+ Control VWheel(string id, string name, Func<double, string> fmt, IBrush lit, bool spring)
+ {
+ int pi = I(id);
+ var grad = new LinearGradientBrush { StartPoint = new RelativePoint(0, 0, RelativeUnit.Relative), EndPoint = new RelativePoint(0, 1, RelativeUnit.Relative),
+ GradientStops = { new GradientStop(Color.Parse("#26231E"), 0), new GradientStop(Color.Parse("#100F0D"), 0.5), new GradientStop(Color.Parse("#26231E"), 1) } };
+ var bar = new Border { Width = 16, Background = grad, BorderBrush = Border2, BorderThickness = new Thickness(1), CornerRadius = new CornerRadius(8), VerticalAlignment = VerticalAlignment.Stretch };
+ var mark = new Border { Height = 2, Width = 12, Background = lit, CornerRadius = new CornerRadius(1) };
+ var lay = new Canvas { Width = 16 };
+ lay.Children.Add(mark); Canvas.SetLeft(mark, 2);
+ var host = new Panel { Width = 16, VerticalAlignment = VerticalAlignment.Stretch, Background = Brushes.Transparent, Cursor = new Cursor(StandardCursorType.SizeNorthSouth), Children = { bar, lay } };
+ bool drag = false; DispatcherTimer? springT = null;
+ void Vis(double v) { double h = host.Bounds.Height; if (h <= 0) h = 90; Canvas.SetTop(mark, (1 - v) * (h - 2)); }
+ void From(PointerEventArgs e) { double h = host.Bounds.Height; double v = h > 0 ? Math.Clamp(1 - e.GetPosition(host).Y / h, 0, 1) : 0.5; if (pi >= 0) engine.PluginParamSet(track, -1, pi, (float)v); Vis(v); Refresh(); }
+ void Spring()
+ {
+ springT?.Stop();
+ springT = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(16) };
+ springT.Tick += (_, _) =>
+ {
+ double v = G(id); v += (0.5 - v) * 0.32;
+ if (Math.Abs(v - 0.5) < 0.002) { v = 0.5; springT!.Stop(); }
+ if (pi >= 0) engine.PluginParamSet(track, -1, pi, (float)v); Vis(v); Refresh();
+ };
+ springT.Start();
+ }
+ host.PointerPressed += (_, e) => { springT?.Stop(); drag = true; if (pi >= 0) engine.BeginAutomationWrite(track, AutomationTarget.PluginParam, -1, -1, id); e.Pointer.Capture(host); From(e); };
+ host.PointerMoved += (_, e) => { if (drag) From(e); };
+ host.PointerReleased += (_, e) => { if (drag) { drag = false; if (pi >= 0) engine.EndAutomationWrite(track, AutomationTarget.PluginParam, -1, -1, id); e.Pointer.Capture(null); if (spring) Spring(); } };
+ host.SizeChanged += (_, _) => Vis(G(id));
+ var nm = new TextBlock { Text = name, FontSize = 7, FontWeight = FontWeight.Bold, Foreground = MutedC, HorizontalAlignment = HorizontalAlignment.Center };
+ readouts.Add(() => { if (!drag) Vis(G(id)); bool live = Math.Abs(G(id) - (spring ? 0.5f : 0f)) > 0.01f; nm.Foreground = live ? AmberLit : MutedC; });
+ var col = new DockPanel { HorizontalAlignment = HorizontalAlignment.Center };
+ DockPanel.SetDock(nm, Avalonia.Controls.Dock.Bottom);
+ col.Children.Add(nm); col.Children.Add(host);
+ if (pi >= 0) MidiLearn.Bind(col, MidiTarget.PluginParam(track, -1, pi), name);
+ return col;
+ }
+
+ // ---- formatters -------------------------------------------------------------
+ static double Exp(double lo, double hi, double v) => lo * Math.Pow(hi / lo, Math.Clamp(v, 0, 1));
+ static string Time(double s) => s >= 1 ? $"{s:0.0} s" : s >= 0.0995 ? $"{s * 1000:0} ms" : $"{s * 1000:0.#} ms";
+ static string ShortTime(double s) => s >= 1 ? $"{s:0.0}s" : $"{s * 1000:0}ms";
+ string Atk(float v) => ShortTime(Exp(0.0005, 10, v));
+ string Dec(float v) => ShortTime(Exp(0.002, 15, v));
+ string Glide(double v) => v < 0.002 ? "off" : Time(Exp(0.005, 10, v));
+ string HzFmt(double hz) => hz >= 1000 ? $"{hz / 1000:0.00}k" : $"{hz:0}";
+ string Cut(float v) => HzFmt(20 * Math.Pow(1000, v));
+ static string Pct(double v) => $"{v * 100:0} %";
+ static string Tenths(double v) => $"{v * 10:0.0}";
+ string LfoRate(float v) => On("lfosync") ? SyncNames[Math.Clamp((int)Math.Round(v * 13), 0, 13)] : $"{Exp(0.05, 20, v):0.0#} Hz";
+ string VolDb(float v) { double g = 2 * v * v; return g <= 1e-4 ? "−∞" : $"{20 * Math.Log10(g):0.0} dB"; }
+ int BendSt() => 1 + Math.Clamp((int)Math.Round(G("bendrange") * 11), 0, 11);
+
+ // ======================================================================
+ // LEFT — wheels
+ // ======================================================================
+ var bendTxt = MonoText("", 7, AmberLit); var modTxt = MonoText("", 7, MutedC);
+ bendTxt.HorizontalAlignment = HorizontalAlignment.Center; modTxt.HorizontalAlignment = HorizontalAlignment.Center;
+ readouts.Add(() => { bendTxt.Text = $"±{BendSt()} st"; modTxt.Text = $"{G("modwheel") * 100:0} %"; modTxt.Foreground = G("modwheel") > 0.01f ? AmberLit : MutedC; });
+ var wheelsBody = new DockPanel { LastChildFill = true };
+ var wTitle = Caps("WHEELS"); wTitle.HorizontalAlignment = HorizontalAlignment.Center; wTitle.Margin = new Thickness(0, 0, 0, 4);
+ wheelsBody.Children.Add(Docked(wTitle, Avalonia.Controls.Dock.Top));
+ wheelsBody.Children.Add(Docked(modTxt, Avalonia.Controls.Dock.Bottom));
+ wheelsBody.Children.Add(Docked(bendTxt, Avalonia.Controls.Dock.Bottom));
+ wheelsBody.Children.Add(new StackPanel { Orientation = Orientation.Horizontal, Spacing = 8, HorizontalAlignment = HorizontalAlignment.Center, Margin = new Thickness(0, 0, 0, 3), Children = {
+ VWheel("bend", "PITCH", v => "", Amber, spring: true),
+ VWheel("modwheel", "MOD", v => "", AmberLit, spring: false) } });
+ var wheels = new Border { Width = 56, Background = Panel, BorderBrush = Border2, BorderThickness = new Thickness(1), CornerRadius = new CornerRadius(5), Padding = new Thickness(0, 5), Child = wheelsBody };
+ DockPanel.SetDock(wheels, Avalonia.Controls.Dock.Left);
+
+ // ======================================================================
+ // CENTRE — Oscillators
+ // ======================================================================
+ const string OscCols = "18,40,40,40,*,62";
+ Control Cell(Control c, int col, HorizontalAlignment ha = HorizontalAlignment.Center) { c.HorizontalAlignment = ha; c.VerticalAlignment = VerticalAlignment.Center; return Col(new Panel { Children = { c } }, col); }
+ Control OscRow(string o)
+ {
+ bool isA = o == "a";
+ string p = "o" + o;
+ var g = new Grid { ColumnDefinitions = new ColumnDefinitions(OscCols) };
+ g.Children.Add(Cell(Lbl(isA ? "A" : "B", 10, TxtC, FontWeight.SemiBold), 0, HorizontalAlignment.Left));
+ g.Children.Add(Cell(K($"{p}oct", "", v => Feet[Math.Clamp((int)Math.Round(v * 3), 0, 3)], false, 26, 40), 1));
+ g.Children.Add(Cell(K($"{p}semi", "", v => { int s = (int)Math.Round((v - 0.5f) * 24); return s == 0 ? "0 st" : $"{s:+0;-0} st"; }, false, 26, 40), 2));
+ g.Children.Add(Cell(K($"{p}fine", "", v => { double c = (v - 0.5) * 100; return Math.Abs(c) < 0.5 ? "0 c" : $"{c:+0;-0} c"; }, false, 26, 40), 3));
+ var chips = isA ? Row(3, WaveChip("oasaw", 0), WaveChip("oapulse", 1)) : Row(3, WaveChip("obsaw", 0), WaveChip("obtri", 2), WaveChip("obpulse", 1));
+ var pw = HSlider($"{p}pw", v => Pct(v), 30, () => !On($"{p}pulse"));
+ pw.Width = 110;
+ g.Children.Add(Cell(Row(6, chips, pw), 4));
+ Control opts = isA ? Toggle("oasync", "Sync")
+ : new StackPanel { Spacing = 4, VerticalAlignment = VerticalAlignment.Center, Children = { Toggle("oblofreq", "Lo freq"), Toggle("obkbd", "Kbd") } };
+ g.Children.Add(Cell(opts, 5, HorizontalAlignment.Right));
+ return new Border { BorderBrush = BorderIn, BorderThickness = new Thickness(0, 1, 0, 0), Child = g };
+ }
+ Control OscTab()
+ {
+ var hdr = new Grid { ColumnDefinitions = new ColumnDefinitions(OscCols), Height = 13 };
+ string[] h = { "OSC", "OCT", "SEMI", "FINE", "SHAPE · PULSE WIDTH", "OPTIONS" };
+ for (int i = 0; i < h.Length; i++)
+ {
+ var t = new TextBlock { Text = h[i], FontSize = 7, FontWeight = FontWeight.Bold, Foreground = DimC, LetterSpacing = 0.8, VerticalAlignment = VerticalAlignment.Center,
+ HorizontalAlignment = i == 0 ? HorizontalAlignment.Left : i == h.Length - 1 ? HorizontalAlignment.Right : HorizontalAlignment.Center };
+ hdr.Children.Add(Col(t, i));
+ }
+ // bottom row: glide · voice mode · voices
+ var glide = Row(4, K("glide", "GLIDE", v => Glide(v), false, 26, 44), Chips("glidemode", new[] { "Off", "On", "Leg" }));
+ var mode = Row(6, Caps("MODE"), Chips("voicemode", new[] { "Poly", "Uni", "Mono" }));
+ var strip = new PentadVoiceStrip { Width = 84, Height = 14 }; voiceStrips.Add(strip);
+ var voices = Row(6, Caps("VOICES"), strip);
+ var bottom = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,Auto,*,Auto"), ColumnSpacing = 14, Height = 50 };
+ bottom.Children.Add(glide); bottom.Children.Add(Col(mode, 1)); bottom.Children.Add(Col(voices, 3));
+ var rows = new Grid { RowDefinitions = new RowDefinitions("*,*") };
+ var rb = OscRow("b"); Grid.SetRow(rb, 1);
+ rows.Children.Add(OscRow("a")); rows.Children.Add(rb);
+ return new DockPanel { LastChildFill = true, Margin = new Thickness(6, 0, 6, 2), Children = {
+ Docked(hdr, Avalonia.Controls.Dock.Top),
+ Docked(new Border { BorderBrush = BorderIn, BorderThickness = new Thickness(0, 1, 0, 0), Padding = new Thickness(0, 2, 0, 0), Child = bottom }, Avalonia.Controls.Dock.Bottom),
+ rows } };
+ }
+
+ // ======================================================================
+ // CENTRE — Filter · Amp
+ // ======================================================================
+ Control FilterPanel()
+ {
+ filtCurve.Changed = (c, r) =>
+ {
+ if (I("cutoff") is var ci and >= 0) engine.PluginParamSet(track, -1, ci, (float)c);
+ if (I("reso") is var ri and >= 0) engine.PluginParamSet(track, -1, ri, (float)r);
+ Refresh();
+ };
+ filtCurve.DragStarted += () => { engine.BeginAutomationWrite(track, AutomationTarget.PluginParam, -1, -1, "cutoff"); engine.BeginAutomationWrite(track, AutomationTarget.PluginParam, -1, -1, "reso"); };
+ filtCurve.DragEnded += () => { engine.EndAutomationWrite(track, AutomationTarget.PluginParam, -1, -1, "cutoff"); engine.EndAutomationWrite(track, AutomationTarget.PluginParam, -1, -1, "reso"); };
+ var graph = new Border { Background = Inset, BorderBrush = BorderIn, BorderThickness = new Thickness(1), CornerRadius = new CornerRadius(4), Margin = new Thickness(0, 3, 0, 3), Child = filtCurve };
+ var keyPct = MonoText("", 7, Txt2);
+ readouts.Add(() => keyPct.Text = Pct(G("keytrk")));
+ var key = new StackPanel { Spacing = 3, VerticalAlignment = VerticalAlignment.Center, Children = { Caps("KEY TRK"), Chips("keytrk", new[] { "0", "½", "1" }), keyPct } };
+ var knobs = new Grid { ColumnDefinitions = new ColumnDefinitions("*,*,*,Auto") };
+ knobs.Children.Add(K("cutoff", "CUTOFF", Cut, false, 32, 44));
+ knobs.Children.Add(Col(K("reso", "RESON", v => Tenths(v), false, 32, 44), 1));
+ knobs.Children.Add(Col(K("fenvamt", "ENV AMT", v => Tenths(v), true, 32, 44), 2));
+ knobs.Children.Add(Col(key, 3));
+ var body = new DockPanel { LastChildFill = true, Children = { Docked(Caps("FILTER"), Avalonia.Controls.Dock.Top), Docked(knobs, Avalonia.Controls.Dock.Bottom), graph } };
+ return new Border { Width = 196, BorderBrush = BorderIn, BorderThickness = new Thickness(0, 0, 1, 0), Padding = new Thickness(7, 4), Child = body };
+ }
+ Control EnvPanel(string title, string pre, PentadEnvCurve curve, bool amp)
+ {
+ var times = MonoText("", 7, Txt2);
+ readouts.Add(() => times.Text = $"{Atk(G(pre + "attack"))} · {Dec(G(pre + "decay"))} · {G(pre + "sustain") * 100:0}% · {(On("releaseon") ? Dec(G(pre + "release")) : "min")}");
+ var head = new DockPanel { Height = 12, LastChildFill = false, Margin = new Thickness(0, 0, 0, 2) };
+ head.Children.Add(Docked(Caps(title), Avalonia.Controls.Dock.Left));
+ if (amp) head.Children.Add(Docked(Toggle("releaseon", "Rel"), Avalonia.Controls.Dock.Right));
+ head.Children.Add(Docked(new Border { Margin = new Thickness(6, 0), Child = times }, Avalonia.Controls.Dock.Right));
+ var graph = new Border { Background = Inset, BorderBrush = BorderIn, BorderThickness = new Thickness(1), CornerRadius = new CornerRadius(4), Child = curve };
+ var knobs = Row(0, K(pre + "attack", "A", Atk, amp, 24, 29), K(pre + "decay", "D", Dec, amp, 24, 29), K(pre + "sustain", "S", v => Pct(v), amp, 24, 29), K(pre + "release", "R", Dec, amp, 24, 29));
+ knobs.Margin = new Thickness(4, 0, 0, 0);
+ return new DockPanel { LastChildFill = true, Children = { Docked(head, Avalonia.Controls.Dock.Top), Docked(knobs, Avalonia.Controls.Dock.Right), graph } };
+ }
+ Control FilterAmpTab()
+ {
+ var envs = new Grid { RowDefinitions = new RowDefinitions("*,*"), Margin = new Thickness(7, 4) };
+ var fe = EnvPanel("FILTER ENV", "f", fEnvCurve, false);
+ var ae = Divider(EnvPanel("AMP ENV", "a", aEnvCurve, true), 4); ae.Margin = new Thickness(0, 4, 0, 0); Grid.SetRow(ae, 1);
+ envs.Children.Add(fe); envs.Children.Add(ae);
+ var g = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,*") };
+ g.Children.Add(FilterPanel()); g.Children.Add(Col(envs, 1));
+ return g;
+ }
+
+ // ======================================================================
+ // CENTRE — Poly Mod · LFO · Wheel Mod
+ // ======================================================================
+ string Dests()
+ {
+ var d = new List<string>();
+ if (On("pmfreqa")) d.Add("Freq A"); if (On("pmpwa")) d.Add("PW A"); if (On("pmfilter")) d.Add("Filter");
+ return d.Count == 0 ? "no dest" : string.Join(" + ", d);
+ }
+ int ActiveRoutes()
+ {
+ int dn = (On("pmfreqa") ? 1 : 0) + (On("pmpwa") ? 1 : 0) + (On("pmfilter") ? 1 : 0);
+ return dn * ((G("pmenv") > 0.001f ? 1 : 0) + (G("pmoscb") > 0.001f ? 1 : 0));
+ }
+ Control RouteRow(string src, string id, bool isPm, Func<string> dest, string? dimWhenZeroOf = null)
+ {
+ var srcT = new TextBlock { Text = src, FontSize = 8, Foreground = TxtC, Width = 58, VerticalAlignment = VerticalAlignment.Center };
+ var destT = new TextBlock { FontSize = 8, Foreground = TxtC, Width = 84, VerticalAlignment = VerticalAlignment.Center, TextTrimming = TextTrimming.CharacterEllipsis };
+ bool Dim() => G(id) < 0.001f || (isPm && !On("pmfreqa") && !On("pmpwa") && !On("pmfilter"));
+ readouts.Add(() => { destT.Text = dest(); bool d = Dim(); srcT.Foreground = d ? Txt2 : TxtC; destT.Foreground = d ? Txt2 : TxtC; });
+ var g = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,Auto,Auto,*"), ColumnSpacing = 6, Height = 18 };
+ g.Children.Add(srcT);
+ g.Children.Add(Col(new TextBlock { Text = "→", FontSize = 8, Foreground = DimC, VerticalAlignment = VerticalAlignment.Center }, 1));
+ g.Children.Add(Col(destT, 2));
+ g.Children.Add(Col(HSlider(id, v => Tenths(v), 26, Dim), 3));
+ return g;
+ }
+ Control PolyModTab()
+ {
+ var dests = Row(12, Caps("DEST"), Toggle("pmfreqa", "Osc A freq"), Toggle("pmpwa", "Osc A PW"), Toggle("pmfilter", "Filter cutoff"));
+ dests.Height = 18;
+ var vel = new Grid { ColumnDefinitions = new ColumnDefinitions("*,*"), ColumnSpacing = 12, Height = 18, Children = {
+ SliderRow("VEL → AMP", "velamp", v => Pct(v), 52, 30),
+ Col(SliderRow("VEL → FILT", "velfilt", v => Pct(v), 52, 30), 1) } };
+ var at = new Grid { ColumnDefinitions = new ColumnDefinitions("*,*"), ColumnSpacing = 12, Height = 18, Children = {
+ SliderRow("AT → CUT", "atcutoff", v => Pct(v), 52, 30),
+ Col(SliderRow("AT → LFO", "atlfo", v => Pct(v), 52, 30), 1) } };
+ var routes = new StackPanel { Spacing = 1, Children = {
+ RouteRow("Filter env", "pmenv", true, Dests),
+ RouteRow("Osc B", "pmoscb", true, Dests),
+ dests, vel, at } };
+
+ // LFO
+ var lfoWaves = Row(2, WaveChip("lfotri", 2, 20, 14), WaveChip("lfosaw", 0, 20, 14), WaveChip("lfosquare", 3, 20, 14));
+ var lfo = new StackPanel { Spacing = 2, Children = {
+ Caps("LFO"),
+ Row(4, K("lforate", "RATE", LfoRate, false, 28, 38), K("lfoamt", "AMOUNT", v => Pct(v), true, 28, 38),
+ new StackPanel { Spacing = 3, VerticalAlignment = VerticalAlignment.Center, Children = { lfoWaves, Chips("lfosync", new[] { "Free", "Sync" }) } }) } };
+ // Wheel mod
+ var wmGrid = new Grid { ColumnDefinitions = new ColumnDefinitions("*,*,*"), RowDefinitions = new RowDefinitions("Auto,Auto"), RowSpacing = 3, ColumnSpacing = 6 };
+ void W(string id, string l, int r, int c) { var t = Toggle(id, l); Grid.SetRow(t, r); Grid.SetColumn(t, c); wmGrid.Children.Add(t); }
+ W("wmfreqa", "Freq A", 0, 0); W("wmfreqb", "Freq B", 0, 1); W("wmfilter", "Filter", 0, 2);
+ W("wmpwa", "PW A", 1, 0); W("wmpwb", "PW B", 1, 1);
+ var mixRow = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,Auto,*,Auto"), ColumnSpacing = 5, Children = {
+ Caps("SOURCE"), Col(Lbl("LFO", 7, DimC, FontWeight.Normal), 1), Col(HSlider("wmmix", v => Pct(v), 26), 2), Col(Lbl("NOISE", 7, DimC, FontWeight.Normal), 3) } };
+ var wm = new StackPanel { Spacing = 3, Children = { Caps("WHEEL MOD — DESTINATIONS"), wmGrid, mixRow } };
+ var wmBox = new Border { BorderBrush = BorderIn, BorderThickness = new Thickness(1, 0, 0, 0), Padding = new Thickness(10, 0, 0, 0), Child = wm };
+ var bottom = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,*"), ColumnSpacing = 10, Children = { lfo, Col(wmBox, 1) } };
+
+ return new DockPanel { LastChildFill = true, Margin = new Thickness(8, 3, 8, 2), Children = {
+ Docked(Caps("POLY MOD — SOURCE → DESTINATION"), Avalonia.Controls.Dock.Top),
+ Docked(Divider(bottom, 4), Avalonia.Controls.Dock.Bottom),
+ new Border { Padding = new Thickness(0, 2, 0, 0), Child = routes } } };
+ }
+
+ // ======================================================================
+ // RIGHT — Mixer / Output
+ // ======================================================================
+ Control MixRow(string onId, string lvlId, string name)
+ {
+ var g = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,34,*"), ColumnSpacing = 6, VerticalAlignment = VerticalAlignment.Center };
+ g.Children.Add(Toggle(onId, ""));
+ g.Children.Add(Col(Caps(name), 1));
+ g.Children.Add(Col(HSlider(lvlId, v => Tenths(v), 20, () => !On(onId)), 2));
+ return g;
+ }
+ Control MixerTab()
+ {
+ bool UniOff() => G("voicemode") < 0.25f && G("unison") < 0.25f;
+ var noiseType = Chips("noisecolor", new[] { "White", "Pink" }); noiseType.Margin = new Thickness(24, 0, 0, 0);
+ var uni = Row(6, new TextBlock { Text = "UNISON", FontSize = 7, FontWeight = FontWeight.Bold, Foreground = MutedC, Width = 38, VerticalAlignment = VerticalAlignment.Center }, Chips("unison", new[] { "Off", "×2", "×5" }));
+ var det = SliderRow("DETUNE", "unidetune", v => $"{v * 50:0} c", 38, 26, UniOff);
+ var sum = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,*,Auto"), ColumnSpacing = 6, Children = { Caps("SUM"), Col(sumBar, 1), Col(sumTxt, 2) } };
+ var g = new Grid { RowDefinitions = new RowDefinitions("*,*,*,*,Auto,*,*,*") };
+ Control[] rows = { MixRow("mixaon", "mixa", "OSC A"), MixRow("mixbon", "mixb", "OSC B"), MixRow("mixnoiseon", "mixnoise", "NOISE"), noiseType,
+ new Border { Height = 1, Background = BorderIn, Margin = new Thickness(0, 3) }, uni, det, sum };
+ for (int r = 0; r < rows.Length; r++) { rows[r].VerticalAlignment = r == 4 ? VerticalAlignment.Center : VerticalAlignment.Center; Grid.SetRow(rows[r], r); g.Children.Add(rows[r]); }
+ return new Border { Padding = new Thickness(6, 4), Child = g };
+ }
+ Control OutputTab()
+ {
+ var scale = new Grid { RowDefinitions = new RowDefinitions("*,*,*"), Height = 56, Children = {
+ MonoText("0", 7, DimC), WithRow(MonoText("−12", 7, DimC), 1), WithRow(MonoText("−48", 7, DimC), 2) } };
+ var meters = Row(4, new StackPanel { Spacing = 2, Children = { meterL, Center(Lbl("L", 7, MutedC, FontWeight.Normal)) } },
+ new StackPanel { Spacing = 2, Children = { meterR, Center(Lbl("R", 7, MutedC, FontWeight.Normal)) } }, scale);
+ meters.VerticalAlignment = VerticalAlignment.Top;
+ var top = Row(10, K("volume", "VOLUME", VolDb, false, 40, 54), meters);
+ var bend = Row(6, new TextBlock { Text = "BEND", FontSize = 7, FontWeight = FontWeight.Bold, Foreground = MutedC, Width = 38, VerticalAlignment = VerticalAlignment.Center },
+ Chips("bendrange", new[] { "2", "5", "7", "12" }, new[] { 1 / 11f, 4 / 11f, 6 / 11f, 1f }), Lbl("st", 7, MutedC, FontWeight.Normal));
+ var velF = new Border { Background = Brushes.Transparent, Cursor = new Cursor(StandardCursorType.Hand) };
+ { // Velocity → filter: a quick switch over the Velocity Filter amount (0 ↔ 50 %).
+ var pill = new Border { Width = 18, Height = 10, CornerRadius = new CornerRadius(5) };
+ var dot = new Border { Width = 7, Height = 7, CornerRadius = new CornerRadius(4) };
+ var host = new Canvas { Width = 18, Height = 10 }; Canvas.SetTop(dot, 1.5); host.Children.Add(dot); pill.Child = host;
+ var tx = new TextBlock { Text = "Velocity → filter", FontSize = 8, VerticalAlignment = VerticalAlignment.Center };
+ velF.Child = Row(5, pill, tx);
+ void Hi() { bool on = G("velfilt") > 0.001f; pill.Background = on ? Amber : OffPill; dot.Background = on ? Panel : MutedC; Canvas.SetLeft(dot, on ? 9.5 : 1.5); tx.Foreground = on ? TxtC : Txt2; }
+ velF.PointerPressed += (_, e) => { SetP("velfilt", G("velfilt") > 0.001f ? 0f : 0.5f); Refresh(); e.Handled = true; };
+ readouts.Add(Hi); Hi();
+ }
+ var strip = new PentadVoiceStrip { Width = 90, Height = 14 }; voiceStrips.Add(strip);
+ var voices = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,Auto,*"), ColumnSpacing = 6, Children = { Caps("VOICES"), Col(strip, 1), Col(Right(voiceCountTxt), 2) } };
+ var body = new DockPanel { LastChildFill = false, Children = {
+ Docked(top, Avalonia.Controls.Dock.Top),
+ Docked(Divider(new StackPanel { Spacing = 6, Children = { SliderRow("SPREAD", "spread", v => Pct(v), 38, 30), bend, velF } }), Avalonia.Controls.Dock.Top),
+ Docked(Divider(voices), Avalonia.Controls.Dock.Bottom) } };
+ ((Control)body.Children[1]).Margin = new Thickness(0, 6, 0, 0);
+ return new Border { Padding = new Thickness(6, 4), Child = body };
+ }
+ static Control WithRow(Control c, int r) { Grid.SetRow(c, r); return c; }
+ static Control Center(Control c) { c.HorizontalAlignment = HorizontalAlignment.Center; return c; }
+ static Control Right(Control c) { c.HorizontalAlignment = HorizontalAlignment.Right; return c; }
+
+ // ======================================================================
+ // Tab frames + extras
+ // ======================================================================
+ var centreHost = new ContentControl();
+ var rightHost = new ContentControl();
+ var extrasHost = new ContentControl { VerticalAlignment = VerticalAlignment.Center };
+ var tabBodies = new Control?[3]; var rightBodies = new Control?[2];
+ int centreTab = 0;
+
+ // Drift slider + seed re-roll (Oscillators tab bar)
+ var reroll = new Border { Padding = new Thickness(3, 0), CornerRadius = new CornerRadius(3), Background = OffPill, Cursor = new Cursor(StandardCursorType.Hand), VerticalAlignment = VerticalAlignment.Center,
+ Child = new TextBlock { Text = "⟳", FontSize = 9, Foreground = Txt2 } };
+ ToolTip.SetTip(reroll, "Re-roll the vintage seed (new per-voice spread)");
+ reroll.PointerPressed += (_, e) => { SetP("seed", (float)Random.Shared.NextDouble()); Refresh(); e.Handled = true; };
+ var driftSl = HSlider("drift", v => $"{v * 100:0}%", 22); driftSl.Width = 76;
+ Control[] extras = {
+ Row(5, Caps("DRIFT"), driftSl, reroll),
+ MonoText("4-pole LP · 24 dB/oct", 7, MutedC),
+ MonoText("", 7, MutedC) };
+ readouts.Add(() => { if (extras[2] is TextBlock t) { int n = ActiveRoutes(); t.Text = $"per voice · {n} active route{(n == 1 ? "" : "s")}"; } });
+
+ Control CentreBody(int t) => tabBodies[t] ??= t switch { 1 => FilterAmpTab(), 2 => PolyModTab(), _ => OscTab() };
+ Control RightBody(int t) => rightBodies[t] ??= t == 1 ? OutputTab() : MixerTab();
+
+ var statusLeft = new TextBlock { FontSize = 8, Foreground = Txt2, VerticalAlignment = VerticalAlignment.Center, TextTrimming = TextTrimming.CharacterEllipsis };
+ var centre = TabFrame(new[] { "Oscillators", "Filter · Amp", "Poly Mod" }, centreHost, CentreBody, false, t => { centreTab = t; extrasHost.Content = extras[t]; Refresh(); }, extrasHost);
+ var rightFrame = TabFrame(new[] { "Mixer", "Output" }, rightHost, RightBody, true, null, null);
+ var right = new Border { Width = 186, Background = Panel, BorderBrush = Border2, BorderThickness = new Thickness(1), CornerRadius = new CornerRadius(5), Child = rightFrame };
+ DockPanel.SetDock(right, Avalonia.Controls.Dock.Right);
+ var centreBox = new Border { Background = Panel, BorderBrush = Border2, BorderThickness = new Thickness(1), CornerRadius = new CornerRadius(5), Margin = new Thickness(5, 0), Child = centre };
+
+ // ======================================================================
+ // Status strip + Voice setup flyout
+ // ======================================================================
+ string StatusText()
+ {
+ int poly = Poly(G("polyphony"));
+ string modeS = Sel("voicemode", 3) switch { 1 => $"Unison ×{poly}", 2 => "Mono", _ => $"Poly {poly}" };
+ int busy = scN >= 2 ? (int)scope[1] : 0;
+ return centreTab switch
+ {
+ 1 => $"Filter env → cutoff {G("fenvamt") * 10:0.0} · key tracking {KeyName(G("keytrk"))}{(G("velfilt") > 0.001f ? " · velocity → filter" : "")}{(On("lowcomp") ? " · bass comp" : "")}",
+ 2 => $"Poly Mod: {ActiveRoutes()} route{(ActiveRoutes() == 1 ? "" : "s")} · LFO {LfoRate(G("lforate"))} {LfoShape()} · unison {(G("unison") < 0.25f ? "off" : G("unison") < 0.75f ? "×2" : "×5")}, detune {G("unidetune") * 50:0} c",
+ _ => $"{modeS} · {busy} voice{(busy == 1 ? "" : "s")} busy · glide {Glide(G("glide"))} · drift {G("drift") * 100:0} %",
+ };
+ }
+ static string KeyName(float v) => Math.Abs(v - 0.5f) < 0.02f ? "½" : Math.Abs(v - 1f) < 0.02f ? "full" : v < 0.02f ? "off" : $"{v * 100:0} %";
+ string LfoShape()
+ {
+ var s = new List<string>();
+ if (On("lfotri")) s.Add("tri"); if (On("lfosaw")) s.Add("saw"); if (On("lfosquare")) s.Add("square");
+ return s.Count == 0 ? "(no wave)" : string.Join("+", s);
+ }
+ var statusRight = MonoText("", 8, Txt2);
+ readouts.Add(() =>
+ {
+ statusLeft.Text = StatusText();
+ if (scN >= 8) statusRight.Text = $"{scope[7] / 1000:0.#} kHz · ×{(int)scope[6]} OS · CPU {scope[5] * 100:0.0} %";
+ });
+
+ var flyReadouts = new List<Action>();
+ Flyout? setupFly = null;
+ Control SetupPanel()
+ {
+ var seedTxt = MonoText("", 8, TxtC);
+ flyReadouts.Add(() => seedTxt.Text = $"#{(int)Math.Round(G("seed") * 16777215):X6}");
+ var rr = new Border { Padding = new Thickness(6, 1), CornerRadius = new CornerRadius(3), Background = OffPill, Cursor = new Cursor(StandardCursorType.Hand), Child = new TextBlock { Text = "Re-roll", FontSize = 8, Foreground = TxtC } };
+ rr.PointerPressed += (_, e) => { SetP("seed", (float)Random.Shared.NextDouble()); Refresh(); foreach (var a in flyReadouts) a(); e.Handled = true; };
+ Control R(string label, Control c) { var g = new Grid { ColumnDefinitions = new ColumnDefinitions("92,*"), Height = 20 }; g.Children.Add(Caps(label)); c.HorizontalAlignment = HorizontalAlignment.Left; g.Children.Add(Col(c, 1)); return g; }
+ var tune = HSlider("tune", v => { double c = (v - 0.5) * 200; return Math.Abs(c) < 0.5 ? "0 c" : $"{c:+0;-0} c"; }, 30, null, flyReadouts); tune.Width = 130;
+ var at = HSlider("aftertouch", v => Pct(v), 30, null, flyReadouts); at.Width = 130;
+ var p = new StackPanel { Spacing = 2, Width = 250, Children = {
+ Lbl("VOICE SETUP", 9, TxtC),
+ new Border { Height = 4 },
+ R("VOICES", Chips("polyphony", new[] { "5", "10", "16" }, null, flyReadouts, 8)),
+ R("ALLOCATION", Chips("alloc", new[] { "Rotate", "Oldest" }, null, flyReadouts, 8)),
+ R("GLIDE", Chips("glidemode", new[] { "Off", "On", "Legato" }, null, flyReadouts, 8)),
+ R("RELEASE", Toggle("releaseon", "Release switch", flyReadouts)),
+ R("OVERSAMPLING", Chips("oversample", new[] { "×2", "×4" }, null, flyReadouts, 8)),
+ R("BASS COMP", Toggle("lowcomp", "Restore lows at high Q", flyReadouts)),
+ R("NOISE FLOOR", Toggle("noisefloor", "−100 dBFS hiss", flyReadouts)),
+ R("VINTAGE SEED", Row(8, seedTxt, rr)),
+ R("MASTER TUNE", tune),
+ R("AFTERTOUCH", at) } };
+ return new Border { Padding = new Thickness(4, 2), Child = p };
+ }
+ var voiceBtn = new Border { Height = 14, Padding = new Thickness(6, 0), CornerRadius = new CornerRadius(3), Background = OffPill, Cursor = new Cursor(StandardCursorType.Hand), VerticalAlignment = VerticalAlignment.Center,
+ Child = new TextBlock { Text = "Voice ▾", FontSize = 8, Foreground = TxtC, VerticalAlignment = VerticalAlignment.Center } };
+ ToolTip.SetTip(voiceBtn, "Voice setup: polyphony, allocation, glide mode, oversampling, vintage seed");
+ voiceBtn.PointerPressed += (_, e) =>
+ {
+ setupFly ??= new Flyout { Content = SetupPanel(), Placement = PlacementMode.TopEdgeAlignedRight };
+ foreach (var a in flyReadouts) a();
+ setupFly.ShowAt(voiceBtn);
+ e.Handled = true;
+ };
+ readouts.Add(() => { if (setupFly?.IsOpen == true) foreach (var a in flyReadouts) a(); });
+
+ var statusGrid = new Grid { ColumnDefinitions = new ColumnDefinitions("*,Auto,Auto"), ColumnSpacing = 8 };
+ statusGrid.Children.Add(statusLeft); statusGrid.Children.Add(Col(voiceBtn, 1)); statusGrid.Children.Add(Col(statusRight, 2));
+ var status = new Border { Height = 18, Background = Inset, BorderBrush = Border2, BorderThickness = new Thickness(0, 1, 0, 0), Padding = new Thickness(8, 0), Child = statusGrid };
+ DockPanel.SetDock(status, Avalonia.Controls.Dock.Bottom);
+
+ // ---- assemble ---------------------------------------------------------------
+ var bodyRow = new DockPanel { LastChildFill = true, Margin = new Thickness(5), Children = { wheels, right, centreBox } };
+ var root = new DockPanel { LastChildFill = true, Background = RailBg, Children = { status, bodyRow } };
+
+ ctx.SetInstLiveViz(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 ? TabBg : Brushes.Transparent; btns[i].BorderBrush = on ? Amber : Brushes.Transparent;
+ var tb = (TextBlock)btns[i].Child!; tb.Foreground = on ? AmberLit : MutedC; tb.FontWeight = on ? FontWeight.SemiBold : FontWeight.Normal;
+ }
+ }
+ var bar = centered ? (Panel)new UniformGrid { Rows = 1 } : new StackPanel { Orientation = Orientation.Horizontal };
+ for (int i = 0; i < tabs.Length; i++)
+ {
+ int iv = i;
+ var b = new Border { Padding = new Thickness(9, 0), BorderThickness = new Thickness(0, 0, 0, 2), BorderBrush = Brushes.Transparent, Cursor = new Cursor(StandardCursorType.Hand),
+ Child = new TextBlock { Text = tabs[i], FontSize = 9, Foreground = MutedC, VerticalAlignment = VerticalAlignment.Center, HorizontalAlignment = HorizontalAlignment.Center } };
+ b.PointerPressed += (_, _) => { sel = iv; Hi(); host.Content = body(iv); changed?.Invoke(iv); };
+ btns[i] = b; bar.Children.Add(b);
+ }
+ var barDock = new DockPanel { Height = 20, LastChildFill = centered };
+ if (extrasCtl != null) { var ex = new Border { Padding = new Thickness(0, 0, 8, 0), Child = extrasCtl }; DockPanel.SetDock(ex, Avalonia.Controls.Dock.Right); barDock.Children.Add(ex); }
+ if (!centered) DockPanel.SetDock(bar, Avalonia.Controls.Dock.Left);
+ barDock.Children.Add(bar);
+ var barBorder = new Border { BorderBrush = Border2, BorderThickness = new Thickness(0, 0, 0, 1), Child = barDock };
+ DockPanel.SetDock(barBorder, Avalonia.Controls.Dock.Top);
+ Hi(); host.Content = body(sel); changed?.Invoke(sel);
+ return new DockPanel { LastChildFill = true, Children = { barBorder, host } };
+ }
+ }
+}
diff --git a/src/managed/Nota.App/DeviceCards/Rack/RackCardView.cs b/src/managed/Nota.App/DeviceCards/Rack/RackCardView.cs
index e196237b..81c1347b 100644
--- a/src/managed/Nota.App/DeviceCards/Rack/RackCardView.cs
+++ b/src/managed/Nota.App/DeviceCards/Rack/RackCardView.cs
@@ -504,7 +504,7 @@ internal sealed class RackCardView(DeviceCardContext ctx)
var f = new MenuFlyout();
void Add(string h, int k) { var mi = new MenuItem { Header = h }; mi.Click += (_, _) => { int c = a.AddChain(k); if (c >= 0) Sel = c; _ctx.RequestRebuild(); }; f.Items.Add(mi); }
Add("Nota Synth", 0); Add("Nota Sampler", 1); Add("Nota Physical", 2); Add("Nota Aurora", 5);
- Add("Nota Volt", 6); Add("Nota Bass", 7); Add("Nota Pendulum", 8); Add("Nota Operator", 9); Add("Nota Grain", 10); Add("Nota Flux", 11); Add("Nota Monolith", 13);
+ Add("Nota Volt", 6); Add("Nota Bass", 7); Add("Nota Pendulum", 8); Add("Nota Operator", 9); Add("Nota Grain", 10); Add("Nota Flux", 11); Add("Nota Monolith", 13); Add("Nota Pentad", 14);
f.ShowAt(anchor, showAtPointer: true);
}
@@ -1739,7 +1739,9 @@ internal sealed class RackCardView(DeviceCardContext ctx)
fl.Click += (_, _) => { a.AddChain(11); _ctx.RequestRebuild(); };
var mo = new MenuItem { Header = "Nota Monolith" };
mo.Click += (_, _) => { a.AddChain(13); _ctx.RequestRebuild(); };
- f.Items.Add(s); f.Items.Add(p); f.Items.Add(w); f.Items.Add(vo); f.Items.Add(ba); f.Items.Add(pe); f.Items.Add(op); f.Items.Add(gr); f.Items.Add(fl); f.Items.Add(mo);
+ var pd = new MenuItem { Header = "Nota Pentad" };
+ pd.Click += (_, _) => { a.AddChain(14); _ctx.RequestRebuild(); };
+ f.Items.Add(s); f.Items.Add(p); f.Items.Add(w); f.Items.Add(vo); f.Items.Add(ba); f.Items.Add(pe); f.Items.Add(op); f.Items.Add(gr); f.Items.Add(fl); f.Items.Add(mo); f.Items.Add(pd);
f.ShowAt(b, showAtPointer: true);
};
return b;
@@ -1905,6 +1907,7 @@ internal sealed class RackCardView(DeviceCardContext ctx)
Add("Nota Grain", 10);
Add("Nota Flux", 11);
Add("Nota Monolith", 13);
+ Add("Nota Pentad", 14);
f.ShowAt(anchor, showAtPointer: true);
}
diff --git a/src/managed/Nota.App/DeviceChainView.Instruments.cs b/src/managed/Nota.App/DeviceChainView.Instruments.cs
index 3c3ceb55..460608a8 100644
--- a/src/managed/Nota.App/DeviceChainView.Instruments.cs
+++ b/src/managed/Nota.App/DeviceChainView.Instruments.cs
@@ -27,7 +27,8 @@ public sealed partial class DeviceChainView
var spec = new ShellSpec(
Name: _engine.DeviceName(_trackId, -1), Subtitle: strategy.Subtitle, DeviceIndex: -1, Count: 1,
Bypassed: false, Bypassable: false, CanMove: false, CanDelete: false,
- PresetKind: kind, IsInstrument: true, Width: strategy.CardWidth, Kind: ChainKind.Instrument);
+ PresetKind: kind, IsInstrument: true, Width: strategy.CardWidth, Kind: ChainKind.Instrument,
+ VoiceLabel: strategy.VoiceLabel);
return BuildCardShell(spec, body);
}
diff --git a/src/managed/Nota.App/DeviceChainView.Shell.cs b/src/managed/Nota.App/DeviceChainView.Shell.cs
index b156a489..adb413ed 100644
--- a/src/managed/Nota.App/DeviceChainView.Shell.cs
+++ b/src/managed/Nota.App/DeviceChainView.Shell.cs
@@ -57,7 +57,8 @@ public sealed partial class DeviceChainView
internal readonly record struct ShellSpec(
string Name, string Subtitle, int DeviceIndex, int Count, bool Bypassed, bool Bypassable,
- bool CanMove, bool CanDelete, int PresetKind, bool IsInstrument, double Width, ChainKind Kind);
+ bool CanMove, bool CanDelete, int PresetKind, bool IsInstrument, double Width, ChainKind Kind,
+ Func<Nota.Application.IAudioEngine, int, int, string?>? VoiceLabel = null);
// Small tertiary caption / mono readout helpers.
private static TextBlock Caps(string t, double fs = 9) => new() { Text = t, FontSize = fs, FontWeight = FontWeight.Bold, Foreground = TextTertiary, VerticalAlignment = VerticalAlignment.Center };
@@ -89,7 +90,7 @@ public sealed partial class DeviceChainView
if (s.IsInstrument && _engine.InstrumentVoiceCount(_trackId) >= 0)
{
var vt = Mono("0/16", 30); vt.Foreground = Teal; vt.TextAlignment = TextAlignment.Left;
- _deviceLiveRefreshers.Add(() => { int v = _engine.InstrumentVoiceCount(_trackId); vt.Text = _engine.PluginParamGet(_trackId, -1, IndexOfId("mono")) > 0.5f ? "MONO" : $"{Math.Max(0, v)}/16"; });
+ _deviceLiveRefreshers.Add(() => { int v = _engine.InstrumentVoiceCount(_trackId); vt.Text = s.VoiceLabel?.Invoke(_engine, _trackId, v) ?? (_engine.PluginParamGet(_trackId, -1, IndexOfId("mono")) > 0.5f ? "MONO" : $"{Math.Max(0, v)}/16"); });
right.Children.Add(vt);
}
diff --git a/src/managed/Nota.App/MainWindow.Browser.cs b/src/managed/Nota.App/MainWindow.Browser.cs
index 7c515019..e917029d 100644
--- a/src/managed/Nota.App/MainWindow.Browser.cs
+++ b/src/managed/Nota.App/MainWindow.Browser.cs
@@ -58,6 +58,7 @@ public partial class MainWindow
11 => Engine.AddFluxSynthTrack(),
12 => Engine.AddRhythmTrack(),
13 => Engine.AddMonolithTrack(),
+ 14 => Engine.AddPentadTrack(),
1 => Engine.AddSamplerInstrumentTrack(),
_ => Engine.AddInstrumentTrack(),
};
diff --git a/src/managed/Nota.App/MainWindow.Dnd.cs b/src/managed/Nota.App/MainWindow.Dnd.cs
index 8d1e214a..39bc94df 100644
--- a/src/managed/Nota.App/MainWindow.Dnd.cs
+++ b/src/managed/Nota.App/MainWindow.Dnd.cs
@@ -62,6 +62,7 @@ public partial class MainWindow
11 => Engine.AddFluxSynthTrack(),
12 => Engine.AddRhythmTrack(),
13 => Engine.AddMonolithTrack(),
+ 14 => Engine.AddPentadTrack(),
1 => Engine.AddSamplerInstrumentTrack(),
_ => Engine.AddInstrumentTrack(),
};
diff --git a/src/managed/Nota.App/PreferencesWindow.cs b/src/managed/Nota.App/PreferencesWindow.cs
index 36b23ab3..81ecaa25 100644
--- a/src/managed/Nota.App/PreferencesWindow.cs
+++ b/src/managed/Nota.App/PreferencesWindow.cs
@@ -103,7 +103,9 @@ public sealed class PreferencesWindow : NotaWindow
((TextBlock)_navItems[i].Child!).Foreground = on ? AccentBright : TextSecondary;
((TextBlock)_navItems[i].Child!).FontWeight = on ? FontWeight.SemiBold : FontWeight.Normal;
}
- _content.Content = new ScrollViewer { Content = BuildPane(index), Padding = new Thickness(20, 18) };
+ // Padding lives inside the scrolled content: a ScrollViewer's own Padding isn't part of
+ // its extent, so the last rows of a long pane (Shortcuts) couldn't be scrolled into view.
+ _content.Content = new ScrollViewer { Content = new Border { Padding = new Thickness(20, 18), Child = BuildPane(index) } };
}
private Control BuildPane(int index) => index switch
@@ -569,6 +571,8 @@ public sealed class PreferencesWindow : NotaWindow
{
("Double-click clip", "Open in the clip editor"),
("Drag ⠿", "Reorder devices (◀ ▶)"),
+ ("Drag knob", "Change a device value · hold ⌘ or ⇧ for fine steps"),
+ ("Double-click knob", "Reset the value to its default"),
}),
};
diff --git a/src/managed/Nota.Application/Engine/IAudioEngine.cs b/src/managed/Nota.Application/Engine/IAudioEngine.cs
index 0282ac53..1aa5142e 100644
--- a/src/managed/Nota.Application/Engine/IAudioEngine.cs
+++ b/src/managed/Nota.Application/Engine/IAudioEngine.cs
@@ -257,6 +257,8 @@ public interface IAudioEngine : IDisposable
int AddRhythmTrack();
/// <summary>Adds an instrument track with the built-in Nota Monolith mono synth (kind 13).</summary>
int AddMonolithTrack();
+ /// <summary>Adds an instrument track with the built-in Nota Pentad 5-voice poly synth (kind 14).</summary>
+ int AddPentadTrack();
/// <summary>UI editing channel for the track's instrument (e.g. Rhythm step patterns).</summary>
void InstrumentAction(int trackId, int id, int iarg, float farg);
/// <summary>Loads a sample file into a Nota Grain track (kind 10). True on success.</summary>
diff --git a/src/managed/Nota.Infrastructure/Interop/NativeMethods.Tracks.cs b/src/managed/Nota.Infrastructure/Interop/NativeMethods.Tracks.cs
index fab1fcbf..756fd31e 100644
--- a/src/managed/Nota.Infrastructure/Interop/NativeMethods.Tracks.cs
+++ b/src/managed/Nota.Infrastructure/Interop/NativeMethods.Tracks.cs
@@ -301,6 +301,9 @@ internal static partial class NativeMethods
[LibraryImport(Lib, EntryPoint = "nota_engine_add_monolith_track")]
internal static partial int AddMonolithTrack(IntPtr engine);
+ [LibraryImport(Lib, EntryPoint = "nota_engine_add_pentad_track")]
+ internal static partial int AddPentadTrack(IntPtr engine);
+
[LibraryImport(Lib, EntryPoint = "nota_track_instrument_action")]
internal static partial void InstrumentAction(IntPtr engine, int trackId, int id, int iarg, float farg);
diff --git a/src/managed/Nota.Infrastructure/Interop/NotaEngine.Tracks.cs b/src/managed/Nota.Infrastructure/Interop/NotaEngine.Tracks.cs
index 71b50dc7..b3c765bb 100644
--- a/src/managed/Nota.Infrastructure/Interop/NotaEngine.Tracks.cs
+++ b/src/managed/Nota.Infrastructure/Interop/NotaEngine.Tracks.cs
@@ -612,6 +612,15 @@ public sealed partial class NotaEngine
return id;
}
+ /// <summary>Adds an instrument track with the built-in Nota Pentad poly synth. Returns its id.</summary>
+ public int AddPentadTrack()
+ {
+ ThrowIfDisposed();
+ var id = NativeMethods.AddPentadTrack(_handle);
+ if (id <= 0) throw new NotaEngineException("Failed to add Pentad track.");
+ return id;
+ }
+
/// <summary>UI editing channel for the track's instrument (e.g. Nota Rhythm step patterns).</summary>
public void InstrumentAction(int trackId, int id, int iarg, float farg)
{ ThrowIfDisposed(); NativeMethods.InstrumentAction(_handle, trackId, id, iarg, farg); }
diff --git a/src/managed/Nota.Infrastructure/Persistence/FactoryPresetCatalog.cs b/src/managed/Nota.Infrastructure/Persistence/FactoryPresetCatalog.cs
index 35c547a2..72c84ff2 100644
--- a/src/managed/Nota.Infrastructure/Persistence/FactoryPresetCatalog.cs
+++ b/src/managed/Nota.Infrastructure/Persistence/FactoryPresetCatalog.cs
@@ -207,6 +207,60 @@ public sealed class FactoryPresetCatalog : IFactoryPresets
Inst("monolith", 13, "Sci-Fi Mod", ("o1range", 0.6f), ("o1wave", 0.4f), ("o3range", 0.0f), ("o3wave", 0.4f), ("osc3kbd", 0f), ("oscmodon", 1f), ("modwheel", 0.5f), ("modmix", 0f), ("cutoff", 0.65f), ("emph", 0.35f), ("contour", 0.5f), ("fsustain", 0.55f), ("volume", 0.72f));
Inst("monolith", 13, "Random Bleeps", ("o1range", 0.8f), ("o1wave", 1f), ("filtmodon", 1f), ("modwheel", 0.4f), ("o3range", 0.0f), ("osc3kbd", 0f), ("cutoff", 0.7f), ("emph", 0.4f), ("contour", 0.4f), ("fdecay", 0.2f), ("fsustain", 0.3f), ("adecay", 0.2f), ("asustain", 0.2f), ("decayon", 1f), ("volume", 0.74f));
+ // ---- Nota Pentad (kind 14) — 5-voice Prophet-5-style poly. Octave 32'/16'/8'/4' =
+ // 0/.333/.667/1; semitone .5 = 0 (±12 over 0..1, +7 = .7917); fine .5 = 0 (±50 c);
+ // cutoff v = log10(Hz/20)/3; voice mode Poly/Uni/Mono = 0/.5/1; toggles 0/1.
+ // Unlisted params keep the init patch (two saws, half-open filter).
+ // Brass
+ Inst("pentad", 14, "Poly Brass", ("obfine", 0.53f), ("cutoff", 0.42f), ("reso", 0.15f), ("fenvamt", 0.55f), ("fattack", 0.45f), ("fdecay", 0.55f), ("fsustain", 0.45f), ("frelease", 0.45f), ("aattack", 0.35f), ("adecay", 0.5f), ("asustain", 0.9f), ("arelease", 0.45f));
+ Inst("pentad", 14, "Soft Horns", ("obfine", 0.52f), ("cutoff", 0.38f), ("fenvamt", 0.45f), ("fattack", 0.6f), ("fdecay", 0.6f), ("fsustain", 0.5f), ("aattack", 0.55f), ("asustain", 0.9f), ("arelease", 0.5f), ("drift", 0.35f));
+ Inst("pentad", 14, "Brass Stab", ("cutoff", 0.40f), ("reso", 0.2f), ("fenvamt", 0.6f), ("fattack", 0.2f), ("fdecay", 0.45f), ("fsustain", 0.15f), ("aattack", 0.05f), ("adecay", 0.5f), ("asustain", 0.4f), ("arelease", 0.3f));
+ Inst("pentad", 14, "Octave Brass", ("oboct", 0.333f), ("mixb", 0.7f), ("cutoff", 0.45f), ("fenvamt", 0.5f), ("fattack", 0.4f), ("fdecay", 0.55f), ("fsustain", 0.5f), ("aattack", 0.3f), ("asustain", 0.9f));
+ Inst("pentad", 14, "Sync Brass", ("oasync", 1f), ("oasemi", 0.625f), ("pmenv", 0.35f), ("pmfreqa", 1f), ("cutoff", 0.5f), ("fenvamt", 0.4f), ("fattack", 0.3f), ("fdecay", 0.55f), ("fsustain", 0.4f), ("aattack", 0.2f));
+ // Strings / pads
+ Inst("pentad", 14, "Glass Strings", ("oapulse", 1f), ("oapw", 0.38f), ("obsaw", 0f), ("obpulse", 1f), ("obpw", 0.52f), ("oboct", 0.333f), ("obfine", 0.57f),
+ ("mixa", 0.82f), ("mixb", 0.7f), ("mixnoise", 0.12f), ("noisecolor", 1f), ("drift", 0.28f), ("glide", 0.418f), ("glidemode", 0.5f),
+ ("cutoff", 0.656f), ("reso", 0.34f), ("fenvamt", 0.5f), ("velfilt", 0.5f), ("fattack", 0.362f), ("fdecay", 0.648f), ("fsustain", 0.52f), ("frelease", 0.6f),
+ ("aattack", 0.624f), ("adecay", 0.736f), ("asustain", 0.74f), ("arelease", 0.707f), ("spread", 0.44f), ("volume", 0.574f), ("unidetune", 0.18f));
+ Inst("pentad", 14, "Analog Strings", ("obfine", 0.56f), ("cutoff", 0.5f), ("reso", 0.05f), ("fenvamt", 0.15f), ("aattack", 0.62f), ("adecay", 0.6f), ("asustain", 0.9f), ("arelease", 0.65f), ("lfoamt", 0.12f), ("lforate", 0.62f), ("drift", 0.35f), ("spread", 0.6f));
+ Inst("pentad", 14, "Warm Pad", ("oasaw", 0f), ("oapulse", 1f), ("oapw", 0.45f), ("obfine", 0.55f), ("cutoff", 0.42f), ("fenvamt", 0.3f), ("fattack", 0.7f), ("fdecay", 0.7f), ("fsustain", 0.6f), ("frelease", 0.7f), ("aattack", 0.7f), ("asustain", 0.95f), ("arelease", 0.75f), ("drift", 0.4f));
+ Inst("pentad", 14, "PWM Pad", ("oasaw", 0f), ("oapulse", 1f), ("obsaw", 0f), ("obpulse", 1f), ("wmpwa", 1f), ("wmpwb", 1f), ("wmfreqa", 0f), ("wmfreqb", 0f), ("lfoamt", 0.35f), ("lforate", 0.52f), ("cutoff", 0.52f), ("aattack", 0.6f), ("asustain", 0.9f), ("arelease", 0.6f));
+ Inst("pentad", 14, "Choir Vox", ("oasaw", 0f), ("oapulse", 1f), ("oapw", 0.3f), ("obsaw", 0f), ("obtri", 1f), ("oboct", 1f), ("cutoff", 0.48f), ("reso", 0.35f), ("fenvamt", 0.2f), ("keytrk", 0.7f), ("aattack", 0.6f), ("asustain", 0.9f), ("arelease", 0.6f), ("mixnoise", 0.08f), ("noisecolor", 1f), ("lfoamt", 0.08f), ("lforate", 0.6f));
+ Inst("pentad", 14, "Sweep Pad", ("cutoff", 0.3f), ("reso", 0.45f), ("fenvamt", 0.55f), ("fattack", 0.85f), ("fdecay", 0.85f), ("fsustain", 0.3f), ("frelease", 0.8f), ("aattack", 0.6f), ("asustain", 0.9f), ("arelease", 0.8f), ("drift", 0.3f));
+ Inst("pentad", 14, "Per-Voice PWM", ("oasaw", 0f), ("oapulse", 1f), ("oapw", 0.5f), ("obsaw", 0f), ("obtri", 1f), ("oblofreq", 1f), ("mixb", 0f), ("pmoscb", 0.55f), ("pmpwa", 1f), ("cutoff", 0.55f), ("aattack", 0.5f), ("asustain", 0.9f), ("arelease", 0.6f), ("drift", 0.4f));
+ Inst("pentad", 14, "Solar Drift", ("drift", 0.8f), ("oasaw", 0f), ("oapulse", 1f), ("oapw", 0.3f), ("obsaw", 0f), ("obtri", 1f), ("obsemi", 0.7917f), ("cutoff", 0.5f), ("fenvamt", 0.25f), ("aattack", 0.65f), ("asustain", 0.9f), ("arelease", 0.75f), ("spread", 0.8f));
+ // Leads
+ Inst("pentad", 14, "Sync Lead", ("oasync", 1f), ("pmenv", 0.45f), ("pmfreqa", 1f), ("mixb", 0f), ("cutoff", 0.75f), ("reso", 0.2f), ("fenvamt", 0.25f), ("fdecay", 0.55f), ("fsustain", 0.4f), ("aattack", 0.1f), ("asustain", 0.9f), ("arelease", 0.35f), ("voicemode", 1f), ("glide", 0.3f));
+ Inst("pentad", 14, "Unison Lead", ("voicemode", 0.5f), ("unidetune", 0.35f), ("cutoff", 0.62f), ("reso", 0.25f), ("fenvamt", 0.4f), ("fdecay", 0.5f), ("fsustain", 0.5f), ("glide", 0.32f));
+ Inst("pentad", 14, "Pulse Lead", ("oasaw", 0f), ("oapulse", 1f), ("oapw", 0.3f), ("mixb", 0f), ("voicemode", 1f), ("cutoff", 0.66f), ("reso", 0.3f), ("fenvamt", 0.35f), ("glide", 0.3f));
+ Inst("pentad", 14, "Screamer", ("voicemode", 1f), ("reso", 0.75f), ("cutoff", 0.55f), ("fenvamt", 0.5f), ("keytrk", 1f), ("mixa", 1f), ("mixb", 0.9f), ("glide", 0.28f));
+ Inst("pentad", 14, "Fifth Lead", ("obsemi", 0.7917f), ("voicemode", 0.5f), ("unidetune", 0.2f), ("cutoff", 0.64f), ("fenvamt", 0.35f), ("glide", 0.3f));
+ Inst("pentad", 14, "Whistle Lead", ("mixa", 0f), ("mixb", 0f), ("mixnoise", 0.01f), ("reso", 0.93f), ("keytrk", 1f), ("cutoff", 0.62f), ("fenvamt", 0.05f), ("voicemode", 1f), ("glide", 0.3f), ("lfoamt", 0.1f), ("lforate", 0.72f));
+ Inst("pentad", 14, "Soft Lead", ("oasaw", 0f), ("oapulse", 1f), ("oapw", 0.5f), ("obsaw", 0f), ("obtri", 1f), ("cutoff", 0.55f), ("fenvamt", 0.2f), ("aattack", 0.35f), ("glide", 0.25f), ("voicemode", 1f));
+ // Bass
+ Inst("pentad", 14, "Pentad Bass", ("oaoct", 0.333f), ("oboct", 0.333f), ("obfine", 0.52f), ("cutoff", 0.33f), ("reso", 0.25f), ("fenvamt", 0.55f), ("fdecay", 0.42f), ("fsustain", 0.15f), ("adecay", 0.5f), ("asustain", 0.7f), ("arelease", 0.25f), ("voicemode", 1f));
+ Inst("pentad", 14, "Sync Bass", ("oaoct", 0.333f), ("oboct", 0f), ("oasync", 1f), ("oasemi", 0.7917f), ("mixb", 0.4f), ("cutoff", 0.4f), ("fenvamt", 0.5f), ("fdecay", 0.4f), ("fsustain", 0.2f), ("voicemode", 1f));
+ Inst("pentad", 14, "Unison Bass", ("oaoct", 0.333f), ("oboct", 0.333f), ("voicemode", 0.5f), ("unidetune", 0.25f), ("cutoff", 0.36f), ("reso", 0.2f), ("fenvamt", 0.5f), ("fdecay", 0.45f), ("fsustain", 0.25f), ("asustain", 0.8f), ("arelease", 0.25f));
+ Inst("pentad", 14, "Pluck Bass", ("oaoct", 0.333f), ("oasaw", 0f), ("oapulse", 1f), ("oapw", 0.3f), ("mixb", 0f), ("cutoff", 0.3f), ("reso", 0.35f), ("fenvamt", 0.6f), ("fdecay", 0.35f), ("fsustain", 0f), ("adecay", 0.45f), ("asustain", 0f), ("arelease", 0.3f), ("voicemode", 1f));
+ Inst("pentad", 14, "Rubber Bass", ("oaoct", 0.333f), ("oboct", 0.333f), ("cutoff", 0.28f), ("reso", 0.6f), ("fenvamt", 0.55f), ("fdecay", 0.38f), ("fsustain", 0.1f), ("voicemode", 1f), ("glide", 0.25f));
+ Inst("pentad", 14, "Sub Drone", ("oaoct", 0f), ("oboct", 0f), ("obsaw", 0f), ("obtri", 1f), ("cutoff", 0.3f), ("fenvamt", 0.1f), ("asustain", 1f), ("arelease", 0.5f));
+ // Keys / plucks
+ Inst("pentad", 14, "Poly Keys", ("cutoff", 0.48f), ("fenvamt", 0.4f), ("fdecay", 0.55f), ("fsustain", 0.2f), ("adecay", 0.65f), ("asustain", 0.3f), ("arelease", 0.5f), ("velfilt", 0.4f), ("velamp", 0.3f));
+ Inst("pentad", 14, "Riley Organ", ("oasaw", 0f), ("oapulse", 1f), ("oapw", 0.5f), ("obsaw", 0f), ("obpulse", 1f), ("oboct", 1f), ("obpw", 0.35f), ("mixb", 0.5f), ("cutoff", 0.6f), ("reso", 0.15f), ("fenvamt", 0.25f), ("fdecay", 0.35f), ("fsustain", 0.3f), ("adecay", 0.4f), ("asustain", 0.6f), ("arelease", 0.2f), ("drift", 0.15f));
+ Inst("pentad", 14, "Clavi", ("oasaw", 0f), ("oapulse", 1f), ("oapw", 0.2f), ("mixb", 0f), ("cutoff", 0.55f), ("reso", 0.3f), ("fenvamt", 0.5f), ("fdecay", 0.3f), ("fsustain", 0f), ("adecay", 0.45f), ("asustain", 0f), ("arelease", 0.15f), ("keytrk", 0.8f), ("velfilt", 0.5f));
+ Inst("pentad", 14, "Bell Keys", ("obsaw", 0f), ("obtri", 1f), ("oboct", 1f), ("obsemi", 0.7917f), ("mixb", 0f), ("pmoscb", 0.35f), ("pmfreqa", 1f), ("cutoff", 0.7f), ("fenvamt", 0.2f), ("adecay", 0.7f), ("asustain", 0f), ("arelease", 0.6f));
+ Inst("pentad", 14, "Harpsi", ("oapulse", 1f), ("oapw", 0.15f), ("oboct", 1f), ("mixb", 0.4f), ("cutoff", 0.62f), ("reso", 0.2f), ("fenvamt", 0.35f), ("fdecay", 0.45f), ("fsustain", 0f), ("adecay", 0.55f), ("asustain", 0f), ("arelease", 0.45f));
+ Inst("pentad", 14, "Marimba Pluck", ("oasaw", 0f), ("obsaw", 0f), ("obtri", 1f), ("mixa", 0f), ("mixb", 1f), ("cutoff", 0.45f), ("reso", 0.5f), ("fenvamt", 0.5f), ("fdecay", 0.3f), ("fsustain", 0f), ("adecay", 0.45f), ("asustain", 0f), ("arelease", 0.35f), ("keytrk", 1f));
+ // Poly-Mod / SFX
+ Inst("pentad", 14, "Poly-Mod Bells", ("obsaw", 0f), ("obtri", 1f), ("oboct", 1f), ("obfine", 0.6f), ("mixb", 0f), ("pmoscb", 0.45f), ("pmfreqa", 1f), ("cutoff", 0.75f), ("fenvamt", 0.1f), ("adecay", 0.7f), ("asustain", 0.1f), ("arelease", 0.7f));
+ Inst("pentad", 14, "Metallic Clang", ("obsaw", 0f), ("obpulse", 1f), ("obsemi", 0.75f), ("mixb", 0.2f), ("pmoscb", 0.7f), ("pmfreqa", 1f), ("pmfilter", 1f), ("cutoff", 0.6f), ("reso", 0.4f), ("fenvamt", 0.3f), ("fdecay", 0.5f), ("fsustain", 0f), ("adecay", 0.55f), ("asustain", 0f), ("arelease", 0.5f));
+ Inst("pentad", 14, "Env Sync Sweep", ("oasync", 1f), ("pmenv", 0.6f), ("pmfreqa", 1f), ("mixb", 0f), ("fattack", 0.5f), ("fdecay", 0.7f), ("fsustain", 0f), ("cutoff", 0.7f), ("fenvamt", 0.2f), ("asustain", 0.9f));
+ Inst("pentad", 14, "Laser Zap", ("pmenv", 0.8f), ("pmfreqa", 1f), ("mixb", 0f), ("fdecay", 0.35f), ("fsustain", 0f), ("adecay", 0.4f), ("asustain", 0f), ("cutoff", 0.8f), ("fenvamt", 0.1f));
+ Inst("pentad", 14, "Wind & Surf", ("mixa", 0f), ("mixb", 0f), ("mixnoise", 1f), ("noisecolor", 1f), ("cutoff", 0.45f), ("reso", 0.6f), ("keytrk", 0f), ("wmfilter", 1f), ("wmfreqa", 0f), ("wmfreqb", 0f), ("lfoamt", 0.5f), ("lforate", 0.35f), ("aattack", 0.75f), ("asustain", 1f), ("arelease", 0.8f));
+ Inst("pentad", 14, "Lo-Freq Growl", ("oblofreq", 1f), ("obkbd", 0f), ("obsaw", 0f), ("obtri", 1f), ("mixb", 0f), ("pmoscb", 0.35f), ("pmfreqa", 1f), ("pmfilter", 1f), ("cutoff", 0.5f), ("reso", 0.4f));
+ Inst("pentad", 14, "Random Computer", ("oasaw", 0f), ("oapulse", 1f), ("lfotri", 0f), ("lfosaw", 1f), ("lfosquare", 1f), ("lforate", 0.75f), ("lfoamt", 0.8f), ("wmfilter", 1f), ("cutoff", 0.6f), ("reso", 0.5f));
+ Inst("pentad", 14, "Dive Bomb", ("oasync", 1f), ("pmenv", 1f), ("pmfreqa", 1f), ("mixb", 0f), ("fattack", 0.8f), ("fdecay", 0.85f), ("fsustain", 0f), ("cutoff", 0.6f), ("reso", 0.3f), ("glide", 0.8f), ("glidemode", 0.5f));
+
// ---- EQ-8 (kind 0) — 8 bands × (On/Type/Freq/Gain/Q), param names "<band> <field>",
// band 1 = low shelf, 2/3 = bells, 4 = high shelf (defaults). Type: 0 LowCut,
// 1 LowShelf, 2 Bell, 3 Notch, 4 HighShelf, 5 HighCut.
@@ -418,6 +472,9 @@ public sealed class FactoryPresetCatalog : IFactoryPresets
return list;
}
+ /// <summary>The preset's document (named params), or null — for validation and tests.</summary>
+ public PresetDocument? Document(string id) => _byId.TryGetValue(id, out var doc) ? doc : null;
+
public string Apply(IAudioEngine engine, string id, int targetTrackId)
=> _byId.TryGetValue(id, out var doc)
? PresetService.Apply(doc, engine, targetTrackId)
diff --git a/src/managed/Nota.Infrastructure/Persistence/PresetService.cs b/src/managed/Nota.Infrastructure/Persistence/PresetService.cs
index a5a032bc..b3f78e64 100644
--- a/src/managed/Nota.Infrastructure/Persistence/PresetService.cs
+++ b/src/managed/Nota.Infrastructure/Persistence/PresetService.cs
@@ -171,6 +171,7 @@ public static class PresetService
11 => engine.AddFluxSynthTrack(),
12 => engine.AddRhythmTrack(),
13 => engine.AddMonolithTrack(),
+ 14 => engine.AddPentadTrack(),
_ => engine.AddInstrumentTrack(),
};
if (t <= 0) return "Failed to add instrument.";
diff --git a/src/managed/Nota.Infrastructure/Persistence/ProjectService.cs b/src/managed/Nota.Infrastructure/Persistence/ProjectService.cs
index 3691443e..e3715a5d 100644
--- a/src/managed/Nota.Infrastructure/Persistence/ProjectService.cs
+++ b/src/managed/Nota.Infrastructure/Persistence/ProjectService.cs
@@ -539,6 +539,7 @@ public sealed class ProjectService
{ Kind: 11 } => engine.AddFluxSynthTrack(), // Nota Flux
{ Kind: 12 } => engine.AddRhythmTrack(), // Nota Rhythm
{ Kind: 13 } => engine.AddMonolithTrack(), // Nota Monolith
+ { Kind: 14 } => engine.AddPentadTrack(), // Nota Pentad
_ => engine.AddInstrumentTrack(), // Nota Synth
};
if (t.Instrument?.State is { } synthState)
diff --git a/src/managed/Nota.Mcp/Tools/InstrumentTools.cs b/src/managed/Nota.Mcp/Tools/InstrumentTools.cs
index f5bb1a50..182f5133 100644
--- a/src/managed/Nota.Mcp/Tools/InstrumentTools.cs
+++ b/src/managed/Nota.Mcp/Tools/InstrumentTools.cs
@@ -19,7 +19,7 @@ public sealed class InstrumentTools(IAudioEngine engine, IEngineDispatch dispatc
(0, "Nota Synth"), (1, "Nota Sampler"), (2, "Nota Physical"), (3, "Instrument Rack"),
(4, "Drum Rack"), (5, "Nota Aurora"), (6, "Nota Volt"), (7, "Nota Bass"),
(8, "Nota Pendulum"), (9, "Nota Operator"), (10, "Nota Grain"), (11, "Nota Flux"),
- (12, "Nota Rhythm"), (13, "Nota Monolith"),
+ (12, "Nota Rhythm"), (13, "Nota Monolith"), (14, "Nota Pentad"),
};
public sealed record InstrumentKind(int Kind, string Name);
@@ -29,7 +29,7 @@ public sealed class InstrumentTools(IAudioEngine engine, IEngineDispatch dispatc
public InstrumentKind[] ListInstrumentKinds() => Array.ConvertAll(Kinds, k => new InstrumentKind(k.Kind, k.Name));
[McpServerTool(Name = "add_instrument_track"), Description("Add an instrument track with the given built-in kind (see list_instrument_kinds). Returns the track id.")]
- public Task<int> AddInstrumentTrack([Description("Instrument kind id (0..13)")] int kind) => Mutate(() => kind switch
+ public Task<int> AddInstrumentTrack([Description("Instrument kind id (0..14)")] int kind) => Mutate(() => kind switch
{
1 => E.AddSamplerInstrumentTrack(),
2 => E.AddPhysicalSynthTrack(),
@@ -44,6 +44,7 @@ public sealed class InstrumentTools(IAudioEngine engine, IEngineDispatch dispatc
11 => E.AddFluxSynthTrack(),
12 => E.AddRhythmTrack(),
13 => E.AddMonolithTrack(),
+ 14 => E.AddPentadTrack(),
_ => E.AddInstrumentTrack(), // 0 = Nota Synth
});
@@ -59,4 +60,19 @@ public sealed class InstrumentTools(IAudioEngine engine, IEngineDispatch dispatc
[McpServerTool(Name = "set_instrument_param"), Description("Set a track instrument parameter by index to a normalized value (0..1). Use get_instrument_params for indices.")]
public Task SetInstrumentParam(int trackId, int paramIndex, [Description("Normalized 0..1")] float value)
=> Mutate(() => E.PluginParamSet(trackId, -1, paramIndex, Math.Clamp(value, 0f, 1f)));
+
+ [McpServerTool(Name = "set_instrument_param_by_id"), Description(
+ "Set a track instrument parameter by its stable id (e.g. \"cutoff\", \"pmoscb\") to a normalized value (0..1). "
+ + "Ids never change between versions, unlike indices. Returns false if the instrument has no such parameter.")]
+ public Task<bool> SetInstrumentParamById(int trackId, string paramId, [Description("Normalized 0..1")] float value) => Mutate(() =>
+ {
+ int pc = E.PluginParamCount(trackId, -1);
+ for (int i = 0; i < pc; i++)
+ {
+ if (E.PluginParamId(trackId, -1, i) != paramId) continue;
+ E.PluginParamSet(trackId, -1, i, Math.Clamp(value, 0f, 1f));
+ return true;
+ }
+ return false;
+ });
}
diff --git a/src/managed/Nota.Presentation/ViewModels/BrowserViewModel.cs b/src/managed/Nota.Presentation/ViewModels/BrowserViewModel.cs
index bf9ddc95..8e425a02 100644
--- a/src/managed/Nota.Presentation/ViewModels/BrowserViewModel.cs
+++ b/src/managed/Nota.Presentation/ViewModels/BrowserViewModel.cs
@@ -189,6 +189,7 @@ public sealed partial class BrowserViewModel : ObservableObject
new() { Name = "Nota Flux", Kind = BrowserItemKind.BuiltinInstrument, BuiltinKind = 11, Sub = "vector-morph synth" },
new() { Name = "Nota Rhythm", Kind = BrowserItemKind.BuiltinInstrument, BuiltinKind = 12, Sub = "drum machine" },
new() { Name = "Nota Monolith", Kind = BrowserItemKind.BuiltinInstrument, BuiltinKind = 13, Sub = "mono synth" },
+ new() { Name = "Nota Pentad", Kind = BrowserItemKind.BuiltinInstrument, BuiltinKind = 14, Sub = "poly synth" },
new() { Name = "Nota Sampler", Kind = BrowserItemKind.BuiltinInstrument, BuiltinKind = 1, Sub = "built-in" },
new() { Name = "Nota Instrument Rack", Kind = BrowserItemKind.BuiltinInstrument, BuiltinKind = 3, Sub = "built-in" },
new() { Name = "Nota Drum Rack", Kind = BrowserItemKind.BuiltinInstrument, BuiltinKind = 4, Sub = "built-in" }
diff --git a/src/native/nota.engine/CMakeLists.txt b/src/native/nota.engine/CMakeLists.txt
index f4756436..c3057fda 100644
--- a/src/native/nota.engine/CMakeLists.txt
+++ b/src/native/nota.engine/CMakeLists.txt
@@ -209,3 +209,33 @@ target_compile_definitions(nota-scanworker PRIVATE ${NOTA_JUCE_DEFS})
if(APPLE)
target_link_libraries(nota-scanworker PRIVATE "-framework CoreAudioKit")
endif()
+
+# --- Nota Pentad as a standalone VST3 (debugging in third-party hosts) -------
+# Off by default: the app runs Pentad in-process; this wraps the same header-only DSP
+# (src/Pentad.h) in a JUCE plugin with the generic editor. Configure with
+# -DNOTA_BUILD_PENTAD_VST3=ON and build the `NotaPentad_VST3` target; the bundle lands
+# in <build>/NotaPentad_artefacts/<config>/VST3/.
+option(NOTA_BUILD_PENTAD_VST3 "Build Nota Pentad as a standalone VST3 plugin" OFF)
+if(NOTA_BUILD_PENTAD_VST3)
+ juce_add_plugin(NotaPentad
+ COMPANY_NAME "Nota"
+ PRODUCT_NAME "Nota Pentad"
+ BUNDLE_ID "app.nota.pentad"
+ PLUGIN_MANUFACTURER_CODE Nota
+ PLUGIN_CODE Pntd
+ FORMATS VST3
+ IS_SYNTH TRUE
+ NEEDS_MIDI_INPUT TRUE
+ NEEDS_MIDI_OUTPUT FALSE
+ VST3_CATEGORIES Instrument Synth
+ COPY_PLUGIN_AFTER_BUILD FALSE)
+ target_sources(NotaPentad PRIVATE plugins/pentad/PentadPlugin.cpp)
+ target_include_directories(NotaPentad PRIVATE
+ ${CMAKE_CURRENT_SOURCE_DIR}/src
+ ${CMAKE_CURRENT_SOURCE_DIR}/vendor)
+ target_compile_definitions(NotaPentad PUBLIC
+ JUCE_WEB_BROWSER=0 JUCE_USE_CURL=0 JUCE_VST3_CAN_REPLACE_VST2=0 JUCE_DISPLAY_SPLASH_SCREEN=0)
+ target_link_libraries(NotaPentad
+ PRIVATE juce::juce_audio_utils
+ PUBLIC juce::juce_recommended_config_flags juce::juce_recommended_warning_flags)
+endif()
diff --git a/src/native/nota.engine/include/nota/nota_engine.h b/src/native/nota.engine/include/nota/nota_engine.h
index 7faa6153..9b80a7f4 100644
--- a/src/native/nota.engine/include/nota/nota_engine.h
+++ b/src/native/nota.engine/include/nota/nota_engine.h
@@ -386,6 +386,8 @@ NOTA_API int32_t nota_engine_add_flux_synth_track(NotaEngine* engine);
NOTA_API int32_t nota_engine_add_rhythm_track(NotaEngine* engine);
/* Adds an instrument track with the built-in Nota Monolith (mono Model-D synth, kind 13). id (>0). */
NOTA_API int32_t nota_engine_add_monolith_track(NotaEngine* engine);
+/* Adds an instrument track with the built-in Nota Pentad (5-voice Prophet-5-style poly, kind 14). id (>0). */
+NOTA_API int32_t nota_engine_add_pentad_track(NotaEngine* engine);
/* UI editing channel for the track's instrument (e.g. Nota Rhythm step patterns):
* id/iarg/farg are instrument-specific (see the instrument's action()). */
NOTA_API void nota_track_instrument_action(NotaEngine* engine, int32_t track_id, int32_t id, int32_t iarg, float farg);
diff --git a/src/native/nota.engine/plugins/pentad/PentadPlugin.cpp b/src/native/nota.engine/plugins/pentad/PentadPlugin.cpp
new file mode 100644
index 00000000..667410c4
--- /dev/null
+++ b/src/native/nota.engine/plugins/pentad/PentadPlugin.cpp
@@ -0,0 +1,130 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.
+//
+// Nota Pentad as a standalone VST3 — for debugging the synth in third-party hosts. A thin
+// JUCE AudioProcessor over the same header-only DSP the app runs (src/Pentad.h): the
+// parameter list (ids, names, defaults) comes from the instrument itself, MIDI notes /
+// pitch bend / mod wheel (CC1) / channel pressure are applied sample-accurately by
+// rendering between events, the host transport drives the tempo-synced LFO, and the
+// plugin state is the instrument's own normalized-parameter blob (the vintage seed
+// included), so a preset moves between the app and a host unchanged. The editor is JUCE's
+// generic one (requirements § 11.5: the full panel lives in the Avalonia card).
+//
+// Built only with -DNOTA_BUILD_PENTAD_VST3=ON (see CMakeLists.txt); the app never links it.
+
+#include "Pentad.h"
+
+#include <juce_audio_processors/juce_audio_processors.h>
+
+#include <memory>
+#include <vector>
+
+namespace {
+
+class PentadProcessor final : public juce::AudioProcessor {
+public:
+ PentadProcessor()
+ : AudioProcessor(BusesProperties().withOutput("Output", juce::AudioChannelSet::stereo(), true)) {
+ synth_ = std::make_unique<nota::Pentad>();
+ for (int i = 0; i < nota::Pentad::kNumParams; ++i) {
+ auto* p = new juce::AudioParameterFloat(juce::ParameterID{ nota::Pentad::paramId(i), 1 },
+ nota::Pentad::paramName(i),
+ juce::NormalisableRange<float>(0.0f, 1.0f),
+ synth_->pluginParamGet(i));
+ params_.push_back(p);
+ addParameter(p);
+ }
+ bendIdx_ = synth_->pluginParamIndexOfId("bend");
+ modIdx_ = synth_->pluginParamIndexOfId("modwheel");
+ atIdx_ = synth_->pluginParamIndexOfId("aftertouch");
+ }
+
+ const juce::String getName() const override { return "Nota Pentad"; }
+ bool acceptsMidi() const override { return true; }
+ bool producesMidi() const override { return false; }
+ bool isMidiEffect() const override { return false; }
+ double getTailLengthSeconds() const override { return 4.0; }
+ int getNumPrograms() override { return 1; }
+ int getCurrentProgram() override { return 0; }
+ void setCurrentProgram(int) override {}
+ const juce::String getProgramName(int) override { return "Init"; }
+ void changeProgramName(int, const juce::String&) override {}
+ bool hasEditor() const override { return true; }
+ juce::AudioProcessorEditor* createEditor() override { return new juce::GenericAudioProcessorEditor(*this); }
+
+ bool isBusesLayoutSupported(const BusesLayout& layouts) const override {
+ return layouts.getMainOutputChannelSet() == juce::AudioChannelSet::stereo();
+ }
+
+ void prepareToPlay(double sampleRate, int maximumBlock) override {
+ synth_->setSampleRate(sampleRate);
+ scratch_.assign(static_cast<size_t>(std::max(1, maximumBlock)) * 2, 0.0f);
+ }
+ void releaseResources() override {}
+ void reset() override { synth_->allNotesOff(); } // transport stop / re-prepare
+
+ void processBlock(juce::AudioBuffer<float>& buffer, juce::MidiBuffer& midi) override {
+ juce::ScopedNoDenormals noDenormals;
+ const int n = buffer.getNumSamples();
+ buffer.clear();
+ if (static_cast<int>(scratch_.size()) < n * 2) scratch_.assign(static_cast<size_t>(n) * 2, 0.0f);
+ std::fill(scratch_.begin(), scratch_.begin() + n * 2, 0.0f);
+
+ for (int i = 0; i < nota::Pentad::kNumParams; ++i) synth_->pluginParamSet(i, params_[static_cast<size_t>(i)]->get());
+
+ if (auto* ph = getPlayHead()) {
+ if (auto pos = ph->getPosition()) {
+ const double bpm = pos->getBpm().orFallback(120.0);
+ const double spb = getSampleRate() * 60.0 / std::max(1.0, bpm);
+ synth_->setTransport(pos->getPpqPosition().orFallback(0.0), spb, pos->getIsPlaying());
+ }
+ }
+
+ int done = 0;
+ for (const auto meta : midi) {
+ const auto m = meta.getMessage();
+ const int at = juce::jlimit(0, n, meta.samplePosition);
+ if (at > done) { synth_->render(scratch_.data() + done * 2, at - done); done = at; }
+ if (m.isNoteOn()) synth_->noteOn(m.getNoteNumber(), m.getFloatVelocity());
+ else if (m.isNoteOff()) synth_->noteOff(m.getNoteNumber());
+ else if (m.isAllNotesOff() || m.isAllSoundOff()) synth_->allNotesOff();
+ else if (m.isPitchWheel()) setController(bendIdx_, m.getPitchWheelValue() / 16383.0f);
+ else if (m.isControllerOfType(1)) setController(modIdx_, m.getControllerValue() / 127.0f);
+ else if (m.isChannelPressure()) setController(atIdx_, m.getChannelPressureValue() / 127.0f);
+ else if (m.isAftertouch()) setController(atIdx_, m.getAfterTouchValue() / 127.0f);
+ }
+ if (done < n) synth_->render(scratch_.data() + done * 2, n - done);
+
+ auto* l = buffer.getWritePointer(0);
+ auto* r = buffer.getWritePointer(1);
+ for (int i = 0; i < n; ++i) { l[i] = scratch_[static_cast<size_t>(i) * 2]; r[i] = scratch_[static_cast<size_t>(i) * 2 + 1]; }
+ }
+
+ void getStateInformation(juce::MemoryBlock& dest) override {
+ for (int i = 0; i < nota::Pentad::kNumParams; ++i) synth_->pluginParamSet(i, params_[static_cast<size_t>(i)]->get());
+ const auto blob = synth_->getState();
+ dest.replaceAll(blob.data(), blob.size());
+ }
+ void setStateInformation(const void* data, int size) override {
+ synth_->setState(static_cast<const uint8_t*>(data), size);
+ for (int i = 0; i < nota::Pentad::kNumParams; ++i)
+ params_[static_cast<size_t>(i)]->setValueNotifyingHost(synth_->pluginParamGet(i));
+ }
+
+private:
+ // Wheels / pressure are plugin params in Pentad; MIDI moves the host-visible param too.
+ void setController(int idx, float v) {
+ if (idx < 0) return;
+ synth_->pluginParamSet(idx, v);
+ *params_[static_cast<size_t>(idx)] = v;
+ }
+
+ std::unique_ptr<nota::Pentad> synth_;
+ std::vector<juce::AudioParameterFloat*> params_;
+ std::vector<float> scratch_;
+ int bendIdx_ = -1, modIdx_ = -1, atIdx_ = -1;
+};
+
+} // namespace
+
+juce::AudioProcessor* JUCE_CALLTYPE createPluginFilter() { return new PentadProcessor(); }
diff --git a/src/native/nota.engine/src/Engine.h b/src/native/nota.engine/src/Engine.h
index f5df2627..26bc01ef 100644
--- a/src/native/nota.engine/src/Engine.h
+++ b/src/native/nota.engine/src/Engine.h
@@ -499,6 +499,7 @@ public:
int32_t addFluxSynthTrack(); // built-in Nota Flux (vector-morph, sidechain React)
int32_t addRhythmSynthTrack(); // built-in Nota Rhythm (drum machine, kind 12)
int32_t addMonolithTrack(); // built-in Nota Monolith (mono Model-D synth, kind 13)
+ int32_t addPentadTrack(); // built-in Nota Pentad (5-voice Prophet-5 poly, kind 14)
void instrumentAction(int32_t trackId, int32_t id, int32_t iarg, float farg); // UI editing channel
bool setRhythmVoiceSample(int32_t trackId, int32_t voice, const std::string& path); // Phase 2
bool rhythmVoiceInfo(int32_t trackId, int32_t voice, NotaSamplerInfo* out) const; // sample id per voice
diff --git a/src/native/nota.engine/src/Engine_Devices.cpp b/src/native/nota.engine/src/Engine_Devices.cpp
index f882cf49..a6ab80a9 100644
--- a/src/native/nota.engine/src/Engine_Devices.cpp
+++ b/src/native/nota.engine/src/Engine_Devices.cpp
@@ -32,6 +32,7 @@
#include "FluxSynth.h"
#include "RhythmMachine.h"
#include "Monolith.h"
+#include "Pentad.h"
#include "GrainSynth.h"
#include "Arpeggiator.h"
#include "MidiChord.h"
@@ -209,6 +210,18 @@ int32_t Engine::addMonolithTrack() {
return id;
}
+int32_t Engine::addPentadTrack() {
+ auto g = std::make_shared<Graph>(*authoring_);
+ const int32_t id = nextTrackId_++;
+ auto track = std::make_shared<Track>(id, TrackType::Instrument);
+ auto inst = std::make_shared<Pentad>();
+ inst->setSampleRate(transport_.sampleRate());
+ track->instrument = inst;
+ g->tracks.push_back(track);
+ publish(g);
+ return id;
+}
+
// UI editing channel for the track's instrument (e.g. Nota Rhythm step patterns). The
// instrument object is stable across snapshots, so this mutates it in place (message thread).
void Engine::instrumentAction(int32_t trackId, int32_t id, int32_t iarg, float farg) {
@@ -447,6 +460,7 @@ std::shared_ptr<Instrument> Engine::cloneInstrument(const Track& src) const {
case 11: { auto fx = std::make_shared<FluxSynth>(); fx->setSampleRate(sr); return fx; }
case 12: { auto rh = std::make_shared<RhythmMachine>(); rh->setSampleRate(sr); return rh; }
case 13: { auto mo = std::make_shared<Monolith>(); mo->setSampleRate(sr); return mo; }
+ case 14: { auto pe = std::make_shared<Pentad>(); pe->setSampleRate(sr); return pe; }
default: return nullptr;
}
}
@@ -565,6 +579,7 @@ static std::shared_ptr<Instrument> makeBuiltinInstrument(int32_t kind) {
case 11: return std::make_shared<FluxSynth>();
case 12: return std::make_shared<RhythmMachine>();
case 13: return std::make_shared<Monolith>();
+ case 14: return std::make_shared<Pentad>();
default: return nullptr; // Racks (3/4) / unknown: no simple swap
}
}
diff --git a/src/native/nota.engine/src/Pentad.h b/src/native/nota.engine/src/Pentad.h
new file mode 100644
index 00000000..59c31d63
--- /dev/null
+++ b/src/native/nota.engine/src/Pentad.h
@@ -0,0 +1,1025 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.
+//
+// Nota Pentad — the built-in 5-voice polyphonic analog synth (kind 14), a musically faithful
+// emulation of the Sequential Prophet-5 (Rev 3 architecture: CEM oscillators + CEM3320
+// filter). Nota's own DSP, not a schematic clone. Per voice:
+//
+// Osc A (saw + pulse, hard-sync to B) ┐
+// Osc B (saw + tri + pulse, lo-freq) ┼─→ Mixer ─(soft sat)─→ 4-pole OTA low-pass ─→ VCA ─→ pan
+// Noise (white / pink, shared) ┘ ▲ Filter Env (ADSR) ▲ Amp Env (ADSR)
+//
+// Poly-Mod : Filter Env + Osc B (audio rate) → Osc A freq / Osc A PW / Filter cutoff
+// Wheel-Mod: LFO ↔ noise × (initial amount + mod wheel) → A/B freq, A/B PW, cutoff
+//
+// Voice management: 5 / 10 / 16 voices, round-robin (authentic — reuses releasing voices,
+// cutting their tails) or oldest-note steal with a ≤ 4 ms fade, Poly / Unison / Mono
+// modes (unison + mono: low-note priority, legato, shared glide), poly unison stacks
+// (×2 / ×5) with detune, per-voice exponential glide, the panel's Release switch.
+//
+// DSP quality. Each voice runs at an internal ×2 (or ×4) rate so hard sync, audio-rate
+// Poly-Mod FM/PWM and the filter's non-linearities stay clean; the stereo voice sum is
+// decimated once with HIIR half-band stages. Oscillator edges are band-limited with
+// 4-point (cubic B-spline) polyBLEP / polyBLAMP residuals, which suppress the aliases that
+// fold back into the audio band far better than the usual 2-point polyBLEP. The filter is
+// a zero-delay-feedback (TPT) cascade of four OTA integrators (dy/dt = ωc·tanh(x − y), the
+// CEM3320 topology) with a resonance loop; the tanh terms are linearised per sample from
+// the previous sample's stage differences ("cheap non-linear ZDF"), so the loop is solved
+// exactly each sample and self-oscillates as a clean, key-trackable sine near the top of
+// Resonance. Bass thins with resonance (authentic); the Bass-Comp option restores it.
+//
+// Analog character ("Vintage Drift"): per-voice static spread of oscillator pitch, cutoff,
+// envelope times and pulse width, plus a slow random walk, all derived from a seed that is
+// a parameter — so it persists with the project/preset and a render is bit-identical for
+// the same seed (Freeze: offline == realtime). Oscillators start at random phases
+// (free-running emulation) and a -100 dBFS noise floor rides the VCA (switchable).
+//
+// Determinism: all state advances per sample with persistent counters (no per-block
+// decisions), and every seeded state is re-seeded on a transport play edge (when silent)
+// and on allNotesOff(), so a render from the same position is reproducible regardless of
+// the host's block size.
+//
+// All parameters ride the Instrument plugin-param interface (normalized 0..1, stable ids)
+// → automation / MIDI learn / persist / clone for free. Header-only; allocation-free after
+// construction; construction is cheap (no tables).
+
+#pragma once
+
+#include "Instrument.h"
+#include "hiir/Downsampler2xFpu.h"
+
+#include <algorithm>
+#include <atomic>
+#include <chrono>
+#include <cmath>
+#include <cstdint>
+#include <cstring>
+#include <memory>
+#include <string>
+
+#if defined(__SSE2__) || defined(_M_X64) || (defined(_M_IX86_FP) && _M_IX86_FP >= 2)
+#include <xmmintrin.h>
+#define NOTA_PENTAD_FTZ_X86 1
+#elif defined(__aarch64__) && !defined(_MSC_VER)
+#define NOTA_PENTAD_FTZ_ARM 1
+#endif
+
+namespace nota {
+
+namespace pentad {
+
+// ---- fast math (accurate enough for pitch / cutoff; branch-light) ---------------------
+inline float exp2f(float x) {
+ x = std::clamp(x, -60.0f, 60.0f);
+ const float fi = std::floor(x);
+ const float f = x - fi;
+ // Taylor series of 2^f on [0,1): ~1.5e-5 relative error (≈0.03 cent).
+ const float p = 1.0f + f * (0.69314718f + f * (0.24022651f + f * (0.05550411f + f * (0.00961813f
+ + f * (0.00133336f + f * 0.00015404f)))));
+ const int32_t e = static_cast<int32_t>(fi) + 127;
+ const uint32_t bits = static_cast<uint32_t>(e) << 23;
+ float s; std::memcpy(&s, &bits, sizeof s);
+ return p * s;
+}
+// tanh(v)/v (rational tanh, exact ±1 limit beyond |v| = 3) — the per-sample
+// linearisation gain of an OTA stage.
+inline float tanhRatio(float v) {
+ const float a = std::fabs(v);
+ if (a > 3.0f) return 1.0f / a;
+ const float v2 = v * v;
+ return (27.0f + v2) / (27.0f + 9.0f * v2);
+}
+// Mixer overdrive: a cubic soft clipper (unity slope at 0, flat at ±1.5) and its
+// antiderivative, run through first-order ADAA so the drive doesn't alias.
+inline double softClip(double x) {
+ if (x >= 1.5) return 1.0;
+ if (x <= -1.5) return -1.0;
+ return x - (4.0 / 27.0) * x * x * x;
+}
+inline double softClipAD(double x) {
+ const double a = std::fabs(x);
+ if (a >= 1.5) return a - 0.5625; // continues F(1.5) = 0.9375 with slope 1
+ const double x2 = x * x;
+ return 0.5 * x2 - x2 * x2 / 27.0;
+}
+struct Adaa {
+ double x1 = 0.0, f1 = 0.0;
+ float process(double x) {
+ const double f = softClipAD(x), dx = x - x1;
+ const double y = std::fabs(dx) > 1e-5 ? (f - f1) / dx : softClip(0.5 * (x + x1));
+ x1 = x; f1 = f;
+ return static_cast<float>(y);
+ }
+ void reset() { x1 = f1 = 0.0; }
+};
+// Padé tan for the bilinear prewarp, x ∈ [0, ~1.3].
+inline float tanPrewarp(float x) {
+ const float x2 = x * x;
+ return x * (15.0f - x2) / (15.0f - 6.0f * x2);
+}
+inline uint32_t hash32(uint32_t x) {
+ x ^= x >> 16; x *= 0x7feb352dU; x ^= x >> 15; x *= 0x846ca68bU; x ^= x >> 16;
+ return x;
+}
+struct Rng {
+ uint32_t s = 0x9E3779B9U;
+ void seed(uint32_t v) { s = v ? v : 0x9E3779B9U; }
+ uint32_t next() { s ^= s << 13; s ^= s >> 17; s ^= s << 5; return s; }
+ float uni() { return static_cast<float>(next() >> 8) * (1.0f / 16777216.0f); } // [0,1)
+ float bi() { return uni() * 2.0f - 1.0f; } // [-1,1)
+};
+
+// ---- 4-point band-limiting residuals (integrated cubic B-spline) ----------------------
+// d = distance (in samples, 0..1) from the discontinuity to the current sample. Taps are
+// for samples m-2, m-1, m, m+1 (m = the sample being computed), so an oscillator's output
+// is delayed by two samples through a 4-slot ring.
+inline void blepTaps(float d, float r[4]) {
+ d = std::clamp(d, 0.0f, 0.99999f);
+ const float d2 = d * d, d3 = d2 * d, d4 = d2 * d2;
+ const float e = d - 1.0f, e2 = e * e, e3 = e2 * e, e4 = e2 * e2;
+ const float o = 1.0f - d, o2 = o * o;
+ r[0] = d4 * (1.0f / 24.0f);
+ r[1] = 1.0f / 24.0f + (4.0f * e - 2.0f * e3 - 0.75f * e4 + 2.75f) * (1.0f / 6.0f);
+ r[2] = -(1.0f / 24.0f + (-4.0f * d + 2.0f * d3 - 0.75f * d4 + 2.75f) * (1.0f / 6.0f));
+ r[3] = -(o2 * o2) * (1.0f / 24.0f);
+}
+inline float blampD(float t) { // ∫ of the integrated B-spline, t ∈ [-2, 0]
+ if (t <= -1.0f) { const float u = 2.0f + t, u2 = u * u; return u2 * u2 * u * (1.0f / 120.0f); }
+ const float t2 = t * t, t4 = t2 * t2, t5 = t4 * t;
+ return 1.0f / 120.0f + (t + 1.0f) * (1.0f / 24.0f)
+ + (2.0f * t2 - 0.5f * t4 - 0.15f * t5 + 2.75f * t + 1.1f) * (1.0f / 6.0f);
+}
+inline void blampTaps(float d, float r[4]) {
+ d = std::clamp(d, 0.0f, 0.99999f);
+ r[0] = blampD(d - 2.0f); r[1] = blampD(d - 1.0f); r[2] = blampD(-d); r[3] = blampD(-d - 1.0f);
+}
+
+struct Ring {
+ float a[4] = { 0, 0, 0, 0 };
+ uint32_t m = 0;
+ void naive(float v) { a[m & 3u] += v; }
+ void blep(float d, float h) {
+ if (h == 0.0f) return;
+ float r[4]; blepTaps(d, r);
+ a[(m - 2u) & 3u] += h * r[0]; a[(m - 1u) & 3u] += h * r[1];
+ a[m & 3u] += h * r[2]; a[(m + 1u) & 3u] += h * r[3];
+ }
+ void blamp(float d, float h) {
+ if (h == 0.0f) return;
+ float r[4]; blampTaps(d, r);
+ a[(m - 2u) & 3u] += h * r[0]; a[(m - 1u) & 3u] += h * r[1];
+ a[m & 3u] += h * r[2]; a[(m + 1u) & 3u] += h * r[3];
+ }
+ float pop() { const uint32_t o = (m - 2u) & 3u; const float v = a[o]; a[o] = 0.0f; ++m; return v; }
+ void clear() { a[0] = a[1] = a[2] = a[3] = 0.0f; }
+};
+
+// Saw + pulse core. `hi` = comparator state (phase < duty).
+struct Osc {
+ double ph = 0.0;
+ bool hi = true;
+ Ring ring;
+};
+
+// Pulse amplitude near the extremes of the width: the comparator stops flipping below 2 %
+// and above 98 % (silence), with a short fade so PWM sweeps into the dead zone don't click.
+inline float pulseZone(float duty) {
+ auto sm = [](float x) { x = std::clamp(x, 0.0f, 1.0f); return x * x * (3.0f - 2.0f * x); };
+ return sm((duty - 0.02f) / 0.03f) * sm((0.98f - duty) / 0.03f);
+}
+
+// Advance a saw/pulse core by `adv` phase over a span ending `tEnd` samples before the
+// current sample; emits the edge residuals. Returns the distance of a phase wrap, or -1.
+inline float advance(Osc& o, double adv, float tEnd, double dt, float duty, float gSaw, float gPul) {
+ const double p0 = o.ph;
+ double p1 = p0 + adv;
+ const float invDt = static_cast<float>(1.0 / dt);
+ float wrapD = -1.0f;
+ if (p1 >= 1.0) {
+ p1 -= 1.0;
+ if (p1 >= 1.0) p1 -= std::floor(p1);
+ wrapD = tEnd + static_cast<float>(p1) * invDt;
+ if (o.hi && p0 < duty) { o.ring.blep(tEnd + static_cast<float>(1.0 - duty + p1) * invDt, -2.0f * gPul); o.hi = false; }
+ o.ring.blep(wrapD, -2.0f * gSaw);
+ if (!o.hi) { o.ring.blep(wrapD, 2.0f * gPul); o.hi = true; }
+ if (p1 >= duty) { o.ring.blep(tEnd + static_cast<float>(p1 - duty) * invDt, -2.0f * gPul); o.hi = false; }
+ } else {
+ const bool nh = p1 < duty;
+ if (nh != o.hi) { // phase crossed the width (or the width moved across the phase)
+ float d = tEnd + static_cast<float>(std::fabs(p1 - duty)) * invDt;
+ const float lim = tEnd + static_cast<float>(adv) * invDt;
+ if (d > lim) d = lim;
+ o.ring.blep(d, nh ? 2.0f * gPul : -2.0f * gPul);
+ o.hi = nh;
+ }
+ }
+ o.ph = p1;
+ return wrapD;
+}
+
+} // namespace pentad
+
+class Pentad final : public Instrument {
+public:
+ // Parameter layout (normalized 0..1). Order == persisted state layout — APPEND ONLY.
+ enum Param {
+ // --- controllers / voice / global (0..23) ---
+ Tune = 0, Bend, ModWheel, Aftertouch, BendRange, Glide, GlideMode, VoiceMode,
+ Polyphony, Alloc, Unison, UniDetune, ReleaseOn, Drift, Seed, Volume,
+ Spread, VelAmp, VelFilt, AtCutoff, AtLfo, NoiseFloor, LowComp, Oversample,
+ // --- oscillator A (24..30) ---
+ OaOct, OaSemi, OaFine, OaSaw, OaPulse, OaPw, OaSync,
+ // --- oscillator B (31..39) ---
+ ObOct, ObSemi, ObFine, ObSaw, ObTri, ObPulse, ObPw, ObLoFreq, ObKbd,
+ // --- mixer (40..46) ---
+ MixA, MixAOn, MixB, MixBOn, MixNoise, MixNoiseOn, NoiseColor,
+ // --- filter (47..50) ---
+ Cutoff, Reso, FEnvAmt, KeyTrk,
+ // --- filter envelope (51..54) ---
+ FAttack, FDecay, FSustain, FRelease,
+ // --- amp envelope (55..58) ---
+ AAttack, ADecay, ASustain, ARelease,
+ // --- LFO (59..64) ---
+ LfoRate, LfoSaw, LfoTri, LfoSquare, LfoAmt, LfoSync,
+ // --- wheel-mod (65..70) ---
+ WmMix, WmFreqA, WmFreqB, WmPwA, WmPwB, WmFilter,
+ // --- poly-mod (71..75) ---
+ PmEnv, PmOscB, PmFreqA, PmPwA, PmFilter,
+ kNumParams
+ };
+
+ static constexpr int kMaxVoices = 16;
+
+ // Scope telemetry layout (scopeRead): see publishTelemetry().
+ enum Scope { ScPoly = 0, ScActive, ScPeakL, ScPeakR, ScMixPeak, ScCpu, ScOs, ScRate, ScVoices, kScopeN = ScVoices + kMaxVoices };
+
+ Pentad() {
+ // A plain two-saw brass-ish init: Osc A + B saws (B a few cents sharp), filter half
+ // open with a moderate envelope and half keyboard tracking, organ-like amp envelope.
+ set(Tune, 0.5f); set(Bend, 0.5f); set(ModWheel, 0.0f); set(Aftertouch, 0.0f);
+ set(BendRange, 1.0f / 11.0f); set(Glide, 0.0f); set(GlideMode, 0.0f); set(VoiceMode, 0.0f);
+ set(Polyphony, 0.0f); set(Alloc, 0.0f); set(Unison, 0.0f); set(UniDetune, 0.3f);
+ set(ReleaseOn, 1.0f); set(Drift, 0.25f); set(Seed, 0.5f); set(Volume, 0.7f);
+ set(Spread, 0.3f); set(VelAmp, 0.0f); set(VelFilt, 0.0f); set(AtCutoff, 0.0f);
+ set(AtLfo, 0.0f); set(NoiseFloor, 1.0f); set(LowComp, 0.0f); set(Oversample, 0.0f);
+ set(OaOct, 2.0f / 3.0f); set(OaSemi, 0.5f); set(OaFine, 0.5f); set(OaSaw, 1.0f);
+ set(OaPulse, 0.0f); set(OaPw, 0.5f); set(OaSync, 0.0f);
+ set(ObOct, 2.0f / 3.0f); set(ObSemi, 0.5f); set(ObFine, 0.54f); set(ObSaw, 1.0f);
+ set(ObTri, 0.0f); set(ObPulse, 0.0f); set(ObPw, 0.5f); set(ObLoFreq, 0.0f); set(ObKbd, 1.0f);
+ set(MixA, 0.8f); set(MixAOn, 1.0f); set(MixB, 0.6f); set(MixBOn, 1.0f);
+ set(MixNoise, 0.0f); set(MixNoiseOn, 1.0f); set(NoiseColor, 0.0f);
+ set(Cutoff, 0.55f); set(Reso, 0.1f); set(FEnvAmt, 0.35f); set(KeyTrk, 0.5f);
+ set(FAttack, 0.0f); set(FDecay, 0.45f); set(FSustain, 0.3f); set(FRelease, 0.4f);
+ set(AAttack, 0.0f); set(ADecay, 0.45f); set(ASustain, 0.85f); set(ARelease, 0.4f);
+ set(LfoRate, 0.55f); set(LfoSaw, 0.0f); set(LfoTri, 1.0f); set(LfoSquare, 0.0f);
+ set(LfoAmt, 0.0f); set(LfoSync, 0.0f);
+ set(WmMix, 0.0f); set(WmFreqA, 1.0f); set(WmFreqB, 1.0f); set(WmPwA, 0.0f); set(WmPwB, 0.0f); set(WmFilter, 0.0f);
+ set(PmEnv, 0.0f); set(PmOscB, 0.0f); set(PmFreqA, 0.0f); set(PmPwA, 0.0f); set(PmFilter, 0.0f);
+ initDecimators();
+ resetAll();
+ }
+
+ int32_t kind() const override { return 14; }
+ const char* displayName() const override { return "Nota Pentad"; }
+
+ // Deferred to the audio thread (render) so a device-rate change can't race a render.
+ void setSampleRate(double sr) override { pendingRate_.store(sr > 0 ? sr : 44100.0, std::memory_order_relaxed); }
+
+ int32_t activeVoiceCount() const override { return static_cast<int32_t>(tele_[ScActive].load(std::memory_order_relaxed)); }
+ int32_t scopeRead(float* out, int32_t maxN) const override {
+ const int n = std::min<int>(maxN, kScopeN);
+ for (int i = 0; i < n; ++i) out[i] = tele_[i].load(std::memory_order_relaxed);
+ return n;
+ }
+ int32_t heldNotes(int32_t* out, int32_t maxN) const override {
+ const int n = std::min<int>(heldN_, maxN);
+ for (int i = 0; i < n; ++i) out[i] = held_[i];
+ return n;
+ }
+
+ // ---- parameters -------------------------------------------------------
+ // Display names group by the part before the last space (the automation menu nests on it).
+ static const char* paramId(int i) {
+ static const char* ids[kNumParams] = {
+ "tune", "bend", "modwheel", "aftertouch", "bendrange", "glide", "glidemode", "voicemode",
+ "polyphony", "alloc", "unison", "unidetune", "releaseon", "drift", "seed", "volume",
+ "spread", "velamp", "velfilt", "atcutoff", "atlfo", "noisefloor", "lowcomp", "oversample",
+ "oaoct", "oasemi", "oafine", "oasaw", "oapulse", "oapw", "oasync",
+ "oboct", "obsemi", "obfine", "obsaw", "obtri", "obpulse", "obpw", "oblofreq", "obkbd",
+ "mixa", "mixaon", "mixb", "mixbon", "mixnoise", "mixnoiseon", "noisecolor",
+ "cutoff", "reso", "fenvamt", "keytrk",
+ "fattack", "fdecay", "fsustain", "frelease",
+ "aattack", "adecay", "asustain", "arelease",
+ "lforate", "lfosaw", "lfotri", "lfosquare", "lfoamt", "lfosync",
+ "wmmix", "wmfreqa", "wmfreqb", "wmpwa", "wmpwb", "wmfilter",
+ "pmenv", "pmoscb", "pmfreqa", "pmpwa", "pmfilter" };
+ return (i >= 0 && i < kNumParams) ? ids[i] : "";
+ }
+ static const char* paramName(int i) {
+ static const char* nm[kNumParams] = {
+ "Master Tune", "Pitch Bend", "Mod Wheel", "Aftertouch Amount", "Bend Range", "Glide Time", "Glide Mode", "Voice Mode",
+ "Voice Count", "Voice Allocation", "Unison Stack", "Unison Detune", "Release Switch", "Vintage Drift", "Vintage Seed", "Output Volume",
+ "Output Spread", "Velocity Amp", "Velocity Filter", "Aftertouch Cutoff", "Aftertouch LFO", "Analog Noise-Floor", "Filter Bass-Comp", "Quality Oversampling",
+ "Osc A Octave", "Osc A Semitone", "Osc A Fine", "Osc A Saw", "Osc A Pulse", "Osc A Pulse-Width", "Osc A Sync",
+ "Osc B Octave", "Osc B Semitone", "Osc B Fine", "Osc B Saw", "Osc B Triangle", "Osc B Pulse", "Osc B Pulse-Width", "Osc B Lo-Freq", "Osc B Keyboard",
+ "Mixer Osc-A Level", "Mixer Osc-A On", "Mixer Osc-B Level", "Mixer Osc-B On", "Mixer Noise Level", "Mixer Noise On", "Mixer Noise Color",
+ "Filter Cutoff", "Filter Resonance", "Filter Env-Amount", "Filter Key-Track",
+ "Filter-Env Attack", "Filter-Env Decay", "Filter-Env Sustain", "Filter-Env Release",
+ "Amp-Env Attack", "Amp-Env Decay", "Amp-Env Sustain", "Amp-Env Release",
+ "LFO Rate", "LFO Saw", "LFO Triangle", "LFO Square", "LFO Initial-Amount", "LFO Tempo-Sync",
+ "Wheel-Mod Source-Mix", "Wheel-Mod Freq-A", "Wheel-Mod Freq-B", "Wheel-Mod PW-A", "Wheel-Mod PW-B", "Wheel-Mod Filter",
+ "Poly-Mod Filter-Env", "Poly-Mod Osc-B", "Poly-Mod Freq-A", "Poly-Mod PW-A", "Poly-Mod Filter" };
+ return (i >= 0 && i < kNumParams) ? nm[i] : "";
+ }
+
+ int32_t pluginParamCount() const override { return kNumParams; }
+ std::string pluginParamId(int32_t i) const override { return paramId(i); }
+ std::string pluginParamName(int32_t i) const override { return paramName(i); }
+ float pluginParamGet(int32_t i) const override {
+ return (i >= 0 && i < kNumParams) ? pn_[i].load(std::memory_order_relaxed) : 0.0f;
+ }
+ void pluginParamSet(int32_t i, float v) override {
+ if (i >= 0 && i < kNumParams && std::isfinite(v)) pn_[i].store(std::clamp(v, 0.0f, 1.0f), std::memory_order_relaxed);
+ }
+ int32_t pluginParamIndexOfId(const std::string& id) const override {
+ for (int32_t i = 0; i < kNumParams; ++i) if (id == paramId(i)) return i;
+ return -1;
+ }
+
+ // ---- project state (kNumParams normalized floats, little-endian; includes the seed) ----
+ std::vector<uint8_t> getState() const override {
+ std::vector<uint8_t> b(kNumParams * sizeof(float));
+ for (int i = 0; i < kNumParams; ++i) {
+ const float v = pn_[i].load(std::memory_order_relaxed);
+ std::memcpy(b.data() + i * sizeof(float), &v, sizeof(float));
+ }
+ return b;
+ }
+ void setState(const uint8_t* data, int32_t size) override {
+ if (!data) return;
+ const int n = std::min<int>(kNumParams, size / static_cast<int>(sizeof(float)));
+ for (int i = 0; i < n; ++i) {
+ float v; std::memcpy(&v, data + i * sizeof(float), sizeof(float));
+ if (std::isfinite(v)) pn_[i].store(std::clamp(v, 0.0f, 1.0f), std::memory_order_relaxed);
+ }
+ }
+ std::shared_ptr<Instrument> clone() const override {
+ auto s = std::make_shared<Pentad>();
+ for (int i = 0; i < kNumParams; ++i) s->pn_[i].store(pn_[i].load(std::memory_order_relaxed), std::memory_order_relaxed);
+ s->setSampleRate(pendingRate_.load(std::memory_order_relaxed));
+ return s;
+ }
+
+ // ---- musical mappings (shared with the editor's readouts) ---------------
+ static int polyphonyOf(float v) { static const int n[3] = { 5, 10, 16 }; return n[std::clamp(static_cast<int>(std::lround(v * 2.0f)), 0, 2)]; }
+ static int unisonOf(float v) { static const int n[3] = { 1, 2, 5 }; return n[std::clamp(static_cast<int>(std::lround(v * 2.0f)), 0, 2)]; }
+ static int bendRangeOf(float v) { return 1 + std::clamp(static_cast<int>(std::lround(v * 11.0f)), 0, 11); }
+ static int octaveOf(float v) { return std::clamp(static_cast<int>(std::lround(v * 3.0f)), 0, 3) - 2; } // 32'..4' → -2..+1
+ static int semiOf(float v) { return std::clamp(static_cast<int>(std::lround((v - 0.5f) * 24.0f)), -12, 12); }
+ static float fineCentsOf(float v) { return (v - 0.5f) * 100.0f; }
+ static float cutoffHzOf(float v) { return 20.0f * std::pow(1000.0f, std::clamp(v, 0.0f, 1.0f)); }
+ static float attackSecOf(float v) { return static_cast<float>(expMap(v, 0.0005, 10.0)); }
+ static float decaySecOf(float v) { return static_cast<float>(expMap(v, 0.002, 15.0)); }
+ static float glideSecOf(float v) { return v < 0.002f ? 0.0f : static_cast<float>(expMap(v, 0.005, 10.0)); }
+ static float lfoHzOf(float v) { return static_cast<float>(expMap(v, 0.05, 20.0)); }
+ static constexpr int kSyncDivs = 14;
+ static float syncBeatsOf(float v) { // cycle length in beats (quarter notes)
+ static const float b[kSyncDivs] = { 32.f, 16.f, 8.f, 4.f, 2.f, 1.5f, 1.f, 0.75f, 2.f / 3.f, 0.5f, 1.f / 3.f, 0.25f, 1.f / 6.f, 0.125f };
+ return b[std::clamp(static_cast<int>(std::lround(v * (kSyncDivs - 1))), 0, kSyncDivs - 1)];
+ }
+ static float volumeGainOf(float v) { return 2.0f * v * v; }
+
+ // ---- transport (play edge → reseed for determinism; LFO tempo sync) -----
+ // A play edge re-seeds when nothing sounds (a live-held key survives pressing Play); a
+ // jump of the rolling timeline (seek, loop wrap, a freeze bounce restarting at 0 without
+ // a stopped block in between) always does — the old voices belong to another position.
+ // Positions compare in samples, so tempo changes never read as a jump.
+ void setTransport(double beatStart, double samplesPerBeat, bool playing) override {
+ const double pos = beatStart * samplesPerBeat;
+ const bool jumped = playing && tPlaying_ && std::fabs(pos - (tPos_ + tFrames_)) > 2.0;
+ if (jumped) resetAll();
+ else if (playing && !tPlaying_) {
+ bool any = false;
+ for (int v = 0; v < kMaxVoices; ++v) any |= voices_[v].active;
+ if (!any) resetAll();
+ }
+ tBeat_ = beatStart; tSpb_ = samplesPerBeat; tFresh_ = true;
+ tPos_ = pos; tFrames_ = 0.0;
+ tPlaying_ = playing;
+ }
+
+ // ---- note events ----------------------------------------------------------
+ void noteOn(int32_t pitch, float velocity) override {
+ syncStructure();
+ const int mode = voiceMode();
+ const bool othersHeld = heldN_ > 0;
+ pushHeld(pitch);
+ const float vel = std::clamp(velocity, 0.0f, 1.0f);
+ const int N = polyphonyOf(get(Polyphony));
+ const float glideT = glideSecOf(get(Glide));
+ if (mode == 0) {
+ const int gm = std::clamp(static_cast<int>(std::lround(get(GlideMode) * 2.0f)), 0, 2);
+ const bool glide = glideT > 0.0f && (gm == 1 || (gm == 2 && othersHeld));
+ const int S = std::min(unisonOf(get(Unison)), N);
+ for (int s = 0; s < S; ++s) {
+ int v = -1;
+ for (int k = 0; k < N; ++k) { // the same key again → retrigger its voice
+ const Voice& V = voices_[k];
+ if (V.active && V.note == pitch && V.stackIdx == s && V.stackN == S && V.pendNote < 0) { v = k; break; }
+ }
+ bool fade = false;
+ if (v < 0) v = allocate(N, fade);
+ if (fade) {
+ Voice& V = voices_[v];
+ V.pendNote = pitch; V.pendVel = vel; V.pendStack = s; V.pendStackN = S; V.pendGlide = glide;
+ V.fade = fadeLen_;
+ } else {
+ startVoice(v, pitch, vel, s, S, glide);
+ }
+ }
+ } else {
+ const int S = (mode == 1) ? N : 1;
+ const int low = lowestHeld();
+ if (!othersHeld) {
+ for (int s = 0; s < S; ++s) startVoice(s, low, vel, s, S, glideT > 0.0f);
+ } else {
+ for (int s = 0; s < S; ++s) { Voice& V = voices_[s]; V.note = low; V.pitchTgt = static_cast<float>(low); if (glideT <= 0.0f) V.pitch = V.pitchTgt; }
+ }
+ }
+ }
+ void noteOff(int32_t pitch) override {
+ syncStructure();
+ removeHeld(pitch);
+ if (voiceMode() == 0) {
+ for (int v = 0; v < kMaxVoices; ++v) {
+ Voice& V = voices_[v];
+ if (V.gate && V.note == pitch) release(V);
+ if (V.pendNote == pitch) V.pendNote = -1; // stolen-voice note ended before it started
+ }
+ return;
+ }
+ const int S = voiceMode() == 1 ? polyphonyOf(get(Polyphony)) : 1;
+ if (heldN_ == 0) { for (int s = 0; s < S; ++s) if (voices_[s].gate) release(voices_[s]); return; }
+ const int low = lowestHeld();
+ const bool glide = glideSecOf(get(Glide)) > 0.0f;
+ for (int s = 0; s < S; ++s) {
+ Voice& V = voices_[s];
+ if (!V.active) continue;
+ V.note = low; V.pitchTgt = static_cast<float>(low);
+ if (!glide) V.pitch = V.pitchTgt;
+ }
+ }
+ void allNotesOff() override { resetAll(); }
+
+ // ---- render ---------------------------------------------------------------
+ void render(float* out, int32_t frames) override {
+ FtzGuard ftz;
+ const auto t0 = std::chrono::steady_clock::now();
+ const double pr = pendingRate_.load(std::memory_order_relaxed);
+ if (pr != sampleRate_) { // voices keep playing; only rate-derived state restarts
+ sampleRate_ = pr;
+ fadeLen_ = std::max(1, static_cast<int>(0.004 * sampleRate_));
+ for (int c = 0; c < 2; ++c) { dnSteep_[c].clear_buffers(); dnMid_[c].clear_buffers(); }
+ smoothInit_ = false;
+ }
+ for (int32_t done = 0; done < frames;) {
+ const int n = std::min<int>(kChunk, frames - done);
+ renderChunk(out + done * 2, n);
+ done += n;
+ }
+ tFrames_ += frames;
+ const double el = std::chrono::duration<double>(std::chrono::steady_clock::now() - t0).count();
+ const double avail = frames / sampleRate_;
+ if (avail > 0.0) cpu_ += 0.05 * (el / avail - cpu_);
+ publishTelemetry(frames);
+ }
+
+private:
+ static constexpr int kChunk = 64;
+ static constexpr int kMaxOs = 4;
+ static constexpr double kPi = 3.14159265358979323846;
+ static constexpr float kStageDrive = 0.35f; // OTA stage saturation (colour)
+ static constexpr float kLoopDrive = 2.0f; // resonance-loop saturation (self-osc level)
+
+ struct Voice {
+ bool active = false, gate = false;
+ int note = 60, stackIdx = 0, stackN = 1;
+ float vel = 0.8f;
+ uint64_t order = 0;
+ // stolen-voice handoff (oldest-steal fade)
+ int pendNote = -1, pendStack = 0, pendStackN = 1, fade = 0;
+ float pendVel = 0.0f; bool pendGlide = false;
+ // pitch (semitones, glided)
+ float pitch = 60.0f, pitchTgt = 60.0f; bool hasPitch = false;
+ // envelopes: stage 0 idle, 1 attack, 2 decay/sustain, 3 release
+ float fenv = 0.0f, aenv = 0.0f; int fst = 0, ast = 0;
+ pentad::Osc A, B;
+ float s[4] = { 0, 0, 0, 0 }, df[4] = { 0, 0, 0, 0 }; // filter integrator states / stage diffs
+ float y4 = 0.0f; // last filter output (loop saturation)
+ pentad::Adaa sat; // mixer overdrive
+ // vintage: static spread (from the seed) + slow random walk
+ float oA = 0, oB = 0, oCut = 0, oEnvF = 0, oEnvA = 0, oPw = 0;
+ float wA = 0, wB = 0, wC = 0, tA = 0, tB = 0, tC = 0; int wCount = 0;
+ pentad::Rng rng;
+ // previous base-rate controls, interpolated across the oversampled sub-steps
+ double pDtA = 0, pDtB = 0; float pG = 0, pCut = 0, pPwA = 0.5f, pPwB = 0.5f, pAmp = 0;
+ bool fresh = true;
+ float panL = 1.0f, panR = 1.0f;
+ float level = 0.0f; // telemetry
+ };
+
+ // Flush-to-zero / denormals-are-zero for the render (restored after).
+ struct FtzGuard {
+#if defined(NOTA_PENTAD_FTZ_X86)
+ unsigned int old; FtzGuard() : old(_mm_getcsr()) { _mm_setcsr(old | 0x8040u); } ~FtzGuard() { _mm_setcsr(old); }
+#elif defined(NOTA_PENTAD_FTZ_ARM)
+ uint64_t old = 0;
+ FtzGuard() { asm volatile("mrs %0, fpcr" : "=r"(old)); const uint64_t n = old | (1ull << 24); asm volatile("msr fpcr, %0" : : "r"(n)); }
+ ~FtzGuard() { asm volatile("msr fpcr, %0" : : "r"(old)); }
+#endif
+ };
+
+ void set(Param p, float v) { pn_[p].store(v, std::memory_order_relaxed); }
+ float get(Param p) const { return pn_[p].load(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)); }
+ int voiceMode() const { return std::clamp(static_cast<int>(std::lround(get(VoiceMode) * 2.0f)), 0, 2); }
+ uint32_t seedValue() const { return static_cast<uint32_t>(std::lround(std::clamp(get(Seed), 0.0f, 1.0f) * 16777215.0f)); }
+
+ // ---- held keys --------------------------------------------------------------
+ void pushHeld(int p) { for (int i = 0; i < heldN_; ++i) if (held_[i] == p) return; if (heldN_ < 128) held_[heldN_++] = p; }
+ void removeHeld(int p) { int w = 0; for (int r = 0; r < heldN_; ++r) if (held_[r] != p) held_[w++] = held_[r]; heldN_ = w; }
+ int lowestHeld() const { int b = heldN_ > 0 ? held_[0] : 60; for (int i = 1; i < heldN_; ++i) b = std::min(b, held_[i]); return b; }
+
+ // ---- voice allocation -----------------------------------------------------
+ int allocate(int N, bool& fade) {
+ fade = false;
+ if (get(Alloc) < 0.5f) { // round-robin: next voice in rotation that isn't held
+ for (int k = 0; k < N; ++k) {
+ const int v = (rr_ + k) % N;
+ if (!voices_[v].gate && voices_[v].pendNote < 0) { rr_ = (v + 1) % N; return v; }
+ }
+ const int v = rr_ % N; rr_ = (v + 1) % N; // all held: reassign in rotation
+ return v;
+ }
+ int best = -1; uint64_t bo = ~0ull; // oldest steal: idle (least recently used) …
+ for (int v = 0; v < N; ++v) if (!voices_[v].active && voices_[v].pendNote < 0 && voices_[v].order < bo) { bo = voices_[v].order; best = v; }
+ if (best >= 0) return best;
+ for (int v = 0; v < N; ++v) if (!voices_[v].gate && voices_[v].pendNote < 0 && voices_[v].order < bo) { bo = voices_[v].order; best = v; }
+ if (best >= 0) return best; // … then the oldest releasing voice, then fade-steal
+ for (int v = 0; v < N; ++v) if (voices_[v].pendNote < 0 && voices_[v].order < bo) { bo = voices_[v].order; best = v; }
+ if (best < 0) best = 0;
+ fade = true;
+ return best;
+ }
+
+ void startVoice(int v, int note, float vel, int s, int S, bool glide) {
+ Voice& V = voices_[v];
+ V.note = note; V.vel = vel; V.gate = true; V.stackIdx = s; V.stackN = S; V.order = ++orderCtr_;
+ V.pitchTgt = static_cast<float>(note);
+ if (!V.hasPitch || !glide) V.pitch = V.pitchTgt;
+ V.hasPitch = true;
+ V.fst = 1; V.ast = 1; // retrigger from the current level (no restart at zero)
+ if (!V.active) wake(V);
+ }
+ // A sleeping voice wakes: free-running oscillators land at arbitrary phases; the
+ // filter/BLEP state it slept with is stale and cleared.
+ void wake(Voice& V) {
+ V.active = true; V.fresh = true;
+ V.A.ph += V.rng.uni(); V.A.ph -= std::floor(V.A.ph);
+ V.B.ph += V.rng.uni(); V.B.ph -= std::floor(V.B.ph);
+ V.A.hi = V.A.ph < get(OaPw); V.B.hi = V.B.ph < get(ObPw);
+ V.A.ring.clear(); V.B.ring.clear(); V.sat.reset();
+ for (int j = 0; j < 4; ++j) { V.s[j] = 0.0f; V.df[j] = 0.0f; }
+ V.y4 = 0.0f;
+ }
+ static void release(Voice& V) { V.gate = false; if (V.fst) V.fst = 3; if (V.ast) V.ast = 3; }
+
+ // ---- reset / seeding --------------------------------------------------------
+ void computeStatics(int v) {
+ pentad::Rng r; r.seed(pentad::hash32(seedCache_ * 2654435761U + pentad::hash32(static_cast<uint32_t>(v) + 17U)));
+ Voice& V = voices_[v];
+ V.oA = r.bi(); V.oB = r.bi(); V.oCut = r.bi(); V.oEnvF = r.bi(); V.oEnvA = r.bi(); V.oPw = r.bi();
+ }
+ void resetAll() {
+ seedCache_ = seedValue();
+ for (int v = 0; v < kMaxVoices; ++v) {
+ Voice& V = voices_[v];
+ V = Voice{};
+ V.rng.seed(pentad::hash32(seedCache_ ^ pentad::hash32(static_cast<uint32_t>(v) * 0x9E3779B9U + 1U)));
+ V.A.ph = V.rng.uni(); V.B.ph = V.rng.uni();
+ V.wCount = 1 + static_cast<int>(V.rng.next() % 4096u);
+ computeStatics(v);
+ }
+ heldN_ = 0; rr_ = 0; orderCtr_ = 0;
+ lfoPh_ = 0.0; tFresh_ = true;
+ noiseRng_.seed(pentad::hash32(seedCache_ ^ 0xA5A5A5A5U));
+ wmRng_.seed(pentad::hash32(seedCache_ ^ 0x5A5A5A5AU));
+ pk0_ = pk1_ = pk2_ = 0.0f;
+ for (int c = 0; c < 2; ++c) { dnSteep_[c].clear_buffers(); dnMid_[c].clear_buffers(); }
+ smoothInit_ = false;
+ lastMode_ = voiceMode(); lastPoly_ = polyphonyOf(get(Polyphony));
+ fadeLen_ = std::max(1, static_cast<int>(0.004 * sampleRate_));
+ peakL_ = peakR_ = mixPeak_ = 0.0f;
+ }
+ void initDecimators() {
+ static const double steep[12] = {
+ 0.017347915108876406, 0.067150480426919179, 0.14330738338179819, 0.23745131944299824,
+ 0.34085550201503761, 0.44601111310335906, 0.54753112652956148, 0.6423859124721446,
+ 0.72968928615804163, 0.81029959388029904, 0.88644514917318362, 0.96150605146543733 };
+ static const double mid[5] = {
+ 0.029113887601773612, 0.11638402872809682, 0.26337786480329456, 0.47885453461538624,
+ 0.78984065611473109 };
+ for (int c = 0; c < 2; ++c) { dnSteep_[c].set_coefs(steep); dnMid_[c].set_coefs(mid); }
+ }
+
+ // Voice mode / polyphony / seed changes, applied before any note event or render
+ // sees them (audio thread): a mode switch releases everything, fewer voices fade
+ // the surplus out, a new seed re-spreads the per-voice vintage offsets.
+ void syncStructure() {
+ const int mode = voiceMode();
+ if (mode != lastMode_) { for (auto& V : voices_) if (V.gate) release(V); heldN_ = 0; lastMode_ = mode; }
+ const int N = polyphonyOf(get(Polyphony));
+ if (N != lastPoly_) {
+ for (int v = N; v < kMaxVoices; ++v) { Voice& V = voices_[v]; if (V.active && V.fade == 0) { V.pendNote = -1; V.fade = fadeLen_; V.gate = false; } }
+ rr_ = 0; lastPoly_ = N;
+ }
+ const uint32_t sd = seedValue();
+ if (sd != seedCache_) { seedCache_ = sd; for (int v = 0; v < kMaxVoices; ++v) computeStatics(v); }
+ }
+
+ // ---- one chunk (≤ kChunk frames) ---------------------------------------------
+ void renderChunk(float* out, int n) {
+ float P[kNumParams];
+ for (int i = 0; i < kNumParams; ++i) P[i] = pn_[i].load(std::memory_order_relaxed);
+ const double sr = sampleRate_;
+
+ syncStructure();
+
+ // Oversampling factor: ×2 / ×4 at ≤ 48 kHz, halved at 88.2/96, ×1 at 176.4/192.
+ int os = P[Oversample] > 0.5f ? 4 : 2;
+ if (sr >= 176000.0) os = 1; else if (sr >= 88000.0) os = std::max(1, os / 2);
+ if (os != osCur_) { for (int c = 0; c < 2; ++c) { dnSteep_[c].clear_buffers(); dnMid_[c].clear_buffers(); } osCur_ = os; }
+ const double fsOs = sr * os;
+
+ // ---- global per-sample controls (smoothed ~20 ms) ----
+ const float sc = 1.0f - static_cast<float>(std::exp(-1.0 / (0.02 * sr)));
+ const float bendRange = static_cast<float>(bendRangeOf(P[BendRange]));
+ const float tgt[kSm] = {
+ (P[Tune] - 0.5f) * 2.0f + (P[Bend] - 0.5f) * 2.0f * bendRange, // SmPitch (semis)
+ P[ModWheel], P[Aftertouch],
+ std::log2(20.0f) + std::clamp(P[Cutoff], 0.0f, 1.0f) * 9.96578428f, // SmCut (log2 Hz)
+ 4.6f * P[Reso],
+ P[MixAOn] > 0.5f ? P[MixA] : 0.0f, P[MixBOn] > 0.5f ? P[MixB] : 0.0f,
+ P[MixNoiseOn] > 0.5f ? P[MixNoise] : 0.0f,
+ P[FEnvAmt] * 9.0f, P[PmEnv], P[PmOscB], P[OaPw], P[ObPw],
+ volumeGainOf(P[Volume]) * 0.35f, P[KeyTrk], P[LfoAmt], P[WmMix], P[UniDetune] * 0.5f };
+ if (!smoothInit_) { for (int k = 0; k < kSm; ++k) sm_[k] = tgt[k]; smoothInit_ = true; }
+
+ // LFO
+ const int lfoN = (P[LfoSaw] > 0.5f) + (P[LfoTri] > 0.5f) + (P[LfoSquare] > 0.5f);
+ const bool lfoSync = P[LfoSync] > 0.5f && tSpb_ > 0.0;
+ double lfoInc = lfoHzOf(P[LfoRate]) / sr;
+ if (lfoSync) {
+ const double beats = syncBeatsOf(P[LfoRate]);
+ lfoInc = 1.0 / (beats * tSpb_);
+ if (tFresh_ && tPlaying_) { const double c = tBeat_ / beats; lfoPh_ = c - std::floor(c); }
+ }
+ tFresh_ = false;
+ const bool wmA = P[WmFreqA] > 0.5f, wmB = P[WmFreqB] > 0.5f, wmPA = P[WmPwA] > 0.5f, wmPB = P[WmPwB] > 0.5f, wmF = P[WmFilter] > 0.5f;
+ const float atCut = P[AtCutoff] * 4.0f, atLfo = P[AtLfo];
+
+ for (int i = 0; i < n; ++i) {
+ for (int k = 0; k < kSm; ++k) sm_[k] += (tgt[k] - sm_[k]) * sc;
+ float lfo = 0.0f;
+ if (lfoN > 0) {
+ const float ph = static_cast<float>(lfoPh_);
+ if (P[LfoSaw] > 0.5f) lfo += 2.0f * ph - 1.0f;
+ if (P[LfoTri] > 0.5f) lfo += ph < 0.5f ? 4.0f * ph - 1.0f : 3.0f - 4.0f * ph;
+ if (P[LfoSquare] > 0.5f) lfo += ph < 0.5f ? 1.0f : -1.0f;
+ lfo /= static_cast<float>(lfoN);
+ }
+ lfoPh_ += lfoInc; if (lfoPh_ >= 1.0) lfoPh_ -= std::floor(lfoPh_);
+ const float wmNoise = wmRng_.bi();
+ const float src = lfo + (wmNoise - lfo) * sm_[SmWmMix];
+ const float amt = std::clamp(sm_[SmLfoAmt] + sm_[SmMod] + atLfo * sm_[SmAt], 0.0f, 1.0f);
+ const float semis = src * amt * amt * 12.0f;
+ gPitchA_[i] = sm_[SmPitch] + (wmA ? semis : 0.0f);
+ gPitchB_[i] = sm_[SmPitch] + (wmB ? semis : 0.0f);
+ gPwA_[i] = sm_[SmPwA] + (wmPA ? src * amt * 0.45f : 0.0f);
+ gPwB_[i] = sm_[SmPwB] + (wmPB ? src * amt * 0.45f : 0.0f);
+ gCut_[i] = sm_[SmCut] + (wmF ? src * amt * 4.0f : 0.0f) + atCut * sm_[SmAt];
+ gK_[i] = sm_[SmK]; gMixA_[i] = sm_[SmMixA]; gMixB_[i] = sm_[SmMixB]; gMixN_[i] = sm_[SmMixN];
+ gFenv_[i] = sm_[SmFenv]; gPmE_[i] = sm_[SmPmEnv]; gPmB_[i] = sm_[SmPmOscB];
+ gVol_[i] = sm_[SmVol]; gKey_[i] = sm_[SmKey]; gDet_[i] = sm_[SmDet];
+ }
+ // Shared noise source at the oversampled rate (white, or Kellet "economy" pink).
+ const bool pink = P[NoiseColor] > 0.5f;
+ for (int k = 0, m = n * os; k < m; ++k) {
+ const float w = noiseRng_.bi();
+ if (pink) {
+ pk0_ = 0.99765f * pk0_ + w * 0.0990460f;
+ pk1_ = 0.96300f * pk1_ + w * 0.2965164f;
+ pk2_ = 0.57000f * pk2_ + w * 1.0526913f;
+ gNoise_[k] = (pk0_ + pk1_ + pk2_ + w * 0.1848f) * 0.3f;
+ } else gNoise_[k] = w;
+ }
+
+ // ---- voices ----
+ const int m = n * os;
+ std::fill(osL_, osL_ + m, 0.0f);
+ std::fill(osR_, osR_ + m, 0.0f);
+ VoiceCtl c{};
+ c.os = os; c.invOs = 1.0f / static_cast<float>(os); c.invFsOs = 1.0 / fsOs; c.fsOs = fsOs; c.sr = sr;
+ c.drift = P[Drift];
+ c.oaOff = 12.0f * octaveOf(P[OaOct]) + semiOf(P[OaSemi]) + fineCentsOf(P[OaFine]) * 0.01f;
+ c.obOff = 12.0f * octaveOf(P[ObOct]) + semiOf(P[ObSemi]) + fineCentsOf(P[ObFine]) * 0.01f;
+ c.sawA = P[OaSaw] > 0.5f ? 1.0f : 0.0f; c.pulA = P[OaPulse] > 0.5f ? 1.0f : 0.0f; c.sync = P[OaSync] > 0.5f;
+ c.sawB = P[ObSaw] > 0.5f ? 1.0f : 0.0f; c.triB = P[ObTri] > 0.5f ? 1.0f : 0.0f; c.pulB = P[ObPulse] > 0.5f ? 1.0f : 0.0f;
+ c.kbdB = P[ObKbd] > 0.5f; c.loB = P[ObLoFreq] > 0.5f;
+ c.pmFreqA = P[PmFreqA] > 0.5f; c.pmPwA = P[PmPwA] > 0.5f; c.pmFilt = P[PmFilter] > 0.5f;
+ c.velAmp = P[VelAmp]; c.velFilt = P[VelFilt];
+ c.comp = P[LowComp] > 0.5f ? 1.0f : 0.0f;
+ c.noiseFloor = P[NoiseFloor] > 0.5f;
+ const bool relOn = P[ReleaseOn] > 0.5f;
+ c.tFA = attackSecOf(P[FAttack]) / 1.4663f; c.tFD = decaySecOf(P[FDecay]) * 0.25f; c.tFR = relOn ? decaySecOf(P[FRelease]) * 0.25f : 0.001f;
+ c.tAA = attackSecOf(P[AAttack]) / 1.4663f; c.tAD = decaySecOf(P[ADecay]) * 0.25f; c.tAR = relOn ? decaySecOf(P[ARelease]) * 0.25f : 0.001f;
+ c.fS = P[FSustain]; c.aS = P[ASustain];
+ const float gT = glideSecOf(P[Glide]);
+ c.glideC = gT > 0.0f ? 1.0f - static_cast<float>(std::exp(-1.0 / (gT / 3.0 * sr))) : 1.0f;
+ c.walkC = 1.0f - static_cast<float>(std::exp(-1.0 / (0.8 * sr)));
+ c.spread = P[Spread];
+ c.invFade = 1.0f / static_cast<float>(fadeLen_);
+ c.cutMax = static_cast<float>(std::min(fsOs * 0.40, 30000.0));
+ mixPeakChunk_ = 0.0f;
+
+ int active = 0;
+ for (int v = 0; v < kMaxVoices; ++v) {
+ Voice& V = voices_[v];
+ if (!V.active) { V.level = 0.0f; continue; }
+ // Pan: unison stacks fan out across the field, poly voices on a golden-ratio spread.
+ float pos = V.stackN > 1 ? (2.0f * V.stackIdx / static_cast<float>(V.stackN - 1) - 1.0f)
+ : (2.0f * static_cast<float>(std::fmod(0.5 + v * 0.61803398875, 1.0)) - 1.0f);
+ const float ang = (std::clamp(c.spread * pos, -1.0f, 1.0f) + 1.0f) * 0.25f * static_cast<float>(kPi);
+ V.panL = std::cos(ang) * 1.41421356f; V.panR = std::sin(ang) * 1.41421356f;
+ renderVoice(V, n, c);
+ if (V.active) ++active;
+ }
+
+ // ---- decimate the oversampled stereo sum and add into the output ----
+ if (os == 1) {
+ for (int i = 0; i < n; ++i) { dsL_[i] = osL_[i]; dsR_[i] = osR_[i]; }
+ } else if (os == 2) {
+ dnSteep_[0].process_block(dsL_, osL_, n); dnSteep_[1].process_block(dsR_, osR_, n);
+ } else {
+ dnMid_[0].process_block(tmpL_, osL_, n * 2); dnMid_[1].process_block(tmpR_, osR_, n * 2);
+ dnSteep_[0].process_block(dsL_, tmpL_, n); dnSteep_[1].process_block(dsR_, tmpR_, n);
+ }
+ float pl = 0.0f, prr = 0.0f;
+ for (int i = 0; i < n; ++i) {
+ float l = dsL_[i], r = dsR_[i];
+ if (!std::isfinite(l) || !std::isfinite(r)) { l = r = 0.0f; }
+ out[i * 2] += l; out[i * 2 + 1] += r;
+ pl = std::max(pl, std::fabs(l)); prr = std::max(prr, std::fabs(r));
+ }
+ const float dec = static_cast<float>(std::exp(-n / (0.3 * sr)));
+ peakL_ = std::max(pl, peakL_ * dec); peakR_ = std::max(prr, peakR_ * dec);
+ mixPeak_ = std::max(mixPeakChunk_, mixPeak_ * dec);
+ activeCount_ = active;
+ }
+
+ struct VoiceCtl {
+ int os; float invOs; double invFsOs, fsOs, sr;
+ float drift, oaOff, obOff, sawA, pulA, sawB, triB, pulB;
+ bool sync, kbdB, loB, pmFreqA, pmPwA, pmFilt, noiseFloor;
+ float velAmp, velFilt, comp;
+ float tFA, tFD, tFR, tAA, tAD, tAR, fS, aS;
+ float glideC, walkC, spread, invFade, cutMax;
+ };
+
+ static float coefOf(float tau, double sr) { return 1.0f - static_cast<float>(std::exp(-1.0 / (std::max(tau, 1e-5f) * sr))); }
+
+ void renderVoice(Voice& V, int n, const VoiceCtl& c) {
+ using namespace pentad;
+ const double sr = c.sr;
+ // Per-voice envelope coefficients with the vintage time spread.
+ const float ef = 1.0f + c.drift * 0.2f * V.oEnvF, ea = 1.0f + c.drift * 0.2f * V.oEnvA;
+ const float fA = coefOf(c.tFA * ef, sr), fD = coefOf(c.tFD * ef, sr), fR = coefOf(c.tFR * ef, sr);
+ const float aA = coefOf(c.tAA * ea, sr), aD = coefOf(c.tAD * ea, sr), aR = coefOf(c.tAR * ea, sr);
+ // Unison stacks stay fat but don't scale linearly with the voice count.
+ const float stackGain = V.stackN > 1 ? std::pow(static_cast<float>(V.stackN), -0.4f) : 1.0f;
+ const float velA = (1.0f - c.velAmp * (1.0f - V.vel)) * stackGain;
+ const float velF = 1.0f - c.velFilt * (1.0f - V.vel);
+ const int os = c.os;
+ const float kPiF = static_cast<float>(kPi);
+ const bool audioCut = c.pmFilt && c.sawB + c.triB + c.pulB > 0.0f;
+ float* L = osL_; float* R = osR_;
+ float mixPk = mixPeakChunk_;
+
+ for (int i = 0; i < n; ++i) {
+ // -- stolen-voice fade → hand the voice to its pending note --
+ float fadeG = 1.0f;
+ if (V.fade > 0) {
+ --V.fade;
+ fadeG = static_cast<float>(V.fade) * c.invFade;
+ if (V.fade == 0) {
+ if (V.pendNote >= 0) {
+ V.fenv = V.aenv = 0.0f;
+ const int pn = V.pendNote; V.pendNote = -1;
+ startVoice(static_cast<int>(&V - voices_), pn, V.pendVel, V.pendStack, V.pendStackN, V.pendGlide);
+ } else { V.active = false; V.gate = false; V.fst = V.ast = 0; V.fenv = V.aenv = 0.0f; V.level = 0.0f; return; }
+ }
+ }
+ // -- glide (exponential, in semitones) --
+ V.pitch += (V.pitchTgt - V.pitch) * c.glideC;
+ // -- envelopes (RC curves; attack aims past 1 like the analog charge) --
+ switch (V.fst) {
+ case 1: V.fenv += (1.3f - V.fenv) * fA; if (V.fenv >= 1.0f) { V.fenv = 1.0f; V.fst = 2; } break;
+ case 2: V.fenv += (c.fS - V.fenv) * fD; break;
+ case 3: V.fenv -= V.fenv * fR; if (V.fenv < 1e-6f) { V.fenv = 0.0f; V.fst = 0; } break;
+ default: break;
+ }
+ switch (V.ast) {
+ case 1: V.aenv += (1.3f - V.aenv) * aA; if (V.aenv >= 1.0f) { V.aenv = 1.0f; V.ast = 2; } break;
+ case 2: V.aenv += (c.aS - V.aenv) * aD; break;
+ case 3: V.aenv -= V.aenv * aR; if (V.aenv < 3e-5f) { V.aenv = 0.0f; V.ast = 0; } break; // ≈ -90 dB
+ default: break;
+ }
+ if (V.ast == 0 && V.fade == 0) { // asleep: stop computing this voice
+ V.active = false; V.gate = false; V.fst = 0; V.level = 0.0f;
+ mixPeakChunk_ = mixPk;
+ return;
+ }
+ // -- slow random walk (vintage drift) --
+ if (--V.wCount <= 0) {
+ V.tA = V.rng.bi(); V.tB = V.rng.bi(); V.tC = V.rng.bi();
+ V.wCount = static_cast<int>(sr * (0.4 + 1.6 * V.rng.uni())) + 1;
+ }
+ V.wA += (V.tA - V.wA) * c.walkC; V.wB += (V.tB - V.wB) * c.walkC; V.wC += (V.tC - V.wC) * c.walkC;
+
+ // -- base-rate control targets --
+ const float key = V.pitch;
+ const float det = V.stackN > 1 ? gDet_[i] * (2.0f * V.stackIdx / static_cast<float>(V.stackN - 1) - 1.0f) : 0.0f;
+ const float fe = V.fenv;
+ const float pmE = gPmE_[i] * gPmE_[i];
+ float noteA = key + det + gPitchA_[i] + c.oaOff + c.drift * (0.15f * V.oA + 0.08f * V.wA);
+ if (c.pmFreqA) noteA += pmE * 60.0f * fe;
+ float noteB = (c.kbdB ? key + det : 60.0f) + gPitchB_[i] + c.obOff + c.drift * (0.15f * V.oB + 0.08f * V.wB);
+ if (c.loB) noteB -= 96.0f;
+ const double dtA = std::min(440.0 * exp2f((noteA - 69.0f) * (1.0f / 12.0f)) * c.invFsOs, 0.45);
+ const double dtB = std::min(440.0 * exp2f((noteB - 69.0f) * (1.0f / 12.0f)) * c.invFsOs, 0.45);
+ float cut = gCut_[i] + gFenv_[i] * fe * velF + gKey_[i] * (key - 60.0f) * (1.0f / 12.0f)
+ + c.drift * (0.3f * V.oCut + 0.1f * V.wC);
+ if (c.pmFilt) cut += gPmE_[i] * 6.0f * fe;
+ const float fc = std::clamp(exp2f(cut), 8.0f, c.cutMax);
+ const float g = tanPrewarp(kPiF * fc * static_cast<float>(c.invFsOs));
+ const float pwA = gPwA_[i] + (c.pmPwA ? gPmE_[i] * 0.5f * fe : 0.0f) + c.drift * 0.02f * V.oPw;
+ const float pwB = gPwB_[i];
+ const float amp = (V.aenv * velA + 3e-5f) * fadeG * gVol_[i];
+ const float pmB = gPmB_[i] * gPmB_[i];
+ const float fmOct = c.pmFreqA ? pmB * 4.0f : 0.0f;
+ const float pwmB = c.pmPwA ? gPmB_[i] * 0.5f : 0.0f;
+ const float cutB = c.pmFilt ? pmB * 4.0f : 0.0f;
+ if (V.fresh) { V.pDtA = dtA; V.pDtB = dtB; V.pG = g; V.pCut = cut; V.pPwA = pwA; V.pPwB = pwB; V.pAmp = amp; V.fresh = false; }
+ const float k = gK_[i];
+ const float mA = gMixA_[i], mB = gMixB_[i], mN = gMixN_[i];
+ const float xin0 = 1.0f + c.comp * k;
+ const float* nz = gNoise_ + i * os;
+ float* lo = L + i * os; float* ro = R + i * os;
+
+ for (int s = 0; s < os; ++s) {
+ const float t = static_cast<float>(s + 1) * c.invOs;
+ // --- Osc B (master) ---
+ const double dB = V.pDtB + (dtB - V.pDtB) * t;
+ const float duB = std::clamp(V.pPwB + (pwB - V.pPwB) * t, 0.0f, 1.0f);
+ const float gzB = c.pulB * pulseZone(duB);
+ const double pb0 = V.B.ph;
+ const float wrapB = advance(V.B, dB, 0.0f, dB, duB, c.sawB, gzB);
+ const float pb = static_cast<float>(V.B.ph);
+ if (c.triB != 0.0f) { // triangle slope corners (BLAMP)
+ const float sl = 8.0f * static_cast<float>(dB) * c.triB;
+ const float inv = static_cast<float>(1.0 / dB);
+ if (wrapB >= 0.0f) {
+ if (pb0 < 0.5) V.B.ring.blamp((0.5f + pb) * inv, -sl);
+ V.B.ring.blamp(wrapB, sl);
+ if (pb >= 0.5f) V.B.ring.blamp((pb - 0.5f) * inv, -sl);
+ } else if (pb0 < 0.5 && pb >= 0.5f) V.B.ring.blamp((pb - 0.5f) * inv, -sl);
+ }
+ float nb = c.sawB * (2.0f * pb - 1.0f);
+ if (c.triB != 0.0f) nb += pb < 0.5f ? 4.0f * pb - 1.0f : 3.0f - 4.0f * pb;
+ nb += gzB * ((V.B.hi ? 1.0f : -1.0f) - (2.0f * duB - 1.0f));
+ V.B.ring.naive(nb);
+ const float bOut = V.B.ring.pop();
+
+ // --- Osc A (slave; Poly-Mod FM / PWM from B at audio rate) ---
+ double dA = V.pDtA + (dtA - V.pDtA) * t;
+ if (fmOct != 0.0f) dA = std::min(dA * exp2f(fmOct * bOut), 0.45);
+ const float duA = std::clamp(V.pPwA + (pwA - V.pPwA) * t + pwmB * bOut, 0.0f, 1.0f);
+ const float gzA = c.pulA * pulseZone(duA);
+ if (c.sync && wrapB >= 0.0f) {
+ advance(V.A, dA * (1.0 - wrapB), wrapB, dA, duA, c.sawA, gzA);
+ const float pr = static_cast<float>(V.A.ph);
+ V.A.ring.blep(wrapB, -2.0f * pr * c.sawA); // saw snaps back to -1
+ if (!V.A.hi && duA > 0.0f) V.A.ring.blep(wrapB, 2.0f * gzA); // pulse goes high
+ V.A.hi = duA > 0.0f;
+ V.A.ph = 0.0;
+ advance(V.A, dA * wrapB, 0.0f, dA, duA, c.sawA, gzA);
+ } else {
+ advance(V.A, dA, 0.0f, dA, duA, c.sawA, gzA);
+ }
+ const float pa = static_cast<float>(V.A.ph);
+ V.A.ring.naive(c.sawA * (2.0f * pa - 1.0f) + gzA * ((V.A.hi ? 1.0f : -1.0f) - (2.0f * duA - 1.0f)));
+ const float aOut = V.A.ring.pop();
+
+ // --- mixer (soft saturation into the filter) ---
+ const float mix = mA * aOut + mB * bOut + mN * nz[s];
+ mixPk = std::max(mixPk, std::fabs(mix));
+ const float x = V.sat.process(mix * 0.6) * (1.0f / 0.6f);
+
+ // --- 4-pole OTA low-pass (ZDF, per-sample linearised tanh) ---
+ float gg;
+ if (audioCut) {
+ const float cc = V.pCut + (cut - V.pCut) * t + cutB * bOut;
+ gg = tanPrewarp(kPiF * std::clamp(exp2f(cc), 8.0f, c.cutMax) * static_cast<float>(c.invFsOs));
+ } else gg = V.pG + (g - V.pG) * t;
+ float G[4], S[4];
+ for (int j = 0; j < 4; ++j) {
+ const float a = gg * tanhRatio(kStageDrive * V.df[j]);
+ const float inv = 1.0f / (1.0f + a);
+ G[j] = a * inv; S[j] = V.s[j] * inv;
+ }
+ const float Gt = G[0] * G[1] * G[2] * G[3];
+ const float St = G[3] * (G[2] * (G[1] * S[0] + S[1]) + S[2]) + S[3];
+ const float xin = x * xin0;
+ // The resonance loop saturates (it bounds the self-oscillation amplitude
+ // without dragging its pitch off the cutoff the way stage clipping would).
+ const float kf = k * tanhRatio(kLoopDrive * V.y4);
+ float y3 = (Gt * xin + St) / (1.0f + kf * Gt);
+ const float u = xin - kf * y3;
+ const float y0 = G[0] * u + S[0], y1 = G[1] * y0 + S[1], y2 = G[2] * y1 + S[2];
+ y3 = G[3] * y2 + S[3];
+ V.df[0] = u - y0; V.df[1] = y0 - y1; V.df[2] = y1 - y2; V.df[3] = y2 - y3;
+ V.s[0] = 2.0f * y0 - V.s[0]; V.s[1] = 2.0f * y1 - V.s[1];
+ V.s[2] = 2.0f * y2 - V.s[2]; V.s[3] = 2.0f * y3 - V.s[3];
+ V.y4 = y3;
+
+ // --- VCA (gentle curvature + leakage) and noise floor ---
+ float o = std::clamp(y3, -6.0f, 6.0f) * (V.pAmp + (amp - V.pAmp) * t);
+ o -= 0.008f * o * o * o;
+ if (c.noiseFloor) o += 1e-5f * V.rng.bi();
+ lo[s] += o * V.panL; ro[s] += o * V.panR;
+ }
+ V.pDtA = dtA; V.pDtB = dtB; V.pG = g; V.pCut = cut; V.pPwA = pwA; V.pPwB = pwB; V.pAmp = amp;
+
+ // Extreme settings must never poison the voice: reset a non-finite filter.
+ if (!std::isfinite(V.s[0] + V.s[1] + V.s[2] + V.s[3])) {
+ for (int j = 0; j < 4; ++j) { V.s[j] = 0.0f; V.df[j] = 0.0f; }
+ V.y4 = 0.0f;
+ }
+ }
+ V.level = V.aenv * velA * (V.fade > 0 ? V.fade * c.invFade : 1.0f);
+ mixPeakChunk_ = mixPk;
+ }
+
+ void publishTelemetry(int32_t /*frames*/) {
+ tele_[ScPoly].store(static_cast<float>(lastPoly_), std::memory_order_relaxed);
+ tele_[ScActive].store(static_cast<float>(activeCount_), std::memory_order_relaxed);
+ tele_[ScPeakL].store(peakL_, std::memory_order_relaxed);
+ tele_[ScPeakR].store(peakR_, std::memory_order_relaxed);
+ tele_[ScMixPeak].store(mixPeak_, std::memory_order_relaxed);
+ tele_[ScCpu].store(static_cast<float>(cpu_), std::memory_order_relaxed);
+ tele_[ScOs].store(static_cast<float>(osCur_), std::memory_order_relaxed);
+ tele_[ScRate].store(static_cast<float>(sampleRate_), std::memory_order_relaxed);
+ for (int v = 0; v < kMaxVoices; ++v)
+ tele_[ScVoices + v].store(voices_[v].active ? voices_[v].level : 0.0f, std::memory_order_relaxed);
+ }
+
+ // ---- state ------------------------------------------------------------------
+ enum Sm { SmPitch = 0, SmMod, SmAt, SmCut, SmK, SmMixA, SmMixB, SmMixN, SmFenv, SmPmEnv, SmPmOscB,
+ SmPwA, SmPwB, SmVol, SmKey, SmLfoAmt, SmWmMix, SmDet, kSm };
+
+ double sampleRate_ = 44100.0;
+ std::atomic<double> pendingRate_{ 44100.0 };
+ Voice voices_[kMaxVoices];
+ int held_[128] = { 0 }; int heldN_ = 0;
+ int rr_ = 0; uint64_t orderCtr_ = 0;
+ int lastMode_ = 0, lastPoly_ = 5, fadeLen_ = 176, osCur_ = 2, activeCount_ = 0;
+ uint32_t seedCache_ = 0;
+ double lfoPh_ = 0.0;
+ double tBeat_ = 0.0, tSpb_ = 0.0, tPos_ = 0.0, tFrames_ = 0.0; bool tPlaying_ = false, tFresh_ = true;
+ pentad::Rng noiseRng_, wmRng_;
+ float pk0_ = 0, pk1_ = 0, pk2_ = 0;
+ float sm_[kSm] = {}; bool smoothInit_ = false;
+ float gPitchA_[kChunk], gPitchB_[kChunk], gPwA_[kChunk], gPwB_[kChunk], gCut_[kChunk], gK_[kChunk];
+ float gMixA_[kChunk], gMixB_[kChunk], gMixN_[kChunk], gFenv_[kChunk], gPmE_[kChunk], gPmB_[kChunk];
+ float gVol_[kChunk], gKey_[kChunk], gDet_[kChunk];
+ float gNoise_[kChunk * kMaxOs];
+ float osL_[kChunk * kMaxOs], osR_[kChunk * kMaxOs], tmpL_[kChunk * 2], tmpR_[kChunk * 2], dsL_[kChunk], dsR_[kChunk];
+ hiir::Downsampler2xFpu<12> dnSteep_[2];
+ hiir::Downsampler2xFpu<5> dnMid_[2];
+ float peakL_ = 0, peakR_ = 0, mixPeak_ = 0, mixPeakChunk_ = 0;
+ double cpu_ = 0.0;
+ mutable std::atomic<float> tele_[kScopeN] = {};
+ std::atomic<float> pn_[kNumParams];
+};
+
+} // namespace nota
diff --git a/src/native/nota.engine/src/RackCore.h b/src/native/nota.engine/src/RackCore.h
index aed37082..d1ffc25c 100644
--- a/src/native/nota.engine/src/RackCore.h
+++ b/src/native/nota.engine/src/RackCore.h
@@ -30,6 +30,7 @@
#include "FluxSynth.h"
#include "RhythmMachine.h"
#include "Monolith.h"
+#include "Pentad.h"
#include "GrainSynth.h"
#include "Sampler.h"
#include "SampleBuffer.h"
@@ -645,6 +646,7 @@ public:
case 11: return std::make_shared<FluxSynth>();
case 12: return std::make_shared<RhythmMachine>();
case 13: return std::make_shared<Monolith>();
+ case 14: return std::make_shared<Pentad>();
default: return nullptr; // -1 = no instrument (effect rack); plugins are a follow-up
}
}
diff --git a/src/native/nota.engine/src/nota_engine_track.cpp b/src/native/nota.engine/src/nota_engine_track.cpp
index 6cf40ce1..05ce63fb 100644
--- a/src/native/nota.engine/src/nota_engine_track.cpp
+++ b/src/native/nota.engine/src/nota_engine_track.cpp
@@ -131,6 +131,9 @@ int32_t nota_engine_add_rhythm_track(NotaEngine* e) {
int32_t nota_engine_add_monolith_track(NotaEngine* e) {
return e ? ENG(e)->addMonolithTrack() : 0;
}
+int32_t nota_engine_add_pentad_track(NotaEngine* e) {
+ return e ? ENG(e)->addPentadTrack() : 0;
+}
void nota_track_instrument_action(NotaEngine* e, int32_t track_id, int32_t id, int32_t iarg, float farg) {
if (e) ENG(e)->instrumentAction(track_id, id, iarg, farg);
}
diff --git a/tests/Nota.SmokeTest/Program.cs b/tests/Nota.SmokeTest/Program.cs
index 4184b33a..aa77d4a4 100644
--- a/tests/Nota.SmokeTest/Program.cs
+++ b/tests/Nota.SmokeTest/Program.cs
@@ -1206,6 +1206,253 @@ Console.WriteLine("-- Nota Monolith --");
}
}
+// ============================ Nota Pentad ==================================
+Console.WriteLine("-- Nota Pentad --");
+{
+ using var pe = new NotaEngine();
+ pe.SetBpm(120); pe.SetTimeSignature(4, 4);
+ int t = pe.AddPentadTrack();
+ Check(t > 0, "AddPentadTrack returns a track");
+ Check(pe.TrackInstrumentKind(t) == 14, $"instrument kind is 14 (got {pe.TrackInstrumentKind(t)})");
+ Check(pe.DeviceName(t, -1) == "Nota Pentad", $"instrument is Nota Pentad (got '{pe.DeviceName(t, -1)}')");
+
+ int pc = pe.PluginParamCount(t, -1);
+ Check(pc == 76, $"Nota Pentad exposes 76 params (got {pc})");
+ var ids = new HashSet<string>();
+ bool namesOk = true;
+ for (int i = 0; i < pc; i++) { ids.Add(pe.PluginParamId(t, -1, i)); if (pe.PluginParamName(t, -1, i).Length == 0) namesOk = false; }
+ Check(ids.Count == pc && !ids.Contains("") && namesOk, "param ids are unique + non-empty, every param has a name");
+ int P(NotaEngine e, int tr, string id) { for (int i = 0; i < e.PluginParamCount(tr, -1); i++) if (e.PluginParamId(tr, -1, i) == id) return i; return -1; }
+ void SetId(NotaEngine e, int tr, string id, float v) => e.PluginParamSet(tr, -1, P(e, tr, id), v);
+ int cut = P(pe, t, "cutoff");
+
+ // State (incl. the vintage seed) round-trips to another track; duplicate clones it.
+ pe.PluginParamSet(t, -1, cut, 0.77f);
+ SetId(pe, t, "seed", 0.123f);
+ var state = pe.GetPluginState(t, -1);
+ Check(state.Length >= 76 * 4, $"pentad state serialized ({state.Length} bytes)");
+ int t2 = pe.AddPentadTrack();
+ pe.SetPluginState(t2, -1, state);
+ Check(Math.Abs(pe.PluginParamGet(t2, -1, cut) - 0.77f) < 1e-4 && Math.Abs(pe.PluginParamGet(t2, -1, P(pe, t2, "seed")) - 0.123f) < 1e-4,
+ "pentad state restores params + vintage seed on another track");
+ pe.PluginParamSet(t, -1, cut, 0.22f);
+ int t3 = pe.DuplicateTrack(t);
+ Check(t3 > 0 && Math.Abs(pe.PluginParamGet(t3, -1, cut) - 0.22f) < 1e-4, "duplicate track clones pentad params");
+
+ // A chord renders audible + finite in every voice mode (Poly / Unison / Mono).
+ var chord = new[] { new NotaNote(48, 0.0, 2.0, 0.9f), new NotaNote(55, 0.0, 2.0, 0.9f), new NotaNote(60, 0.0, 2.0, 0.9f), new NotaNote(64, 0.0, 2.0, 0.9f) };
+ foreach (var (mode, name) in new[] { (0f, "Poly"), (0.5f, "Unison"), (1f, "Mono") })
+ {
+ int ta = pe.AddPentadTrack();
+ SetId(pe, ta, "voicemode", mode);
+ pe.AddMidiClip(ta, 0.0, 4.0);
+ pe.SetClipNotes(ta, 0, chord);
+ var pbuf = new float[8192 * 2];
+ pe.Seek(0.0); pe.Play(); pe.RenderOffline(pbuf, 8192);
+ int voices = pe.InstrumentVoiceCount(ta);
+ pe.StopTransport();
+ bool finite = pbuf.All(float.IsFinite);
+ Check(finite && Rms(pbuf, 8192) > 0.001f, $"Nota Pentad {name} is audible + finite (RMS {Rms(pbuf, 8192):F3}, {voices} voices)");
+ int want = name == "Poly" ? 4 : name == "Unison" ? 5 : 1;
+ Check(voices == want, $"Nota Pentad {name} sounds {want} voice(s) for a 4-note chord (got {voices})");
+ pe.RemoveTrack(ta);
+ }
+
+ // Polyphony: 8 held pnotes on 5 voices → 5 sounding; 16-voice mode → 8.
+ foreach (var (poly, want) in new[] { (0f, 5), (1f, 8) })
+ {
+ int ta = pe.AddPentadTrack();
+ SetId(pe, ta, "polyphony", poly);
+ pe.AddMidiClip(ta, 0.0, 4.0);
+ var pnotes = new NotaNote[8];
+ for (int i = 0; i < 8; i++) pnotes[i] = new NotaNote(48 + i * 3, 0.0, 4.0, 0.8f);
+ pe.SetClipNotes(ta, 0, pnotes);
+ var pbuf = new float[4096 * 2];
+ pe.Seek(0.0); pe.Play(); pe.RenderOffline(pbuf, 4096);
+ int v = pe.InstrumentVoiceCount(ta);
+ pe.StopTransport();
+ Check(v == want, $"Nota Pentad {(poly < 0.5f ? 5 : 16)}-voice mode sounds {want} of 8 held notes (got {v})");
+ pe.RemoveTrack(ta);
+ }
+
+ // Determinism (Freeze: offline == realtime): the same patch + seed renders bit-identically
+ // regardless of block size, and a different seed changes the vintage spread.
+ float[] RenderPhrase(float seed, int block)
+ {
+ using var de = new NotaEngine();
+ de.SetBpm(120);
+ int dt = de.AddPentadTrack();
+ SetId(de, dt, "seed", seed); SetId(de, dt, "drift", 0.8f); SetId(de, dt, "mixnoise", 0.3f);
+ SetId(de, dt, "pmoscb", 0.5f); SetId(de, dt, "pmfreqa", 1f); SetId(de, dt, "oasync", 1f); SetId(de, dt, "lfoamt", 0.3f);
+ de.AddMidiClip(dt, 0.0, 4.0);
+ de.SetClipNotes(dt, 0, new[] { new NotaNote(60, 0.0, 1.5, 0.8f), new NotaNote(64, 0.25, 1.0, 0.7f), new NotaNote(67, 0.5, 1.5, 0.9f), new NotaNote(72, 1.0, 0.5, 0.6f) });
+ const int N = 44100;
+ var outv = new float[N * 2]; var tmp = new float[block * 2];
+ de.Seek(0.0); de.Play();
+ for (int done = 0; done < N;) { int m = Math.Min(block, N - done); de.RenderOffline(tmp, m); Array.Copy(tmp, 0, outv, done * 2, m * 2); done += m; }
+ de.StopTransport();
+ return outv;
+ }
+ var ra = RenderPhrase(0.5f, 4096); var rb = RenderPhrase(0.5f, 128); var rc = RenderPhrase(0.5f, 777); var rd = RenderPhrase(0.9f, 4096);
+ double dAB = 0, dAC = 0, dAD = 0;
+ for (int i = 0; i < ra.Length; i++) { dAB = Math.Max(dAB, Math.Abs(ra[i] - rb[i])); dAC = Math.Max(dAC, Math.Abs(ra[i] - rc[i])); dAD = Math.Max(dAD, Math.Abs(ra[i] - rd[i])); }
+ Check(Rms(ra, 44100) > 0.001f && dAB == 0 && dAC == 0, $"Nota Pentad null test: same seed renders bit-identically at blocks 4096/128/777 (maxdiff {Math.Max(dAB, dAC):G3})");
+ Check(dAD > 1e-3, $"Nota Pentad: a different vintage seed changes the render (maxdiff {dAD:F3})");
+
+ // Extreme settings never produce NaN/Inf (resonance 100 % + Poly-Mod at max + sync + 16-voice unison).
+ {
+ int ta = pe.AddPentadTrack();
+ foreach (var id in new[] { "reso", "pmenv", "pmoscb", "pmfreqa", "pmpwa", "pmfilter", "oasync", "oapulse", "obpulse", "obtri", "mixa", "mixb", "mixnoise", "fenvamt", "lfoamt", "wmfilter", "wmpwa", "wmpwb", "cutoff", "keytrk", "modwheel", "polyphony" })
+ SetId(pe, ta, id, 1f);
+ SetId(pe, ta, "voicemode", 0.5f);
+ pe.AddMidiClip(ta, 0.0, 8.0);
+ pe.SetClipNotes(ta, 0, new[] { new NotaNote(24, 0.0, 4.0, 1f), new NotaNote(108, 0.0, 4.0, 1f), new NotaNote(60, 4.0, 4.0, 1f) });
+ var pbuf = new float[44100 * 4 * 2];
+ pe.Seek(0.0); pe.Play(); pe.RenderOffline(pbuf, 44100 * 4);
+ SetId(pe, ta, "cutoff", 0f); pe.RenderOffline(pbuf, 44100 * 2);
+ pe.StopTransport();
+ Check(pbuf.All(float.IsFinite), "Nota Pentad stays finite at resonance 100 % + Poly-Mod max + 16-voice unison");
+ pe.RemoveTrack(ta);
+ }
+
+ // Aliasing (13.2): a 5 kHz-ish saw / pulse, filter open — spurious (non-harmonic)
+ // components in 20 Hz–20 kHz must stay ≤ -80 dB below the fundamental.
+ foreach (var (wave, os) in new[] { ("saw", 0f), ("pulse", 0f), ("saw", 1f), ("pulse", 1f) })
+ {
+ using var ae = new NotaEngine();
+ ae.SetBpm(120);
+ int ta = ae.AddPentadTrack();
+ foreach (var (id, v) in new[] { ("drift", 0f), ("noisefloor", 0f), ("cutoff", 1f), ("reso", 0f), ("keytrk", 0f), ("fenvamt", 0f), ("aattack", 0f), ("asustain", 1f),
+ ("mixb", 0f), ("mixa", 0.5f), ("spread", 0f), ("oversample", os), ("oasaw", wave == "saw" ? 1f : 0f), ("oapulse", wave == "pulse" ? 1f : 0f), ("oapw", 0.3f) })
+ SetId(ae, ta, id, v);
+ ae.AddMidiClip(ta, 0.0, 8.0);
+ ae.SetClipNotes(ta, 0, new[] { new NotaNote(111, 0.0, 8.0, 1f) });
+ const int N = 32768;
+ var warm = new float[22050 * 2]; var pbuf = new float[N * 2];
+ ae.Seek(0.0); ae.Play(); ae.RenderOffline(warm, 22050); ae.RenderOffline(pbuf, N); ae.StopTransport();
+ double sr = 44100, f0 = 440 * Math.Pow(2, (111 - 69) / 12.0);
+ var re = new double[N]; var im = new double[N];
+ for (int i = 0; i < N; i++) { double w = 2 * Math.PI * i / (N - 1); re[i] = pbuf[i * 2] * (0.35875 - 0.48829 * Math.Cos(w) + 0.14128 * Math.Cos(2 * w) - 0.01168 * Math.Cos(3 * w)); }
+ Fft(re, im);
+ double peak = 0, worst = 0, binHz = sr / N;
+ for (int i = 1; i < N / 2; i++) peak = Math.Max(peak, Math.Sqrt(re[i] * re[i] + im[i] * im[i]));
+ for (int i = (int)(20 / binHz); i < (int)(20000 / binHz); i++)
+ {
+ double h = i * binHz / f0;
+ if (Math.Round(h) >= 1 && Math.Abs(h - Math.Round(h)) * f0 < 10 * binHz) continue; // a true harmonic
+ worst = Math.Max(worst, Math.Sqrt(re[i] * re[i] + im[i] * im[i]));
+ }
+ double db = 20 * Math.Log10(worst / peak + 1e-30);
+ Check(db <= -80, $"Nota Pentad {wave} at {f0:0} Hz, ×{(os > 0.5f ? 4 : 2)} oversampling: worst alias {db:0.0} dB (≤ -80)");
+ }
+
+ // Stress (13.4): 16-voice unison + max resonance + Poly-Mod renders 128-frame blocks in real time.
+ {
+ using var se = new NotaEngine();
+ se.SetBpm(120);
+ int ta = se.AddPentadTrack();
+ foreach (var id in new[] { "reso", "pmenv", "pmoscb", "pmfreqa", "pmpwa", "pmfilter", "oasync", "polyphony", "oversample" }) SetId(se, ta, id, 1f);
+ SetId(se, ta, "voicemode", 0.5f);
+ se.AddMidiClip(ta, 0.0, 16.0);
+ se.SetClipNotes(ta, 0, new[] { new NotaNote(48, 0.0, 16.0, 1f) });
+ var blk = new float[128 * 2];
+ se.Seek(0.0); se.Play();
+ for (int i = 0; i < 50; i++) se.RenderOffline(blk, 128); // warm up
+ double worstMs = 0, totalMs = 0; const int blocks = 2000;
+ var sw = new System.Diagnostics.Stopwatch();
+ for (int i = 0; i < blocks; i++) { sw.Restart(); se.RenderOffline(blk, 128); sw.Stop(); worstMs = Math.Max(worstMs, sw.Elapsed.TotalMilliseconds); totalMs += sw.Elapsed.TotalMilliseconds; }
+ int active = se.InstrumentVoiceCount(ta);
+ se.StopTransport();
+ double budget = 128 / 44.1;
+ Check(active == 16 && totalMs / blocks < budget * 0.5, $"Nota Pentad stress: 16-voice unison ×4 OS avg {totalMs / blocks:0.000} ms, worst {worstMs:0.000} ms per 128-frame block (budget {budget:0.00} ms)");
+ }
+
+ // Automation: a plugin-param lane drives the cutoff during playback.
+ {
+ int ta = pe.AddPentadTrack();
+ int fi = P(pe, ta, "cutoff");
+ pe.PluginParamSet(ta, -1, fi, 0.1f);
+ int lane = pe.AddPluginAutomationLane(ta, -1, "cutoff");
+ Check(lane >= 0, "add plugin automation lane on pentad cutoff");
+ pe.SetAutomationPoints(ta, lane, new[] { new AutomationPoint(0.0, 0.1f, 0f), new AutomationPoint(2.0, 0.9f, 0f) });
+ var abuf = new float[4096 * 2];
+ pe.Seek(1.99); pe.Play(); pe.RenderOffline(abuf, 4096); pe.StopTransport();
+ Check(pe.PluginParamGet(ta, -1, fi) > 0.7f, $"automation drives Pentad cutoff (cutoff = {pe.PluginParamGet(ta, -1, fi):F2})");
+ }
+
+ // Freeze captures exactly what the live chain plays (deterministic voice state).
+ {
+ using var fe = new NotaEngine();
+ fe.SetBpm(120);
+ int ft = fe.AddPentadTrack();
+ SetId(fe, ft, "drift", 0.7f); SetId(fe, ft, "mixnoise", 0.2f);
+ fe.AddMidiClip(ft, 0.0, 4.0);
+ fe.SetClipNotes(ft, 0, new[] { new NotaNote(57, 0.0, 3.0, 0.9f), new NotaNote(64, 0.5, 2.0, 0.8f) });
+ const int N = 8192 * 4;
+ fe.Seek(0); fe.Play(); var live = new float[N * 2]; fe.RenderOffline(live, N); fe.StopTransport();
+ fe.Stop(); fe.SetLoop(false, 0, 0); fe.SetMetronome(false); fe.StopTransport();
+ long total = fe.BeginFreeze(ft, 4.0);
+ fe.StopTransport(); fe.Seek(0); fe.Play();
+ var chunk = new float[4096 * 2];
+ for (long rem = total; rem > 0;) { int m = (int)Math.Min(4096, rem); fe.RenderOffline(chunk, m); rem -= m; }
+ fe.StopTransport(); fe.EndFreeze(ft);
+ fe.Seek(0); fe.Play(); var frozen = new float[N * 2]; fe.RenderOffline(frozen, N); fe.StopTransport();
+ double md = 0; for (int i = 0; i < live.Length; i++) md = Math.Max(md, Math.Abs(live[i] - frozen[i]));
+ Check(fe.IsTrackFrozen(ft) && Rms(live, N) > 1e-3f && md < 1e-5, $"Nota Pentad freeze == live render (maxdiff {md:G3})");
+ }
+
+ // Factory presets: 40 ship, every named param is a real Pentad id, each applies in place.
+ {
+ var cat = new FactoryPresetCatalog();
+ var mine = cat.All().Where(p => p.IsInstrument && p.BuiltinKind == 14).ToList();
+ Check(mine.Count == 40, $"Nota Pentad ships 40 factory presets (got {mine.Count})");
+ var bad = mine.SelectMany(p => cat.Document(p.Id)!.NamedParams!.Keys.Where(k => !ids.Contains(k)).Select(k => $"{p.DisplayName}:{k}")).ToList();
+ Check(bad.Count == 0, $"every Pentad preset param id exists{(bad.Count > 0 ? " — bad: " + string.Join(", ", bad) : "")}");
+ int ta = pe.AddPentadTrack();
+ int fails = mine.Count(p => cat.ApplyInPlace(pe, p.Id, ta, -1).Length != 0);
+ Check(fails == 0, $"every Pentad preset applies in place ({fails} failed)");
+ cat.ApplyInPlace(pe, "pentad/Sync Lead", ta, -1);
+ Check(pe.PluginParamGet(ta, -1, P(pe, ta, "oasync")) > 0.5f && pe.PluginParamGet(ta, -1, P(pe, ta, "voicemode")) > 0.9f, "Sync Lead preset sets sync + mono mode");
+ }
+
+ // MCP: add by kind 14, set a param by stable id.
+ {
+ var mcp = new Nota.Mcp.Tools.InstrumentTools(pe, new Nota.SmokeTest.SyncDispatch(), new Nota.SmokeTest.NoRefresh());
+ int mt = mcp.AddInstrumentTrack(14).Result;
+ Check(mt > 0 && pe.TrackInstrumentKind(mt) == 14, "MCP add_instrument_track(14) adds a Nota Pentad");
+ Check(mcp.ListInstrumentKinds().Any(k => k.Kind == 14 && k.Name == "Nota Pentad"), "MCP list_instrument_kinds includes Nota Pentad");
+ Check(mcp.SetInstrumentParamById(mt, "pmoscb", 0.4f).Result && Math.Abs(pe.PluginParamGet(mt, -1, P(pe, mt, "pmoscb")) - 0.4f) < 1e-4, "MCP set_instrument_param_by_id sets Poly-Mod Osc-B");
+ Check(!mcp.SetInstrumentParamById(mt, "nope", 0.4f).Result, "MCP set_instrument_param_by_id rejects an unknown id");
+ }
+}
+
+static void Fft(double[] re, double[] im)
+{
+ int n = re.Length;
+ for (int i = 1, j = 0; i < n; i++)
+ {
+ int bit = n >> 1;
+ for (; (j & bit) != 0; bit >>= 1) j ^= bit;
+ j ^= bit;
+ if (i < j) { (re[i], re[j]) = (re[j], re[i]); (im[i], im[j]) = (im[j], im[i]); }
+ }
+ for (int len = 2; len <= n; len <<= 1)
+ {
+ double ang = -2 * Math.PI / len, wr = Math.Cos(ang), wi = Math.Sin(ang);
+ for (int i = 0; i < n; i += len)
+ {
+ double cr = 1, ci = 0;
+ for (int k = 0; k < len / 2; k++)
+ {
+ int a = i + k, b = a + len / 2;
+ double tr = re[b] * cr - im[b] * ci, ti = re[b] * ci + im[b] * cr;
+ re[b] = re[a] - tr; im[b] = im[a] - ti; re[a] += tr; im[a] += ti;
+ double nr = cr * wr - ci * wi; ci = cr * wi + ci * wr; cr = nr;
+ }
+ }
+ }
+}
+
// ============================ Nota Pendulum ================================
Console.WriteLine("-- Nota Pendulum --");
{