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
(fix) Release 0.57.1 review: device CPU back to 0.56.1, render pool race, range cut automation, playhead grab (#288)
Egor Khindikaynenc8715b96691a
diff --git a/.specify/bugs/dsp-perf-regressions/fix.md b/.specify/bugs/dsp-perf-regressions/fix.mdindex 258065db..90b3b129 100644--- a/.specify/bugs/dsp-perf-regressions/fix.md+++ b/.specify/bugs/dsp-perf-regressions/fix.md@@ -88,3 +88,60 @@ Mid / Side and glides. `BiquadCascade` gains `bank(int)` for that. Output is uncEQ-8 x8 4.40 ms (develop 9.86, 0.56.1 4.79); instructions retired per second of audio(`/usr/bin/time -l`, whole process) 111 M vs develop 133 M; silent-32 653 vs 656 M,sparse-32 1688 vs 1716 M.++## Addendum — the remaining rows on the release PR (#285)++After #287 the develop → main gate still failed 18 rows (x86 CI: Strata +27 %, Reverb++12 %, Crush +10 %, Keys +10 %, Delay +9.6 %, Auto Filter +9 %, Flanger +9 %, Phaser,+Chorus, Utility, Synth, Compressor, Consort, Shutter, Pentad, EQ-3 +1–6 %). Callgrind with+`-g` on both builds (Linux arm64 container, `scripts/perf-gate.sh origin/main`), compared+per function and per source line, showed two causes, neither the one guessed above:++- **Lost inlining, the same as `SvfFilter`.** #212 moved per-sample methods out of headers:+ `DelayLine` (push / read / readLinear / readHermite4p / processAllpass), `LadderFilter::process`,+ `TruePeakMeter::push/detect`, `BleOscillator::tick/polyBlep`, `LfoGenerator::tick`, the+ three envelopes' `tick`/`process`, `OnePoleSmoother::tick` and `VoiceExpr::tick` (every+ voice of every instrument, from other TUs). They are inline in their headers again.+ Device helpers that were in-class (implicitly inline) before and became plain members in+ the device's `.cpp` lost the hint and GCC stopped inlining them: `Reverb::readPre`+ (200 M of Reverb's 800 M instructions), `Flanger::readLine`, `Chorus::readLine`,+ `Phaser::chain`, `Crush::shape`, `Utility::truePeak`, `Consort::readLine` — now `inline`.+- **Per-sample peaks for the idle sleep.** Strata kept a running output peak, Flanger a+ feed peak, Phaser and Crush a feed/crushed-path peak, on every sample of every block.+ Strata checks its output with one SIMD pass after the loop, only when everything else is+ quiet; Flanger reads back the block's writes to its line with the new+ `simd_audio::peakAbs`; Phaser and Crush measure only in silent-input blocks (a loud block+ resets the quiet count anyway, and the decayed peak still guards the tail).+- Smaller: Keys' `renderVoice` took the expression offsets by pointer (stores to `mono[]`+ could alias them, so `VoiceExpr::tick` reloaded them per sample) and recomputed the+ pickup's dist/model terms per sample — it copies the offsets locally and precomputes+ `keys::PickupShape` (same operations, same order). Compressor computed `dbToLin` twice per+ sample in linked mode, where both channels' reductions are equal — the right channel+ reuses the left's gain.++Results (arm64 container, instructions, effect's own share vs `main` 0.56.1): everything+that failed is within 1 % or faster except Strata (+4.4 %: ~1 instruction per sample on a+~25-instruction loop that is now line-for-line the 0.56.1 loop; the cost is the idle+skip's silence check, which is what makes `silent-32` 70 % cheaper) and Flanger (+2.0 %,+code generation of the unchanged Hermite read). Delay is 24 % below 0.56.1, Compressor 9 %, Reverb 2 %,+Keys 0.6 %. x86 numbers come from the gate on the PR.++Null test (`tests/perf` scenarios rendered 2 s each through the C ABI, develop vs this+fix, Apple Silicon): same-build renders bit-identical; 45 of 52 scenarios bit-identical;+Auto Filter, Prism and the `mix-*` scenarios differ at −105 dBFS peak or below (FMA+contraction across the newly inlined calls).++## Addendum — Volt on x86 (PR #288 gate)++The x86 gate (develop → this fix) passed every row except Volt (+6.0 %) and the `mix-*`+scenarios built from Volt tracks (+2.6 %). Reproduced under Valgrind in an amd64 container:+with `VoiceExpr::tick` now inline, `VoltSynth::render` hit GCC's function-growth budget+and stopped inlining `VoltSynth::osc` (6.6 M instructions as a call); marking `osc` inline+pushed `svf` out instead. `osc`, `svf` and `advanceEnv` — in-class (implicitly inline)+before #212, inlined by develop — are `NOTA_ALWAYS_INLINE`. x86 instructions vs develop:+Volt 100.9 M → 98.7 M, `mix-4` 557.4 M → 539.1 M, Synth 46.4 M → 44.0 M. Volt renders+bit-identical to develop.++The same push hardens `AudioThreadPool` (review on #288): a worker whose epoch view lags+could combine fields from two generations of a reused slot. Workers now snapshot all four+fields, fence (acquire) and re-check `epoch_`; the publisher's field stores are release.diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 27782ab3..6306406b 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -22,12 +22,6 @@ Entry categories: `Added`, `Changed`, `Fixed`, `Removed`.## [Unreleased]-### Fixed-- **Nota Prism, Nota EQ-8 and Nota Auto Filter use as little CPU as before the engine- rebuild**: Prism and EQ-8 had become up to twice as heavy, Auto Filter about 40 %- heavier, with the same sound. The shared filter core runs inline again and EQ-8 runs all- its bands per sample; the output is unchanged to well below the last bit of 16-bit audio.-## [0.57.1] — 2026-10-22### Added@@ -149,6 +143,21 @@ Entry categories: `Added`, `Changed`, `Fixed`, `Removed`.`scripts/perf-gate.sh develop` (Linux).### Fixed+- **The other built-in devices use as little CPU as before the engine rebuild too**:+ Nota Delay, Flanger, Chorus, Phaser, Reverb, Crush, Utility, Strata and Compressor, and+ every built-in instrument (Keys most of all), had become 2–30 % heavier. Their+ per-sample helpers run inline again, and the peaks that decide when a device may sleep+ are measured once per block instead of on every sample. The sound is unchanged.+- **Cutting a time range takes its automation with it**: ⌘X on a range left the volume,+ pan and effect automation inside it behind, so the pasted copy came on top of points+ that still played at the old place. The cut now removes them in the same undo step.+- **A stopped playhead no longer hides the handles under it in the audio clip editor**:+ dragging a warp marker, a trim bracket or an envelope point that sat under the playhead+ moved the playhead instead. The handle now wins; the ruler still seeks.+- **Nota Prism, Nota EQ-8 and Nota Auto Filter use as little CPU as before the engine+ rebuild**: Prism and EQ-8 had become up to twice as heavy, Auto Filter about 40 %+ heavier, with the same sound. The shared filter core runs inline again and EQ-8 runs all+ its bands per sample; the output is unchanged to well below the last bit of 16-bit audio.- **The audio clip editor shows the playhead while stopped** (nota-daw/nota#277): wheneverthe song position is inside the clip, as the piano roll does.- **⌘1–⌘5 change a grid you can see** (nota-daw/nota#114): after a click in the audio clipdiff --git a/scripts/bench-chart.py b/scripts/bench-chart.pyindex bb5fc86c..2f8dc77f 100755--- a/scripts/bench-chart.py+++ b/scripts/bench-chart.py@@ -1,5 +1,6 @@#!/usr/bin/env python3# SPDX-License-Identifier: AGPL-3.0-only+# Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms."""Turn scripts/bench-engine.sh output into charts and a Markdown summary.Usage: scripts/bench-chart.py <out-dir> [label=Display name ...]diff --git a/scripts/bench-engine.sh b/scripts/bench-engine.shindex aa0cd107..6cba6aaf 100755--- a/scripts/bench-engine.sh+++ b/scripts/bench-engine.sh@@ -1,5 +1,6 @@#!/usr/bin/env bash# SPDX-License-Identifier: AGPL-3.0-only+# Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.## Engine benchmark: compares engine builds on the same machine through the public C ABI# (scripts/bench/engine-bench.cpp). Each label points at a directory that holds a Releasediff --git a/scripts/perf-gate.py b/scripts/perf-gate.pyindex f973386e..68fe0e14 100755--- a/scripts/perf-gate.py+++ b/scripts/perf-gate.py@@ -1,5 +1,6 @@#!/usr/bin/env python3# SPDX-License-Identifier: AGPL-3.0-only+# Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.## Compares two perf-gate result sets (scripts/perf-gate.sh) and decides the gate.# Work rows: id, label, instructions, peak. Timing rows: id, wall_ms_per_s (one perdiff --git a/scripts/perf-gate.sh b/scripts/perf-gate.shindex dca2a459..f6a0abe1 100755--- a/scripts/perf-gate.sh+++ b/scripts/perf-gate.sh@@ -1,5 +1,6 @@#!/usr/bin/env bash# SPDX-License-Identifier: AGPL-3.0-only+# Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.## Engine performance regression gate (specs/034-engine-perf-gate).# Builds the engine at two commits and renders the same scenarios with each. Two checks:diff --git a/scripts/release-credits.sh b/scripts/release-credits.shindex f46f6c41..f98dff6d 100755--- a/scripts/release-credits.sh+++ b/scripts/release-credits.sh@@ -1,5 +1,6 @@#!/usr/bin/env bash# SPDX-License-Identifier: AGPL-3.0-only+# Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.## What /release needs to write the full change list and the contributors of a release# (release-notes/X.Y.Z.{en,ru}.md, format in .claude/skills/release/SKILL.md § P4).diff --git a/src/managed/Nota.App/AudioClipEditorView.cs b/src/managed/Nota.App/AudioClipEditorView.csindex 335940c3..7355ee0f 100644--- a/src/managed/Nota.App/AudioClipEditorView.cs+++ b/src/managed/Nota.App/AudioClipEditorView.cs@@ -1058,16 +1058,36 @@ public sealed class AudioClipEditorView : UserControlreturn best;}+ // Whether a press at p would grab an edit handle in the current mode (mirrors the+ // hit tests in OnPointerPressed, without acting on them).+ private bool OverEditHandle(Point p, double w, double h)+ {+ if (_adsrMode) return ClipAdsrKit.Hit(p, AdsrFrameNow(w, h), _adsr) != AdsrHandle.None;+ if (!_envMode)+ foreach (var b in _bpmHot)+ if (b.rect.Contains(p)) return true;+ if (_envMode) return HitEnv(p.X, p.Y, w, h) >= 0 || HitEnvSegment(p.X, p.Y, w, h) is not null;+ if (_srcMode)+ return Math.Abs(p.X - SrcToX(_srcOff, w)) <= HandlePx || Math.Abs(p.X - SrcToX(_srcOff + _srcLen, w)) <= HandlePx;+ if (_trimMode && (Math.Abs(p.X - BeatToX(_trimStart, w)) <= HandlePx || Math.Abs(p.X - BeatToX(_trimEnd, w)) <= HandlePx))+ return true;+ if (_mk.Count < 2) return false;+ int m = HitMarker(p.X, w);+ return m > 0 && m < _mk.Count - 1;+ }+protected override void OnPointerPressed(PointerPressedEventArgs e){double W = Bounds.Width, H = Bounds.Height;_free = (e.KeyModifiers & KeyModifiers.Alt) != 0;- // The ruler, and the playhead line wherever it runs, move the transport (#278) —- // ahead of every other gesture, but only inside the ruler / the line's grab zone.+ // The ruler, and the playhead line wherever it runs, move the transport (#278).+ // The line yields to an edit handle under the pointer (a warp marker, a bracket,+ // an ADSR or envelope point), so a stopped playhead never hides one.var pt = e.GetCurrentPoint(this);if (Seek is not null && pt.Properties.IsLeftButtonPressed && e.ClickCount == 1- && (pt.Position.Y < RulerH || OnPlayheadLine(pt.Position.X, W)))+ && (pt.Position.Y < RulerH+ || (OnPlayheadLine(pt.Position.X, W) && !OverEditHandle(pt.Position, W, H)))){_seekDrag = true;_lastSeek = double.NaN;diff --git a/src/native/nota.engine/src/devices/effects/Chorus.cpp b/src/native/nota.engine/src/devices/effects/Chorus.cppindex ee503d82..3557d596 100644--- a/src/native/nota.engine/src/devices/effects/Chorus.cpp+++ b/src/native/nota.engine/src/devices/effects/Chorus.cpp@@ -480,7 +480,7 @@ double Chorus::warm(double& z, double x) const {return z + warmS_ * (std::tanh(k * z) / k - z);}-float Chorus::readLine(const float* line, double d) const {+inline float Chorus::readLine(const float* line, double d) const {const double r = (double)w_ - d;const double fl = std::floor(r);const float t = (float)(r - fl);diff --git a/src/native/nota.engine/src/devices/effects/Chorus.h b/src/native/nota.engine/src/devices/effects/Chorus.hindex c00cb5cf..1ea4f4a4 100644--- a/src/native/nota.engine/src/devices/effects/Chorus.h+++ b/src/native/nota.engine/src/devices/effects/Chorus.h@@ -198,7 +198,7 @@ class Chorus : public Device {}// 4-point Hermite read `d` samples behind the write head (d ≥ 2, so every tap is written).- float readLine(const float* line, double d) const;+ inline float readLine(const float* line, double d) const;void clearLines();void resetMeters() { inPkM_ = outPkLM_ = outPkRM_ = 0.0f; }diff --git a/src/native/nota.engine/src/devices/effects/Compressor.cpp b/src/native/nota.engine/src/devices/effects/Compressor.cppindex 38a40b39..245d22a3 100644--- a/src/native/nota.engine/src/devices/effects/Compressor.cpp+++ b/src/native/nota.engine/src/devices/effects/Compressor.cpp@@ -212,7 +212,7 @@ void Compressor::process(float* buf, int32_t frames) {keyPk = std::max(keyPk, std::max(std::fabs(key[0]), std::fabs(key[1])));const float gainL = (1.0f - mix) + mix * fast_math::dbToLin(makeupDb + autoMk - gr[0]);- const float gainR = (1.0f - mix) + mix * fast_math::dbToLin(makeupDb + autoMk - gr[1]);+ const float gainR = linked ? gainL : (1.0f - mix) + mix * fast_math::dbToLin(makeupDb + autoMk - gr[1]);// Look-ahead: apply the current gain to the delayed audio.laBuf_[laW_ * 2] = l;diff --git a/src/native/nota.engine/src/devices/effects/Crush.cpp b/src/native/nota.engine/src/devices/effects/Crush.cppindex 3621a67e..a2f3714c 100644--- a/src/native/nota.engine/src/devices/effects/Crush.cpp+++ b/src/native/nota.engine/src/devices/effects/Crush.cpp@@ -204,7 +204,9 @@ void Crush::process(float* buf, int32_t frames) {dcY_[1] = yR;cR = yR;}- feedPk = std::max(feedPk, std::max(std::fabs(cL), std::fabs(cR)));+ // Only a silent-input block can count towards sleep, so only it measures the+ // crushed path (a loud block resets the count anyway). Loop-invariant: unswitched.+ if (inSilent) feedPk = std::max(feedPk, std::max(std::fabs(cL), std::fabs(cR)));// Analysis ring: the driven input and the crushed path (before the mix).ringIn_[w & ringMask_] = drvMono;@@ -429,7 +431,7 @@ std::string Crush::deviceText(int32_t id) const {return {};}-float Crush::shape(int mode, float x) {+inline float Crush::shape(int mode, float x) {switch (mode) {case 1: return fast_math::tanhPrecise(x * 1.5f) / 0.905f; // Analog: soft clipcase 2: return wavefold(x * 2.5f, 0.7f); // Folddiff --git a/src/native/nota.engine/src/devices/effects/Crush.h b/src/native/nota.engine/src/devices/effects/Crush.hindex 22b3c74b..83b237bf 100644--- a/src/native/nota.engine/src/devices/effects/Crush.h+++ b/src/native/nota.engine/src/devices/effects/Crush.h@@ -138,7 +138,7 @@ class Crush : public Device {static float db(float lin) { return lin > 1e-6f ? 20.0f * std::log10(lin) : -120.0f; }static float dbMs(double ms) { return ms > 1e-12 ? (float)(10.0 * std::log10(ms)) : -120.0f; }- static float shape(int mode, float x);+ static inline float shape(int mode, float x);// A triangle fold: straight through ±threshold, then reflected back and forth for as far as// the input goes (a 4·threshold period), normalised to ±1. More drive, more folds.static float wavefold(float x, float threshold);diff --git a/src/native/nota.engine/src/devices/effects/Flanger.cpp b/src/native/nota.engine/src/devices/effects/Flanger.cppindex 0e310090..ecb5d9dd 100644--- a/src/native/nota.engine/src/devices/effects/Flanger.cpp+++ b/src/native/nota.engine/src/devices/effects/Flanger.cpp@@ -112,8 +112,9 @@ void Flanger::process(float* buf, int32_t frames) {return;}- float inPk = 0.0f, outPkL = 0.0f, outPkR = 0.0f, pushPk = 0.0f;+ float inPk = 0.0f, outPkL = 0.0f, outPkR = 0.0f;double tauL = 0.0, tauR = 0.0;+ const int w0 = w_;for (int32_t i = 0; i < frames; ++i) {if (locked) {const double beat = beatStart_ + (double)i / spb_;@@ -143,7 +144,6 @@ void Flanger::process(float* buf, int32_t frames) {const float pushR = sanitize(xR + (float)fbS_ * yR);lineL_[w_] = pushL;lineR_[w_] = pushR;- pushPk = std::max(pushPk, std::max(std::fabs(pushL), std::fabs(pushR)));w_ = (w_ + 1) & kMask;const double norm = 1.0 / std::max(dryS_ + std::fabs(wetS_), 1e-3);@@ -166,7 +166,16 @@ void Flanger::process(float* buf, int32_t frames) {// Loop-feed peak (decays slowly so a ringing comb blocks accrual); sleep// additionally waits out the sweep's flight time so an in-flight echo is never- // cut: output silence alone proves nothing while the line is full.+ // cut: output silence alone proves nothing while the line is full. The block's+ // writes are the last `frames` slots before w_, read back in one pass (at most two+ // runs around the wrap) rather than tracked per sample.+ float pushPk = 0.0f;+ for (int at = w0, left = std::min<int32_t>(frames, kBuf); left > 0;) {+ const int run = std::min(left, kBuf - at);+ pushPk = std::max({pushPk, simd_audio::peakAbs(lineL_ + at, run), simd_audio::peakAbs(lineR_ + at, run)});+ left -= run;+ at = (at + run) & kMask;+ }feedPk_ = pushPk > feedPk_ ? pushPk : feedPk_ * 0.90f;const double flight = 0.008 * (1.0 + kDepthScale) * sr_; // 8 ms · 1.92, the longest modulated lineif (inSilent && outPkL <= 1.0e-5f && outPkR <= 1.0e-5f && feedPk_ <= 1.0e-5f) quietSamples_ += (uint64_t)frames;@@ -379,7 +388,7 @@ double Flanger::lfo(int wave, double p) {return 2.0 * (g - std::floor(g)) - 1.0;}-float Flanger::readLine(const float* line, double d) const {+inline float Flanger::readLine(const float* line, double d) const {const double r = (double)w_ - d;const double fl = std::floor(r);const float t = (float)(r - fl);diff --git a/src/native/nota.engine/src/devices/effects/Flanger.h b/src/native/nota.engine/src/devices/effects/Flanger.hindex b1204901..ed86f3db 100644--- a/src/native/nota.engine/src/devices/effects/Flanger.h+++ b/src/native/nota.engine/src/devices/effects/Flanger.h@@ -174,7 +174,7 @@ class Flanger : public Device {static double lfo(int wave, double p);// 4-point Hermite read `d` samples behind the write head (d ≥ 2, so every tap is written).- float readLine(const float* line, double d) const;+ inline float readLine(const float* line, double d) const;void clearLine();void resetMeters() { inPkM_ = outPkLM_ = outPkRM_ = 0.0f; }diff --git a/src/native/nota.engine/src/devices/effects/Phaser.cpp b/src/native/nota.engine/src/devices/effects/Phaser.cppindex fbf4fd3f..bffe1eb9 100644--- a/src/native/nota.engine/src/devices/effects/Phaser.cpp+++ b/src/native/nota.engine/src/devices/effects/Phaser.cpp@@ -154,7 +154,9 @@ void Phaser::process(float* buf, int32_t frames) {inPk = std::max(inPk, std::max(std::fabs(xL), std::fabs(xR)));const double yL = chain(sL_, aL_, xL, fbS_);const double yR = chain(sR_, aR_, xR, fbS_);- feedPk = std::max(feedPk, (float)std::max(std::fabs(yL), std::fabs(yR)));+ // Only a silent-input block can count towards sleep, so only it measures the+ // chain (a loud block resets the count anyway). Loop-invariant: unswitched.+ if (inSilent) feedPk = std::max(feedPk, (float)std::max(std::fabs(yL), std::fabs(yR)));const double wg = wetS_ * stGain_;const double norm = 1.0 / std::max(dryS_ + std::fabs(wetS_), 1e-3);@@ -398,7 +400,7 @@ double Phaser::coef(double fc) const {return (t - 1.0) / (t + 1.0);}-double Phaser::chain(double* s, double a, double x, double fb) const {+inline double Phaser::chain(double* s, double a, double x, double fb) const {const int n = stages_;double g = 1.0, S = 0.0;for (int k = 0; k < n; ++k) {diff --git a/src/native/nota.engine/src/devices/effects/Phaser.h b/src/native/nota.engine/src/devices/effects/Phaser.hindex 140015aa..7d761ccd 100644--- a/src/native/nota.engine/src/devices/effects/Phaser.h+++ b/src/native/nota.engine/src/devices/effects/Phaser.h@@ -171,7 +171,7 @@ class Phaser : public Device {// One channel through the chain with its feedback loop solved delay-free: each stage is// y = a·x + s (s' = x − a·y), so the chain is y = g·w + S and w = x + fb·y.- double chain(double* s, double a, double x, double fb) const;+ inline double chain(double* s, double a, double x, double fb) const;float get(int i) const { return p_[i].load(std::memory_order_relaxed); }static double expMap(float v, double lo, double hi) {diff --git a/src/native/nota.engine/src/devices/effects/Reverb.cpp b/src/native/nota.engine/src/devices/effects/Reverb.cppindex 385656ca..5585929d 100644--- a/src/native/nota.engine/src/devices/effects/Reverb.cpp+++ b/src/native/nota.engine/src/devices/effects/Reverb.cpp@@ -360,7 +360,7 @@ std::string Reverb::deviceText(int32_t id) const {return std::string(b);}-float Reverb::readPre(const std::vector<float>& b, double delay) const {+inline float Reverb::readPre(const std::vector<float>& b, double delay) const {const int n = static_cast<int>(b.size());double rp = preW_ - std::clamp(delay, 0.0, static_cast<double>(n) - 2.0);if (rp < 0) rp += n;diff --git a/src/native/nota.engine/src/devices/effects/Reverb.h b/src/native/nota.engine/src/devices/effects/Reverb.hindex acd2f94c..e0116f7d 100644--- a/src/native/nota.engine/src/devices/effects/Reverb.h+++ b/src/native/nota.engine/src/devices/effects/Reverb.h@@ -148,7 +148,7 @@ class Reverb : public Device {}// Fractional read `delay` samples behind the pre-delay write head (0 = the sample just written).- float readPre(const std::vector<float>& b, double delay) const;+ inline float readPre(const std::vector<float>& b, double delay) const;void wipe();diff --git a/src/native/nota.engine/src/devices/effects/Strata.cpp b/src/native/nota.engine/src/devices/effects/Strata.cppindex ae578a89..c8740647 100644--- a/src/native/nota.engine/src/devices/effects/Strata.cpp+++ b/src/native/nota.engine/src/devices/effects/Strata.cpp@@ -136,7 +136,6 @@ void Strata::process(float* buf, int32_t frames) {}}- float outPk = 0.0f;for (int32_t i = 0; i < frames; ++i) {const float inL = buf[i * 2] * inGain, inR = buf[i * 2 + 1] * inGain;const bool recording = (mode == M_Rec || mode == M_Over) && recL >= 0;@@ -199,7 +198,6 @@ void Strata::process(float* buf, int32_t frames) {buf[i * 2] = inL + wetL;buf[i * 2 + 1] = inR + wetR;- outPk = std::max(outPk, std::max(std::fabs(buf[i * 2]), std::fabs(buf[i * 2 + 1])));// Advance the loop / recording clock.if (mode == M_Rec && loopLen_.load() <= 0) {@@ -232,9 +230,10 @@ void Strata::process(float* buf, int32_t frames) {// Auto-sleep: silent in / silent out settles only once no layer can still sound// (stopped / empty / no layers) and nothing is being recorded. A sounding loop- // (playing layers) and any queued command keep the hangover at zero.+ // (playing layers) and any queued command keep the hangover at zero. The output+ // is checked last, in one SIMD pass, and only when everything else is quiet.const bool still = (mode == M_Stop || mode == M_Empty || layerCount_.load() == 0);- if (inSilent && outPk <= 1.0e-5f && still && pending_.load(std::memory_order_acquire) < 0)+ if (inSilent && still && pending_.load(std::memory_order_acquire) < 0 && simd_audio::isSilent(buf, frames * 2))quietSamples_ += (uint64_t)frames;else {quietSamples_ = 0;diff --git a/src/native/nota.engine/src/devices/effects/Utility.cpp b/src/native/nota.engine/src/devices/effects/Utility.cppindex 3dad1d5d..f43d56c5 100644--- a/src/native/nota.engine/src/devices/effects/Utility.cpp+++ b/src/native/nota.engine/src/devices/effects/Utility.cpp@@ -578,7 +578,7 @@ float Utility::catmull(float y0, float y1, float y2, float y3, float t) {return a + t * (b + t * ((3 * (c - a) - 2 * b - d) + t * (2 * (a - c) + b + d)));}-float Utility::truePeak(Tp& s, float x) {+inline float Utility::truePeak(Tp& s, float x) {float pk = std::fabs(s.y2);for (int k = 1; k < 4; ++k) pk = std::max(pk, std::fabs(catmull(s.y0, s.y1, s.y2, x, k * 0.25f)));s.y0 = s.y1;diff --git a/src/native/nota.engine/src/devices/effects/Utility.h b/src/native/nota.engine/src/devices/effects/Utility.hindex a96d91b9..25baa30f 100644--- a/src/native/nota.engine/src/devices/effects/Utility.h+++ b/src/native/nota.engine/src/devices/effects/Utility.h@@ -247,7 +247,7 @@ class Utility : public Device {float y0 = 0, y1 = 0, y2 = 0;};static float catmull(float y0, float y1, float y2, float y3, float t);- static float truePeak(Tp& s, float x);+ static inline float truePeak(Tp& s, float x);// Limiter: the inter-sample peak between the previous sample and this one, with the next// sample extrapolated — no look-ahead, so no latency.static float isp(Tp& s, float x);diff --git a/src/native/nota.engine/src/devices/instruments/Consort.cpp b/src/native/nota.engine/src/devices/instruments/Consort.cppindex 4c827aa3..71c69dd5 100644--- a/src/native/nota.engine/src/devices/instruments/Consort.cpp+++ b/src/native/nota.engine/src/devices/instruments/Consort.cpp@@ -1316,7 +1316,7 @@ float Consort::readGain(int ch, float delay) const { // the compander gain storereturn y1 + (y2 - y1) * (rp - fl);}-float Consort::readLine(int ch, float delay) const {+inline float Consort::readLine(int ch, float delay) const {const float* b = dlyBuf_.get() + ch * dlyN_;const float rp = static_cast<float>(dlyW_) - delay;const float fl = std::floor(rp);diff --git a/src/native/nota.engine/src/devices/instruments/Consort.h b/src/native/nota.engine/src/devices/instruments/Consort.hindex d4347a9a..2fe8dd7a 100644--- a/src/native/nota.engine/src/devices/instruments/Consort.h+++ b/src/native/nota.engine/src/devices/instruments/Consort.h@@ -726,7 +726,7 @@ class Consort final : public Instrument {void setupDelayRate();void clearDelay();float readGain(int ch, float delay) const;- float readLine(int ch, float delay) const;+ inline float readLine(int ch, float delay) const;void processDelay(int n, const float* P);void publishTelemetry();diff --git a/src/native/nota.engine/src/devices/instruments/Keys.cpp b/src/native/nota.engine/src/devices/instruments/Keys.cppindex 32d770b8..01993e4f 100644--- a/src/native/nota.engine/src/devices/instruments/Keys.cpp+++ b/src/native/nota.engine/src/devices/instruments/Keys.cpp@@ -441,7 +441,12 @@ void Keys::retune(Voice& v, float bend) {}void Keys::renderVoice(Voice& v, float* mono, int n, int /*model*/, float sym, float dist, float pnorm, float noiseLin,- float relLin, const float exAdd[kExprDims], float exprCoef) {+ float relLin, const float exAddIn[kExprDims], float exprCoef) {+ // A local copy: through the pointer, every store to mono[] could alias the offsets,+ // so the expression tick would reload them each sample.+ float exAdd[kExprDims];+ std::copy(exAddIn, exAddIn + kExprDims, exAdd);+ const keys::PickupShape pickup = keys::pickupShape(dist, v.model);const float killStep = 1.0f / static_cast<float>(killLen());const float invNorm = 1.0f / pnorm;const float relLp = 1.0f - std::exp(-2.0f * keys::kPi * 700.0f / static_cast<float>(sr_));@@ -472,7 +477,7 @@ void Keys::renderVoice(Voice& v, float* mono, int n, int /*model*/, float sym, f// Pickup.const float xd = std::clamp(x * v.drive * (1.0f + 0.6f * v.ex.pressure()), -1.6f, 1.6f);const float s = std::clamp(sym + v.symOff + 0.4f * v.ex.slide(), -1.5f, 1.5f);- float o = keys::pickupRaw(xd, s, dist, v.model) * invNorm * v.level * (1.0f + 0.3f * v.ex.pressure());+ float o = keys::pickupRaw(xd, s, pickup) * invNorm * v.level * (1.0f + 0.3f * v.ex.pressure());// Hammer + damper noise.if (v.hnEnv > 1e-4f && noiseLin > 0.0f) {const float nz = rnd(v);diff --git a/src/native/nota.engine/src/devices/instruments/Keys.h b/src/native/nota.engine/src/devices/instruments/Keys.hindex 08a5879b..8df63eed 100644--- a/src/native/nota.engine/src/devices/instruments/Keys.h+++ b/src/native/nota.engine/src/devices/instruments/Keys.h@@ -59,15 +59,26 @@ constexpr float kPi = 3.14159265358979f;// The PICKUP transfer curve, shared with the editor's graph (KeysModel.cs mirrors it):// x = tine displacement (−1..1 at full scale), sym −1..1, dist 0..1, model 0..3.-inline float pickupRaw(float x, float sym, float dist, int model) {+// The terms that depend only on dist and model, worked out once per block rather than+// per sample (same operations in the same order, so the curve is unchanged).+struct PickupShape {+ float a, k, twoMinusDist;+ int model;+};+inline PickupShape pickupShape(float dist, int model) {const float a = 0.3f + (1.0f - dist) * 3.2f;- if (model == 2) { // Reed — electrostatic: odd-heavy, a little symmetry- const float k = (1.0f - dist) * 0.8f;- return x / (1.0f + a * 0.6f * std::fabs(x)) * (1.0f + k * x * x) / (1.0f + k) +- sym * 0.35f * (2.0f - dist) * x * x;+ if (model == 2) return {a * 0.6f, (1.0f - dist) * 0.8f, 2.0f - dist, model}; // Reed+ return {model == 3 ? a * 0.5f : a, 0.0f, 2.0f - dist, model}; // Clav: gentler+}+inline float pickupRaw(float x, float sym, const PickupShape& p) {+ if (p.model == 2) { // Reed — electrostatic: odd-heavy, a little symmetry+ return x / (1.0f + p.a * std::fabs(x)) * (1.0f + p.k * x * x) / (1.0f + p.k) ++ sym * 0.35f * p.twoMinusDist * x * x;}- const float aa = model == 3 ? a * 0.5f : a; // Clav — a gentler magnetic pickup- return x / (1.0f + aa * std::fabs(x)) + sym * 0.55f * (2.0f - dist) * x * x;+ return x / (1.0f + p.a * std::fabs(x)) + sym * 0.55f * p.twoMinusDist * x * x; // magnetic+}+inline float pickupRaw(float x, float sym, float dist, int model) {+ return pickupRaw(x, sym, pickupShape(dist, model));}// The curve's peak magnitude on −1..1 (the editor scales its graph by the same number).inline float pickupNorm(float sym, float dist, int model) {diff --git a/src/native/nota.engine/src/devices/instruments/VoltSynth.cpp b/src/native/nota.engine/src/devices/instruments/VoltSynth.cppindex ad93336a..9bf41bd6 100644--- a/src/native/nota.engine/src/devices/instruments/VoltSynth.cpp+++ b/src/native/nota.engine/src/devices/instruments/VoltSynth.cpp@@ -616,7 +616,7 @@ void VoltSynth::startVoice(Voice& v, int32_t pitch, float velocity) {v.modCount = 0;}-void VoltSynth::advanceEnv(float& env, Stage& st, float atk, float dec, float sus, float rel) {+NOTA_ALWAYS_INLINE void VoltSynth::advanceEnv(float& env, Stage& st, float atk, float dec, float sus, float rel) {switch (st) {case Stage::Attack:env += atk;@@ -651,7 +651,7 @@ void VoltSynth::setSvf(double& a1, double& a2, double& a3, double fc, double k)a3 = g * a2;}-double VoltSynth::svf(double* st, double a1, double a2, double a3, double k, double in, int type) {+NOTA_ALWAYS_INLINE double VoltSynth::svf(double* st, double a1, double a2, double a3, double k, double in, int type) {const double v3 = in - st[1];const double v1 = a1 * st[0] + a2 * v3;const double v2 = st[1] + a2 * st[0] + a3 * v3;@@ -689,7 +689,7 @@ float VoltSynth::fadeInc(Param p) const {return (float)(1.0 / (expMap(t, 0.01, 5.0) * sampleRate_));}-double VoltSynth::osc(int wave, double shape, double pw, double ph, double dt) {+NOTA_ALWAYS_INLINE double VoltSynth::osc(int wave, double shape, double pw, double ph, double dt) {if (shape <= 0.0) return oscBlep(wave, ph, dt, pw);static constexpr int kPos[4] = {2, 3, 1, 0}; // chip → morph positionstatic constexpr int kWave[4] = {3, 2, 0, 1}; // morph position → chipdiff --git a/src/native/nota.engine/src/devices/instruments/VoltSynth.h b/src/native/nota.engine/src/devices/instruments/VoltSynth.hindex 2b02bb3c..8dc86d89 100644--- a/src/native/nota.engine/src/devices/instruments/VoltSynth.h+++ b/src/native/nota.engine/src/devices/instruments/VoltSynth.h@@ -290,11 +290,11 @@ class VoltSynth final : public Instrument {}static double wrap(double x) { return x >= 1.0 ? x - 1.0 : x; }- static void advanceEnv(float& env, Stage& st, float atk, float dec, float sus, float rel);+ static inline void advanceEnv(float& env, Stage& st, float atk, float dec, float sus, float rel);void setSvf(double& a1, double& a2, double& a3, double fc, double k) const;// TPT SVF (Cytomic). type: 0 LP, 1 HP, 2 BP, 3 Notch. state[0]=ic1, state[1]=ic2.- static double svf(double* st, double a1, double a2, double a3, double k, double in, int type);+ static inline double svf(double* st, double a1, double a2, double a3, double k, double in, int type);// LFO shape: 0 sin, 1 tri, 2 sqr, 3 sample & hold. Returns -1..+1.static double lfoValue(int shape, double ph, float shHold);@@ -304,7 +304,7 @@ class VoltSynth final : public Instrument {// Wave chip (0 saw, 1 square, 2 tri, 3 sine) with Shape blending it toward the next wave// in sine → triangle → saw → square order; Shape 0 is the chip itself.- static double osc(int wave, double shape, double pw, double ph, double dt);+ static inline double osc(int wave, double shape, double pw, double ph, double dt);static double oscBlep(int wave, double ph, double dt, double pw);static double polyBlep(double t, double dt);float noise();diff --git a/src/native/nota.engine/src/dsp/core/Parameter.cpp b/src/native/nota.engine/src/dsp/core/Parameter.cppindex d4e31068..6386bd30 100644--- a/src/native/nota.engine/src/dsp/core/Parameter.cpp+++ b/src/native/nota.engine/src/dsp/core/Parameter.cpp@@ -63,11 +63,6 @@ void OnePoleSmoother::setSampleRate(double sr, double timeMs) NOTA_RT_SAFE {if (!(coeff_ >= 0.0f && coeff_ <= 1.0f)) coeff_ = 0.01f;}-float OnePoleSmoother::tick() NOTA_RT_SAFE {- value_ += coeff_ * (target_ - value_);- return value_;-}-void OnePoleSmoother::processBlock(float* dst, int32_t n) NOTA_RT_SAFE {if (dst == nullptr || n <= 0) return;for (int32_t i = 0; i < n; ++i) {diff --git a/src/native/nota.engine/src/dsp/core/Parameter.h b/src/native/nota.engine/src/dsp/core/Parameter.hindex 1401f1c7..f0d52093 100644--- a/src/native/nota.engine/src/dsp/core/Parameter.h+++ b/src/native/nota.engine/src/dsp/core/Parameter.h@@ -10,6 +10,7 @@#include <cstdint>#include "dsp/core/RtAttributes.h"+#include "dsp/math/FastMath.h"namespace nota {namespace dsp {@@ -55,5 +56,12 @@ class ParameterChangeTracker {bool initialized_ = false;};+// Per-sample hot path: inline, so callers in other TUs inline it (no LTO).++inline float OnePoleSmoother::tick() NOTA_RT_SAFE {+ value_ += coeff_ * (target_ - value_);+ return value_;+}+} // namespace dsp} // namespace notadiff --git a/src/native/nota.engine/src/dsp/math/SimdAudio.h b/src/native/nota.engine/src/dsp/math/SimdAudio.hindex 9a2227ad..03ff57e8 100644--- a/src/native/nota.engine/src/dsp/math/SimdAudio.h+++ b/src/native/nota.engine/src/dsp/math/SimdAudio.h@@ -69,6 +69,36 @@ inline bool isSilent(const float* src, int32_t count, float threshold = 1.0e-5f)return true;}+// Peak absolute amplitude of a flat or interleaved float buffer (0 when empty). For a+// peak a device needs only once per block: one pass after the loop is cheaper than a+// running max inside a per-sample loop.+inline float peakAbs(const float* src, int32_t count) noexcept {+ if (!src || count <= 0) return 0.0f;+ int32_t i = 0;+ float peak = 0.0f;+#if defined(NOTA_SIMD_NEON)+ float32x4_t m0 = vdupq_n_f32(0.0f), m1 = vdupq_n_f32(0.0f);+ for (; i + 8 <= count; i += 8) {+ m0 = vmaxq_f32(m0, vabsq_f32(vld1q_f32(src + i)));+ m1 = vmaxq_f32(m1, vabsq_f32(vld1q_f32(src + i + 4)));+ }+ peak = vmaxvq_f32(vmaxq_f32(m0, m1));+#elif defined(NOTA_SIMD_SSE)+ static const __m128 absMask = _mm_castsi128_ps(_mm_set1_epi32(0x7fffffff));+ __m128 m0 = _mm_setzero_ps(), m1 = _mm_setzero_ps();+ for (; i + 8 <= count; i += 8) {+ m0 = _mm_max_ps(m0, _mm_and_ps(_mm_loadu_ps(src + i), absMask));+ m1 = _mm_max_ps(m1, _mm_and_ps(_mm_loadu_ps(src + i + 4), absMask));+ }+ __m128 m = _mm_max_ps(m0, m1);+ m = _mm_max_ps(m, _mm_movehl_ps(m, m));+ m = _mm_max_ss(m, _mm_shuffle_ps(m, m, 1));+ peak = _mm_cvtss_f32(m);+#endif+ for (; i < count; ++i) peak = std::max(peak, std::fabs(src[i]));+ return peak;+}+// Single-pass peak absolute amplitude finder and sum-of-squares accumulator for float audio buffers.inline void peakAndSumSquares(const float* src, int32_t count, float& outPeak, double& outSumSquares) noexcept {if (!src || count <= 0) {diff --git a/src/native/nota.engine/src/dsp/primitives/DelayLine.cpp b/src/native/nota.engine/src/dsp/primitives/DelayLine.cppindex 8f0fcdf4..92f4d06b 100644--- a/src/native/nota.engine/src/dsp/primitives/DelayLine.cpp+++ b/src/native/nota.engine/src/dsp/primitives/DelayLine.cpp@@ -26,61 +26,5 @@ void DelayLine::reset() noexcept {apPrev_ = 0.0f;}-void DelayLine::push(float x) NOTA_RT_SAFE {- if (size_ <= 0) return;- buf_[pos_] = x;- pos_ = (pos_ + 1) & mask_;-}--const float* DelayLine::at(int32_t delaySamples) const NOTA_RT_SAFE {- // Caller guarantees size_ > 0; guard anyway for standalone use.- if (size_ <= 0) return nullptr;- if (delaySamples < 0) delaySamples = 0;- if (delaySamples >= size_) delaySamples = size_ - 1;- return &buf_[(pos_ - 1 - delaySamples) & mask_];-}--float DelayLine::readSample(int32_t delaySamples) const NOTA_RT_SAFE {- const float* p = at(delaySamples);- return p != nullptr ? *p : 0.0f;-}--float DelayLine::readLinear(float delaySamples) const NOTA_RT_SAFE {- if (size_ <= 0) return 0.0f;- if (delaySamples < 0.0f) delaySamples = 0.0f;- const float maxD = static_cast<float>(size_ - 1);- if (delaySamples > maxD) delaySamples = maxD;- const int32_t d0 = static_cast<int32_t>(delaySamples);- const float frac = delaySamples - static_cast<float>(d0);- const float a = readSample(d0);- const float b = readSample(d0 + 1);- return a + frac * (b - a);-}--float DelayLine::readHermite4p(float delaySamples) const NOTA_RT_SAFE {- if (size_ <= 0) return 0.0f;- if (delaySamples < 1.0f) delaySamples = 1.0f;- const float maxD = static_cast<float>(size_ - 2);- if (delaySamples > maxD) delaySamples = maxD;- const int32_t d = static_cast<int32_t>(delaySamples);- const float t = delaySamples - static_cast<float>(d);- // 4-point Catmull-Rom Hermite: y[-1], y[0], y[1], y[2] around the tap.- // Exact at t=0 (y0) and t=1 (y1); C1-continuous across taps.- const float ym1 = readSample(d - 1);- const float y0 = readSample(d);- const float y1 = readSample(d + 1);- const float y2 = readSample(d + 2);- const float t2 = t * t, t3 = t2 * t;- return 0.5f * ((2.0f * y0) + (-ym1 + y1) * t + (2.0f * ym1 - 5.0f * y0 + 4.0f * y1 - y2) * t2 +- (-ym1 + 3.0f * y0 - 3.0f * y1 + y2) * t3);-}--float DelayLine::processAllpass(float x, float delaySamples, float g) NOTA_RT_SAFE {- const float delayed = readLinear(delaySamples);- const float y = -g * x + delayed + g * apPrev_;- apPrev_ = y;- return y;-}-} // namespace dsp} // namespace notadiff --git a/src/native/nota.engine/src/dsp/primitives/DelayLine.h b/src/native/nota.engine/src/dsp/primitives/DelayLine.hindex 7eb64c7b..01bea95d 100644--- a/src/native/nota.engine/src/dsp/primitives/DelayLine.h+++ b/src/native/nota.engine/src/dsp/primitives/DelayLine.h@@ -10,6 +10,7 @@#pragma once+#include <algorithm>#include <cstdint>#include <vector>@@ -50,5 +51,63 @@ class DelayLine {const float* at(int32_t delaySamples) const NOTA_RT_SAFE;};+// Per-sample hot path: inline, so callers in other TUs inline it (no LTO).++inline void DelayLine::push(float x) NOTA_RT_SAFE {+ if (size_ <= 0) return;+ buf_[pos_] = x;+ pos_ = (pos_ + 1) & mask_;+}++inline const float* DelayLine::at(int32_t delaySamples) const NOTA_RT_SAFE {+ // Caller guarantees size_ > 0; guard anyway for standalone use.+ if (size_ <= 0) return nullptr;+ if (delaySamples < 0) delaySamples = 0;+ if (delaySamples >= size_) delaySamples = size_ - 1;+ return &buf_[(pos_ - 1 - delaySamples) & mask_];+}++inline float DelayLine::readSample(int32_t delaySamples) const NOTA_RT_SAFE {+ const float* p = at(delaySamples);+ return p != nullptr ? *p : 0.0f;+}++inline float DelayLine::readLinear(float delaySamples) const NOTA_RT_SAFE {+ if (size_ <= 0) return 0.0f;+ if (delaySamples < 0.0f) delaySamples = 0.0f;+ const float maxD = static_cast<float>(size_ - 1);+ if (delaySamples > maxD) delaySamples = maxD;+ const int32_t d0 = static_cast<int32_t>(delaySamples);+ const float frac = delaySamples - static_cast<float>(d0);+ const float a = readSample(d0);+ const float b = readSample(d0 + 1);+ return a + frac * (b - a);+}++inline float DelayLine::readHermite4p(float delaySamples) const NOTA_RT_SAFE {+ if (size_ <= 0) return 0.0f;+ if (delaySamples < 1.0f) delaySamples = 1.0f;+ const float maxD = static_cast<float>(size_ - 2);+ if (delaySamples > maxD) delaySamples = maxD;+ const int32_t d = static_cast<int32_t>(delaySamples);+ const float t = delaySamples - static_cast<float>(d);+ // 4-point Catmull-Rom Hermite: y[-1], y[0], y[1], y[2] around the tap.+ // Exact at t=0 (y0) and t=1 (y1); C1-continuous across taps.+ const float ym1 = readSample(d - 1);+ const float y0 = readSample(d);+ const float y1 = readSample(d + 1);+ const float y2 = readSample(d + 2);+ const float t2 = t * t, t3 = t2 * t;+ return 0.5f * ((2.0f * y0) + (-ym1 + y1) * t + (2.0f * ym1 - 5.0f * y0 + 4.0f * y1 - y2) * t2 ++ (-ym1 + 3.0f * y0 - 3.0f * y1 + y2) * t3);+}++inline float DelayLine::processAllpass(float x, float delaySamples, float g) NOTA_RT_SAFE {+ const float delayed = readLinear(delaySamples);+ const float y = -g * x + delayed + g * apPrev_;+ apPrev_ = y;+ return y;+}+} // namespace dsp} // namespace notadiff --git a/src/native/nota.engine/src/dsp/primitives/Envelope.cpp b/src/native/nota.engine/src/dsp/primitives/Envelope.cppindex f125837d..0b0fd071 100644--- a/src/native/nota.engine/src/dsp/primitives/Envelope.cpp+++ b/src/native/nota.engine/src/dsp/primitives/Envelope.cpp@@ -41,35 +41,6 @@ void AdsrEnvelope::reset() noexcept {stage_ = Stage::Idle;}-float AdsrEnvelope::tick() NOTA_RT_SAFE {- switch (stage_) {- case Stage::Idle: value_ = 0.0f; break;- case Stage::Attack:- value_ += attackInc_ * (1.0f - value_);- if (value_ >= 0.999f) {- value_ = 1.0f;- stage_ = Stage::Decay;- }- break;- case Stage::Decay:- value_ = sustain_ + decayCoef_ * (value_ - sustain_);- if (std::fabs(value_ - sustain_) < 0.0005f) {- value_ = sustain_;- stage_ = Stage::Sustain;- }- break;- case Stage::Sustain: value_ = sustain_; break;- case Stage::Release:- value_ *= releaseCoef_;- if (value_ < 0.0005f) {- value_ = 0.0f;- stage_ = Stage::Idle;- }- break;- }- return value_;-}-void ArEnvelope::setSampleRate(double sr) noexcept {sr_ = sr > 0.0 ? sr : 44100.0;}@@ -90,25 +61,6 @@ void ArEnvelope::reset() noexcept {stage_ = 0;}-float ArEnvelope::tick() NOTA_RT_SAFE {- if (stage_ == 1) {- value_ += attackInc_ * (1.0f - value_);- if (value_ >= 0.999f) {- value_ = 1.0f;- stage_ = 2;- }- } else if (stage_ == 2) {- value_ *= releaseCoef_;- if (value_ < 0.0005f) {- value_ = 0.0f;- stage_ = 0;- }- } else {- value_ = 0.0f;- }- return value_;-}-void EnvelopeFollower::setSampleRate(double sr) noexcept {sr_ = sr > 0.0 ? sr : 44100.0;}@@ -124,14 +76,6 @@ void EnvelopeFollower::reset(float v) noexcept {value_ = v;}-float EnvelopeFollower::process(float x) NOTA_RT_SAFE {- const float a = x < 0.0f ? -x : x;- if (a > value_) value_ += attackCoef_ * (a - value_);- else- value_ *= releaseCoef_;- return value_;-}-float EnvelopeFollower::levelDb() const NOTA_RT_SAFE {return fast_math::linToDb(value_);}diff --git a/src/native/nota.engine/src/dsp/primitives/Envelope.h b/src/native/nota.engine/src/dsp/primitives/Envelope.hindex db28373c..d10d4bd2 100644--- a/src/native/nota.engine/src/dsp/primitives/Envelope.h+++ b/src/native/nota.engine/src/dsp/primitives/Envelope.h@@ -8,7 +8,10 @@#pragma once+#include <cmath>+#include "dsp/core/RtAttributes.h"+#include "dsp/math/FastMath.h"namespace nota {namespace dsp {@@ -84,5 +87,63 @@ class EnvelopeFollower {float value_ = 0.0f;};+// Per-sample hot path: inline, so callers in other TUs inline it (no LTO).++inline float AdsrEnvelope::tick() NOTA_RT_SAFE {+ switch (stage_) {+ case Stage::Idle: value_ = 0.0f; break;+ case Stage::Attack:+ value_ += attackInc_ * (1.0f - value_);+ if (value_ >= 0.999f) {+ value_ = 1.0f;+ stage_ = Stage::Decay;+ }+ break;+ case Stage::Decay:+ value_ = sustain_ + decayCoef_ * (value_ - sustain_);+ if (std::fabs(value_ - sustain_) < 0.0005f) {+ value_ = sustain_;+ stage_ = Stage::Sustain;+ }+ break;+ case Stage::Sustain: value_ = sustain_; break;+ case Stage::Release:+ value_ *= releaseCoef_;+ if (value_ < 0.0005f) {+ value_ = 0.0f;+ stage_ = Stage::Idle;+ }+ break;+ }+ return value_;+}++inline float ArEnvelope::tick() NOTA_RT_SAFE {+ if (stage_ == 1) {+ value_ += attackInc_ * (1.0f - value_);+ if (value_ >= 0.999f) {+ value_ = 1.0f;+ stage_ = 2;+ }+ } else if (stage_ == 2) {+ value_ *= releaseCoef_;+ if (value_ < 0.0005f) {+ value_ = 0.0f;+ stage_ = 0;+ }+ } else {+ value_ = 0.0f;+ }+ return value_;+}++inline float EnvelopeFollower::process(float x) NOTA_RT_SAFE {+ const float a = x < 0.0f ? -x : x;+ if (a > value_) value_ += attackCoef_ * (a - value_);+ else+ value_ *= releaseCoef_;+ return value_;+}+} // namespace dsp} // namespace notadiff --git a/src/native/nota.engine/src/dsp/primitives/LadderFilter.cpp b/src/native/nota.engine/src/dsp/primitives/LadderFilter.cppindex 823c0b8a..dc71dcaa 100644--- a/src/native/nota.engine/src/dsp/primitives/LadderFilter.cpp+++ b/src/native/nota.engine/src/dsp/primitives/LadderFilter.cpp@@ -32,19 +32,5 @@ void LadderFilter::reset() noexcept {l1_ = l2_ = l3_ = l4_ = 0.0;}-float LadderFilter::process(float x, bool bassComp) NOTA_RT_SAFE {- const double f = f_, fb = fb_;- for (int os = 0; os < 2; ++os) {- const double in = x - fb * fast_math::tanhPrecise(static_cast<float>(l4_));- l1_ += f * (fast_math::tanhPrecise(static_cast<float>(in)) - fast_math::tanhPrecise(static_cast<float>(l1_)));- l2_ += f * (fast_math::tanhPrecise(static_cast<float>(l1_)) - fast_math::tanhPrecise(static_cast<float>(l2_)));- l3_ += f * (fast_math::tanhPrecise(static_cast<float>(l2_)) - fast_math::tanhPrecise(static_cast<float>(l3_)));- l4_ += f * (fast_math::tanhPrecise(static_cast<float>(l3_)) - fast_math::tanhPrecise(static_cast<float>(l4_)));- }- double y = l4_ * (1.0 + reso_ * 0.7); // makeup for resonant passband loss- if (bassComp) y += x * (reso_ * 0.20); // restore low end lost to resonance- return static_cast<float>(y);-}-} // namespace dsp} // namespace notadiff --git a/src/native/nota.engine/src/dsp/primitives/LadderFilter.h b/src/native/nota.engine/src/dsp/primitives/LadderFilter.hindex 30bbce51..7d7473ff 100644--- a/src/native/nota.engine/src/dsp/primitives/LadderFilter.h+++ b/src/native/nota.engine/src/dsp/primitives/LadderFilter.h@@ -9,7 +9,11 @@#pragma once+#include <algorithm>+#include <cmath>+#include "dsp/core/RtAttributes.h"+#include "dsp/math/FastMath.h"namespace nota {namespace dsp {@@ -33,5 +37,21 @@ class LadderFilter {double l1_ = 0.0, l2_ = 0.0, l3_ = 0.0, l4_ = 0.0;};+// Per-sample hot path: inline, so callers in other TUs inline it (no LTO).++inline float LadderFilter::process(float x, bool bassComp) NOTA_RT_SAFE {+ const double f = f_, fb = fb_;+ for (int os = 0; os < 2; ++os) {+ const double in = x - fb * fast_math::tanhPrecise(static_cast<float>(l4_));+ l1_ += f * (fast_math::tanhPrecise(static_cast<float>(in)) - fast_math::tanhPrecise(static_cast<float>(l1_)));+ l2_ += f * (fast_math::tanhPrecise(static_cast<float>(l1_)) - fast_math::tanhPrecise(static_cast<float>(l2_)));+ l3_ += f * (fast_math::tanhPrecise(static_cast<float>(l2_)) - fast_math::tanhPrecise(static_cast<float>(l3_)));+ l4_ += f * (fast_math::tanhPrecise(static_cast<float>(l3_)) - fast_math::tanhPrecise(static_cast<float>(l4_)));+ }+ double y = l4_ * (1.0 + reso_ * 0.7); // makeup for resonant passband loss+ if (bassComp) y += x * (reso_ * 0.20); // restore low end lost to resonance+ return static_cast<float>(y);+}+} // namespace dsp} // namespace notadiff --git a/src/native/nota.engine/src/dsp/primitives/Oscillator.cpp b/src/native/nota.engine/src/dsp/primitives/Oscillator.cppindex fbe8d496..2029adc9 100644--- a/src/native/nota.engine/src/dsp/primitives/Oscillator.cpp+++ b/src/native/nota.engine/src/dsp/primitives/Oscillator.cpp@@ -26,47 +26,6 @@ void BleOscillator::reset(float phase) noexcept {if (phase_ < 0.0f) phase_ += 1.0f;}-float BleOscillator::polyBlep(float t, float dt) NOTA_RT_SAFE {- if (t < dt) {- t /= dt;- return t + t - t * t - 1.0f;- }- if (t > 1.0f - dt) {- t = (t - 1.0f) / dt;- return t * t + t + t + 1.0f;- }- return 0.0f;-}--float BleOscillator::tick() NOTA_RT_SAFE {- const float dt = freq_ / static_cast<float>(sr_);- float v = 0.0f;- switch (wave_) {- case 0: { // saw: 2*phase - 1 with BLEP at wrap- v = 2.0f * phase_ - 1.0f;- v -= polyBlep(phase_, dt);- break;- }- case 1: { // square/pulse with BLEP at both edges- v = phase_ < pw_ ? 1.0f : -1.0f;- v += polyBlep(phase_, dt);- float t = phase_ - pw_;- if (t < 0.0f) t += 1.0f;- v -= polyBlep(t, dt);- break;- }- case 2: { // triangle: naive (matches Synth.h — the repo's proven shape)- const float d = phase_ < 0.5f ? phase_ : 1.0f - phase_;- v = 4.0f * d - 1.0f;- break;- }- default: v = fast_math::sin(phase_); break; // sine- }- phase_ += dt;- if (phase_ >= 1.0f) phase_ -= 1.0f;- return v;-}-void LfoGenerator::setSampleRate(double sr) noexcept {sr_ = sr > 0.0 ? sr : 44100.0;}@@ -87,28 +46,5 @@ void LfoGenerator::reset(float phase) noexcept {if (phase_ < 0.0f) phase_ += 1.0f;}-float LfoGenerator::tick() NOTA_RT_SAFE {- float v = 0.0f;- switch (wave_) {- case LfoWave::Sine: v = fast_math::sin(phase_); break;- case LfoWave::Triangle: v = phase_ < 0.5f ? phase_ * 4.0f - 1.0f : 3.0f - phase_ * 4.0f; break;- case LfoWave::Saw: v = phase_ * 2.0f - 1.0f; break;- case LfoWave::Square: v = phase_ < 0.5f ? 1.0f : -1.0f; break;- case LfoWave::SampleHold: {- if (phase_ < inc_) {- holdSeed_ ^= holdSeed_ << 13;- holdSeed_ ^= holdSeed_ >> 17;- holdSeed_ ^= holdSeed_ << 5;- holdValue_ = static_cast<float>(holdSeed_ >> 8) * (1.0f / 16777216.0f) * 2.0f - 1.0f;- }- v = holdValue_;- break;- }- }- phase_ += inc_;- if (phase_ >= 1.0f) phase_ -= 1.0f;- return v;-}-} // namespace dsp} // namespace notadiff --git a/src/native/nota.engine/src/dsp/primitives/Oscillator.h b/src/native/nota.engine/src/dsp/primitives/Oscillator.hindex a86ad046..d67b299a 100644--- a/src/native/nota.engine/src/dsp/primitives/Oscillator.h+++ b/src/native/nota.engine/src/dsp/primitives/Oscillator.h@@ -11,6 +11,7 @@#include <cstdint>#include "dsp/core/RtAttributes.h"+#include "dsp/math/FastMath.h"namespace nota {namespace dsp {@@ -65,5 +66,71 @@ class LfoGenerator {float holdValue_ = 0.0f;};+// Per-sample hot path: inline, so callers in other TUs inline it (no LTO).++inline float BleOscillator::polyBlep(float t, float dt) NOTA_RT_SAFE {+ if (t < dt) {+ t /= dt;+ return t + t - t * t - 1.0f;+ }+ if (t > 1.0f - dt) {+ t = (t - 1.0f) / dt;+ return t * t + t + t + 1.0f;+ }+ return 0.0f;+}++inline float BleOscillator::tick() NOTA_RT_SAFE {+ const float dt = freq_ / static_cast<float>(sr_);+ float v = 0.0f;+ switch (wave_) {+ case 0: { // saw: 2*phase - 1 with BLEP at wrap+ v = 2.0f * phase_ - 1.0f;+ v -= polyBlep(phase_, dt);+ break;+ }+ case 1: { // square/pulse with BLEP at both edges+ v = phase_ < pw_ ? 1.0f : -1.0f;+ v += polyBlep(phase_, dt);+ float t = phase_ - pw_;+ if (t < 0.0f) t += 1.0f;+ v -= polyBlep(t, dt);+ break;+ }+ case 2: { // triangle: naive (matches Synth.h — the repo's proven shape)+ const float d = phase_ < 0.5f ? phase_ : 1.0f - phase_;+ v = 4.0f * d - 1.0f;+ break;+ }+ default: v = fast_math::sin(phase_); break; // sine+ }+ phase_ += dt;+ if (phase_ >= 1.0f) phase_ -= 1.0f;+ return v;+}++inline float LfoGenerator::tick() NOTA_RT_SAFE {+ float v = 0.0f;+ switch (wave_) {+ case LfoWave::Sine: v = fast_math::sin(phase_); break;+ case LfoWave::Triangle: v = phase_ < 0.5f ? phase_ * 4.0f - 1.0f : 3.0f - phase_ * 4.0f; break;+ case LfoWave::Saw: v = phase_ * 2.0f - 1.0f; break;+ case LfoWave::Square: v = phase_ < 0.5f ? 1.0f : -1.0f; break;+ case LfoWave::SampleHold: {+ if (phase_ < inc_) {+ holdSeed_ ^= holdSeed_ << 13;+ holdSeed_ ^= holdSeed_ >> 17;+ holdSeed_ ^= holdSeed_ << 5;+ holdValue_ = static_cast<float>(holdSeed_ >> 8) * (1.0f / 16777216.0f) * 2.0f - 1.0f;+ }+ v = holdValue_;+ break;+ }+ }+ phase_ += inc_;+ if (phase_ >= 1.0f) phase_ -= 1.0f;+ return v;+}+} // namespace dsp} // namespace notadiff --git a/src/native/nota.engine/src/dsp/primitives/TruePeakMeter.cpp b/src/native/nota.engine/src/dsp/primitives/TruePeakMeter.cppindex 957e3f2a..75a5040d 100644--- a/src/native/nota.engine/src/dsp/primitives/TruePeakMeter.cpp+++ b/src/native/nota.engine/src/dsp/primitives/TruePeakMeter.cpp@@ -45,27 +45,5 @@ void TruePeakMeter::reset() noexcept {w_ = 0;}-float TruePeakMeter::push(float x) NOTA_RT_SAFE {- hist_[w_] = x;- hist_[w_ + 16] = x;- w_ = (w_ + 1) & 15;- // Window of the last 16 samples ending at the newest: hist_[w_ .. w_+15].- const float* win = hist_.data() + w_;- const auto& c = coefs();- float pk = win[kDelay - 1] < 0.0f ? -win[kDelay - 1] : win[kDelay - 1];- for (int p = 0; p < 3; ++p) {- const float acc = simd::dot16(c[p].data(), win);- const float a = acc < 0.0f ? -acc : acc;- if (a > pk) pk = a;- }- return pk;-}--float TruePeakMeter::detect(float x) NOTA_RT_SAFE {- const float a = x < 0.0f ? -x : x;- const float tp = push(x);- return a > tp ? a : tp;-}-} // namespace dsp} // namespace notadiff --git a/src/native/nota.engine/src/dsp/primitives/TruePeakMeter.h b/src/native/nota.engine/src/dsp/primitives/TruePeakMeter.hindex 6045b619..ca617c00 100644--- a/src/native/nota.engine/src/dsp/primitives/TruePeakMeter.h+++ b/src/native/nota.engine/src/dsp/primitives/TruePeakMeter.h@@ -9,10 +9,12 @@#pragma once+#include <cmath>#include <array>#include <cstdint>#include "dsp/core/RtAttributes.h"+#include "dsp/math/Simd.h"namespace nota {namespace dsp {@@ -40,5 +42,29 @@ class TruePeakMeter {int w_ = 0;};+// Per-sample hot path: inline, so callers in other TUs inline it (no LTO).++inline float TruePeakMeter::push(float x) NOTA_RT_SAFE {+ hist_[w_] = x;+ hist_[w_ + 16] = x;+ w_ = (w_ + 1) & 15;+ // Window of the last 16 samples ending at the newest: hist_[w_ .. w_+15].+ const float* win = hist_.data() + w_;+ const auto& c = coefs();+ float pk = win[kDelay - 1] < 0.0f ? -win[kDelay - 1] : win[kDelay - 1];+ for (int p = 0; p < 3; ++p) {+ const float acc = simd::dot16(c[p].data(), win);+ const float a = acc < 0.0f ? -acc : acc;+ if (a > pk) pk = a;+ }+ return pk;+}++inline float TruePeakMeter::detect(float x) NOTA_RT_SAFE {+ const float a = x < 0.0f ? -x : x;+ const float tp = push(x);+ return a > tp ? a : tp;+}+} // namespace dsp} // namespace notadiff --git a/src/native/nota.engine/src/engine/AudioThreadPool.cpp b/src/native/nota.engine/src/engine/AudioThreadPool.cppindex 4e16d71f..26425847 100644--- a/src/native/nota.engine/src/engine/AudioThreadPool.cpp+++ b/src/native/nota.engine/src/engine/AudioThreadPool.cpp@@ -134,14 +134,21 @@ void AudioThreadPool::workerLoop(int id) {const uint64_t t = claimed_.load(std::memory_order_relaxed);const uint64_t lg = epoch_.load(std::memory_order_acquire);if (stop_.load(std::memory_order_relaxed)) return;+ // Snapshot the slot, then prove it is generation lg's: the slot is rewritten+ // only for generation lg + kSlots, published once epoch_ has passed lg, and+ // a field read from that rewrite makes the re-load below see the newer epoch.const JobSlot& s = slots_[lg & (kSlots - 1)];- if (t - s.base >= (uint64_t)s.n) {- if (epoch_.load(std::memory_order_acquire) == lg) break; // stable: truly beyond- continue;- }+ const uint64_t base = s.base.load(std::memory_order_relaxed);+ const int n = s.n.load(std::memory_order_relaxed);+ const JobCall call = s.call.load(std::memory_order_relaxed);+ void* const ctx = s.ctx.load(std::memory_order_relaxed);+ std::atomic_thread_fence(std::memory_order_acquire);+ if (epoch_.load(std::memory_order_relaxed) != lg) continue; // moved on: re-read+ if (t - base >= (uint64_t)n) break; // stable: truly beyonduint64_t expect = t;if (claimed_.compare_exchange_weak(expect, t + 1, std::memory_order_relaxed)) {- s.call(s.ctx, id, (int)(t - s.base));+ // The CAS proved no ticket was claimed since t, so job lg is still live.+ call(ctx, id, (int)(t - base));done_.fetch_add(1, std::memory_order_release); // publishes this task's writes}}diff --git a/src/native/nota.engine/src/engine/AudioThreadPool.h b/src/native/nota.engine/src/engine/AudioThreadPool.hindex 8d8e65c2..6c691424 100644--- a/src/native/nota.engine/src/engine/AudioThreadPool.h+++ b/src/native/nota.engine/src/engine/AudioThreadPool.h@@ -31,7 +31,10 @@// progress, bounded retries with W+1 <= 18 threads).// - job descriptors live in generation-indexed slots; a publish writes its// slot before the epoch bump (release) and is gated on the previous-// job's completion, so a live ticket's slot is stable while held.+// job's completion, so a live ticket's slot is stable while held. A+// worker whose epoch view is stale may still read a slot mid-rewrite, so+// it validates the snapshot like a seqlock (read the fields, acquire+// fence, epoch_ unchanged) before trusting any field.// - parking is Dekker-style (all seq_cst): a worker bumps sleepers_, then// re-checks epoch_ before waiting on wake_; dispatch() stores epoch_,// then reads sleepers_. Either the worker sees the new epoch or the@@ -111,10 +114,12 @@ class AudioThreadPool {// workers observe the slot through the epoch's acquire chain.const uint64_t g = epoch_.load(std::memory_order_relaxed) + 1;JobSlot& s = slots_[g & (kSlots - 1)];- s.call = &callTrampoline<F>;- s.ctx = (void*)&fn;- s.n = n;- s.base = claimed_.load(std::memory_order_relaxed);+ // Release stores: a worker that reads any of them also sees the epoch this+ // thread had reached, so its re-check of epoch_ catches a slot being reused.+ s.call.store(&callTrampoline<F>, std::memory_order_release);+ s.ctx.store((void*)&fn, std::memory_order_release);+ s.n.store(n, std::memory_order_release);+ s.base.store(claimed_.load(std::memory_order_relaxed), std::memory_order_release);doneBase_ = done_.load(std::memory_order_relaxed);epoch_.store(g, std::memory_order_seq_cst); // publish (seq_cst: pairs with park())// Wake parked workers — at most `helpers`, and never more than there are@@ -141,12 +146,13 @@ class AudioThreadPool {uint64_t t = claimed_.load(std::memory_order_relaxed);uint64_t lg = epoch_.load(std::memory_order_acquire);const JobSlot& ls = slots_[lg & (kSlots - 1)];- if (t - ls.base >= (uint64_t)ls.n) {+ const uint64_t base = ls.base.load(std::memory_order_relaxed);+ if (t - base >= (uint64_t)ls.n.load(std::memory_order_relaxed)) {if (epoch_.load(std::memory_order_acquire) == lg) break; // stable: truly beyondcontinue; // view moved under us — re-evaluate, nothing consumed}if (claimed_.compare_exchange_weak(t, t + 1, std::memory_order_relaxed)) {- fn(self, (int)(t - ls.base));+ fn(self, (int)(t - base));done_.fetch_add(1, std::memory_order_release); // publishes this task's writes}}@@ -167,11 +173,16 @@ class AudioThreadPool {}using JobCall = void (*)(void*, int, int);+ // Fields are atomics because a lagging worker may still read a slot while the+ // caller rewrites it kSlots jobs later. Workers read them seqlock-style: all four,+ // then an acquire fence, then epoch_ again; a changed epoch discards the read, so+ // fields from two generations are never combined (release stores on the writer+ // side; on x86 these are plain moves).struct JobSlot {- JobCall call = nullptr;- void* ctx = nullptr;- int n = 0;- uint64_t base = 0;+ std::atomic<JobCall> call{nullptr};+ std::atomic<void*> ctx{nullptr};+ std::atomic<int> n{0};+ std::atomic<uint64_t> base{0};};void workerLoop(int id);diff --git a/src/native/nota.engine/src/engine/Engine.h b/src/native/nota.engine/src/engine/Engine.hindex 64cc5d33..67570c5c 100644--- a/src/native/nota.engine/src/engine/Engine.h+++ b/src/native/nota.engine/src/engine/Engine.h@@ -491,9 +491,12 @@ class Engine {// Time-range clip ops (arrangement time-selection). Both split clips at the range// boundaries so only the covered content is affected, in one undo step. No ripple.- // deleteClipsInRange carves [start,end) out of every listed track. duplicateRange- // copies that slice to [end, end+(end-start)) and returns the range length (>0), or -1.- bool deleteClipsInRange(const std::vector<int32_t>& trackIds, double start, double end);+ // deleteClipsInRange carves [start,end) out of every listed track; withAutomation also+ // clears the automation under the carved slices (what copyRange captured with them).+ // duplicateRange copies that slice to [end, end+(end-start)) and returns the range+ // length (>0), or -1.+ bool deleteClipsInRange(const std::vector<int32_t>& trackIds, double start, double end,+ bool withAutomation = false);double duplicateRange(const std::vector<int32_t>& trackIds, double start, double end);// insertTime opens a `len`-beat gap at `at` across the whole arrangement (every track and// the master): clips crossing `at` are cut, everything at or after it — clips and@@ -549,7 +552,7 @@ class Engine {// Range copy/cut (arrangement time-selection ⌘C / ⌘X): the slice of every listed track's// clips inside [start,end) becomes the block clipboard, beats relative to `start` (so a// leading gap is kept), each slice with its automation. Copy leaves the project alone;- // cut then carves the range out like deleteClipsInRange (one undo step). A range block+ // cut then carves the range and its automation out (one undo step). A range block// pastes in overwrite mode — it replaces what it lands on, like a range duplicate.bool copyRange(const std::vector<int32_t>& trackIds, double start, double end);bool cutRange(const std::vector<int32_t>& trackIds, double start, double end);diff --git a/src/native/nota.engine/src/engine/Engine_Tracks.cpp b/src/native/nota.engine/src/engine/Engine_Tracks.cppindex 8ce470fd..e74d0dd8 100644--- a/src/native/nota.engine/src/engine/Engine_Tracks.cpp+++ b/src/native/nota.engine/src/engine/Engine_Tracks.cpp@@ -1669,7 +1669,8 @@ bool rangeTouchesTrack(const Track& t, double s, double e, double spb, double de}} // namespace-bool Engine::deleteClipsInRange(const std::vector<int32_t>& trackIds, double start, double end) {+bool Engine::deleteClipsInRange(const std::vector<int32_t>& trackIds, double start, double end,+ bool withAutomation) {if (end <= start + 1e-9 || trackIds.empty()) return false;const double spb = transport_.samplesPerBeat(), devSR = transport_.sampleRate();auto listed = [&](int32_t id) { return std::find(trackIds.begin(), trackIds.end(), id) != trackIds.end(); };@@ -1680,6 +1681,16 @@ bool Engine::deleteClipsInRange(const std::vector<int32_t>& trackIds, double stafor (auto& t : authoring_->tracks) {if (t->type() != TrackType::Return && listed(t->id()) && rangeTouchesTrack(*t, start, end, spb, devSR)) {auto nt = cloneTrack(*t);+ if (withAutomation) { // the spans copyRange captured: each clip's slice of the range+ auto clear = [&](double cs, double ce) {+ if (ce > start + 1e-6 && cs < end - 1e-6)+ removeAutomationInRange(*nt, std::max(cs, start), std::min(ce, end));+ };+ if (nt->type() == TrackType::Instrument)+ for (const auto& c : nt->midiClips) clear(c.startBeat, c.startBeat + c.lengthBeats);+ else+ for (const auto& c : nt->clips) clear(c.startBeat, c.startBeat + audioDisplayLenBeats(c, spb, devSR));+ }if (nt->type() == TrackType::Instrument) midiOverwriteRange(nt->midiClips, start, end);elseaudioOverwriteRange(nt->clips, start, end, spb, devSR);@@ -2799,7 +2810,7 @@ bool Engine::copyRange(const std::vector<int32_t>& trackIds, double start, doublbool Engine::cutRange(const std::vector<int32_t>& trackIds, double start, double end) {if (!copyRange(trackIds, start, end)) return false;- deleteClipsInRange(trackIds, start, end);+ deleteClipsInRange(trackIds, start, end, /*withAutomation=*/true);return true;}diff --git a/src/native/nota.engine/src/engine/NoteExpression.cpp b/src/native/nota.engine/src/engine/NoteExpression.cppindex 07db96d4..5b94b089 100644--- a/src/native/nota.engine/src/engine/NoteExpression.cpp+++ b/src/native/nota.engine/src/engine/NoteExpression.cpp@@ -17,9 +17,4 @@ void VoiceExpr::set(int32_t dim, float v, const float add[kExprDims]) {if (fresh) cur[dim] = v + add[dim];}-void VoiceExpr::tick(const float add[kExprDims], float coef) {- fresh = false;- for (int d = 0; d < kExprDims; ++d) cur[d] += (tgt[d] + add[d] - cur[d]) * coef;-}-} // namespace notadiff --git a/src/native/nota.engine/src/engine/NoteExpression.h b/src/native/nota.engine/src/engine/NoteExpression.hindex 8d1ce124..ffb8bd07 100644--- a/src/native/nota.engine/src/engine/NoteExpression.h+++ b/src/native/nota.engine/src/engine/NoteExpression.h@@ -72,8 +72,12 @@ struct VoiceExpr {fresh = true;}void set(int32_t dim, float v, const float add[kExprDims]);- // One sample of smoothing towards own + global.- void tick(const float add[kExprDims], float coef);+ // One sample of smoothing towards own + global. Inline: every voice of every+ // instrument calls it per sample, from other TUs (the engine builds without LTO).+ void tick(const float add[kExprDims], float coef) {+ fresh = false;+ for (int d = 0; d < kExprDims; ++d) cur[d] += (tgt[d] + add[d] - cur[d]) * coef;+ }float bend() const { return cur[ExprBend]; } // semitonesfloat pressure() const { return std::clamp(cur[ExprPressure], 0.0f, 1.0f); } // 0..1diff --git a/tests/Nota.SmokeTest/RangeClipboardTests.cs b/tests/Nota.SmokeTest/RangeClipboardTests.csindex ccd4d112..aa59d8c2 100644--- a/tests/Nota.SmokeTest/RangeClipboardTests.cs+++ b/tests/Nota.SmokeTest/RangeClipboardTests.cs@@ -97,6 +97,27 @@ internal static class RangeClipboardTests"range: the cut slice pastes at beat 20");}+ // Cut takes the automation under the slice with it: it leaves the source, and the+ // paste brings it back once (not on top of a copy left behind).+ {+ using var e = new NotaEngine();+ int a = e.AddInstrumentTrack();+ e.AddMidiClip(a, 0.0, 8.0);+ int lane = e.AddAutomationLane(a, AutomationTarget.Volume, -1, -1);+ e.SetAutomationPoints(a, lane, new[] { new AutomationPoint(1.0, 0.2f), new AutomationPoint(3.0, 0.4f),+ new AutomationPoint(5.0, 0.6f), new AutomationPoint(7.0, 0.8f) });+ e.CutRange(new[] { a }, 2.0, 6.0);+ var left = e.GetAutomationPoints(a, lane).Select(p => p.Beat).ToArray();+ yield return (left.Length == 2 && Near(left[0], 1) && Near(left[1], 7),+ $"range: cut removes the automation inside [2,6) ({string.Join(" ", left)})");+ e.PasteClipBlock(20.0, -1);+ var pasted = e.GetAutomationPoints(a, lane).Select(p => p.Beat).Where(b => b >= 20 - Eps).ToArray();+ yield return (pasted.Length == 2 && Near(pasted[0], 21) && Near(pasted[1], 23),+ $"range: the cut automation pastes with the slice ({string.Join(" ", pasted)})");+ yield return (e.Undo() && e.Undo() && e.GetAutomationPoints(a, lane).Length == 4,+ "range: undoing paste and cut restores the automation");+ }+// Cross-track paste anchors on the range's top row, even when that row is empty.{using var e = new NotaEngine();