Skip to content

armgit / nota

Public Imported from GitHub
0

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

Redesign of Nota Synth

Egor Khindikaynencc464b9be549
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a0eb324a..1e67c55f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,6 +19,19 @@ Entry categories: `Added`, `Changed`, `Fixed`, `Removed`.
## [Unreleased]
### Added
+- **Nota Synth grew an oscillator and a voice section, and its editor is now three tabs.**
+ The oscillator gains **pulse width** (on the square), **detune**, **octave** and a
+ **unison** stack of 1 / 2 / 4 / 7 voices with a stereo **spread**; the filter gains a
+ **type** (Off / LP / HP / BP) and an **Env → Cutoff** amount; the voice section gains
+ **Poly 16 / Mono / Legato**, **glide**, **pan** and **Vel → Vol**. The card lays them out
+ as **Osc · Env · Filter** tabs — each one showing its graph full size with its knobs under
+ it — over a rail that keeps voice mode, volume, pan, glide, spread, velocity tracking and
+ the track's meter in view on every tab, and a status strip that reads the patch back in
+ words. The envelope's breakpoints and the filter's curve are draggable. Projects saved
+ before this load unchanged: the original eight parameters keep their index, and the new
+ ones start at values that sound exactly as before.
+- **Nota Synth ships 25 factory presets** (was 4) — pads, basses, leads, keys and moving
+ patches, including the four that existed before under their old names.
- **Clip tools — generative writing and rewriting in the piano roll.** A **Tools** rail
opens beside the roll with fifteen tools. Six **generators** write notes: *Rhythm*
(a pattern weighted toward the strong beats, with density, variation and accent),
diff --git a/FEATURES.md b/FEATURES.md
index 59795d5b..4f316f94 100644
--- a/FEATURES.md
+++ b/FEATURES.md
@@ -252,7 +252,11 @@ voice count (on synths), move arrows, delete, and the ⠿ drag handle. All suppo
and user presets, automation, persistence and cloning.
### Instruments
-- **Nota Synth** — subtractive synthesizer (the basic one).
+- **Nota Synth** — subtractive synthesizer (the basic one): one oscillator
+ (Saw/Square/Triangle/Sine) with pulse width, detune, octave and a 1/2/4/7-voice unison
+ stack with stereo spread; ADSR; a filter with type Off/LP/HP/BP, resonance and an
+ Env → Cutoff amount; voice modes Poly 16 / Mono / Legato with glide, pan and Vel→Vol.
+ Osc · Env · Filter tabs with draggable envelope and filter graphs. 25 factory presets.
- **Nota Sampler** — sampler (one-shot and loop), voice modes Poly 16 / Mono / Choke, loop
crossfade, reverse loop, filter key-tracking, Vel→Vol; Sample · Pitch · Env · Filter
tabs; an editable waveform.
diff --git a/src/managed/Nota.App/Controls/SynthViz.cs b/src/managed/Nota.App/Controls/SynthViz.cs
index 19c3ef64..3ce274e5 100644
--- a/src/managed/Nota.App/Controls/SynthViz.cs
+++ b/src/managed/Nota.App/Controls/SynthViz.cs
@@ -1,161 +1,352 @@
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.
//
-// Detail · Devices — the two Nota Synth graphs (mockup 2f). The envelope panel draws the
-// live ADSR in teal (= modulation) with a handle at every breakpoint and a note-off line;
-// the filter panel draws the low-pass response in brass (= audio) with a log Hz axis, a
-// 0 dB reference and a cutoff handle + readout. Both read the same normalized param values
-// the knobs write and denormalise them with the engine's exact maps, so the scales are real.
+// Detail · Devices — the three Nota Synth graph windows, one per tab of the editor. Each
+// fills the top of its tab and carries the readouts that tab is about:
+//
+// Osc the oscillator shape over eight cycles, the unison stack drawn behind it
+// Env the amplitude ADSR with a note-off marker; its breakpoints drag the params
+// Filter the response curve for the chosen type, a drag pad for cutoff (X) / reso (Y),
+// with the envelope's reach on the cutoff drawn as a teal ghost
+//
+// All three read the engine's normalized params straight and denormalise them with the
+// exact maps Synth.h uses, so the scales are real. Drawn through NotaGraph — well ground,
+// hairline frame, corner axis labels, no fills under curves.
using System;
+using System.Collections.Generic;
using System.Globalization;
using Avalonia;
using Avalonia.Controls;
+using Avalonia.Input;
using Avalonia.Media;
+using Nota.Application;
namespace Nota.App;
-internal sealed class SynthViz : Control
+internal sealed class SynthViz : Control, IMidiLearnRegions
{
- public enum K { Adsr, Filter }
+ public enum K { Osc, Adsr, Filter }
- private static readonly IBrush Sunken = NotaPalette.BgSunken;
- private static readonly IBrush BorderDef = NotaPalette.BorderDefault;
private static readonly IBrush TextTertiary = NotaPalette.TextTertiary;
private static readonly IBrush Teal = NotaPalette.Teal;
- private static readonly IBrush TealFill = NotaPalette.Wash(NotaPalette.Teal, 0x1A);
private static readonly IBrush Brass = NotaPalette.Accent;
- private static readonly IBrush BrassFill = NotaPalette.Wash(NotaPalette.Accent, 0x17);
- private static readonly IBrush Handle = NotaPalette.AccentBright;
- private static readonly IBrush DimMono = NotaPalette.TextAxis;
- private static readonly IBrush Grid = NotaGraph.Grid;
- private static readonly IBrush GridDash = NotaGraph.Grid;
- private static readonly Typeface Face = NotaFonts.Mono;
+ private static readonly IBrush Axis = NotaPalette.TextAxis;
+ private static readonly IBrush Ghost = NotaPalette.Wash(NotaPalette.Accent, 0x40);
+ private static readonly Typeface Mono = NotaFonts.Mono;
- private const double Pad = 8;
+ private const double Pad = 6;
private readonly K _k;
- private double _a, _d, _s, _r, _cut, _res;
+ private readonly IAudioEngine _e;
+ private readonly int _t;
+ private readonly Dictionary<string, int> _idx;
+ private int _drag = -1; // Env: 0 attack · 1 decay/sustain · 2 release. Filter: 0 pad.
+
+ public SynthViz(K k, IAudioEngine engine, int track, Dictionary<string, int> idx)
+ {
+ _k = k; _e = engine; _t = track; _idx = idx;
+ MinWidth = 180; MinHeight = 56;
+ if (k != K.Osc) Cursor = new Cursor(StandardCursorType.Hand);
+ }
- public SynthViz(K k) { _k = k; MinWidth = 180; MinHeight = 40; }
+ public void Refresh() => InvalidateVisual();
- public void Set(double a, double d, double s, double r, double cut, double res)
- { _a = a; _d = d; _s = s; _r = r; _cut = cut; _res = res; InvalidateVisual(); }
+ private int I(string id) => _idx.TryGetValue(id, out var i) ? i : -1;
+ private float G(string id) { int i = I(id); return i >= 0 ? _e.PluginParamGet(_t, -1, i) : 0f; }
+ private void Set(string id, double v) { int i = I(id); if (i >= 0) _e.PluginParamSet(_t, -1, i, (float)Math.Clamp(v, 0, 1)); }
- // Engine's perceptual map (Synth.h): lo * (hi/lo)^v.
+ // ---- the engine's maps, mirrored (Synth.h) -----------------------------
private static double ExpMap(double v, double lo, double hi) => lo * Math.Pow(hi / lo, Math.Clamp(v, 0, 1));
- private static string Secs(double s) => s < 1.0
- ? $"{(s * 1000).ToString("0", NotaNum.Culture)}\u2009ms"
- : $"{s.ToString("0.00", NotaNum.Culture)}\u2009s";
+ /// <summary>A bipolar amount with its sign always shown ("+12", "−8", "0").</summary>
+ private static string Signed(double v) => v.ToString("+0;−0;0", NotaNum.Culture);
+ private static double Osc(int wave, double ph, double pw) => wave switch
+ {
+ 1 => ph < pw ? 1.0 : -1.0,
+ 2 => 4.0 * Math.Abs(ph - 0.5) - 1.0,
+ 3 => Math.Sin(2.0 * Math.PI * ph),
+ _ => 2.0 * ph - 1.0,
+ };
+ private static readonly int[] UnisonCounts = { 1, 2, 4, 7 };
+ private int Unison() => UnisonCounts[Math.Clamp((int)Math.Round(G("unison") * 3), 0, 3)];
+ private int Wave() => Math.Clamp((int)Math.Round(G("wave") * 3), 0, 3);
+ private int FilType() => Math.Clamp((int)Math.Round(G("filtype") * 3), 0, 3);
+
+ private (double x0, double x1, double top, double bot) Geo()
+ => (Pad, Math.Max(Pad + 1, Bounds.Width - Pad), Pad + 11, Math.Max(Pad + 12, Bounds.Height - Pad - 9));
+
+ private void Text(DrawingContext ctx, string t, double x, double y, IBrush ink, double size = 8)
+ => ctx.DrawText(new FormattedText(t, CultureInfo.InvariantCulture, FlowDirection.LeftToRight, Mono, size, ink), new Point(x, y));
+ private static double MeasureW(string t, double size = 8)
+ => new FormattedText(t, CultureInfo.InvariantCulture, FlowDirection.LeftToRight, Mono, size, NotaPalette.TextPrimary).Width;
+
+ // ---- MIDI learn --------------------------------------------------------
+ // The graphs are the only place some of these params can be grabbed, so each drag
+ // target gets a region that learns it.
+ public IReadOnlyList<(Rect rect, MidiTarget target, string name)> GetMidiLearnRegions()
+ {
+ var list = new List<(Rect, MidiTarget, string)>(4);
+ var (x0, x1, top, bot) = Geo();
+ void Add(string id, string name, double fx, double fw)
+ {
+ int i = I(id); if (i < 0) return;
+ double w = (x1 - x0);
+ list.Add((new Rect(x0 + w * fx, top, w * fw, bot - top), MidiTarget.PluginParam(_t, -1, i), name));
+ }
+ if (_k == K.Adsr)
+ {
+ Add("attack", "Attack", 0, 0.25); Add("decay", "Decay", 0.25, 0.25);
+ Add("sustain", "Sustain", 0.5, 0.25); Add("release", "Release", 0.75, 0.25);
+ }
+ else if (_k == K.Filter)
+ {
+ Add("cutoff", "Cutoff", 0, 0.5); Add("resonance", "Reso", 0.5, 0.5);
+ }
+ return list;
+ }
+
+ // ---- interaction -------------------------------------------------------
+ protected override void OnPointerPressed(PointerPressedEventArgs e)
+ {
+ if (_k == K.Osc || !e.GetCurrentPoint(this).Properties.IsLeftButtonPressed) return;
+ var p = e.GetPosition(this);
+ if (_k == K.Filter) _drag = 0;
+ else
+ {
+ var (xa, xd, sy, _, xr) = EnvNodes();
+ var (_, _, top, bot) = Geo();
+ double dA = Math.Abs(p.X - xa) + Math.Abs(p.Y - top);
+ double dDS = Math.Abs(p.X - xd) + Math.Abs(p.Y - sy);
+ double dR = Math.Abs(p.X - xr) + Math.Abs(p.Y - bot);
+ _drag = (dA <= dDS && dA <= dR) ? 0 : (dDS <= dR ? 1 : 2);
+ }
+ Gesture(true); e.Pointer.Capture(this); Apply(p); e.Handled = true;
+ }
+ protected override void OnPointerMoved(PointerEventArgs e) { if (_drag >= 0) Apply(e.GetPosition(this)); }
+ protected override void OnPointerReleased(PointerReleasedEventArgs e)
+ { if (_drag >= 0) { Gesture(false); _drag = -1; e.Pointer.Capture(null); } }
+
+ /// <summary>Raised after a drag writes a param, so the card's readouts follow.</summary>
+ public event Action? Changed;
+
+ private void Gesture(bool begin)
+ {
+ void One(string id)
+ {
+ if (I(id) < 0) return;
+ if (begin) _e.BeginAutomationWrite(_t, AutomationTarget.PluginParam, -1, -1, id);
+ else _e.EndAutomationWrite(_t, AutomationTarget.PluginParam, -1, -1, id);
+ }
+ if (_k == K.Filter) { One("cutoff"); One("resonance"); }
+ else if (_drag == 0) One("attack");
+ else if (_drag == 1) { One("decay"); One("sustain"); }
+ else One("release");
+ }
- private void Text(DrawingContext ctx, string t, double x, double y, IBrush brush, double size = 8, bool mono = false)
- => ctx.DrawText(new FormattedText(t, CultureInfo.InvariantCulture, FlowDirection.LeftToRight,
- mono ? NotaFonts.Mono : Face, size, brush), new Point(x, y));
+ private void Apply(Point p)
+ {
+ var (x0, x1, top, bot) = Geo();
+ double span = Math.Max(1, x1 - x0), height = Math.Max(1, bot - top);
+ if (_k == K.Filter)
+ {
+ Set("cutoff", (p.X - x0) / span);
+ Set("resonance", 1 - (p.Y - top) / height);
+ }
+ else
+ {
+ double xa = x0 + G("attack") * 0.30 * span;
+ if (_drag == 0) Set("attack", (p.X - x0) / (0.30 * span));
+ else if (_drag == 1) { Set("decay", (p.X - xa) / (0.25 * span)); Set("sustain", 1 - (p.Y - top) / height); }
+ else { double xh = Math.Min(x1, xa + G("decay") * 0.25 * span + 0.20 * span); Set("release", (p.X - xh) / (0.25 * span)); }
+ }
+ InvalidateVisual();
+ Changed?.Invoke();
+ }
+
+ private (double xa, double xd, double sy, double xh, double xr) EnvNodes()
+ {
+ var (x0, x1, top, bot) = Geo();
+ double span = x1 - x0;
+ double xa = x0 + G("attack") * 0.30 * span;
+ double xd = Math.Min(x1, xa + G("decay") * 0.25 * span);
+ double xh = Math.Min(x1, xd + 0.20 * span);
+ double xr = Math.Min(x1, xh + G("release") * 0.25 * span);
+ double sy = top + (1 - G("sustain")) * (bot - top);
+ return (xa, xd, sy, xh, xr);
+ }
+ // ---- drawing -----------------------------------------------------------
public override void Render(DrawingContext ctx)
{
double w = Bounds.Width, h = Bounds.Height;
if (w <= 0 || h <= 0) return;
NotaGraph.Window(ctx, new Rect(0, 0, w, h));
-
- double x0 = Pad, x1 = w - Pad, top = Pad + 12, bot = h - Pad - 9;
- if (_k == K.Adsr) RenderEnvelope(ctx, x0, x1, top, bot);
- else RenderFilter(ctx, x0, x1, top, bot);
+ var (x0, x1, top, bot) = Geo();
+ switch (_k)
+ {
+ case K.Osc: RenderOsc(ctx, x0, x1, top, bot); break;
+ case K.Adsr: RenderEnvelope(ctx, x0, x1, top, bot); break;
+ default: RenderFilter(ctx, x0, x1, top, bot); break;
+ }
}
- private void RenderEnvelope(DrawingContext ctx, double x0, double x1, double top, double bot)
+ private static readonly string[] WaveWords = { "saw", "square", "triangle", "sine" };
+
+ private void RenderOsc(DrawingContext ctx, double x0, double x1, double top, double bot)
{
- var gridPen = new Pen(Grid, 1);
- for (int i = 1; i <= 2; i++) { double gy = top + (bot - top) * i / 3.0; ctx.DrawLine(gridPen, new Point(x0, gy), new Point(x1, gy)); }
+ double span = x1 - x0, mid = (top + bot) / 2, amp = (bot - top) / 2 - 1;
+ var gridPen = new Pen(NotaGraph.Grid, 1);
+ ctx.DrawLine(gridPen, new Point(x0, mid), new Point(x1, mid));
+ for (int i = 1; i <= 3; i++) { double gx = x0 + span * i / 4.0; ctx.DrawLine(gridPen, new Point(gx, top), new Point(gx, bot)); }
- double span = x1 - x0;
- double aw = _a * 0.30 * span, dw = _d * 0.25 * span, hold = 0.20 * span, rw = _r * 0.25 * span;
- double sy = top + (1 - _s) * (bot - top);
- double xa = x0 + aw, xd = Math.Min(x1, xa + dw), xh = Math.Min(x1, xd + hold), xr = Math.Min(x1, xh + rw);
+ const int cycles = 8, steps = 480;
+ int wave = Wave(), uni = Unison();
+ double pw = 0.05 + G("pulsewidth") * 0.90;
+ double cents = (G("detune") - 0.5) * 100.0;
- // The envelope as a stroked curve (almanac: no fills under curves).
- var fill = new StreamGeometry();
- using (var g = fill.Open())
+ // The unison stack behind the shape it is built from: each copy runs at its own
+ // detuned rate, so the drawing shows the beating the ear hears.
+ void Curve(double ratio, IPen pen)
{
- g.BeginFigure(new Point(x0, bot), true);
- g.LineTo(new Point(xa, top)); g.LineTo(new Point(xd, sy)); g.LineTo(new Point(xh, sy)); g.LineTo(new Point(xr, bot));
- g.EndFigure(true);
+ var geo = new StreamGeometry();
+ using (var g = geo.Open())
+ {
+ for (int s = 0; s <= steps; s++)
+ {
+ double t = s / (double)steps;
+ double ph = (t * cycles * ratio) % 1.0;
+ var pt = new Point(x0 + t * span, mid - Osc(wave, ph, pw) * amp);
+ if (s == 0) g.BeginFigure(pt, false); else g.LineTo(pt);
+ }
+ g.EndFigure(false);
+ }
+ ctx.DrawGeometry(null, pen, geo);
}
- var pen = new Pen(Teal, 1.8, lineCap: PenLineCap.Round, lineJoin: PenLineJoin.Round);
+ if (uni > 1)
+ {
+ var ghostPen = new Pen(Ghost, 1.0, lineJoin: PenLineJoin.Round);
+ for (int u = 0; u < uni; u++)
+ {
+ double t = 2.0 * u / (uni - 1) - 1.0;
+ if (Math.Abs(t) < 1e-6) continue; // the centre copy is the main curve
+ Curve(Math.Pow(2.0, cents * t / 1200.0), ghostPen);
+ }
+ }
+ Curve(1.0, new Pen(Brass, NotaGraph.PrimaryWidth, lineJoin: PenLineJoin.Round));
+
+ string left = $"{WaveWords[wave]} · {cycles} cycles · unison {uni}";
+ if (wave == 1) left += $" · pw {(pw * 100).ToString("0", NotaNum.Culture)} %";
+ Text(ctx, left, x0 + 1, Pad - 3, TextTertiary);
+ string right = uni == 1 && Math.Abs(cents) < 0.5 ? "one shape, no detune"
+ : $"detune {Signed(cents)} c";
+ Text(ctx, right, x1 - 1 - MeasureW(right), Pad - 3, Axis);
+ }
+
+ private void RenderEnvelope(DrawingContext ctx, double x0, double x1, double top, double bot)
+ {
+ var gridPen = new Pen(NotaGraph.Grid, 1);
+ for (int i = 1; i <= 3; i++) { double gy = top + (bot - top) * i / 4.0; ctx.DrawLine(gridPen, new Point(x0, gy), new Point(x1, gy)); }
+
+ var (xa, xd, sy, xh, xr) = EnvNodes();
+ var pen = new Pen(Brass, NotaGraph.PrimaryWidth, lineCap: PenLineCap.Round, lineJoin: PenLineJoin.Round);
ctx.DrawLine(pen, new Point(x0, bot), new Point(xa, top));
ctx.DrawLine(pen, new Point(xa, top), new Point(xd, sy));
ctx.DrawLine(pen, new Point(xd, sy), new Point(xh, sy));
ctx.DrawLine(pen, new Point(xh, sy), new Point(xr, bot));
- // Note-off line at the end of the sustain hold.
- ctx.DrawLine(new Pen(GridDash, 1) { DashStyle = new DashStyle(new double[] { 3, 3 }, 0) }, new Point(xh, top - 6), new Point(xh, bot));
+ // Note-off: where the key is released and the release stage begins.
+ ctx.DrawLine(new Pen(Ghost, 1) { DashStyle = new DashStyle(new double[] { 3, 3 }, 0) }, new Point(xh, top - 5), new Point(xh, bot));
- // Breakpoint handles.
- Dot(ctx, xa, top); Dot(ctx, xd, sy); Dot(ctx, xh, sy); Dot(ctx, xr, bot);
+ NotaGraph.Node(ctx, new Point(xa, top), active: true);
+ NotaGraph.Node(ctx, new Point(xd, sy), active: true);
+ NotaGraph.Node(ctx, new Point(xr, bot), active: true);
- // Labels: title + real reach time (top-right), note-off caption.
- double reach = ExpMap(_a, 0.001, 2.0) + ExpMap(_d, 0.002, 2.0);
- string reachTxt = $"{Secs(reach)} + rel";
- Text(ctx, "ENVELOPE", x1 - 52, Pad - 2, TextTertiary);
- Text(ctx, reachTxt, x1 - 52 - MeasureW(reachTxt, 8, true) - 8, Pad - 2, DimMono, 8, true);
- Text(ctx, "note off", Math.Min(xh + 3, x1 - 40), bot - 10, DimMono, 8, true);
+ double a = ExpMap(G("attack"), 0.001, 2.0), d = ExpMap(G("decay"), 0.002, 2.0), r = ExpMap(G("release"), 0.002, 3.0);
+ string left = $"{NotaNum.Time(a)} · {NotaNum.Time(d)} · {NotaNum.Db(AudioMath.LinToDb(G("sustain")))} · {NotaNum.Time(r)}";
+ Text(ctx, left, x0 + 1, Pad - 3, TextTertiary);
+ string right = $"{NotaNum.Time(a + d)} + rel";
+ Text(ctx, right, x1 - 1 - MeasureW(right), Pad - 3, Axis);
+ // Left of the marker: the release ramp leaves that corner empty, the one to its right not.
+ Text(ctx, "note off", Math.Max(x0 + 1, xh - 4 - MeasureW("note off")), bot - 10, Axis);
}
private void RenderFilter(DrawingContext ctx, double x0, double x1, double top, double bot)
{
double span = x1 - x0;
- // Log Hz axis over 20 .. 20k; cutoff denormalised with the engine's 20 .. 18k map.
- double lo = Math.Log(20), hi = Math.Log(20000), lspan = hi - lo;
- double HzToX(double hz) => x0 + (Math.Log(hz) - lo) / lspan * span;
- double cutHz = ExpMap(_cut, 20, 18000);
- double cx = HzToX(cutHz);
-
- // 0 dB reference (dashed) + three evenly-spaced vertical grid lines.
- double flatY = top + (bot - top) * 0.38;
- ctx.DrawLine(new Pen(GridDash, 1) { DashStyle = new DashStyle(new double[] { 3, 3 }, 0) }, new Point(x0, flatY), new Point(x1, flatY));
- var gridPen = new Pen(Grid, 1);
- for (int i = 1; i <= 3; i++) { double gx = x0 + span * i / 4.0; ctx.DrawLine(gridPen, new Point(gx, top - 6), new Point(gx, bot)); }
-
- // Response: flat, resonance bump at cutoff, then roll-off to the floor.
- double bumpY = flatY - _res * (flatY - top) * 0.95;
- double kx = Math.Max(x0, cx - Math.Min(14, span * 0.05));
- var fill = new StreamGeometry();
- using (var g = fill.Open())
+ var gridPen = new Pen(NotaGraph.Grid, 1);
+ for (int i = 1; i <= 2; i++) { double gy = top + (bot - top) * i / 3.0; ctx.DrawLine(gridPen, new Point(x0, gy), new Point(x1, gy)); }
+ for (int i = 1; i <= 4; i++) { double gx = x0 + span * i / 5.0; ctx.DrawLine(gridPen, new Point(gx, top), new Point(gx, bot)); }
+
+ int type = FilType();
+ double cut = G("cutoff"), res = G("resonance");
+ double flatY = top + (bot - top) * 0.34;
+
+ // Off: the signal passes untouched — one flat line and nothing else to read.
+ if (type == 0)
{
- g.BeginFigure(new Point(x0, flatY), true);
- g.LineTo(new Point(kx, flatY)); g.LineTo(new Point(cx, bumpY)); g.LineTo(new Point(x1, bot));
- g.LineTo(new Point(x1, bot)); g.LineTo(new Point(x0, bot));
- g.EndFigure(true);
+ ctx.DrawLine(new Pen(NotaPalette.BorderStrong, NotaGraph.PrimaryWidth), new Point(x0, flatY), new Point(x1, flatY));
+ Text(ctx, "filter off · signal passes", x0 + 1, Pad - 3, TextTertiary);
+ HzAxis(ctx, x0, x1, bot);
+ return;
}
- var pen = new Pen(Brass, 1.8, lineJoin: PenLineJoin.Round);
- ctx.DrawLine(pen, new Point(x0, flatY), new Point(kx, flatY));
- ctx.DrawLine(pen, new Point(kx, flatY), new Point(cx, bumpY));
- ctx.DrawLine(pen, new Point(cx, bumpY), new Point(x1, bot));
-
- // Cutoff handle + guide line.
- ctx.DrawLine(new Pen(NotaPalette.Wash(NotaPalette.AccentBright, 0x38), 1), new Point(cx, top - 6), new Point(cx, bot));
- NotaGraph.Node(ctx, new Point(cx, bumpY), active: true);
-
- // Labels: title, cutoff/Q readout, evenly-spaced Hz axis captions.
- Text(ctx, "FILTER", x0, Pad - 2, TextTertiary);
- var inv = CultureInfo.InvariantCulture;
- string hzTxt = cutHz >= 1000 ? $"{(cutHz / 1000).ToString("0.0", inv)}\u2009k" : $"{cutHz.ToString("0", inv)}\u2009Hz";
- string readout = $"{hzTxt} Q {_res.ToString("0.00", inv)}";
- Text(ctx, readout, x1 - MeasureW(readout, 9, true), Pad - 2, Handle, 9, true);
- string[] ticks = { "20", "100", "1 k", "10 k", "20 k" };
- for (int i = 0; i < ticks.Length; i++)
+
+ // The envelope's reach on the cutoff, drawn as the curve it sweeps to.
+ double env = (G("filenv") - 0.5) * 2.0;
+ if (Math.Abs(env) > 0.01)
{
- double tx = x0 + span * i / (ticks.Length - 1);
- if (i == ticks.Length - 1) tx -= MeasureW(ticks[i], 8, true); // last flush-right
- else if (i > 0) tx -= MeasureW(ticks[i], 8, true) / 2; // interior centred
- Text(ctx, ticks[i], tx, bot + 1, DimMono, 8, true);
+ double modCut = Math.Clamp(cut + env * 4.0 / Math.Log2(18000.0 / 20.0), 0, 1);
+ DrawCurve(ctx, x0, x1, top, bot, modCut, res, type, NotaGraph.SecondaryPen(Teal, NotaGraph.SecondaryWidth));
}
+ DrawCurve(ctx, x0, x1, top, bot, cut, res, type, new Pen(Brass, NotaGraph.PrimaryWidth, lineJoin: PenLineJoin.Round));
+
+ double cx = x0 + cut * span;
+ ctx.DrawLine(new Pen(Ghost, 1) { DashStyle = new DashStyle(new double[] { 3, 3 }, 0) }, new Point(cx, top - 5), new Point(cx, bot));
+ NotaGraph.Node(ctx, new Point(cx, CurveTop(top, bot, res)), active: true);
+
+ double hz = ExpMap(cut, 20, 18000);
+ string[] names = { "Off", "LP", "HP", "BP" };
+ Text(ctx, $"{names[type]} 12 dB/oct · {NotaNum.Hz(hz)} · Q {res.ToString("0.00", NotaNum.Culture)}", x0 + 1, Pad - 3, TextTertiary);
+ if (Math.Abs(env) > 0.01)
+ {
+ string e = $"env {Signed(env * 100)} %";
+ Text(ctx, e, x1 - 1 - MeasureW(e), Pad - 3, Teal);
+ }
+ HzAxis(ctx, x0, x1, bot);
}
- private static void Dot(DrawingContext ctx, double x, double y)
- => ctx.DrawEllipse(Teal, new Pen(Sunken, 2), new Point(x, y), 4.5, 4.5);
+ // Where the curve peaks at the cutoff — the handle sits there for every type.
+ private static double CurveTop(double top, double bot, double res)
+ { double flat = top + (bot - top) * 0.34; return Math.Max(top + 2, flat - res * (flat - top) * 0.92); }
+
+ // The magnitude curve as a polyline, by filter type (1 LP · 2 HP · 3 BP).
+ private static void DrawCurve(DrawingContext ctx, double x0, double x1, double top, double bot,
+ double cut, double res, int type, IPen pen)
+ {
+ double span = x1 - x0, cx = x0 + cut * span;
+ double flatY = top + (bot - top) * 0.34;
+ double peakY = Math.Max(top + 2, flatY - res * (flatY - top) * 0.92);
+ double kx = Math.Max(x0, cx - 14), rx = Math.Min(x1, cx + 14);
+ double mid = (peakY + bot) / 2 + (bot - peakY) * 0.15;
+ var p = new List<Point>();
+ switch (type)
+ {
+ case 2: p.Add(new(x0, bot)); p.Add(new((x0 + cx) / 2, mid)); p.Add(new(cx, peakY)); p.Add(new(rx, flatY)); p.Add(new(x1, flatY)); break;
+ case 3: p.Add(new(x0, bot)); p.Add(new(kx, mid)); p.Add(new(cx, peakY)); p.Add(new(rx, mid)); p.Add(new(x1, bot)); break;
+ default: p.Add(new(x0, flatY)); p.Add(new(kx, flatY)); p.Add(new(cx, peakY)); p.Add(new((cx + x1) / 2, mid)); p.Add(new(x1, bot)); break;
+ }
+ for (int i = 1; i < p.Count; i++) ctx.DrawLine(pen, p[i - 1], p[i]);
+ }
- private static double MeasureW(string t, double size, bool mono)
- => new FormattedText(t, CultureInfo.InvariantCulture, FlowDirection.LeftToRight,
- mono ? NotaFonts.Mono : Face, size, NotaPalette.TextPrimary).Width;
+ private void HzAxis(DrawingContext ctx, double x0, double x1, double bot)
+ {
+ string[] ticks = { "20", "100", "1 k", "10 k", "20 k" };
+ double span = x1 - x0;
+ for (int i = 0; i < ticks.Length; i++)
+ {
+ double tx = x0 + span * i / (ticks.Length - 1);
+ if (i == ticks.Length - 1) tx -= MeasureW(ticks[i]);
+ else if (i > 0) tx -= MeasureW(ticks[i]) / 2;
+ Text(ctx, ticks[i], tx, bot + 1, Axis);
+ }
+ }
}
diff --git a/src/managed/Nota.App/DeviceCards/Instruments/SynthInstrumentCard.cs b/src/managed/Nota.App/DeviceCards/Instruments/SynthInstrumentCard.cs
index 28b3f686..3d2f8774 100644
--- a/src/managed/Nota.App/DeviceCards/Instruments/SynthInstrumentCard.cs
+++ b/src/managed/Nota.App/DeviceCards/Instruments/SynthInstrumentCard.cs
@@ -1,20 +1,26 @@
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.
//
-// Detail · Devices — built-in Nota Synth editor (instrument kind 0), mockup 2f. Left half:
-// three labelled bands — OSCILLATOR (shape buttons), ENVELOPE (A/D/S/R) and FILTER & OUTPUT
-// (cutoff/reso/gain), every knob reading a real unit (ms / dB / kHz). Right half: the live
-// teal envelope + brass filter graphs (SynthViz). Pure re-skin — no DSP change.
+// Detail · Devices — built-in Nota Synth editor (instrument kind 0). The synth's three
+// sections are tabs inside the 700 × 260 card, so each one gets its graph full size with
+// its knobs under it instead of three cramped bands:
+//
+// Osc waveform over eight cycles · WAVE · PULSE W · DETUNE · OCTAVE · UNISON
+// Env the amplitude ADSR (drag its breakpoints) · A / D / S / R · VEL → VOL
+// Filter the response curve (drag for cutoff / reso) · TYPE · CUTOFF · RESO · ENV
+//
+// A 186px rail stays put on every tab — voice mode, volume, pan, glide, unison spread,
+// velocity tracking and the track's meter — over a status strip that reads the patch back
+// in words. Brass is the parameter itself; teal is modulation (detune, env → cutoff).
using System;
using System.Collections.Generic;
-using System.Globalization;
using Avalonia;
using Avalonia.Controls;
-using Avalonia.Controls.Shapes;
using Avalonia.Input;
using Avalonia.Layout;
using Avalonia.Media;
+using Nota.Application;
using static Nota.App.DeviceCardKit;
namespace Nota.App;
@@ -24,24 +30,35 @@ internal sealed class SynthInstrumentCard : IInstrumentCard
public bool BodyOnly => true;
public string Subtitle => "SUBTRACTIVE";
- // Waveform button glyphs (viewBox 0 0 22 16), matching the mockup shapes.
- private static readonly (string name, string path)[] Waves =
+ private const double RailW = 186, TabH = 20, StatusH = 18, RowH = 60;
+
+ private static readonly string[] WaveNames = { "Saw", "Square", "Triangle", "Sine" };
+ private static readonly string[] FilterNames = { "Off", "LP", "HP", "BP" };
+ private static readonly string[] UnisonNames = { "1", "2", "4", "7" };
+ private static readonly int[] UnisonCounts = { 1, 2, 4, 7 };
+ private static readonly string[] VoiceNames = { "Poly 16", "Mono", "Legato" };
+ private static readonly string[] TabNames = { "Osc", "Env", "Filter" };
+ private static readonly string[] TabHints =
{
- ("Saw", "M1 13 L11 3 L11 13 L21 3 L21 13"),
- ("Square", "M1 12 V4 H8 V12 H15 V4 H21"),
- ("Triangle", "M1 12 L6 4 L11 12 L16 4 L21 12"),
- ("Sine", "M1 8 C4 1 8 1 11 8 C14 15 18 15 21 8"),
+ "wave · pulse width · detune",
+ "a · d · s · r",
+ "type · cutoff · reso · env",
};
- private static readonly CultureInfo Inv = CultureInfo.InvariantCulture;
-
// Engine's perceptual map (Synth.h): lo * (hi/lo)^v.
private static double ExpMap(float v, double lo, double hi) => lo * Math.Pow(hi / lo, Math.Clamp(v, 0f, 1f));
- private static string Secs(float v, double lo, double hi)
- { double s = ExpMap(v, lo, hi); return s < 1.0 ? $"{(s * 1000).ToString("0", Inv)}\u2009ms" : $"{s.ToString("0.00", Inv)}\u2009s"; }
- private static string Db(float v) => v <= 1e-4f ? "−∞\u2009dB" : $"{(20.0 * Math.Log10(v)).ToString("0.0", Inv).Replace("-", "−")}\u2009dB";
- private static string KHz(float v)
- { double hz = ExpMap(v, 20, 18000); return hz >= 1000 ? $"{(hz / 1000).ToString("0.0", Inv)}\u2009k" : $"{hz.ToString("0", Inv)}\u2009Hz"; }
+ private static string Secs(float v, double lo, double hi) => NotaNum.Time(ExpMap(v, lo, hi));
+ private static string Db(float v) => NotaNum.Db(AudioMath.LinToDb(v));
+ private static string KHz(float v) => NotaNum.Hz(ExpMap(v, 20, 18000));
+ private static string Cents(float v) => NotaNum.Unit((v - 0.5f) * 100, "+0;−0;0", "c");
+ private static string Octaves(float v) => ((int)Math.Round((v - 0.5f) * 4)).ToString("+0;−0;0", NotaNum.Culture);
+ private static string Glide(float v) => v <= 1e-4f ? NotaNum.Unit(0, "0", "ms") : NotaNum.Time(v * v * 2.0);
+ private static string Bipolar(float v) => NotaNum.Unit((v - 0.5f) * 200, "+0;−0;0", "%");
+ private static string PanText(float v)
+ {
+ int p = (int)Math.Round((v - 0.5f) * 200);
+ return p == 0 ? "C" : p < 0 ? $"{-p} L" : $"{p} R";
+ }
public Control Build(DeviceCardContext ctx)
{
@@ -51,121 +68,361 @@ internal sealed class SynthInstrumentCard : IInstrumentCard
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;
+ void SetP(string id, float v) { if (I(id) is var i and >= 0) engine.PluginParamSet(track, -1, i, Math.Clamp(v, 0f, 1f)); }
+ int Sel(string id, int n) => Math.Clamp((int)Math.Round(G(id) * (n - 1)), 0, n - 1);
- var adsr = new SynthViz(SynthViz.K.Adsr);
- var filter = new SynthViz(SynthViz.K.Filter);
- void Sync()
+ var readouts = new List<Action>(); // everything that re-reads a param
+ int tab = 0; // the open tab: 0 Osc · 1 Env · 2 Filter
+ var bodies = new (Control Graph, Control Row)[TabNames.Length];
+ var osc = new SynthViz(SynthViz.K.Osc, engine, track, idx);
+ var env = new SynthViz(SynthViz.K.Adsr, engine, track, idx);
+ var flt = new SynthViz(SynthViz.K.Filter, engine, track, idx);
+ var status = new TextBlock { FontSize = 8, Foreground = TextSecondary, VerticalAlignment = VerticalAlignment.Center, TextTrimming = TextTrimming.CharacterEllipsis };
+ var meta = new TextBlock { FontSize = 8, Foreground = TextSecondary, VerticalAlignment = VerticalAlignment.Center };
+ meta.BindResource(TextBlock.FontFamilyProperty, "Font.Mono");
+
+ void Refresh()
{
- adsr.Set(G("attack"), G("decay"), G("sustain"), G("release"), G("cutoff"), G("resonance"));
- filter.Set(G("attack"), G("decay"), G("sustain"), G("release"), G("cutoff"), G("resonance"));
+ osc.Refresh(); env.Refresh(); flt.Refresh();
+ foreach (var a in readouts) a();
+ status.Text = Summary();
+ meta.Text = Meta();
}
- ctx.SetInstLiveViz(Sync);
+ ctx.SetInstLiveViz(Refresh);
+ env.Changed += Refresh; flt.Changed += Refresh;
+
+ // ---- shared builders --------------------------------------------------
+ Control Knob(string id, string name, Func<float, string> fmt, double size = 34, double cellW = 46, IBrush? arc = null)
+ => InstrumentControls.InstKnob(ctx, idx, id, name, Refresh, fmt, size, cellW, arc);
- // ---- OSCILLATOR band: four shape buttons in one even row --------------
- var waveCells = new (Border box, Path glyph, TextBlock label)[4];
- void SyncWave()
+ // A param-backed segment strip. `values` are the normalized stops it writes.
+ Control Chips(string id, string[] names)
{
- int cur = idx.TryGetValue("wave", out var wi) ? (int)Math.Round(engine.PluginParamGet(track, -1, wi) * 3) : 0;
- for (int i = 0; i < 4; i++)
- {
- bool on = i == cur;
- waveCells[i].box.Background = on ? AccentSubtleB : Brushes.Transparent;
- waveCells[i].box.BorderBrush = on ? Brass : BorderStrong;
- var c = on ? AccentBright : TextTertiary;
- waveCells[i].glyph.Stroke = c; waveCells[i].label.Foreground = c;
- }
+ int n = names.Length;
+ var seg = Segments(names, () => Sel(id, n), iv => { SetP(id, iv / (float)(n - 1)); Refresh(); }, out var sync);
+ readouts.Add(sync);
+ if (I(id) is var pi and >= 0) MidiLearn.Bind(seg, MidiTarget.PluginParam(track, -1, pi), id);
+ return seg;
}
- var waveRow = new Grid { ColumnDefinitions = new ColumnDefinitions("*,*,*,*"), ColumnSpacing = 4 };
- for (int i = 0; i < 4; i++)
+
+ // A caps caption over a control, left-aligned — the almanac's label-above form.
+ Control Capped(string label, Control c) => new StackPanel
{
- int wv = i;
- var glyph = new Path
+ Spacing = 4, VerticalAlignment = VerticalAlignment.Center,
+ Children =
{
- Data = Geometry.Parse(Waves[i].path), Width = 18, Height = 13, Stretch = Stretch.Uniform,
- StrokeThickness = 1.7, StrokeLineCap = PenLineCap.Round, StrokeJoin = PenLineJoin.Round,
+ new TextBlock
+ {
+ Text = label, FontSize = NotaType.KnobLabel, FontWeight = FontWeight.Bold,
+ LetterSpacing = NotaType.KnobLabelTracking, Foreground = TextTertiary,
+ },
+ c,
+ },
+ };
+
+ // The row of controls under a tab's graph.
+ Control Row(params Control[] cells)
+ {
+ var sp = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 14, VerticalAlignment = VerticalAlignment.Center };
+ foreach (var c in cells) sp.Children.Add(c);
+ return new Border
+ {
+ Height = RowH, BorderBrush = NotaPalette.GraphBorder, BorderThickness = new Thickness(0, 1, 0, 0),
+ Padding = new Thickness(0, 4, 0, 0), Child = sp,
};
- var label = new TextBlock { Text = Waves[i].name, FontSize = 9, FontWeight = FontWeight.SemiBold, VerticalAlignment = VerticalAlignment.Center };
- var inner = new StackPanel
+ }
+
+ // ---- Osc tab ----------------------------------------------------------
+ var pwKnobCell = Knob("pulsewidth", "Pulse W", v => NotaNum.Pct(0.05 + v * 0.90));
+ // Pulse width only shapes the square — dim it (never hide it) on the other shapes.
+ var pwKnob = FindKnob(pwKnobCell);
+ void SyncPw() { if (pwKnob is not null) pwKnob.IsDim = Sel("wave", 4) != 1; }
+ readouts.Add(SyncPw);
+
+ var oscRow = Row(
+ Capped("WAVE", Chips("wave", WaveNames)),
+ pwKnobCell,
+ Knob("detune", "Detune", Cents, arc: Teal),
+ Knob("octave", "Octave", Octaves),
+ Capped("UNISON", Chips("unison", UnisonNames)));
+
+ // ---- Env tab ----------------------------------------------------------
+ // The switch turns velocity tracking off and back on; the rail knob is the amount.
+ float lastVel = Math.Max(0.05f, G("velamp"));
+ var velSwitch = Switch("Vel → Vol",
+ () => G("velamp") > 1e-3f,
+ () => { if (G("velamp") > 1e-3f) { lastVel = G("velamp"); SetP("velamp", 0f); } else SetP("velamp", lastVel); Refresh(); },
+ out var velSync,
+ liveLabel: () => G("velamp") > 1e-3f ? $"Vel → Vol {NotaNum.Pct(G("velamp"))}" : "Vel → Vol off");
+ readouts.Add(velSync);
+ if (I("velamp") is var vi and >= 0) MidiLearn.Bind(velSwitch, MidiTarget.PluginParam(track, -1, vi), "Vel → Vol");
+
+ var envRow = Row(
+ Knob("attack", "Attack", v => Secs(v, 0.001, 2.0)),
+ Knob("decay", "Decay", v => Secs(v, 0.002, 2.0)),
+ Knob("sustain", "Sustain", Db, size: 44, cellW: 52),
+ Knob("release", "Release", v => Secs(v, 0.002, 3.0)),
+ velSwitch);
+
+ // ---- Filter tab -------------------------------------------------------
+ var cutCell = Knob("cutoff", "Cutoff", KHz, size: 44, cellW: 52);
+ var resoCell = Knob("resonance", "Reso", v => v.ToString("0.00", NotaNum.Culture));
+ var envCell = Knob("filenv", "Env → Cutoff", Bipolar, cellW: 66, arc: Teal);
+ var cutKnob = FindKnob(cutCell); var resoKnob = FindKnob(resoCell); var envKnob = FindKnob(envCell);
+ // Off bypasses the filter entirely — its three knobs go inactive but stay editable.
+ void SyncFilter()
+ {
+ bool off = Sel("filtype", 4) == 0;
+ if (cutKnob is not null) cutKnob.IsDim = off;
+ if (resoKnob is not null) resoKnob.IsDim = off;
+ if (envKnob is not null) envKnob.IsDim = off;
+ }
+ readouts.Add(SyncFilter);
+
+ var fltRow = Row(
+ Capped("TYPE", Chips("filtype", FilterNames)),
+ cutCell, resoCell, envCell);
+
+ // ---- the tab panel ----------------------------------------------------
+ var tabCells = new Border[TabNames.Length];
+ var tabTexts = new TextBlock[TabNames.Length];
+ var hint = new TextBlock
+ {
+ FontSize = NotaType.Axis, Foreground = TextTertiary, VerticalAlignment = VerticalAlignment.Center,
+ Margin = new Thickness(0, 0, 8, 0),
+ };
+ hint.BindResource(TextBlock.FontFamilyProperty, "Font.Mono");
+ var tabStrip = new Grid
+ {
+ Height = TabH, ColumnDefinitions = new ColumnDefinitions("Auto,*"),
+ Background = Brushes.Transparent,
+ };
+ var tabRow = new StackPanel { Orientation = Orientation.Horizontal };
+ for (int i = 0; i < TabNames.Length; i++)
+ {
+ int iv = i;
+ var tb = new TextBlock { Text = TabNames[i], FontSize = NotaType.DeviceSection, VerticalAlignment = VerticalAlignment.Center };
+ var cell = new Border
{
- Orientation = Orientation.Horizontal, Spacing = 5,
- HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center,
- Children = { glyph, label },
+ Padding = new Thickness(7, 0), BorderThickness = new Thickness(0, 0, 0, 2),
+ Cursor = new Cursor(StandardCursorType.Hand), Child = tb,
};
- var box = new Border
+ cell.PointerPressed += (_, e) =>
{
- Height = 28, BorderThickness = new Thickness(1), CornerRadius = NotaRadius.Control,
- Cursor = new Cursor(StandardCursorType.Hand), Child = inner,
+ if (!e.GetCurrentPoint(cell).Properties.IsLeftButtonPressed) return;
+ tab = iv; ShowTab(); e.Handled = true;
};
- box.PointerPressed += (_, _) => { if (idx.TryGetValue("wave", out var wi)) { engine.PluginParamSet(track, -1, wi, wv / 3f); SyncWave(); } };
- waveCells[i] = (box, glyph, label);
- Grid.SetColumn(box, i); waveRow.Children.Add(box);
+ tabCells[i] = cell; tabTexts[i] = tb; tabRow.Children.Add(cell);
}
- SyncWave();
+ tabStrip.Children.Add(tabRow);
+ Grid.SetColumn(hint, 1); hint.HorizontalAlignment = HorizontalAlignment.Right; tabStrip.Children.Add(hint);
- // ---- ENVELOPE + FILTER & OUTPUT bands ---------------------------------
- Control Knob(string id, string name, Func<float, string> fmt) =>
- InstrumentControls.InstKnob(ctx, idx, id, name, Sync, fmt, knobSize: 40, cellW: 80);
+ var graphHost = new Panel();
+ var rowHost = new Panel();
+ bodies[0] = (osc, oscRow); bodies[1] = (env, envRow); bodies[2] = (flt, fltRow);
+ foreach (var (g, r) in bodies) { graphHost.Children.Add(g); rowHost.Children.Add(r); }
- var envRow = SpreadRow(
- Knob("attack", "Attack", v => Secs(v, 0.001, 2.0)),
- Knob("decay", "Decay", v => Secs(v, 0.002, 2.0)),
- Knob("sustain", "Sustain", Db),
- Knob("release", "Release", v => Secs(v, 0.002, 3.0)));
-
- var fltRow = SpreadRow(
- Knob("cutoff", "Cutoff", KHz),
- Knob("resonance", "Reso", v => v.ToString("0.00", NotaNum.Culture)),
- Knob("gain", "Gain", Db));
-
- var left = new StackPanel { Width = 358, Spacing = 5, Children =
- {
- Band("OSCILLATOR", TextTertiary, waveRow, grow: false),
- Hairline(),
- Band("ENVELOPE", Teal, envRow, grow: true),
- Hairline(),
- Band("FILTER & OUTPUT", TextTertiary, fltRow, grow: true),
- } };
-
- // ---- graphs fill the remaining width, two equal rows ------------------
- adsr.VerticalAlignment = VerticalAlignment.Stretch;
- filter.VerticalAlignment = VerticalAlignment.Stretch;
- var graphs = new Grid { RowDefinitions = new RowDefinitions("*,*"), RowSpacing = 8, VerticalAlignment = VerticalAlignment.Stretch, HorizontalAlignment = HorizontalAlignment.Stretch };
- graphs.Children.Add(adsr);
- Grid.SetRow(filter, 1); graphs.Children.Add(filter);
- Sync();
-
- var graphHost = new Border
- {
- Background = NotaPalette.SurfaceRaised, BorderBrush = BorderDef, BorderThickness = new Thickness(1, 0, 0, 0),
- Padding = new Thickness(10, 8), Child = graphs,
+ void ShowTab()
+ {
+ for (int i = 0; i < TabNames.Length; i++)
+ {
+ bool on = i == tab;
+ tabCells[i].Background = on ? NotaPalette.SurfaceRaised : Brushes.Transparent;
+ tabCells[i].BorderBrush = on ? Brass : Brushes.Transparent;
+ tabTexts[i].Foreground = on ? AccentBright : TextTertiary;
+ tabTexts[i].FontWeight = on ? FontWeight.SemiBold : FontWeight.Normal;
+ bodies[i].Graph.IsVisible = on;
+ bodies[i].Row.IsVisible = on;
+ }
+ hint.Text = TabHints[tab];
+ Refresh();
+ }
+
+ var tabBody = new Grid { RowDefinitions = new RowDefinitions("*,Auto"), RowSpacing = 5, Margin = new Thickness(7, 5) };
+ tabBody.Children.Add(graphHost);
+ Grid.SetRow(rowHost, 1); tabBody.Children.Add(rowHost);
+
+ var tabPanel = SectionBox(new Grid { RowDefinitions = new RowDefinitions("Auto,*") });
+ var tabGrid = (Grid)tabPanel.Child!;
+ tabGrid.Children.Add(HeaderStrip(tabStrip));
+ Grid.SetRow(tabBody, 1); tabGrid.Children.Add(tabBody);
+
+ // ---- the rail ---------------------------------------------------------
+ Grid Slider(string label, string id, Func<string> text, bool bipolar = false)
+ {
+ int pi = I(id);
+ var row = SliderRow(label, () => G(id), v => { SetP(id, (float)v); Refresh(); }, text, out var sync,
+ begin: pi >= 0 ? () => engine.BeginAutomationWrite(track, AutomationTarget.PluginParam, -1, -1, id) : null,
+ end: pi >= 0 ? () => engine.EndAutomationWrite(track, AutomationTarget.PluginParam, -1, -1, id) : null,
+ reset: pi >= 0 ? () => { SetP(id, engine.InstrumentParamDefault(track, pi)); Refresh(); } : null,
+ bipolar: bipolar, labelWidth: 42, valueWidth: 40);
+ readouts.Add(sync);
+ if (pi >= 0) MidiLearn.Bind(row, MidiTarget.PluginParam(track, -1, pi), id);
+ return row;
+ }
+
+ var voiceChips = Chips("voicemode", VoiceNames);
+ var railHeader = new Grid { Height = TabH, ColumnDefinitions = new ColumnDefinitions("Auto,*"), Margin = new Thickness(8, 0) };
+ railHeader.Children.Add(new TextBlock
+ {
+ Text = "VOICES", FontSize = NotaType.KnobLabel, FontWeight = FontWeight.Bold,
+ LetterSpacing = NotaType.KnobLabelTracking, Foreground = TextTertiary, VerticalAlignment = VerticalAlignment.Center,
+ });
+ voiceChips.HorizontalAlignment = HorizontalAlignment.Right;
+ Grid.SetColumn(voiceChips, 1); railHeader.Children.Add(voiceChips);
+
+ var meter = new MeterBar { VerticalAlignment = VerticalAlignment.Stretch, Width = MeterScale.StereoWidth };
+ ctx.AddDeviceRefresher(() => { if (engine.TryGetTrackMeter(track, out var m)) meter.Push(m); });
+ // The three captions sit at their real height on the meter's scale (−60 … +6 dB),
+ // not spread evenly — a scale that lies is worse than no scale.
+ var meterScale = new Grid
+ {
+ VerticalAlignment = VerticalAlignment.Stretch,
+ RowDefinitions = new RowDefinitions(string.Join(",", ScaleRows(0, -12, -48))),
+ };
+ for (int i = 0; i < 3; i++)
+ {
+ var cap = Axis(i == 0 ? "0" : i == 1 ? "−12" : "−48");
+ Grid.SetRow(cap, i * 2 + 1); meterScale.Children.Add(cap);
+ }
+ var meterBlock = new Grid
+ {
+ ColumnDefinitions = new ColumnDefinitions("Auto,Auto"), ColumnSpacing = 4,
+ HorizontalAlignment = HorizontalAlignment.Right, Margin = new Thickness(0, 0, 0, 9),
+ };
+ meterBlock.Children.Add(meter);
+ Grid.SetColumn(meterScale, 1); meterBlock.Children.Add(meterScale);
+
+ var railBottom = new StackPanel
+ {
+ Orientation = Orientation.Horizontal, Spacing = 8, VerticalAlignment = VerticalAlignment.Center,
+ Children =
+ {
+ Knob("spread", "Spread", v => NotaNum.Pct(v), size: 44, cellW: 50),
+ Knob("velamp", "Vel → Vol", v => NotaNum.Pct(v), cellW: 46, arc: Teal),
+ },
};
- var bodyGrid = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,*"), VerticalAlignment = VerticalAlignment.Stretch };
- var leftHost = new Border { Padding = new Thickness(10, 8, 10, 6), Child = left };
- bodyGrid.Children.Add(leftHost);
- Grid.SetColumn(graphHost, 1); bodyGrid.Children.Add(graphHost);
- return bodyGrid;
+ var railBottomHost = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,*"), VerticalAlignment = VerticalAlignment.Stretch };
+ railBottomHost.Children.Add(railBottom);
+ Grid.SetColumn(meterBlock, 1); railBottomHost.Children.Add(meterBlock);
+
+ var railBody = new StackPanel
+ {
+ Spacing = 6, Margin = new Thickness(8, 6),
+ Children =
+ {
+ Slider("Volume", "gain", () => Db(G("gain"))),
+ Slider("Pan", "pan", () => PanText(G("pan")), bipolar: true),
+ Slider("Glide", "glide", () => Glide(G("glide"))),
+ },
+ };
+ var railGrid = new Grid { RowDefinitions = new RowDefinitions("Auto,Auto,*") };
+ railGrid.Children.Add(HeaderStrip(railHeader));
+ Grid.SetRow(railBody, 1); railGrid.Children.Add(railBody);
+ var railBottomFrame = new Border
+ {
+ BorderBrush = NotaPalette.GraphBorder, BorderThickness = new Thickness(0, 1, 0, 0),
+ Margin = new Thickness(8, 0, 8, 6), Padding = new Thickness(0, 5, 0, 0), Child = railBottomHost,
+ };
+ Grid.SetRow(railBottomFrame, 2); railGrid.Children.Add(railBottomFrame);
+ var rail = SectionBox(railGrid);
+ rail.Width = RailW;
+
+ // ---- status strip -----------------------------------------------------
+ string Summary() => tab switch
+ {
+ 0 => $"{WaveNames[Sel("wave", 4)]} · unison {UnisonCounts[Sel("unison", 4)]} · detune {Cents(G("detune"))}"
+ + (Sel("wave", 4) == 1 ? $" · pulse {NotaNum.Pct(0.05 + G("pulsewidth") * 0.90)}" : ""),
+ 1 => $"Env {Secs(G("attack"), 0.001, 2.0)} · {Secs(G("decay"), 0.002, 2.0)} · {Db(G("sustain"))} · {Secs(G("release"), 0.002, 3.0)}",
+ _ => Sel("filtype", 4) == 0
+ ? "Filter off — the oscillator goes straight to the amplifier"
+ : $"Filter {FilterNames[Sel("filtype", 4)]} · cutoff {KHz(G("cutoff"))} · Q {G("resonance").ToString("0.00", NotaNum.Culture)} · env {Bipolar(G("filenv"))}",
+ };
+ string Meta()
+ {
+ int uni = UnisonCounts[Sel("unison", 4)];
+ string mode = VoiceNames[Sel("voicemode", 3)].ToUpperInvariant();
+ string oct = Octaves(G("octave"));
+ return $"{mode} · UNISON {uni} · OCT {oct} · {Db(G("gain"))}";
+ }
+ var statusBar = new Grid
+ {
+ Height = StatusH, ColumnDefinitions = new ColumnDefinitions("*,Auto"), ColumnSpacing = 10,
+ Background = NotaPalette.SurfaceAbyss,
+ };
+ var statusHost = new Border
+ {
+ Height = StatusH, BorderBrush = BorderDef, BorderThickness = new Thickness(0, 1, 0, 0),
+ Background = NotaPalette.SurfaceAbyss, Padding = new Thickness(8, 0), Child = statusBar,
+ };
+ statusBar.Children.Add(status);
+ Grid.SetColumn(meta, 1); statusBar.Children.Add(meta);
+
+ // ---- assembly ---------------------------------------------------------
+ var body = new Grid
+ {
+ ColumnDefinitions = new ColumnDefinitions("*,Auto"), ColumnSpacing = NotaSpace.DeviceGap,
+ Margin = new Thickness(NotaSpace.DeviceGap),
+ };
+ body.Children.Add(tabPanel);
+ Grid.SetColumn(rail, 1); body.Children.Add(rail);
+
+ DockPanel.SetDock(statusHost, Dock.Bottom);
+ var root = new DockPanel
+ {
+ LastChildFill = true, Background = NotaPalette.Gutter,
+ Children = { statusHost, body },
+ };
+ ShowTab();
+ return root;
}
- // A labelled band: an 8px caps caption over its content. grow → the row fills the
- // free vertical space (so the two knob bands centre their knobs evenly).
- private static Control Band(string caption, IBrush color, Control content, bool grow)
+ public string? VoiceLabel(IAudioEngine engine, int trackId, int active)
{
- var lbl = new TextBlock { Text = caption, FontSize = 8, FontWeight = FontWeight.Bold, Foreground = color, Margin = new Thickness(0, 0, 0, 4) };
- var grid = new Grid { RowDefinitions = new RowDefinitions("Auto,*") };
- grid.Children.Add(lbl);
- Grid.SetRow(content, 1); grid.Children.Add(content);
- if (grow) grid.VerticalAlignment = VerticalAlignment.Stretch;
- else grid.RowDefinitions = new RowDefinitions("Auto,Auto");
- return grid;
+ int i = -1, pc = engine.PluginParamCount(trackId, -1);
+ for (int k = 0; k < pc; k++) if (engine.PluginParamId(trackId, -1, k) == "voicemode") { i = k; break; }
+ if (i < 0) return null;
+ int mode = Math.Clamp((int)Math.Round(engine.PluginParamGet(trackId, -1, i) * 2), 0, 2);
+ return mode == 0 ? null : $"{Math.Min(active, 1)}/1";
+ }
+
+ // A device section: card ground, hairline, radius 6 — the almanac's section box.
+ private static Border SectionBox(Control child) => new()
+ {
+ Background = NotaPalette.SurfaceCard, BorderBrush = BorderDef, BorderThickness = new Thickness(1),
+ CornerRadius = NotaRadius.Tile, ClipToBounds = true, Child = child,
+ };
+
+ // A section's own header strip: a hairline under it, nothing else.
+ private static Border HeaderStrip(Control child) => new()
+ {
+ BorderBrush = BorderDef, BorderThickness = new Thickness(0, 0, 0, 1), Child = child,
+ };
+
+ /// <summary>Row definitions that put a caption for each dB mark at its place on the
+ /// meter's scale: a star gap, the caption (Auto), … and a star gap for the remainder.</summary>
+ private static IEnumerable<string> ScaleRows(params double[] dbs)
+ {
+ double prev = 0;
+ foreach (var db in dbs)
+ {
+ double fromTop = 1.0 - MeterScale.NormDb(db);
+ yield return Math.Max(0, fromTop - prev).ToString("0.000", NotaNum.Culture) + "*";
+ yield return "Auto";
+ prev = fromTop;
+ }
+ yield return Math.Max(0, 1.0 - prev).ToString("0.000", NotaNum.Culture) + "*";
}
- // A row of cells spread evenly across the band width, vertically centred.
- private static Control SpreadRow(params Control[] cells)
+ private static TextBlock Axis(string text)
{
- var grid = new Grid { ColumnDefinitions = new ColumnDefinitions(string.Join(",", System.Linq.Enumerable.Repeat("*", cells.Length))), VerticalAlignment = VerticalAlignment.Center };
- for (int i = 0; i < cells.Length; i++) { cells[i].HorizontalAlignment = HorizontalAlignment.Center; Grid.SetColumn(cells[i], i); grid.Children.Add(cells[i]); }
- return grid;
+ var tb = new TextBlock { Text = text, FontSize = NotaType.Axis, Foreground = NotaPalette.TextAxis };
+ tb.BindResource(TextBlock.FontFamilyProperty, "Font.Mono");
+ return tb;
}
- private static Control Hairline() => new Border { Height = 1, Background = BorderDef, Margin = new Thickness(0, 1) };
+ /// <summary>The Knob inside a KnobCell, so the card can dim it when its section is off.</summary>
+ private static Knob? FindKnob(Control cell)
+ => cell is Panel p ? System.Linq.Enumerable.FirstOrDefault(System.Linq.Enumerable.OfType<Knob>(p.Children)) : null;
}
diff --git a/src/managed/Nota.Infrastructure/Persistence/FactoryPresetCatalog.cs b/src/managed/Nota.Infrastructure/Persistence/FactoryPresetCatalog.cs
index 92f93a50..138ce0d2 100644
--- a/src/managed/Nota.Infrastructure/Persistence/FactoryPresetCatalog.cs
+++ b/src/managed/Nota.Infrastructure/Persistence/FactoryPresetCatalog.cs
@@ -21,11 +21,41 @@ public sealed class FactoryPresetCatalog : IFactoryPresets
public FactoryPresetCatalog()
{
- // ---- Nota Synth (kind 0) — wave: Saw 0 / Square .33 / Triangle .66 / Sine 1
- Inst("synth", 0, "Warm Pad", ("wave", 0f), ("attack", 0.55f), ("decay", 0.40f), ("sustain", 0.85f), ("release", 0.60f), ("cutoff", 0.42f), ("resonance", 0.10f), ("gain", 0.80f));
- Inst("synth", 0, "Rubber Bass", ("wave", 0f), ("attack", 0.01f), ("decay", 0.35f), ("sustain", 0.55f), ("release", 0.12f), ("cutoff", 0.34f), ("resonance", 0.22f), ("gain", 0.85f));
- Inst("synth", 0, "Bright Lead", ("wave", 0f), ("attack", 0.02f), ("decay", 0.22f), ("sustain", 0.72f), ("release", 0.22f), ("cutoff", 0.82f), ("resonance", 0.28f), ("gain", 0.78f));
- Inst("synth", 0, "Soft Pluck", ("wave", 0.33f), ("attack", 0.01f), ("decay", 0.42f), ("sustain", 0.00f), ("release", 0.22f), ("cutoff", 0.60f), ("resonance", 0.20f), ("gain", 0.80f));
+ // ---- Nota Synth (kind 0) — 25 patches across pads, basses, leads, keys and motion.
+ // wave: Saw 0 / Square .333 / Triangle .667 / Sine 1 · filtype: Off 0 / LP .333 /
+ // HP .667 / BP 1 · unison: 1 / 2 / 4 / 7 · voicemode: Poly 0 / Mono .5 / Legato 1.
+ // Bipolar params (detune, octave, pan, filenv) are neutral at 0.5; anything a
+ // preset does not name goes back to the instrument's default.
+ Inst("synth", 0, "Init Saw", ("wave", 0f));
+ // Pads
+ Inst("synth", 0, "Warm Pad", ("wave", 0f), ("attack", 0.55f), ("decay", 0.55f), ("sustain", 0.85f), ("release", 0.78f), ("cutoff", 0.46f), ("resonance", 0.10f), ("filenv", 0.60f), ("unison", 0.667f), ("detune", 0.60f), ("spread", 0.60f), ("velamp", 0.50f), ("gain", 0.78f));
+ Inst("synth", 0, "Glass Pad", ("wave", 0.667f), ("attack", 0.45f), ("decay", 0.60f), ("sustain", 0.70f), ("release", 0.82f), ("cutoff", 0.84f), ("resonance", 0.08f), ("unison", 0.667f), ("detune", 0.58f), ("spread", 0.70f), ("gain", 0.76f));
+ Inst("synth", 0, "String Ensemble",("wave", 0f), ("attack", 0.42f), ("decay", 0.50f), ("sustain", 0.88f), ("release", 0.70f), ("cutoff", 0.62f), ("resonance", 0.12f), ("unison", 1f), ("detune", 0.62f), ("spread", 0.80f), ("gain", 0.72f));
+ Inst("synth", 0, "Choir Pad", ("wave", 0.667f), ("attack", 0.58f), ("decay", 0.55f), ("sustain", 0.90f), ("release", 0.85f), ("cutoff", 0.55f), ("resonance", 0.10f), ("unison", 0.667f), ("detune", 0.56f), ("spread", 0.75f), ("gain", 0.75f));
+ Inst("synth", 0, "Drone", ("wave", 0f), ("attack", 0.70f), ("decay", 0.80f), ("sustain", 1f), ("release", 0.88f), ("cutoff", 0.50f), ("resonance", 0.20f), ("unison", 1f), ("detune", 0.72f), ("spread", 1f), ("octave", 0.25f), ("gain", 0.68f));
+ // Basses
+ Inst("synth", 0, "Rubber Bass", ("wave", 0f), ("attack", 0f), ("decay", 0.50f), ("sustain", 0.45f), ("release", 0.37f), ("cutoff", 0.40f), ("resonance", 0.28f), ("filenv", 0.70f), ("octave", 0.25f), ("voicemode", 0.5f), ("gain", 0.85f));
+ Inst("synth", 0, "Sub Bass", ("wave", 1f), ("attack", 0f), ("decay", 0.60f), ("sustain", 0.70f), ("release", 0.37f), ("cutoff", 0.34f), ("resonance", 0.05f), ("octave", 0.25f), ("voicemode", 0.5f), ("gain", 0.88f));
+ Inst("synth", 0, "Acid Bass", ("wave", 0f), ("attack", 0f), ("decay", 0.42f), ("sustain", 0.15f), ("release", 0.37f), ("cutoff", 0.35f), ("resonance", 0.78f), ("filenv", 0.85f), ("octave", 0.25f), ("voicemode", 0.5f), ("glide", 0.18f), ("gain", 0.82f));
+ Inst("synth", 0, "Square Bass", ("wave", 0.333f), ("attack", 0f), ("decay", 0.55f), ("sustain", 0.55f), ("release", 0.37f), ("cutoff", 0.44f), ("resonance", 0.20f), ("filenv", 0.62f), ("octave", 0.25f), ("voicemode", 0.5f), ("gain", 0.85f));
+ Inst("synth", 0, "Growl Bass", ("wave", 0f), ("attack", 0f), ("decay", 0.50f), ("sustain", 0.50f), ("release", 0.40f), ("cutoff", 0.38f), ("resonance", 0.55f), ("filenv", 0.72f), ("unison", 0.333f), ("detune", 0.58f), ("octave", 0.25f), ("voicemode", 0.5f), ("gain", 0.82f));
+ // Leads
+ Inst("synth", 0, "Bright Lead", ("wave", 0f), ("attack", 0.06f), ("decay", 0.55f), ("sustain", 0.75f), ("release", 0.45f), ("cutoff", 0.82f), ("resonance", 0.28f), ("filenv", 0.58f), ("unison", 0.333f), ("detune", 0.55f), ("voicemode", 0.5f), ("gain", 0.78f));
+ Inst("synth", 0, "Super Saw", ("wave", 0f), ("attack", 0.10f), ("decay", 0.60f), ("sustain", 0.85f), ("release", 0.60f), ("cutoff", 0.80f), ("resonance", 0.14f), ("unison", 1f), ("detune", 0.68f), ("spread", 0.90f), ("gain", 0.70f));
+ Inst("synth", 0, "Solo Lead", ("wave", 0f), ("attack", 0.02f), ("decay", 0.50f), ("sustain", 0.80f), ("release", 0.40f), ("cutoff", 0.72f), ("resonance", 0.30f), ("voicemode", 0.5f), ("glide", 0.16f), ("gain", 0.78f));
+ Inst("synth", 0, "Slide Lead", ("wave", 0.333f), ("pulsewidth", 0.35f), ("attack", 0.05f), ("decay", 0.55f), ("sustain", 0.80f), ("release", 0.45f), ("cutoff", 0.70f), ("resonance", 0.25f), ("voicemode", 1f), ("glide", 0.30f), ("gain", 0.78f));
+ Inst("synth", 0, "Whistle", ("wave", 1f), ("attack", 0.30f), ("decay", 0.50f), ("sustain", 0.85f), ("release", 0.50f), ("cutoff", 0.90f), ("resonance", 0.05f), ("octave", 0.75f), ("voicemode", 0.5f), ("glide", 0.12f), ("gain", 0.74f));
+ // Keys and plucks
+ Inst("synth", 0, "Soft Pluck", ("wave", 0.667f), ("attack", 0f), ("decay", 0.60f), ("sustain", 0f), ("release", 0.45f), ("cutoff", 0.66f), ("resonance", 0.18f), ("filenv", 0.55f), ("gain", 0.80f));
+ Inst("synth", 0, "Glass Bell", ("wave", 1f), ("attack", 0f), ("decay", 0.78f), ("sustain", 0f), ("release", 0.70f), ("cutoff", 0.90f), ("resonance", 0.10f), ("octave", 0.75f), ("gain", 0.76f));
+ Inst("synth", 0, "Electric Piano", ("wave", 1f), ("attack", 0f), ("decay", 0.70f), ("sustain", 0.25f), ("release", 0.55f), ("cutoff", 0.74f), ("resonance", 0.10f), ("filenv", 0.45f), ("gain", 0.80f));
+ Inst("synth", 0, "Music Box", ("wave", 1f), ("attack", 0f), ("decay", 0.62f), ("sustain", 0f), ("release", 0.50f), ("cutoff", 0.88f), ("resonance", 0.06f), ("octave", 0.75f), ("gain", 0.74f));
+ Inst("synth", 0, "Hollow Keys", ("wave", 0.333f), ("pulsewidth", 0.22f), ("attack", 0.02f), ("decay", 0.58f), ("sustain", 0.45f), ("release", 0.48f), ("cutoff", 0.64f), ("resonance", 0.18f), ("gain", 0.78f));
+ Inst("synth", 0, "Organ Tone", ("wave", 0.333f), ("attack", 0f), ("decay", 0f), ("sustain", 1f), ("release", 0.30f), ("filtype", 0f), ("velamp", 0.20f), ("gain", 0.76f));
+ // Motion
+ Inst("synth", 0, "Air Sweep", ("wave", 0f), ("attack", 0.62f), ("decay", 0.65f), ("sustain", 0.80f), ("release", 0.80f), ("filtype", 0.667f), ("cutoff", 0.55f), ("resonance", 0.30f), ("filenv", 0.78f), ("unison", 0.667f), ("detune", 0.58f), ("spread", 0.80f), ("gain", 0.70f));
+ Inst("synth", 0, "Filter Sweep", ("wave", 0f), ("attack", 0.35f), ("decay", 0.70f), ("sustain", 0.75f), ("release", 0.70f), ("cutoff", 0.30f), ("resonance", 0.45f), ("filenv", 0.92f), ("unison", 0.333f), ("detune", 0.57f), ("gain", 0.74f));
+ Inst("synth", 0, "Band Motion", ("wave", 0.333f), ("pulsewidth", 0.44f), ("attack", 0.28f), ("decay", 0.62f), ("sustain", 0.70f), ("release", 0.62f), ("filtype", 1f), ("cutoff", 0.58f), ("resonance", 0.50f), ("filenv", 0.74f), ("unison", 0.333f), ("detune", 0.60f), ("spread", 0.65f), ("gain", 0.74f));
// ---- Nota Physical (kind 2) — modal percussion. Res1 Type: Beam 0 / Marimba .2 /
// String .4 / Membrane .6 / Plate .8 / Pipe 1. Tune/Ratio are neutral at 0.5.
diff --git a/src/managed/Nota.Presentation/ViewModels/BrowserViewModel.cs b/src/managed/Nota.Presentation/ViewModels/BrowserViewModel.cs
index 6e47ade2..b6fffe2d 100644
--- a/src/managed/Nota.Presentation/ViewModels/BrowserViewModel.cs
+++ b/src/managed/Nota.Presentation/ViewModels/BrowserViewModel.cs
@@ -217,7 +217,7 @@ public sealed partial class BrowserViewModel : ObservableObject
var instruments = new List<BrowserItem>
{
- new() { Name = "Nota Synth", Kind = BrowserItemKind.BuiltinInstrument, BuiltinKind = 0, Sub = "simple synth" },
+ new() { Name = "Nota Synth", Kind = BrowserItemKind.BuiltinInstrument, BuiltinKind = 0, Sub = "subtractive synth" },
new() { Name = "Nota Physical", Kind = BrowserItemKind.BuiltinInstrument, BuiltinKind = 2, Sub = "physical synth" },
new() { Name = "Nota Aurora", Kind = BrowserItemKind.BuiltinInstrument, BuiltinKind = 5, Sub = "wavetable synth" },
new() { Name = "Nota Volt", Kind = BrowserItemKind.BuiltinInstrument, BuiltinKind = 6, Sub = "analog synth" },
diff --git a/src/native/nota.engine/src/Synth.h b/src/native/nota.engine/src/Synth.h
index d426a158..fb20adb5 100644
--- a/src/native/nota.engine/src/Synth.h
+++ b/src/native/nota.engine/src/Synth.h
@@ -1,12 +1,17 @@
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.
//
-// Nota Synth — the built-in polyphonic synth. Oscillator (saw/square/triangle/
-// sine) → linear ADSR amplitude envelope → per-voice TPT state-variable low-pass
-// (cutoff + resonance) → master gain. All eight parameters are exposed through the
-// Instrument plugin-parameter interface (normalized 0..1 + stable string ids), so
-// they automate and record exactly like a hosted plugin's params. Deliberately
-// modest DSP (naive/aliased oscillators) — richer modes come later.
+// Nota Synth — the built-in polyphonic subtractive synth. One oscillator
+// (saw/square+pulse-width/triangle/sine) with octave, detune and up to seven
+// unison voices → linear ADSR amplitude envelope → per-voice TPT state-variable
+// filter (Off/LP/HP/BP with an envelope amount) → pan + master gain. Poly 16,
+// Mono or Legato, with glide and velocity→volume tracking. Every parameter is
+// exposed through the Instrument plugin-parameter interface (normalized 0..1 +
+// stable string ids), so they automate and record exactly like a hosted plugin's.
+//
+// The first eight parameters keep their original index and meaning, so projects
+// saved before the oscillator/voice sections existed load unchanged (setState
+// reads whatever floats are present and leaves the rest at their defaults).
#pragma once
@@ -26,11 +31,15 @@ class Synth final : public Instrument {
public:
// Parameter layout (normalized 0..1). The order is the persisted state layout —
// append only.
- enum Param { Wave = 0, Attack, Decay, Sustain, Release, Cutoff, Resonance, Gain, kNumParams };
+ enum Param {
+ Wave = 0, Attack, Decay, Sustain, Release, Cutoff, Resonance, Gain,
+ FilType, FilEnv, PulseWidth, Detune, Octave, Unison, Spread,
+ Glide, VelAmp, Pan, VoiceMode, kNumParams
+ };
Synth() {
- // Musical defaults.
- pn_[Wave].store(0.0f); // Saw
+ // Musical defaults (also the "Init" patch the editor's double-click restores).
+ pn_[Wave].store(0.0f); // Saw
pn_[Attack].store(0.02f);
pn_[Decay].store(0.25f);
pn_[Sustain].store(0.7f);
@@ -38,6 +47,17 @@ public:
pn_[Cutoff].store(0.62f);
pn_[Resonance].store(0.12f);
pn_[Gain].store(0.80f);
+ pn_[FilType].store(1.0f / 3.0f); // LP
+ pn_[FilEnv].store(0.5f); // bipolar centre = no envelope on the cutoff
+ pn_[PulseWidth].store(0.5f); // 50 % — a plain square
+ pn_[Detune].store(0.5f); // bipolar centre = 0 cents
+ pn_[Octave].store(0.5f); // bipolar centre = 0 octaves
+ pn_[Unison].store(0.0f); // 1 voice
+ pn_[Spread].store(0.35f);
+ pn_[Glide].store(0.0f);
+ pn_[VelAmp].store(1.0f); // full velocity tracking — the pre-2026 behaviour
+ pn_[Pan].store(0.5f); // centre
+ pn_[VoiceMode].store(0.0f); // Poly 16
}
int32_t kind() const override { return 0; } // built-in Synth (M7-6) — project compat
@@ -48,11 +68,17 @@ public:
// ---- parameters (automatable via the plugin-param interface) ----------
int32_t pluginParamCount() const override { return kNumParams; }
std::string pluginParamId(int32_t i) const override {
- static const char* ids[] = { "wave", "attack", "decay", "sustain", "release", "cutoff", "resonance", "gain" };
+ static const char* ids[] = {
+ "wave", "attack", "decay", "sustain", "release", "cutoff", "resonance", "gain",
+ "filtype", "filenv", "pulsewidth", "detune", "octave", "unison", "spread",
+ "glide", "velamp", "pan", "voicemode" };
return (i >= 0 && i < kNumParams) ? std::string(ids[i]) : std::string{};
}
std::string pluginParamName(int32_t i) const override {
- static const char* nm[] = { "Wave", "Attack", "Decay", "Sustain", "Release", "Cutoff", "Resonance", "Gain" };
+ static const char* nm[] = {
+ "Wave", "Attack", "Decay", "Sustain", "Release", "Cutoff", "Resonance", "Gain",
+ "Filter Type", "Env →Cutoff", "Pulse Width", "Detune", "Octave", "Unison", "Spread",
+ "Glide", "Vel →Vol", "Pan", "Voice Mode" };
return (i >= 0 && i < kNumParams) ? std::string(nm[i]) : std::string{};
}
float pluginParamGet(int32_t i) const override {
@@ -66,7 +92,9 @@ public:
return -1;
}
- // ---- project state (the eight normalized floats, little-endian) --------
+ // ---- project state (the normalized floats, little-endian) -------------
+ // Reads however many floats the blob carries, so a project written by an older
+ // build (eight params) loads and the parameters added since keep their defaults.
std::vector<uint8_t> getState() const override {
std::vector<uint8_t> b(kNumParams * sizeof(float));
for (int i = 0; i < kNumParams; ++i) {
@@ -76,8 +104,9 @@ public:
return b;
}
void setState(const uint8_t* data, int32_t size) override {
- if (!data || size < static_cast<int32_t>(kNumParams * sizeof(float))) return;
- for (int i = 0; i < kNumParams; ++i) {
+ if (!data || size <= 0) 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);
}
@@ -90,24 +119,51 @@ public:
}
void noteOn(int32_t pitch, float velocity) override {
- Voice* v = findFreeVoice();
- v->active = true;
- v->pitch = pitch;
- v->freq = 440.0 * std::pow(2.0, (pitch - 69) / 12.0);
- v->phase = 0.0;
- v->velocity = velocity;
- v->env = 0.0f;
- v->stage = Stage::Attack;
- v->ic1eq = 0.0; v->ic2eq = 0.0;
+ const int mode = voiceMode();
+ if (mode != 0) { // Mono / Legato share one voice
+ const bool hadHeld = heldCount_ > 0; // another key still down → true overlap
+ pushHeld(pitch);
+ Voice& v = voices_[0];
+ const bool releasing = v.stage == Stage::Release;
+ // Legato holds the envelope only while another key is down; a note struck while
+ // the voice is merely releasing must retrigger or it never actually sounds.
+ const bool legato = mode == 2 && hadHeld && v.active && !releasing;
+ const double target = freqOf(pitch);
+ if (!v.active || releasing || glideSeconds() <= 0.0) v.freq = target;
+ v.target = target;
+ v.pitch = pitch;
+ v.velocity = velocity;
+ if (!legato) startEnvelope(v, !v.active || releasing);
+ v.active = true;
+ return;
+ }
+ pushHeld(pitch);
+ Voice& v = *findFreeVoice();
+ v.pitch = pitch;
+ v.velocity = velocity;
+ v.target = freqOf(pitch);
+ v.freq = v.target; // no portamento in poly
+ startEnvelope(v, true);
+ v.active = true;
}
void noteOff(int32_t pitch) override {
+ popHeld(pitch);
+ if (voiceMode() != 0) {
+ Voice& v = voices_[0];
+ if (heldCount_ == 0) { v.stage = Stage::Release; return; }
+ const int32_t top = held_[heldCount_ - 1]; // fall back to the key still down
+ v.pitch = top;
+ v.target = freqOf(top);
+ if (glideSeconds() <= 0.0) v.freq = v.target;
+ return;
+ }
for (auto& v : voices_)
if (v.active && v.pitch == pitch && v.stage != Stage::Release)
v.stage = Stage::Release;
}
- void allNotesOff() override { for (auto& v : voices_) v.active = false; }
+ void allNotesOff() override { heldCount_ = 0; for (auto& v : voices_) v.active = false; }
void render(float* out, int32_t frames) override {
// Snapshot params once per block (denormalise to musical units).
@@ -117,18 +173,40 @@ public:
const float relRate = static_cast<float>(1.0 / (secOf(Release, 0.002, 3.0) * sampleRate_));
const float sustain = pn_[Sustain].load(std::memory_order_relaxed);
const float gain = pn_[Gain].load(std::memory_order_relaxed);
+ const float velAmp = pn_[VelAmp].load(std::memory_order_relaxed);
+ const int filType = filterType();
+ const float filEnv = (pn_[FilEnv].load(std::memory_order_relaxed) - 0.5f) * 2.0f; // −1..+1
+ const double pw = 0.05 + pn_[PulseWidth].load(std::memory_order_relaxed) * 0.90;
+ const double reso = pn_[Resonance].load(std::memory_order_relaxed);
+ const double baseCut = expMap(pn_[Cutoff].load(std::memory_order_relaxed), 20.0, 18000.0);
+ const int uni = unisonCount();
+ const double spread = pn_[Spread].load(std::memory_order_relaxed);
+ const double cents = (pn_[Detune].load(std::memory_order_relaxed) - 0.5) * 100.0; // ±50 c
+ const double tune = std::pow(2.0, octaveShift());
+ const double glideC = glideCoef();
+
+ // Unison detune ratios and pan gains — the same for every voice this block.
+ double uDet[kMaxUnison], uL[kMaxUnison], uR[kMaxUnison];
+ for (int u = 0; u < uni; ++u) {
+ // One voice: `cents` is a plain fine tune. Several: they spread across ±cents.
+ const double t = (uni == 1) ? 1.0 : (2.0 * u / (uni - 1) - 1.0);
+ uDet[u] = std::pow(2.0, cents * t / 1200.0);
+ const double p = (uni == 1) ? 0.0 : t * spread; // −1..+1
+ uL[u] = std::sqrt(0.5 * (1.0 - p));
+ uR[u] = std::sqrt(0.5 * (1.0 + p));
+ }
+ const double uNorm = 1.0 / std::sqrt(static_cast<double>(uni));
- // TPT state-variable low-pass coefficients (cutoff + resonance).
- const double fc = expMap(pn_[Cutoff].load(std::memory_order_relaxed), 20.0, 18000.0);
- const double g = std::tan(kPi * std::min(fc, sampleRate_ * 0.49) / sampleRate_);
- const double k = 2.0 - 1.94 * pn_[Resonance].load(std::memory_order_relaxed); // 2=no res → ~0.06 max res
- const double a1 = 1.0 / (1.0 + g * (g + k));
- const double a2 = g * a1;
- const double a3 = g * a2;
+ // Static pan (equal power) and the block's amplitude scale.
+ const double pan = (pn_[Pan].load(std::memory_order_relaxed) - 0.5) * 2.0;
+ const double panL = std::sqrt(0.5 * (1.0 - pan)) * kSqrt2;
+ const double panR = std::sqrt(0.5 * (1.0 + pan)) * kSqrt2;
for (auto& v : voices_) {
if (!v.active) continue;
- const double inc = v.freq / sampleRate_;
+ double coefEnv = -1.0; // env value the coefficients were built for
+ double a1 = 0, a2 = 0, a3 = 0, k = 0;
+ int coefAge = 0;
for (int32_t i = 0; i < frames; ++i) {
switch (v.stage) {
case Stage::Attack:
@@ -145,20 +223,48 @@ public:
if (v.env <= 0.0f) { v.env = 0.0f; v.active = false; }
break;
}
- const double osc = oscSample(wave, v.phase);
- v.phase += inc;
- if (v.phase >= 1.0) v.phase -= 1.0;
-
- // TPT SVF low-pass (Zavalishin). v2 is the low-pass output.
- const double v3 = osc - v.ic2eq;
- const double v1 = a1 * v.ic1eq + a2 * v3;
- const double v2 = v.ic2eq + a2 * v.ic1eq + a3 * v3;
- v.ic1eq = 2.0 * v1 - v.ic1eq;
- v.ic2eq = 2.0 * v2 - v.ic2eq;
-
- const float s = static_cast<float>(v2) * v.env * v.velocity * gain * 0.25f;
- out[i * 2] += s;
- out[i * 2 + 1] += s;
+
+ // Glide: a one-pole slide of the playing frequency towards the note's.
+ if (glideC > 0.0 && v.freq != v.target) {
+ v.freq += (v.target - v.freq) * glideC;
+ if (std::fabs(v.target - v.freq) < 1e-4) v.freq = v.target;
+ } else if (glideC <= 0.0) {
+ v.freq = v.target;
+ }
+
+ // Oscillator stack: `uni` detuned copies, panned across the stereo field.
+ double sl = 0.0, sr = 0.0;
+ const double base = v.freq * tune / sampleRate_;
+ for (int u = 0; u < uni; ++u) {
+ const double s = oscSample(wave, v.phase[u], pw);
+ v.phase[u] += base * uDet[u];
+ if (v.phase[u] >= 1.0) v.phase[u] -= 1.0;
+ sl += s * uL[u];
+ sr += s * uR[u];
+ }
+ sl *= uNorm; sr *= uNorm;
+
+ if (filType > 0) {
+ // Rebuild the coefficients when the envelope has moved the cutoff far
+ // enough to matter (every 16 samples at most) — tan() is not cheap.
+ if (coefEnv < 0.0 || (filEnv != 0.0f && --coefAge <= 0)) {
+ const double octs = filEnv * v.env * 4.0; // ±4 octaves
+ const double fc = std::clamp(baseCut * std::pow(2.0, octs), 20.0, 20000.0);
+ const double g = std::tan(kPi * std::min(fc, sampleRate_ * 0.49) / sampleRate_);
+ k = 2.0 - 1.94 * reso; // 2 = no res
+ a1 = 1.0 / (1.0 + g * (g + k));
+ a2 = g * a1;
+ a3 = g * a2;
+ coefEnv = v.env; coefAge = 16;
+ }
+ sl = svf(v.fl, sl, a1, a2, a3, k, filType);
+ sr = svf(v.fr, sr, a1, a2, a3, k, filType);
+ }
+
+ const double amp = (1.0f - velAmp) + velAmp * v.velocity;
+ const double e = v.env * amp * gain * 0.25;
+ out[i * 2] += static_cast<float>(sl * e * panL);
+ out[i * 2 + 1] += static_cast<float>(sr * e * panR);
if (!v.active) break;
}
}
@@ -166,30 +272,80 @@ public:
private:
static constexpr double kPi = 3.14159265358979323846;
+ static constexpr double kSqrt2 = 1.41421356237309504880; // equal-power pan back to unity at centre
+ static constexpr int kMaxUnison = 7;
+ static constexpr int kHeldStack = 16;
- static double oscSample(int wave, double phase) {
+ // Naive (aliased) shapes — deliberately modest, as the rest of the synth.
+ static double oscSample(int wave, double phase, double pw) {
switch (wave) {
- case 1: return phase < 0.5 ? 1.0 : -1.0; // square
+ case 1: return phase < pw ? 1.0 : -1.0; // square / pulse
case 2: return 4.0 * std::fabs(phase - 0.5) - 1.0; // triangle
case 3: return std::sin(2.0 * kPi * phase); // sine
default: return 2.0 * phase - 1.0; // saw
}
}
+
+ struct Svf { double ic1 = 0.0, ic2 = 0.0; };
+
+ // TPT state-variable filter (Zavalishin): low = v2, band = v1, high = in − k·v1 − v2.
+ static double svf(Svf& s, double in, double a1, double a2, double a3, double k, int type) {
+ const double v3 = in - s.ic2;
+ const double v1 = a1 * s.ic1 + a2 * v3;
+ const double v2 = s.ic2 + a2 * s.ic1 + a3 * v3;
+ s.ic1 = 2.0 * v1 - s.ic1;
+ s.ic2 = 2.0 * v2 - s.ic2;
+ switch (type) {
+ case 2: return in - k * v1 - v2; // high-pass
+ case 3: return v1; // band-pass
+ default: return v2; // low-pass
+ }
+ }
+
// Exponential (perceptual) map from a normalized value to [lo, hi].
static double expMap(double v, double lo, double hi) { return lo * std::pow(hi / lo, std::clamp(v, 0.0, 1.0)); }
// Denormalised time (seconds) for an ADSR param, clamped to [lo, hi].
double secOf(Param p, double lo, double hi) const { return expMap(pn_[p].load(std::memory_order_relaxed), lo, hi); }
+ static double freqOf(int32_t pitch) { return 440.0 * std::pow(2.0, (pitch - 69) / 12.0); }
+
+ int filterType() const { return static_cast<int>(std::lround(pn_[FilType].load(std::memory_order_relaxed) * 3.0f)); }
+ int voiceMode() const { return static_cast<int>(std::lround(pn_[VoiceMode].load(std::memory_order_relaxed) * 2.0f)); }
+ int octaveShift() const { return static_cast<int>(std::lround((pn_[Octave].load(std::memory_order_relaxed) - 0.5f) * 4.0f)); }
+ int unisonCount() const {
+ static const int n[] = { 1, 2, 4, 7 };
+ return n[std::clamp(static_cast<int>(std::lround(pn_[Unison].load(std::memory_order_relaxed) * 3.0f)), 0, 3)];
+ }
+ // Glide time: squared so the low end of the slider is finely graded. 0 → off.
+ double glideSeconds() const {
+ const double g = pn_[Glide].load(std::memory_order_relaxed);
+ return g <= 1e-4 ? 0.0 : g * g * 2.0;
+ }
+ double glideCoef() const {
+ const double s = glideSeconds();
+ return s <= 0.0 ? 0.0 : std::clamp(1.0 - std::exp(-1.0 / (s * 0.25 * sampleRate_)), 0.0, 1.0);
+ }
+
enum class Stage { Attack, Decay, Sustain, Release };
struct Voice {
bool active = false;
int32_t pitch = 0;
- double freq = 0.0, phase = 0.0;
+ double freq = 0.0, target = 0.0;
+ double phase[kMaxUnison] = { 0.0 };
float velocity = 0.0f, env = 0.0f;
- double ic1eq = 0.0, ic2eq = 0.0; // SVF integrator state
+ Svf fl, fr; // one filter per channel (unison is stereo)
Stage stage = Stage::Attack;
};
+ // Retrigger: a fresh note resets the phases and the filter; a legato slide does not.
+ void startEnvelope(Voice& v, bool fresh) {
+ v.stage = Stage::Attack;
+ if (!fresh) return;
+ v.env = 0.0f;
+ for (int u = 0; u < kMaxUnison; ++u) v.phase[u] = u * 0.13; // spread the stack's phases
+ v.fl = {}; v.fr = {};
+ }
+
Voice* findFreeVoice() {
for (auto& v : voices_) if (!v.active) return &v;
Voice* q = &voices_[0];
@@ -197,8 +353,22 @@ private:
return q;
}
+ // Held-note stack for Mono / Legato: releasing the top note falls back to the one under
+ // it. A fixed array — the audio thread must not allocate.
+ void pushHeld(int32_t pitch) {
+ popHeld(pitch);
+ if (heldCount_ < kHeldStack) held_[heldCount_++] = pitch;
+ }
+ void popHeld(int32_t pitch) {
+ int w = 0;
+ for (int r = 0; r < heldCount_; ++r) if (held_[r] != pitch) held_[w++] = held_[r];
+ heldCount_ = w;
+ }
+
static constexpr int kVoices = 16;
Voice voices_[kVoices];
+ int32_t held_[kHeldStack] = {};
+ int heldCount_ = 0;
double sampleRate_ = 44100.0;
std::atomic<float> pn_[kNumParams]; // normalized param values
};
diff --git a/tests/Nota.SmokeTest/Program.cs b/tests/Nota.SmokeTest/Program.cs
index b540e94b..e03b5c03 100644
--- a/tests/Nota.SmokeTest/Program.cs
+++ b/tests/Nota.SmokeTest/Program.cs
@@ -976,7 +976,7 @@ Console.WriteLine("-- Nota Synth --");
Check(se.DeviceName(t, -1) == "Nota Synth", $"instrument is Nota Synth (got '{se.DeviceName(t, -1)}')");
int pc = se.PluginParamCount(t, -1);
- Check(pc == 8, $"Nota Synth exposes 8 params (got {pc})");
+ Check(pc == 19, $"Nota Synth exposes 19 params (got {pc})");
int cut = -1; bool idsOk = true;
for (int i = 0; i < pc; i++)
{
@@ -984,6 +984,20 @@ Console.WriteLine("-- Nota Synth --");
if (se.PluginParamId(t, -1, i) == "cutoff") cut = i;
}
Check(idsOk && cut >= 0, "params have ids + names; cutoff present");
+ int PIdx(int tr, string id)
+ { for (int i = 0; i < se.PluginParamCount(tr, -1); i++) if (se.PluginParamId(tr, -1, i) == id) return i; return -1; }
+
+ // The first eight keep their index and id — the persisted layout is append-only, so
+ // automation lanes and project states written before the oscillator/voice sections
+ // still address the same parameters.
+ string[] legacyIds = { "wave", "attack", "decay", "sustain", "release", "cutoff", "resonance", "gain" };
+ bool layoutOk = true;
+ for (int i = 0; i < legacyIds.Length; i++) if (se.PluginParamId(t, -1, i) != legacyIds[i]) layoutOk = false;
+ Check(layoutOk, "the original eight params keep their index and id");
+ string[] newIds = { "filtype", "filenv", "pulsewidth", "detune", "octave", "unison", "spread", "glide", "velamp", "pan", "voicemode" };
+ bool newOk = true;
+ foreach (var id in newIds) if (PIdx(t, id) < 8) newOk = false;
+ Check(newOk, "oscillator / filter / voice params are all present");
se.PluginParamSet(t, -1, cut, 0.33f);
Check(Math.Abs(se.PluginParamGet(t, -1, cut) - 0.33f) < 1e-4, "param set/get round-trips");
@@ -1020,6 +1034,62 @@ Console.WriteLine("-- Nota Synth --");
var nbuf = new float[8192 * 2];
se.Seek(0.0); se.Play(); se.RenderOffline(nbuf, 8192); se.StopTransport();
Check(Rms(nbuf, 8192) > 0.005f, $"Nota Synth is audible (RMS {Rms(nbuf, 8192):F3})");
+
+ // A project written before the new sections carries only the first eight floats: it
+ // must still load, leaving the rest at their defaults (unison 1, poly, no glide).
+ int tl = se.AddInstrumentTrack();
+ var legacy = new byte[8 * 4];
+ for (int i = 0; i < 8; i++) BitConverter.GetBytes(i == 5 ? 0.42f : 0.5f).CopyTo(legacy, i * 4);
+ se.SetPluginState(tl, -1, legacy);
+ Check(Math.Abs(se.PluginParamGet(tl, -1, cut) - 0.42f) < 1e-4, "an eight-param state from an older project still loads");
+ Check(Math.Abs(se.PluginParamGet(tl, -1, PIdx(tl, "unison")) - 0f) < 1e-4
+ && Math.Abs(se.PluginParamGet(tl, -1, PIdx(tl, "voicemode")) - 0f) < 1e-4,
+ "params added since keep their defaults when an old state is loaded");
+
+ // Off / LP / HP / BP all pass signal, and each one sounds different from the others.
+ int tf = se.AddInstrumentTrack();
+ se.AddMidiClip(tf, 0.0, 4.0);
+ se.SetClipNotes(tf, 0, new[] { new NotaNote(48, 0.0, 2.0, 1.0f) });
+ int ftIdx = PIdx(tf, "filtype");
+ var levels = new float[4];
+ for (int k = 0; k < 4; k++)
+ {
+ se.PluginParamSet(tf, -1, ftIdx, k / 3f);
+ var fbuf = new float[8192 * 2];
+ se.Seek(0.0); se.Play(); se.RenderOffline(fbuf, 8192); se.StopTransport();
+ levels[k] = Rms(fbuf, 8192);
+ }
+ Check(levels[0] > 0.005f && levels[1] > 0.005f && levels[2] > 0.005f && levels[3] > 0.005f,
+ $"every filter type passes signal (off {levels[0]:F3}, lp {levels[1]:F3}, hp {levels[2]:F3}, bp {levels[3]:F3})");
+ Check(Math.Abs(levels[0] - levels[1]) > 1e-3 && Math.Abs(levels[1] - levels[2]) > 1e-3,
+ "the filter types do not render identically");
+
+ // Unison stacks voices: seven detuned copies are louder than one.
+ int tu = se.AddInstrumentTrack();
+ se.AddMidiClip(tu, 0.0, 4.0);
+ se.SetClipNotes(tu, 0, new[] { new NotaNote(60, 0.0, 2.0, 1.0f) });
+ se.PluginParamSet(tu, -1, PIdx(tu, "detune"), 0.7f);
+ var ubuf1 = new float[8192 * 2];
+ se.Seek(0.0); se.Play(); se.RenderOffline(ubuf1, 8192); se.StopTransport();
+ float one = Rms(ubuf1, 8192);
+ se.PluginParamSet(tu, -1, PIdx(tu, "unison"), 1f);
+ var ubuf7 = new float[8192 * 2];
+ se.Seek(0.0); se.Play(); se.RenderOffline(ubuf7, 8192); se.StopTransport();
+ float seven = Rms(ubuf7, 8192);
+ Check(seven > one * 1.05f, $"unison 7 thickens the tone (1 voice {one:F3} -> 7 voices {seven:F3})");
+
+ // Mono collapses a chord onto one voice; Legato does the same but does not retrigger.
+ int tm = se.AddInstrumentTrack();
+ se.AddMidiClip(tm, 0.0, 4.0);
+ se.SetClipNotes(tm, 0, new[] { new NotaNote(60, 0.0, 2.0, 1.0f), new NotaNote(64, 0.0, 2.0, 1.0f), new NotaNote(67, 0.0, 2.0, 1.0f) });
+ var pbuf = new float[8192 * 2];
+ se.Seek(0.0); se.Play(); se.RenderOffline(pbuf, 8192); se.StopTransport();
+ float poly = Rms(pbuf, 8192);
+ se.PluginParamSet(tm, -1, PIdx(tm, "voicemode"), 0.5f);
+ var mbuf = new float[8192 * 2];
+ se.Seek(0.0); se.Play(); se.RenderOffline(mbuf, 8192); se.StopTransport();
+ float mono = Rms(mbuf, 8192);
+ Check(mono > 0.005f && mono < poly, $"Mono collapses a three-note chord onto one voice (poly {poly:F3} -> mono {mono:F3})");
}
// ============================ Nota Physical ===============================