Nota — a free DAW for macOS, Windows and Linux. No subscription, no account — just open it and make music.
C# audioaudio-unitavaloniacpp20cross-platformdawdigital-audio-workstationdspjucelinux-audiomcp-servermidimusicmusic-productionpiano-rollplugin-hostsequencersynthesizervstvst3
(feat) Sustain pedal holds notes on every melodic built-in instrument (#179)
Chris Laupamae307b6b6294e
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 7f88afac..80ff75eb 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -23,6 +23,12 @@ Entry categories: `Added`, `Changed`, `Fixed`, `Removed`.## [Unreleased]### Added+- **The sustain pedal on every built-in instrument** (nota-daw/nota#99): with the pedal down,+ released keys keep sounding on Synth, Sampler, Volt, Bass, Flux, Grain, Operator,+ Wavetable, Physical, Pentad, Consort, Monolith and Pendulum (and on an Instrument Rack's+ chains) until the pedal comes up; striking a held key again restarts it. It works for a+ keyboard's pedal and for a pedal recorded or drawn in a clip. Keys, Mosaic and plug-ins keep+ their own pedal handling, and drums (Drum Rack, Rhythm) ignore it.- **Release notes from the status bar** (nota-daw/nota#127): the version number at thebottom right of the main window, next to the sample rate, is now a button: click it toopen What's New for the installed version (it never starts an update). Escape closes What'sdiff --git a/FEATURES.md b/FEATURES.mdindex e9c826e9..e57aa835 100644--- a/FEATURES.md+++ b/FEATURES.md@@ -297,9 +297,11 @@ track count and closes with Escape.Controllers move, copy, split, trim and consolidate with the clip and are saved with theproject. Polyphonic aftertouch from an ordinary keyboard is kept as each note's pressure.Live and from clips, hosted plug-ins get every controller (the pedal with its real value, for- half-pedalling); built-ins act on those they know — the pedal (Keys, Mosaic), the wheel,- pressure, CC74, and the mod wheel on synths with a *Mod Wheel* control (Bass, Monolith, Volt,- Aurora, Operator, Pentad, Consort). MCP `get_clip_controllers` / `set_clip_controller`.+ half-pedalling); built-ins act on those they know — the pedal, the wheel, pressure, CC74,+ and the mod wheel on synths with a *Mod Wheel* control (Bass, Monolith, Volt, Aurora,+ Operator, Pentad, Consort). The sustain pedal holds released keys on every melodic built-in+ (Keys and Mosaic model their own damper; drums ignore it); a re-struck held key restarts.+ MCP `get_clip_controllers` / `set_clip_controller`.- **MPE (per-note expression)** — an MPE controller's notes each carry their own pitchbend, pressure and slide (CC74): channels 2–16 are per-note (lower zone, ±48 semitones bydefault; the controller's MPE Configuration and bend-range messages are honoured), channel 1diff --git a/src/native/nota.engine/pluginhost/PluginHost.cpp b/src/native/nota.engine/pluginhost/PluginHost.cppindex 7351b385..7f1c7f4c 100644--- a/src/native/nota.engine/pluginhost/PluginHost.cpp+++ b/src/native/nota.engine/pluginhost/PluginHost.cpp@@ -692,6 +692,7 @@ public:editor_.onNoteOff = [this](int32_t pitch) { guiNotes_.push({false, pitch, 0.0f}); };}const char* displayName() const override { return name_.empty() ? "Plugin" : name_.c_str(); }+ bool handlesSustain() const override { return true; } // the plug-in gets CC64 itself~PluginInstrument() override { if (plugin_) plugin_->removeListener(this); }void setSampleRate(double sr) override { prepare(sr); }diff --git a/src/native/nota.engine/src/Audition.cpp b/src/native/nota.engine/src/Audition.cppindex 405037ba..59257bf9 100644--- a/src/native/nota.engine/src/Audition.cpp+++ b/src/native/nota.engine/src/Audition.cpp@@ -456,6 +456,7 @@ public:int32_t kind() const override { return 4; }const char* displayName() const override { return "Kit"; }+ bool handlesSustain() const override { return true; }private:static constexpr int64_t kIdle = 48000; // ~1 s of silence ends a pad's taildiff --git a/src/native/nota.engine/src/DrumRack.h b/src/native/nota.engine/src/DrumRack.hindex f4f6a36d..0ea3820a 100644--- a/src/native/nota.engine/src/DrumRack.h+++ b/src/native/nota.engine/src/DrumRack.h@@ -28,6 +28,7 @@ class DrumRack final : public RackInstrument {public:int32_t kind() const override { return 4; } // built-in Drum Rack (project compat)const char* displayName() const override { return "Nota Drum Rack"; }+ bool handlesSustain() const override { return true; } // pads ignore the pedal (#99)// Route a note only to the pad(s) assigned to it, applying choke + tune and// arming the pad's decay envelope.diff --git a/src/native/nota.engine/src/Engine_Render.cpp b/src/native/nota.engine/src/Engine_Render.cppindex dfd0efea..c7dcd09e 100644--- a/src/native/nota.engine/src/Engine_Render.cpp+++ b/src/native/nota.engine/src/Engine_Render.cpp@@ -116,6 +116,38 @@ inline bool midiEvLess(const MidiEv& a, const MidiEv& b) {return a.off < b.off || (a.off == b.off && !a.on && b.on);}+// The engine's sustain pedal (#99) for an instrument without a damper of its own: while the+// pedal is down a released key's note-off waits in inst.pedalHeld; the pedal coming up sends+// them all, and striking a held key again releases it right before the new note-on.+inline bool pedalHolds(const Instrument& inst, int32_t pitch) {+ return pitch >= 0 && pitch < 128 && ((inst.pedalHeld[pitch >> 6] >> (pitch & 63)) & 1u);+}+inline void sendNoteOn(Instrument& inst, int32_t pitch, float vel) {+ if (pedalHolds(inst, pitch)) {+ inst.pedalHeld[pitch >> 6] &= ~(uint64_t{1} << (pitch & 63));+ inst.noteOff(pitch);+ }+ inst.noteOn(pitch, vel);+}+inline void sendNoteOff(Instrument& inst, int32_t pitch) {+ if (inst.pedalDown && pitch >= 0 && pitch < 128 && !inst.handlesSustain()) {+ inst.pedalHeld[pitch >> 6] |= uint64_t{1} << (pitch & 63);+ return;+ }+ inst.noteOff(pitch);+}+inline void sendController(Instrument& inst, int32_t ctl, float value) {+ if (ctl == kCtlSustain && !inst.handlesSustain()) {+ inst.pedalDown = value >= 0.5f;+ if (!inst.pedalDown) {+ for (int32_t p = 0; p < 128; ++p)+ if (pedalHolds(inst, p)) inst.noteOff(p);+ inst.pedalHeld[0] = inst.pedalHeld[1] = 0;+ }+ }+ inst.controller(ctl, value);+}+// Stop / jump: pedals left down and a bent wheel go back to rest (the chase that follows a jump// sets them again where the clip has them).inline void releaseHeldControllers(Instrument& inst) {@@ -123,7 +155,7 @@ inline void releaseHeldControllers(Instrument& inst) {const float v = inst.deliveredCtl[ctl].load(std::memory_order_relaxed);if (std::isnan(v) || v == kCtlRest) continue;inst.deliveredCtl[ctl].store(kCtlRest, std::memory_order_relaxed);- inst.controller(ctl, kCtlRest);+ sendController(inst, ctl, kCtlRest);}}@@ -135,7 +167,7 @@ inline void deliverExpr(Instrument& inst, int32_t pitch, int32_t dim, float valuconst int32_t ctl = dim - kCtlDimBase;if (ctl < 0 || ctl >= kCtlCount) return;inst.deliveredCtl[ctl].store(value, std::memory_order_relaxed);- inst.controller(ctl, value);+ sendController(inst, ctl, value);} else {inst.noteExpression(pitch, dim, value);}@@ -170,8 +202,8 @@ void playEvents(Instrument& inst, float* dst, int32_t frames, const MidiEv* evs,const int32_t xOff = x < xn ? std::clamp(xev[x].off, 0, frames) : INT32_MAX;if (nOff <= xOff) {renderTo(nOff);- if (evs[k].on) inst.noteOn(evs[k].pitch, evs[k].vel);- else inst.noteOff(evs[k].pitch);+ if (evs[k].on) sendNoteOn(inst, evs[k].pitch, evs[k].vel);+ else sendNoteOff(inst, evs[k].pitch);++k;} else {renderTo(xOff);diff --git a/src/native/nota.engine/src/Instrument.h b/src/native/nota.engine/src/Instrument.hindex 99a75aa3..498ac441 100644--- a/src/native/nota.engine/src/Instrument.h+++ b/src/native/nota.engine/src/Instrument.h@@ -68,6 +68,16 @@ public:}}+ // The sustain pedal for instruments without a damper of their own (#99): while CC64 is+ // down the engine holds back their note-offs and sends them when it comes up, and a+ // re-struck held key is released right before it sounds again (Engine_Render.cpp,+ // playEvents / deliverExpr). An instrument that models the pedal itself (Keys, Mosaic, a+ // hosted plug-in) or ignores it on purpose (drums) returns true and is left alone.+ virtual bool handlesSustain() const { return false; }+ // The engine's damper state for this instrument. Audio thread only.+ bool pedalDown = false;+ uint64_t pedalHeld[2] = { 0, 0 }; // released keys the pedal is holding, one bit per pitch+// Add `frames` of interleaved stereo into `out`. Continues current voices.virtual void render(float* out, int32_t frames) = 0;diff --git a/src/native/nota.engine/src/Keys.h b/src/native/nota.engine/src/Keys.hindex c81d9ede..f93ab487 100644--- a/src/native/nota.engine/src/Keys.h+++ b/src/native/nota.engine/src/Keys.h@@ -186,6 +186,7 @@ public:// MPE: bend → pitch, pressure → drive into the pickup (+ a little level), slide → pickup symmetry.bool supportsMpe() const override { return true; }+ bool handlesSustain() const override { return true; } // its own damper model (CC64)void noteExpression(int32_t pitch, int32_t dim, float value) override {if (pitch < 0) {if (dim == ExprSustain) cc64_ = value >= 0.5f;diff --git a/src/native/nota.engine/src/Mosaic.h b/src/native/nota.engine/src/Mosaic.hindex 880f33af..e8172838 100644--- a/src/native/nota.engine/src/Mosaic.h+++ b/src/native/nota.engine/src/Mosaic.h@@ -369,6 +369,7 @@ public:const char* displayName() const override { return "Nota Mosaic"; }void setSampleRate(double sr) override { sr_ = sr > 0 ? sr : 44100.0; }bool supportsMpe() const override { return true; }+ bool handlesSustain() const override { return true; } // holds released keys itself (CC64)// ---- the program (message thread) ---------------------------------------------------// Parses and starts loading `text`. A program whose files are all loaded already (a zonediff --git a/src/native/nota.engine/src/RhythmMachine.h b/src/native/nota.engine/src/RhythmMachine.hindex a7cd2736..23ff59d4 100644--- a/src/native/nota.engine/src/RhythmMachine.h+++ b/src/native/nota.engine/src/RhythmMachine.h@@ -121,6 +121,7 @@ public:int32_t kind() const override { return 12; }const char* displayName() const override { return "Nota Rhythm"; }+ bool handlesSustain() const override { return true; } // drums ignore the pedal (#99)void setSampleRate(double sr) override {sampleRate_ = sr > 0 ? sr : 44100.0;diff --git a/tests/Nota.SmokeTest/Program.cs b/tests/Nota.SmokeTest/Program.csindex 45e07832..9ede90f9 100644--- a/tests/Nota.SmokeTest/Program.cs+++ b/tests/Nota.SmokeTest/Program.cs@@ -401,6 +401,8 @@ if (args.Length >= 1 && args[0] == "--midi-ctl"){Console.WriteLine("-- midi controllers --");foreach (var (ok, label) in MidiControllerTests.Run()) Check(ok, label);+ Console.WriteLine("-- sustain pedal --");+ foreach (var (ok, label) in SustainPedalTests.Run()) Check(ok, label);Console.WriteLine(failures == 0 ? "MIDI CTL PASSED" : $"MIDI CTL FAILED ({failures})");return failures == 0 ? 0 : 1;}@@ -14794,6 +14796,8 @@ Console.WriteLine("-- live midi recording --");foreach (var (ok, label) in LiveRecordTests.Run()) Check(ok, label);Console.WriteLine("-- midi controllers --");foreach (var (ok, label) in MidiControllerTests.Run()) Check(ok, label);+Console.WriteLine("-- sustain pedal --");+foreach (var (ok, label) in SustainPedalTests.Run()) Check(ok, label);Console.WriteLine("-- loop seam --");foreach (var (ok, label) in LoopSeamTests.Run()) Check(ok, label);Console.WriteLine("-- loop record mode --");diff --git a/tests/Nota.SmokeTest/SustainPedalTests.cs b/tests/Nota.SmokeTest/SustainPedalTests.csnew file mode 100644index 00000000..ac6a50e4--- /dev/null+++ b/tests/Nota.SmokeTest/SustainPedalTests.cs@@ -0,0 +1,114 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.+//+// The sustain pedal on every built-in instrument (#99): with CC64 down a released key keeps+// sounding exactly as if it were still held, the pedal coming up releases it exactly as a+// note-off would have, a re-struck held key starts again, racks sustain through their chains,+// and drums ignore the pedal.++using Nota.Application;+using Nota.Infrastructure;++namespace Nota.SmokeTest;++internal static class SustainPedalTests+{+ private const int Block = 512;+ private const int Sustain = MidiController.Sustain;++ private static float[] Render(NotaEngine e, int blocks)+ {+ var all = new float[blocks * Block * 2];+ var b = new float[Block * 2];+ for (int i = 0; i < blocks; i++) { e.RenderOffline(b, Block); Array.Copy(b, 0, all, i * Block * 2, Block * 2); }+ return all;+ }+ private static double Rms(float[] st)+ {+ double s = 0;+ foreach (var v in st) s += v * (double)v;+ return Math.Sqrt(s / Math.Max(1, st.Length));+ }+ private static double MaxDiff(float[] a, float[] b)+ {+ double d = 0;+ for (int i = 0; i < Math.Min(a.Length, b.Length); i++) d = Math.Max(d, Math.Abs(a[i] - b[i]));+ return d;+ }++ // One take: the key goes down, then (after `pedal` decides) up; what follows is returned.+ // pedal: 0 = never, 1 = down before the release and still down, 2 = down, then up later.+ private static (float[] AfterRelease, float[] AfterPedalUp) Take(Func<NotaEngine, int> add, bool release, int pedal)+ {+ using var e = new NotaEngine();+ int t = add(e);+ Render(e, 2);+ if (pedal > 0) { e.SendTrackController(t, Sustain, 1f); Render(e, 1); }+ else Render(e, 1);+ e.TrackNoteOn(t, 60, 0.9f);+ Render(e, 16);+ if (release) e.TrackNoteOff(t, 60);+ var afterRelease = Render(e, 16);+ if (pedal == 2) e.SendTrackController(t, Sustain, 0f);+ else if (pedal == 0 && !release) e.TrackNoteOff(t, 60); // the reference for "pedal up"+ var afterUp = Render(e, 24);+ return (afterRelease, afterUp);+ }++ public static IEnumerable<(bool, string)> Run()+ {+ var melodic = new (string Name, Func<NotaEngine, int> Add)[]+ {+ ("Nota Synth", e => e.AddInstrumentTrack()),+ ("Nota Physical", e => e.AddPhysicalSynthTrack()),+ ("Nota Wavetable", e => e.AddWavetableSynthTrack()),+ ("Nota Volt", e => e.AddVoltSynthTrack()),+ ("Nota Bass", e => e.AddBassSynthTrack()),+ ("Nota Operator", e => e.AddOperatorSynthTrack()),+ ("Nota Grain", e => e.AddGrainSynthTrack()),+ ("Nota Flux", e => e.AddFluxSynthTrack()),+ ("Nota Monolith", e => e.AddMonolithTrack()),+ ("Nota Pentad", e => e.AddPentadTrack()),+ ("Nota Consort", e => e.AddConsortTrack()),+ ("Instrument Rack (a Synth chain)", e => { int t = e.AddInstrumentRackTrack(); e.RackAddChain(t, 0); return t; }),+ };+ foreach (var (name, add) in melodic)+ {+ var held = Take(add, release: false, pedal: 0); // key held throughout, released at "pedal up"+ var released = Take(add, release: true, pedal: 0); // plain release, no pedal+ var pedalled = Take(add, release: true, pedal: 2); // released under the pedal, pedal up later+ double hold = MaxDiff(pedalled.AfterRelease, held.AfterRelease);+ double up = MaxDiff(pedalled.AfterPedalUp, held.AfterPedalUp);+ double sounding = Rms(held.AfterRelease), cut = Rms(released.AfterRelease);+ yield return (sounding > 1e-4 && hold < 1e-6,+ $"{name}: a key released with the pedal down sounds exactly as if held (rms {sounding:F4}, diff {hold:E1}; without the pedal {cut:F4})");+ yield return (up < 1e-6, $"{name}: the pedal coming up releases it exactly like a note-off (diff {up:E1})");+ }++ // A key re-struck under the pedal starts again, and a key still physically down when the+ // pedal comes up keeps sounding until its own release.+ using (var e = new NotaEngine())+ {+ int t = e.AddInstrumentTrack();+ Render(e, 2);+ e.SendTrackController(t, Sustain, 1f); Render(e, 1);+ e.TrackNoteOn(t, 60, 0.9f); Render(e, 8);+ e.TrackNoteOff(t, 60); Render(e, 4);+ e.TrackNoteOn(t, 60, 0.9f); Render(e, 8); // re-struck, still down+ e.SendTrackController(t, Sustain, 0f);+ double still = Rms(Render(e, 16));+ e.TrackNoteOff(t, 60);+ Render(e, 40);+ double after = Rms(Render(e, 8));+ yield return (still > 1e-3 && after < still * 0.05,+ $"a re-struck key sounds past the pedal while held and stops on its own release (held {still:F4}, after {after:F5})");+ }++ // Drums ignore the pedal: a Drum Rack pad renders the same with and without it.+ Func<NotaEngine, int> drums = e => { int t = e.AddDrumRackTrack(); int p = e.RackAddChain(t, 0); e.RackSetChainTriggerNote(t, p, 60); return t; };+ var dPlain = Take(drums, release: true, pedal: 0);+ var dPedal = Take(drums, release: true, pedal: 1);+ double dd = MaxDiff(dPlain.AfterRelease, dPedal.AfterRelease);+ yield return (dd < 1e-6, $"Drum Rack ignores the sustain pedal (diff {dd:E1})");+ }+}