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.

(feat) Smooth waveform with an RMS body as the default for audio clips (#267) (#393)

Chris Laupama184e643ab7d9
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 92fc7960..a17a0328 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -41,6 +41,13 @@ Entry categories: `Added`, `Changed`, `Fixed`, `Removed`.
the same way.
### Changed
+- **Smoother, clearer waveforms on audio clips** (#267): clips in the Arrangement and the
+ audio clip editor now draw an anti-aliased peak outline around a denser body that follows
+ the loudness (RMS) of the audio. Every zoom level reads cleanly — zoomed out, no peak slips
+ between pixels; zoomed in, the wave slopes from point to point instead of stepping, down to
+ a fine line at sample level — and on a HiDPI screen it is drawn at the screen's full
+ resolution. This is the new default, **Smooth**; **Solid** and **Bars** are still in
+ Settings → Appearance → Waveform (a saved Bars choice moves to Smooth once).
- **Clip inspector and MIDI tools in two columns** (#276): in a short clip editor the
inspector (MIDI and audio) and the Tools rail lay their sections out in two columns instead
of one scrolling column, so Clip, Quantize, Transpose and Selection (or Clip, Playback and
diff --git a/FEATURES.md b/FEATURES.md
index 8b099c61..8f53b8df 100644
--- a/FEATURES.md
+++ b/FEATURES.md
@@ -490,7 +490,10 @@ docks as a panel under any of the three, or floats in its own window — see
track) — dropped frames are padded with silence, so there is no cumulative drift.
- **Import** of audio files by drag and drop: WAV / AIFF / FLAC / MP3.
- **Audio clip**: start and end, waveform drawing, trimming, split, fade in/out, clip
- gain. Changing the length shows the material actually being revealed or hidden.
+ gain. Changing the length shows the material actually being revealed or hidden. The
+ waveform (lanes and clip editor) is an anti-aliased peak outline around its RMS body,
+ resolved to device pixels at every zoom; the lanes can draw **Solid** or **Bars** instead
+ (Settings → Appearance → Waveform).
- **Reverse** (clip editor ▸ DIRECTION, or the clip's context menu): plays the clip
backwards without touching the file, so it costs nothing to toggle and composes with
gain, pitch and warp. The arrangement lane and the clip editor both draw it the way it
@@ -1089,9 +1092,9 @@ audio effects after it keep running and keep their settings; saved with the proj
group by source, favourites first — each remembered across sessions — plus the tag editor.
- A **status line** counts what the tab is showing (`13 built-in · 4 plug-ins`), and the
search box counts the matches.
-- **Sample player** under the Files tab: the file's real waveform, drawn as Bars or Solid
- like the arrangement (Settings → Appearance → Waveform; click to play from a point,
- hover for the time), Play / Stop, time readout, Loop, Auto (play on select) and a
+- **Sample player** under the Files tab: the file's real waveform, drawn Solid when the
+ arrangement is set to Solid and as Bars otherwise (Settings → Appearance → Waveform;
+ click to play from a point, hover for the time), Play / Stop, time readout, Loop, Auto (play on select) and a
preview volume fader; ↑ ↓ step through files and Space plays the selected one. It stays
hidden until you use a list and tightens in a narrow browser. Space in the arrangement
always drives the project transport.
@@ -1289,7 +1292,8 @@ audio effects after it keep running and keep their settings; saved with the proj
dark mode and one for light mode, switched with the OS appearance; the choice applies
live and is remembered. **Interface scale** — 75 / 100 / 125 / 150 / 200 % for the whole
interface (every window, menu, tooltip and dialog; text stays sharp), applied live and
- remembered; timeline, piano roll and audio editor zoom work on top of it. Also
+ remembered; timeline, piano roll and audio editor zoom work on top of it. **Waveform** —
+ **Smooth** (default), **Solid** or **Bars** for audio clips on the lanes. Also
**AI control (MCP)** on/off, a port field, and "Copy config" (copies a
ready-made client JSON config to the clipboard).
- **Shortcuts**: the shortcut list.
diff --git a/specs/057-waveform-rendering/plan.md b/specs/057-waveform-rendering/plan.md
new file mode 100644
index 00000000..e32154e3
--- /dev/null
+++ b/specs/057-waveform-rendering/plan.md
@@ -0,0 +1,65 @@
+# Implementation Plan: Default waveform rendering
+
+**Branch**: `057-waveform-rendering` | **Spec**: [spec.md](spec.md) | **Issue**: #267
+
+## Summary
+
+Add an RMS level to the engine's waveform buckets and draw a new default style, **Smooth**, in
+the arrangement lanes and the audio clip editor through one shared painter.
+
+## Audio-Thread Impact
+
+None. Nothing in the render path changes: `Engine_Render` and the clip readers never touch
+`rmsTable`, `rmsRange` or the levels calls.
+
+- The RMS table is filled in `updatePeakTable`, which runs only where the peak table already
+ is built: the decode in `AudioFile` / `AudioImportJob::step` / `finish` (loader thread) and
+ `AuditionRig` (control thread). It is sized together with `peakTable` there. The cost is one
+ extra `float` per 512 frames (at most 0.2% of the sample memory, for mono).
+- `rmsRange` and `nota_clip_get_levels` are UI-thread queries on the same path as the
+ existing `nota_clip_get_peaks*` calls. They write only into the caller's arrays, take no lock
+ of their own and allocate nothing.
+- AR-5: no graph or snapshot edits. AR-7: the managed side reaches the RMS only through the
+ new C function, which uses plain C types. AR-9: no musical-time source added. No JUCE and no
+ new dependency.
+
+## Constitution Check
+
+| Principle | Status | Note |
+|---|---|---|
+| I. Real-Time Audio Safety | Pass | No audio-thread code changes (above). |
+| II. Boundary Discipline | Pass | One new pure C call in `nota_engine.h`; existing calls unchanged. |
+| III. Licensing Hygiene | Pass | New `WaveformPainter.cs` carries the SPDX header; no new dependency. |
+| IV. Verification Gate | Pass | Smoke test extended (RMS vs brute-force scan, envelope bounds) and green. |
+| V. One Logical Change per PR | Pass | Waveform rendering only. |
+| VI. Documentation Stays in Sync | Pass | `CHANGELOG.md`, `FEATURES.md`; `nota-docs` appearance page is a follow-up in that repo. |
+| VII. Spec-First | Pass | This spec/plan/tasks run. |
+| VIII. Safety Rules Never Weakened | Pass | No guard or check relaxed. |
+
+## Engine
+
+- `SampleBuffer`: `rmsTable` (mean square of the stereo mid per `kPeakBlock`), built and
+ sentinel-filled with `peakTable`; `rmsRange(f0, f1)` reads whole blocks from the table and
+ scans the partial ends, like `peakRange`. A seeded (cached) peak table has no RMS until the
+ decode finishes and rebuilds both.
+- `Engine::getClip*Peaks*`: optional `float* outRms`; `reversePeaks` flips it too.
+- ABI: `nota_clip_get_levels(engine, track, clip, view, a, b, out_min_max, out_rms, max)` with
+ `NOTA_CLIP_LEVELS_*` views mapping to the five existing calls.
+
+## Managed
+
+- `IAudioEngine.GetClip*Peaks*` gain an optional `float[]? outRms`; `NotaEngine` routes to
+ `nota_clip_get_levels` only when it is given.
+- `WaveformPainter` (replaces the unused top-level `WaveformView`): folds buckets into
+ device-pixel columns, fills the envelope then the body as two `StreamGeometry` polygons.
+- Lanes: `ClipVM.Rms` / `DetailRms`, resize-preview RMS; Smooth path in `DrawWaveform` /
+ `DrawResizeWaveform`; detail fetched at device-pixel resolution.
+- Clip editor: overview and detail carry RMS; `DrawPeaks` / remapped path feed the painter;
+ detail thresholds in device pixels.
+- `WaveformStyle { Smooth, Solid, Bars }`; preference picker, settings doc, clamps.
+
+## Testing
+
+- Smoke test: RMS vs brute-force scan (frame-scan and block-table paths), min/max unchanged,
+ RMS within the envelope on warped buckets.
+- Screenshots: before/after, lanes at 6 / 28 / 220 px a beat, clip editor at 1× / 6× / 60×.
diff --git a/specs/057-waveform-rendering/spec.md b/specs/057-waveform-rendering/spec.md
new file mode 100644
index 00000000..40504de7
--- /dev/null
+++ b/specs/057-waveform-rendering/spec.md
@@ -0,0 +1,113 @@
+# Feature Specification: Default waveform rendering
+
+**Feature Branch**: `057-waveform-rendering`
+
+**Created**: 2026-10-30
+
+**Status**: Implemented
+
+**Input**: GitHub issue nota-daw/nota#267 — "A reviewer's first impression of the arrangement
+was the waveform drawing: 'really nasty waveform rendering'. Review the default waveform style
+in arrangement clips and the clip editor: anti-aliased min/max peaks with RMS body, correct
+mapping at every zoom level (no stair-stepping or aliasing when zoomed out), crisp on HiDPI.
+Pick the best-looking style as the default; keep the Waveform Style preference for the others.
+Before/after screenshots at three zoom levels in the PR."
+
+## Nota Context *(fill in — drives plan and tasks)*
+
+**Feature area** *(pick the main one)*:
+
+- [x] Engine (C++, `src/native/nota.engine`) — real-time audio rules apply, see `ARCHITECTURE.md` AR table
+- [x] Managed app (C#, `src/managed/*`) — domain, application, infrastructure, presentation
+- [x] UI (Avalonia, `src/managed/Nota.Presentation`) — follow `DESIGN.md` (Studio)
+- [ ] Plugin hosting (`pluginhost/`) — the only place JUCE is allowed
+- [ ] Build / packaging / CI (`scripts/`, `.github/`) — see `BUILD.md`
+- [ ] Docs only
+
+**Nota docs to keep in mind**: [`ARCHITECTURE.md`](../../ARCHITECTURE.md),
+[`CONTRIBUTING.md`](../../CONTRIBUTING.md), [`DESIGN.md`](../../DESIGN.md),
+[`FEATURES.md`](../../FEATURES.md).
+
+**Existing behaviour this builds on**: audio clips on the lanes draw min/max peaks either as
+**Bars** (a 1 px stroke every 3 px, mirrored about the centre — the default) or **Solid** (a
+1 px column per logical pixel), Settings → Appearance → Waveform. The clip editor draws one
+rectangle per peak bucket. The engine only returns min/max per bucket (a 512-frame min/max
+block table, `SampleBuffer::peakTable`); zoomed views fetch range peaks at one bucket per
+logical pixel (#299).
+
+## Clarifications
+
+### Session 2026-10-30
+
+- Q: Where does the RMS body come from? → A: The engine — a mean-square table per 512-frame
+ block next to the min/max table, so RMS over long spans costs the same as the peaks.
+ Approximating it from min/max in the UI would not be RMS.
+- Q: What is the new default called, and what happens to people on the old default? → A:
+ **Smooth**. The setting stores 0 for the default; 0 now means Smooth, Solid stays 1 and
+ Bars moves to 2. Everyone who never changed it (and anyone who picked Bars) sees Smooth once
+ and can pick Bars again.
+- Q: Does the clip editor follow the preference? → A: No — it never did; it now always draws
+ Smooth. The preference keeps covering the lanes (and Solid / Bars in the browser preview).
+
+## User Scenarios & Testing *(mandatory)*
+
+### User Story 1 - Audio clips read cleanly on the lanes (Priority: P1)
+
+A user drops audio onto the arrangement. At any zoom, the clip shows a smooth outline of its
+peaks with a denser body for its loudness; transients stand out, quiet parts stay visible as a
+line.
+
+**Acceptance Scenarios**:
+
+1. **Given** a drum loop on a lane, **When** zoomed far out, **Then** every transient shows
+ (nothing drops between pixels) and the outline has no jagged steps.
+2. **Given** the same clip zoomed in past one bucket per pixel, **Then** the outline slopes
+ between points instead of stair-stepping.
+3. **Given** a HiDPI display, **Then** the waveform is resolved per device pixel.
+
+### User Story 2 - The clip editor matches (Priority: P1)
+
+The audio clip editor draws the same style; zoomed to sample level it shows a thin
+anti-aliased trace rather than filled blocks.
+
+### User Story 3 - The other styles stay available (Priority: P2)
+
+Settings → Appearance → Waveform offers Smooth (default), Solid and Bars; Solid and Bars draw
+exactly as before.
+
+### Edge Cases
+
+- Silence draws as a line one device pixel thick.
+- Import placeholders (no RMS known yet) draw the outline only.
+- Reversed, warped, trimmed-while-dragging and ADSR-shaped clips keep their mapping; gain and
+ the ADSR scale the body like the peaks.
+
+## Requirements *(mandatory)*
+
+- **FR-001**: The engine returns, with any clip peak query, each bucket's RMS of the stereo
+ mid, over the same frames as its min/max.
+- **FR-002**: One new C ABI call (`nota_clip_get_levels`) covers the five clip peak views; the
+ existing calls are unchanged.
+- **FR-003**: The lanes (Smooth) and the clip editor draw an anti-aliased filled peak envelope
+ in a lighter ink of the clip's waveform colour and the RMS body in the full ink.
+- **FR-004**: Peak buckets narrower than a device pixel aggregate into that pixel (min of mins,
+ max of maxes, power-mean of RMS); wider buckets become one vertex at their centre.
+- **FR-005**: Zoom-detail fetches request one bucket per device pixel.
+- **FR-006**: The preference offers Smooth / Solid / Bars, Smooth by default.
+
+## Success Criteria *(mandatory)*
+
+- **SC-001**: Before/after screenshots at three zoom levels for the lanes and the clip editor.
+- **SC-002**: Smoke test checks RMS against a brute-force scan (short and long spans) and that
+ min/max are unchanged when RMS is requested.
+
+## Nota Compliance Checklist
+
+- [x] Every new source file carries the AGPL-3.0-only SPDX header
+- [x] No new dependency
+- [x] Audio-thread impact: none — the table is built where the min/max table is (decode /
+ load, message thread); queries run on the UI thread against the authoring graph
+- [x] Managed/native crossings go through `nota_engine.h` only (AR-7)
+- [x] Smoke test extended
+- [x] `CHANGELOG.md` and `FEATURES.md` updated
+- [x] Follows `DESIGN.md`: waveform ink from the clip colour, washes via `NotaPalette.Wash`
diff --git a/specs/057-waveform-rendering/tasks.md b/specs/057-waveform-rendering/tasks.md
new file mode 100644
index 00000000..b76d2916
--- /dev/null
+++ b/specs/057-waveform-rendering/tasks.md
@@ -0,0 +1,13 @@
+# Tasks: Default waveform rendering
+
+- [X] T001 `SampleBuffer` RMS table and `rmsRange` (`src/native/nota.engine/src/media/SampleBuffer.*`)
+- [X] T002 Optional RMS output on the clip peak queries (`src/native/nota.engine/src/engine/Engine*.{h,cpp}`)
+- [X] T003 `nota_clip_get_levels` + `NOTA_CLIP_LEVELS_*` (`nota_engine.h`, `abi/nota_engine_track.cpp`)
+- [X] T004 Interop and `IAudioEngine` optional `outRms` (`Nota.Infrastructure/Interop`, `Nota.Application/Engine`)
+- [X] T005 `WaveformPainter` (`src/managed/Nota.App/WaveformPainter.cs`)
+- [X] T006 Lanes: RMS plumbing and the Smooth path (`ArrangementView*.cs`)
+- [X] T007 Clip editor: RMS plumbing, painter, device-pixel detail (`AudioClipEditorView.cs`)
+- [X] T008 `WaveformStyle` Smooth / Solid / Bars, preference, setting doc (`ArrangementView.cs`, `PreferencesWindow.cs`, `Settings.cs`)
+- [X] T009 Smoke test RMS checks (`tests/Nota.SmokeTest/Program.cs`)
+- [X] T010 `CHANGELOG.md`, `FEATURES.md`
+- [X] T011 Before/after screenshots at three zoom levels (in the PR description)
diff --git a/src/managed/Nota.App/ArrangementView.LaneControl.cs b/src/managed/Nota.App/ArrangementView.LaneControl.cs
index 81a9370e..2bb129ed 100644
--- a/src/managed/Nota.App/ArrangementView.LaneControl.cs
+++ b/src/managed/Nota.App/ArrangementView.LaneControl.cs
@@ -85,13 +85,15 @@ public sealed partial class ArrangementView
// window [S0,S1] in that material's domain, captured at drag start. Drawing maps
// each timeline beat through the committed anchor to a material point, so a resize
// reveals/hides the REAL audio instead of squashing the fixed window peaks.
- private float[]? _rpPeaks;
+ private float[]? _rpPeaks, _rpRms;
private int _rpCount;
private double _rpMTotal, _rpS0, _rpS1; // material total + committed window (frames for unwarped, beats for warped)
private bool _rpWarped;
private int _rpTrack, _rpClip;
private float[]? _rpDetail; // the lane's visible material at one bucket per pixel (#299)
+ private float[]? _rpDetailRms;
private int _rpDetailCount;
+ private readonly WaveformPainter _painter = new();
private double _rpDetailM0, _rpDetailM1;
private const double EdgePx = 6;
@@ -1560,11 +1562,12 @@ public sealed partial class ArrangementView
if (eng is null || !eng.TryGetAudioClipInfo(trackId, clipIndex, out var ai)) return;
const int buckets = 2048;
var peaks = new float[buckets * 2];
+ var rms = new float[buckets];
if (ai.WarpEnabled != 0 && ai.WarpBeats > 0)
{
- int n = eng.GetClipWarpFullPeaks(trackId, clipIndex, peaks, buckets);
+ int n = eng.GetClipWarpFullPeaks(trackId, clipIndex, peaks, buckets, rms);
if (n <= 0) return;
- _rpCount = n; _rpPeaks = peaks; _rpWarped = true;
+ _rpCount = n; _rpPeaks = peaks; _rpRms = rms; _rpWarped = true;
_rpMTotal = ai.WarpBeats;
_rpS0 = ai.WarpPlayStart;
_rpS1 = ai.WarpPlayEnd > 0 ? ai.WarpPlayEnd : ai.WarpBeats;
@@ -1572,9 +1575,9 @@ public sealed partial class ArrangementView
else
{
if (ai.SampleId == 0 || !eng.TryGetSampleInfo(ai.SampleId, out var si) || si.Frames <= 0) return;
- int n = eng.GetClipSourcePeaks(trackId, clipIndex, peaks, buckets);
+ int n = eng.GetClipSourcePeaks(trackId, clipIndex, peaks, buckets, rms);
if (n <= 0) return;
- _rpCount = n; _rpPeaks = peaks; _rpWarped = false;
+ _rpCount = n; _rpPeaks = peaks; _rpRms = rms; _rpWarped = false;
_rpMTotal = si.Frames;
_rpS0 = ai.SourceOffsetFrames;
double len = ai.LengthFrames > 0 ? ai.LengthFrames : si.Frames - ai.SourceOffsetFrames;
@@ -1595,21 +1598,44 @@ public sealed partial class ArrangementView
// The whole-material overview, or — when the lane shows it wider than it has buckets —
// the material under the whole lane at one bucket per pixel, fetched once per drag (#299).
float[] pk = _rpPeaks!;
+ float[]? rms = _rpRms;
int count = _rpCount;
double m0 = 0, m1 = _rpMTotal;
double lm0 = Math.Clamp(MaterialAt(0), 0, _rpMTotal), lm1 = Math.Clamp(MaterialAt(Bounds.Width), 0, _rpMTotal);
- if (lm1 > lm0 && (lm1 - lm0) / _rpMTotal * _rpCount * 1.5 < Bounds.Width && _o._engine is { } eng)
+ bool smooth = _o.Waveform == WaveformStyle.Smooth;
+ double scale = smooth ? WaveformPainter.Scale(this) : 1;
+ if (lm1 > lm0 && (lm1 - lm0) / _rpMTotal * _rpCount * 1.5 < Bounds.Width * scale && _o._engine is { } eng)
{
- int n = Math.Clamp((int)Math.Ceiling(Bounds.Width), 1, 8192);
+ int n = Math.Clamp((int)Math.Ceiling(Bounds.Width * scale), 1, 8192);
if (_rpDetail is null || _rpDetailCount <= 0 || _rpDetailM0 != lm0 || _rpDetailM1 != lm1)
{
_rpDetail ??= new float[8192 * 2];
+ _rpDetailRms ??= new float[8192];
_rpDetailCount = _rpWarped
- ? eng.GetClipWarpPeaksRange(_rpTrack, _rpClip, lm0, lm1, _rpDetail, n)
- : eng.GetClipSourcePeaksRange(_rpTrack, _rpClip, lm0, lm1, _rpDetail, n);
+ ? eng.GetClipWarpPeaksRange(_rpTrack, _rpClip, lm0, lm1, _rpDetail, n, _rpDetailRms)
+ : eng.GetClipSourcePeaksRange(_rpTrack, _rpClip, lm0, lm1, _rpDetail, n, _rpDetailRms);
(_rpDetailM0, _rpDetailM1) = (lm0, lm1);
}
- if (_rpDetailCount > 0) (pk, count, m0, m1) = (_rpDetail, _rpDetailCount, lm0, lm1);
+ if (_rpDetailCount > 0) (pk, rms, count, m0, m1) = (_rpDetail, _rpDetailRms, _rpDetailCount, lm0, lm1);
+ }
+ if (smooth)
+ {
+ // Material → screen is linear while the drag holds the committed window.
+ double XAt(double m) => ((m - _rpS0) / rate + _origStart - scroll) * ppb;
+ double bm = (m1 - m0) / count;
+ int i0 = Math.Max(0, (int)Math.Floor((MaterialAt(vx0) - m0) / bm) - 1);
+ int i1 = Math.Min(count, (int)Math.Ceiling((MaterialAt(vx1) - m0) / bm) + 1);
+ _painter.Begin(scale);
+ for (int i = i0; i < i1; i++)
+ {
+ double ma = m0 + i * bm, mb = ma + bm;
+ if (mb <= 0 || ma >= _rpMTotal) continue; // past the material's ends: nothing to draw
+ _painter.Add(XAt(ma), XAt(mb), Math.Clamp(pk[i * 2] * gain, -1f, 1f), Math.Clamp(pk[i * 2 + 1] * gain, -1f, 1f),
+ rms is null ? -1f : Math.Min(1f, rms[i] * gain));
+ }
+ using (ctx.PushClip(new Rect(vx0, r.Y, Math.Max(0, vx1 - vx0), r.Height)))
+ _painter.Fill(ctx, mid, amp, WaveformPainter.PeakInk(brush), brush);
+ return;
}
var geo = new StreamGeometry();
using (var g = geo.Open())
@@ -1684,16 +1710,38 @@ public sealed partial class ArrangementView
// The whole-clip overview, or — when the clip is drawn wider than it has buckets —
// peaks for just the visible slice at one bucket per pixel (#299).
float[] pk = c.Peaks;
+ float[]? rms = c.Rms;
int count = c.PeakCount;
double fa = 0, fb = 1;
- if (r.Width > c.PeakCount * 1.5 && EnsureDetailPeaks(c, trackId, (vx0 - r.X) / r.Width, (vx1 - r.X) / r.Width,
- (int)Math.Ceiling(vx1 - vx0), r.Width))
+ // Smooth resolves to device pixels, so a HiDPI screen gets twice the detail.
+ bool smooth = _o.Waveform == WaveformStyle.Smooth;
+ double scale = smooth ? WaveformPainter.Scale(this) : 1;
+ if (r.Width * scale > c.PeakCount * 1.5 && EnsureDetailPeaks(c, trackId, (vx0 - r.X) / r.Width, (vx1 - r.X) / r.Width,
+ (int)Math.Ceiling((vx1 - vx0) * scale), r.Width))
{
- (pk, count, fa, fb) = (c.DetailPeaks!, c.DetailCount, c.DetailF0, c.DetailF1);
+ (pk, rms, count, fa, fb) = (c.DetailPeaks!, c.DetailRms, c.DetailCount, c.DetailF0, c.DetailF1);
}
double span = (fb - fa) * r.Width;
var adsr = c.Adsr.Fit(c.LengthBeats);
bool shaped = !adsr.IsIdentity;
+ if (smooth)
+ {
+ double ox = r.X + fa * r.Width, bw = span / count;
+ int i0 = Math.Max(0, (int)Math.Floor((vx0 - ox) / bw) - 1);
+ int i1 = Math.Min(count, (int)Math.Ceiling((vx1 - ox) / bw) + 1);
+ _painter.Begin(scale);
+ for (int i = i0; i < i1; i++)
+ {
+ double x0 = ox + i * bw;
+ float g = c.Gain;
+ if (shaped) g *= (float)adsr.GainAt((x0 + bw / 2 - r.X) / r.Width * c.LengthBeats, c.LengthBeats);
+ _painter.Add(x0, x0 + bw, Math.Clamp(pk[i * 2] * g, -1f, 1f), Math.Clamp(pk[i * 2 + 1] * g, -1f, 1f),
+ rms is null ? -1f : Math.Min(1f, rms[i] * g));
+ }
+ using (ctx.PushClip(new Rect(vx0, r.Y, vx1 - vx0, r.Height)))
+ _painter.Fill(ctx, mid, amp, WaveformPainter.PeakInk(brush), brush);
+ return;
+ }
var geo = new StreamGeometry();
using (var gc = geo.Open())
ForEachWaveColumn(r.X, vx0, vx1, (cx0, cx1, x) =>
@@ -1727,18 +1775,19 @@ public sealed partial class ArrangementView
bool rev = ai.Reversed != 0;
double a = rev ? 1 - f1 : f0, b = rev ? 1 - f0 : f1; // file-order fractions of the window
var buf = c.DetailPeaks is { } old && old.Length >= n * 2 ? old : new float[n * 2];
+ var rms = c.DetailRms is { } oldRms && oldRms.Length >= n ? oldRms : new float[n];
int got;
if (ai.WarpEnabled != 0 && ai.WarpBeats > 0)
{
double ps = ai.WarpPlayStart, pe = ai.WarpPlayEnd > 0 ? ai.WarpPlayEnd : ai.WarpBeats;
- got = eng.GetClipWarpPeaksRange(trackId, c.ClipIndex, ps + a * (pe - ps), ps + b * (pe - ps), buf, n);
+ got = eng.GetClipWarpPeaksRange(trackId, c.ClipIndex, ps + a * (pe - ps), ps + b * (pe - ps), buf, n, rms);
}
else
{
double len = ai.LengthFrames;
if (len <= 0 && eng.TryGetSampleInfo(ai.SampleId, out var si)) len = si.Frames - ai.SourceOffsetFrames;
if (len <= 0) return false;
- got = eng.GetClipSourcePeaksRange(trackId, c.ClipIndex, ai.SourceOffsetFrames + a * len, ai.SourceOffsetFrames + b * len, buf, n);
+ got = eng.GetClipSourcePeaksRange(trackId, c.ClipIndex, ai.SourceOffsetFrames + a * len, ai.SourceOffsetFrames + b * len, buf, n, rms);
}
if (got <= 0) return false;
if (rev)
@@ -1746,8 +1795,9 @@ public sealed partial class ArrangementView
{
(buf[i * 2], buf[j * 2]) = (buf[j * 2], buf[i * 2]);
(buf[i * 2 + 1], buf[j * 2 + 1]) = (buf[j * 2 + 1], buf[i * 2 + 1]);
+ (rms[i], rms[j]) = (rms[j], rms[i]);
}
- (c.DetailPeaks, c.DetailCount, c.DetailF0, c.DetailF1) = (buf, got, f0, f1);
+ (c.DetailPeaks, c.DetailRms, c.DetailCount, c.DetailF0, c.DetailF1) = (buf, rms, got, f0, f1);
return true;
}
diff --git a/src/managed/Nota.App/ArrangementView.Vms.cs b/src/managed/Nota.App/ArrangementView.Vms.cs
index 6d3a9ff1..fd4728a2 100644
--- a/src/managed/Nota.App/ArrangementView.Vms.cs
+++ b/src/managed/Nota.App/ArrangementView.Vms.cs
@@ -80,11 +80,14 @@ public sealed partial class ArrangementView
public bool Active = true; // false = deactivated (key 0): stays but silent + greyed
public float[]? Peaks;
public int PeakCount;
+ /// <summary>RMS level per bucket of <see cref="Peaks"/> (null when unknown — an import placeholder).</summary>
+ public float[]? Rms;
/// <summary>Peaks over just the visible slice [DetailF0, DetailF1] of the clip (fractions
/// of its played length), at one bucket per pixel — fetched when the clip is drawn wider
/// than <see cref="Peaks"/> has buckets, so a long or zoomed-in clip doesn't draw as
/// blocks (#299).</summary>
public float[]? DetailPeaks;
+ public float[]? DetailRms;
public int DetailCount;
public double DetailF0, DetailF1;
/// <summary>Clip gain (linear) — peaks are raw material, the lane scales them by this.</summary>
diff --git a/src/managed/Nota.App/ArrangementView.cs b/src/managed/Nota.App/ArrangementView.cs
index bc3ba207..bd2e0ce2 100644
--- a/src/managed/Nota.App/ArrangementView.cs
+++ b/src/managed/Nota.App/ArrangementView.cs
@@ -28,8 +28,9 @@ public enum NewTrackKind { Instrument, Audio, Return }
/// <summary>How much of the arrangement names its clips (View ▸ Clip names).</summary>
public enum ClipLabelMode { Every, RunStart, None }
-/// <summary>How audio clips draw their waveform: spaced peak strokes, or a solid column per pixel.</summary>
-public enum WaveformStyle { Bars, Solid }
+/// <summary>How audio clips draw their waveform: the peak outline around its RMS body (default),
+/// a solid column per pixel, or spaced peak strokes. The values are the stored setting.</summary>
+public enum WaveformStyle { Smooth, Solid, Bars }
public sealed partial class ArrangementView : UserControl
{
@@ -567,7 +568,7 @@ public sealed partial class ArrangementView : UserControl
get => _waveform;
set { if (_waveform == value) return; _waveform = value; _lanes.InvalidateVisual(); }
}
- private WaveformStyle _waveform = WaveformStyle.Bars;
+ private WaveformStyle _waveform = WaveformStyle.Smooth;
/// <summary>Show/edit parameter-automation envelopes over the lanes (M9-A3).</summary>
public bool AutomationMode
{
@@ -1074,8 +1075,10 @@ public sealed partial class ArrangementView : UserControl
{
// Unchanged audio clip on a live refresh: reuse the peaks (no native recompute).
cvm.Peaks = prev.Peaks;
+ cvm.Rms = prev.Rms;
cvm.PeakCount = prev.PeakCount;
- (cvm.DetailPeaks, cvm.DetailCount, cvm.DetailF0, cvm.DetailF1) = (prev.DetailPeaks, prev.DetailCount, prev.DetailF0, prev.DetailF1);
+ (cvm.DetailPeaks, cvm.DetailRms, cvm.DetailCount, cvm.DetailF0, cvm.DetailF1)
+ = (prev.DetailPeaks, prev.DetailRms, prev.DetailCount, prev.DetailF0, prev.DetailF1);
}
else
{
@@ -1083,8 +1086,10 @@ public sealed partial class ArrangementView : UserControl
// (the lane draws one aggregated column per pixel).
const int buckets = 2048;
var peaks = new float[buckets * 2];
- cvm.PeakCount = eng.GetClipPeaks(ti.Id, c, peaks, buckets);
+ var rms = new float[buckets];
+ cvm.PeakCount = eng.GetClipPeaks(ti.Id, c, peaks, buckets, rms);
cvm.Peaks = peaks;
+ cvm.Rms = rms;
}
if (!ci.IsMidi && eng.TryGetAudioClipInfo(ti.Id, c, out var ai))
{
diff --git a/src/managed/Nota.App/AudioClipEditorView.cs b/src/managed/Nota.App/AudioClipEditorView.cs
index 74fc03b0..3e5b7379 100644
--- a/src/managed/Nota.App/AudioClipEditorView.cs
+++ b/src/managed/Nota.App/AudioClipEditorView.cs
@@ -91,15 +91,16 @@ public sealed class AudioClipEditorView : UserControl
_wave.DetailPeaks = (f0, f1, n) =>
{
var pk = new float[n * 2];
+ var rms = new float[n];
int got = 0;
if (_warpEnabled)
{
if (_engine.TryGetAudioClipInfo(TrackId, ClipIndex, out var wi) && wi.WarpBeats > 0)
- got = _engine.GetClipWarpPeaksRange(TrackId, ClipIndex, f0 * wi.WarpBeats, f1 * wi.WarpBeats, pk, n);
+ got = _engine.GetClipWarpPeaksRange(TrackId, ClipIndex, f0 * wi.WarpBeats, f1 * wi.WarpBeats, pk, n, rms);
}
else if (_srcFrames > 0)
- got = _engine.GetClipSourcePeaksRange(TrackId, ClipIndex, f0 * _srcFrames, f1 * _srcFrames, pk, n);
- return (pk, got);
+ got = _engine.GetClipSourcePeaksRange(TrackId, ClipIndex, f0 * _srcFrames, f1 * _srcFrames, pk, n, rms);
+ return (pk, rms, got);
};
_wave.SourceRegionCommitted = (off, len) =>
{
@@ -339,13 +340,14 @@ public sealed class AudioClipEditorView : UserControl
// Warp markers (only meaningful while warping). Unwarped clips instead show the
// whole sample with draggable Start/End brackets (source-region editing).
var peaks = new float[1024 * 2];
+ var rms = new float[1024];
int markers = 0;
if (_warpEnabled)
{
// Show the FULL warp with markers + Start/End trim brackets (trim the played
// window without stretching).
- int n = _engine.GetClipWarpFullPeaks(TrackId, ClipIndex, peaks, 1024);
- _wave.SetPeaks(peaks, n);
+ int n = _engine.GetClipWarpFullPeaks(TrackId, ClipIndex, peaks, 1024, rms);
+ _wave.SetPeaks(peaks, rms, n);
var ms = new double[128]; var mb = new double[128];
markers = Math.Min(_engine.GetClipWarpMarkers(TrackId, ClipIndex, ms, mb), 128);
_wave.SetMarkers(ms, mb, markers);
@@ -357,8 +359,8 @@ public sealed class AudioClipEditorView : UserControl
else
{
_wave.SetWarpTrim(0, 0, 0); // warp trim brackets off (unwarped)
- int n = _engine.GetClipSourcePeaks(TrackId, ClipIndex, peaks, 1024);
- _wave.SetPeaks(peaks, n);
+ int n = _engine.GetClipSourcePeaks(TrackId, ClipIndex, peaks, 1024, rms);
+ _wave.SetPeaks(peaks, rms, n);
_wave.SetMarkers(Array.Empty<double>(), Array.Empty<double>(), 0);
_mkSrc = _mkBeat = Array.Empty<double>();
if (haveSample)
@@ -708,8 +710,10 @@ public sealed class AudioClipEditorView : UserControl
private const double RulerH = 24, StripH = 22, WaveTop = RulerH + StripH;
private const int BeatsPerBar = 4; // matches the props-rail bar.beat readouts
private IBrush _wave = NotaPalette.TrackBrushes[1];
- private float[]? _peaks;
+ private float[]? _peaks, _rms;
private int _count;
+ private readonly WaveformPainter _painter = new();
+ private double _scale = 1; // device pixels per DIP, as of the last render
private double _frac = -1;
private double _gain = 1.0;
private readonly System.Collections.Generic.List<(double src, double beat)> _mk = new();
@@ -986,7 +990,7 @@ public sealed class AudioClipEditorView : UserControl
}
public void SetColor(IBrush b) { _wave = b; InvalidateVisual(); }
- public void SetPeaks(float[] peaks, int count) { _peaks = peaks; _count = count; ClearDetail(); InvalidateVisual(); }
+ public void SetPeaks(float[] peaks, float[]? rms, int count) { _peaks = peaks; _rms = rms; _count = count; ClearDetail(); InvalidateVisual(); }
public void SetPlayhead(double frac)
{
if (Math.Abs(frac - _frac) < 1e-4) return;
@@ -1498,15 +1502,15 @@ public sealed class AudioClipEditorView : UserControl
// The overview (_peaks) spans the whole clip at a fixed resolution; zoomed in, the
// host fetches peaks for just the visible slice (padded a screen either side so a
// scroll doesn't refetch at once). Content (file-order) fracs, like the overview.
- /// <summary>Set by the host: peaks over content fracs [f0, f1] at n buckets → (peaks, count).</summary>
- public Func<double, double, int, (float[] peaks, int count)>? DetailPeaks;
- private float[]? _dPeaks;
+ /// <summary>Set by the host: peaks over content fracs [f0, f1] at n buckets → (peaks, rms, count).</summary>
+ public Func<double, double, int, (float[] peaks, float[]? rms, int count)>? DetailPeaks;
+ private float[]? _dPeaks, _dRms;
private int _dCount;
private double _dF0, _dF1;
private bool _detailQueued;
- private const double DetailPx = 1.5; // overview buckets wider than this → fetch detail
+ private const double DetailPx = 1.5; // overview buckets wider than this many device pixels → fetch detail
- private void ClearDetail() { _dPeaks = null; _dCount = 0; }
+ private void ClearDetail() { _dPeaks = null; _dRms = null; _dCount = 0; }
// Visible content-frac range (mirrored back when the clip is drawn reversed).
private (double f0, double f1) VisibleContent(double w)
@@ -1518,7 +1522,7 @@ public sealed class AudioClipEditorView : UserControl
private bool DetailCovers(double f0, double f1, double w)
{
if (_dPeaks is null || _dCount <= 0 || _dF0 > f0 + 1e-12 || _dF1 < f1 - 1e-12) return false;
- double px = (_dF1 - _dF0) * _zoom * w / _dCount; // detail bucket width at this zoom
+ double px = (_dF1 - _dF0) * _zoom * w * _scale / _dCount; // detail bucket width at this zoom, device px
return px <= DetailPx * 1.01 && px >= 0.25; // fine enough, and not zoomed far back out
}
@@ -1535,12 +1539,13 @@ public sealed class AudioClipEditorView : UserControl
double span = b - a;
if (span <= 0) return;
double p0 = Math.Max(0, a - span), p1 = Math.Min(1, b + span);
- int n = (int)Math.Clamp(Math.Ceiling((p1 - p0) * _zoom * ww), 1, MaxDetail);
+ double dev = _zoom * ww * _scale; // device pixels per unit of content frac
+ int n = (int)Math.Clamp(Math.Ceiling((p1 - p0) * dev), 1, MaxDetail);
// Too wide a slice for one fetch → just the visible part.
- if ((p1 - p0) * _zoom * ww / n > DetailPx) { p0 = a; p1 = b; n = (int)Math.Clamp(Math.Ceiling(span * _zoom * ww), 1, MaxDetail); }
- var (pk, cnt) = DetailPeaks(p0, p1, n);
+ if ((p1 - p0) * dev / n > DetailPx) { p0 = a; p1 = b; n = (int)Math.Clamp(Math.Ceiling(span * dev), 1, MaxDetail); }
+ var (pk, rms, cnt) = DetailPeaks(p0, p1, n);
if (cnt <= 0) return;
- _dPeaks = pk; _dCount = cnt; _dF0 = p0; _dF1 = p1;
+ _dPeaks = pk; _dRms = rms; _dCount = cnt; _dF0 = p0; _dF1 = p1;
InvalidateVisual();
}, DispatcherPriority.Background);
}
@@ -1548,41 +1553,48 @@ public sealed class AudioClipEditorView : UserControl
// Peaks whose buckets evenly span content fracs [f0, f1], drawn through the zoom/
// scroll (and mirror) axis; only the visible buckets are visited.
- private void DrawPeaks(DrawingContext ctx, float[] peaks, int count, double f0, double f1, double w,
+ private void DrawPeaks(DrawingContext ctx, float[] peaks, float[]? rms, int count, double f0, double f1, double w,
double mid, double wh, AdsrFrame adsrF, ClipAdsr adsrFit, bool shaped)
{
double amp = wh / 2 - 6;
double span = f1 - f0;
if (span <= 0) return;
- if (Remapped) { DrawPeaksRemapped(ctx, peaks, count, f0, f1, w, mid, amp, adsrF, adsrFit, shaped); return; }
- double bwRaw = span * _zoom * w / count;
- double bw = Math.Max(1, bwRaw);
- var (c0, c1) = VisibleContent(w);
- int i0 = Math.Max(0, (int)Math.Floor((c0 - f0) / span * count) - 1);
- int i1 = Math.Min(count - 1, (int)Math.Ceiling((c1 - f0) / span * count) + 1);
- for (int i = i0; i <= i1; i++)
+ _painter.Begin(_scale);
+ if (Remapped) AddPeaksRemapped(peaks, rms, count, f0, f1, w, adsrF, adsrFit, shaped);
+ else
{
- // FracToX marks the bucket's leading edge — its RIGHT edge once mirrored.
- double fx = FracToX(f0 + span * i / count, w);
- if (_reversed) fx -= bwRaw;
- if (fx + bw < 0 || fx > w) continue;
- // The ADSR shapes the played region the way it sounds (outside it is darkened anyway).
- double g = _gain;
- if (shaped)
+ double bw = span * _zoom * w / count;
+ var (c0, c1) = VisibleContent(w);
+ int i0 = Math.Max(0, (int)Math.Floor((c0 - f0) / span * count) - 1);
+ int i1 = Math.Min(count - 1, (int)Math.Ceiling((c1 - f0) / span * count) + 1);
+ for (int i = i0; i <= i1; i++)
{
- double bt = adsrF.Beat(fx + bw / 2);
- if (bt >= 0 && bt <= _adsrLen) g *= adsrFit.GainAt(bt, _adsrLen);
+ // FracToX marks the bucket's leading edge — its RIGHT edge once mirrored.
+ double fx = FracToX(f0 + span * i / count, w);
+ if (_reversed) fx -= bw;
+ AddBucket(peaks, rms, i, fx, fx + bw, adsrF, adsrFit, shaped);
}
- float mn = (float)Math.Clamp(peaks[i * 2] * g, -1.0, 1.0);
- float mx = (float)Math.Clamp(peaks[i * 2 + 1] * g, -1.0, 1.0);
- ctx.FillRectangle(_wave, new Rect(fx, mid - mx * amp, bw, Math.Max(1, (mx - mn) * amp)));
}
+ _painter.Fill(ctx, mid, amp, WaveformPainter.PeakInk(_wave), _wave);
+ }
+
+ private void AddBucket(float[] peaks, float[]? rms, int i, double x0, double x1, AdsrFrame adsrF, ClipAdsr adsrFit, bool shaped)
+ {
+ // The ADSR shapes the played region the way it sounds (outside it is darkened anyway).
+ double g = _gain;
+ if (shaped)
+ {
+ double bt = adsrF.Beat((x0 + x1) / 2);
+ if (bt >= 0 && bt <= _adsrLen) g *= adsrFit.GainAt(bt, _adsrLen);
+ }
+ _painter.Add(x0, x1, (float)Math.Clamp(peaks[i * 2] * g, -1.0, 1.0), (float)Math.Clamp(peaks[i * 2 + 1] * g, -1.0, 1.0),
+ rms is null ? -1f : (float)Math.Min(1.0, rms[i] * g));
}
// The peaks re-timed to the live markers: each bucket's committed beat span is carried to
// where the live markers put that audio, so the wave stretches with the drag.
- private void DrawPeaksRemapped(DrawingContext ctx, float[] peaks, int count, double f0, double f1, double w,
- double mid, double amp, AdsrFrame adsrF, ClipAdsr adsrFit, bool shaped)
+ private void AddPeaksRemapped(float[] peaks, float[]? rms, int count, double f0, double f1, double w,
+ AdsrFrame adsrF, ClipAdsr adsrFit, bool shaped)
{
for (int i = 0; i < _mk.Count; i++) _lBeat[i] = _mk[i].beat;
double oldTotal = _cBeat[^1], span = f1 - f0;
@@ -1592,18 +1604,10 @@ public sealed class AudioClipEditorView : UserControl
for (int i = 0; i < count; i++)
{
double xb = XAtBucket(i + 1);
- double lo = Math.Min(xa, xb), bw = Math.Max(1, Math.Abs(xb - xa));
+ double lo = Math.Min(xa, xb), hi = Math.Max(xa, xb);
xa = xb;
- if (lo + bw < 0 || lo > w) continue;
- double g = _gain;
- if (shaped)
- {
- double bt = adsrF.Beat(lo + bw / 2);
- if (bt >= 0 && bt <= _adsrLen) g *= adsrFit.GainAt(bt, _adsrLen);
- }
- float mn = (float)Math.Clamp(peaks[i * 2] * g, -1.0, 1.0);
- float mx = (float)Math.Clamp(peaks[i * 2 + 1] * g, -1.0, 1.0);
- ctx.FillRectangle(_wave, new Rect(lo, mid - mx * amp, bw, Math.Max(1, (mx - mn) * amp)));
+ if (hi < 0 || lo > w) continue;
+ AddBucket(peaks, rms, i, lo, hi, adsrF, adsrFit, shaped);
}
}
@@ -1655,6 +1659,7 @@ public sealed class AudioClipEditorView : UserControl
// Zoomed in, buckets, markers and the playhead can sit past either edge: keep every
// stroke inside the editor instead of over the inspector or the panel beside it.
using var bounds = ctx.PushClip(new Rect(0, 0, w, h));
+ _scale = WaveformPainter.Scale(this);
double top = WaveTop, wh = Math.Max(0, h - top);
ctx.FillRectangle(Bg, new Rect(0, 0, w, h));
_bpmHot.Clear();
@@ -1701,12 +1706,12 @@ public sealed class AudioClipEditorView : UserControl
// detail keeps drawing wherever it reaches (it's still far finer than the
// overview), so zooming never flashes back to the overview's wide blocks.
var (c0, c1) = VisibleContent(w);
- bool coarse = _zoom * w / _count > DetailPx;
+ bool coarse = _zoom * w * _scale / _count > DetailPx;
if (coarse && !DetailCovers(c0, c1, w)) RequestDetail();
bool useDetail = coarse && _dPeaks is not null && _dCount > 0
&& (_dF1 - _dF0) / _dCount < 1.0 / _count && _dF1 > c0 && _dF0 < c1;
if (!useDetail)
- DrawPeaks(ctx, _peaks, _count, 0, 1, w, mid, wh, adsrF, adsrFit, shaped);
+ DrawPeaks(ctx, _peaks, _rms, _count, 0, 1, w, mid, wh, adsrF, adsrFit, shaped);
else
{
// The overview only outside the detail's span, the detail inside it.
@@ -1714,12 +1719,12 @@ public sealed class AudioClipEditorView : UserControl
if (xa > xb) (xa, xb) = (xb, xa);
if (xa > 0)
using (ctx.PushClip(new Rect(0, top, xa, wh)))
- DrawPeaks(ctx, _peaks, _count, 0, 1, w, mid, wh, adsrF, adsrFit, shaped);
+ DrawPeaks(ctx, _peaks, _rms, _count, 0, 1, w, mid, wh, adsrF, adsrFit, shaped);
if (xb < w)
using (ctx.PushClip(new Rect(xb, top, w - xb, wh)))
- DrawPeaks(ctx, _peaks, _count, 0, 1, w, mid, wh, adsrF, adsrFit, shaped);
+ DrawPeaks(ctx, _peaks, _rms, _count, 0, 1, w, mid, wh, adsrF, adsrFit, shaped);
using (ctx.PushClip(new Rect(Math.Max(0, xa), top, Math.Max(0, Math.Min(w, xb) - Math.Max(0, xa)), wh)))
- DrawPeaks(ctx, _dPeaks!, _dCount, _dF0, _dF1, w, mid, wh, adsrF, adsrFit, shaped);
+ DrawPeaks(ctx, _dPeaks!, _dRms, _dCount, _dF0, _dF1, w, mid, wh, adsrF, adsrFit, shaped);
}
}
diff --git a/src/managed/Nota.App/MainWindow.axaml.cs b/src/managed/Nota.App/MainWindow.axaml.cs
index 5a774b66..f770398f 100644
--- a/src/managed/Nota.App/MainWindow.axaml.cs
+++ b/src/managed/Nota.App/MainWindow.axaml.cs
@@ -396,10 +396,10 @@ public partial class MainWindow : Window
vm.Settings.Current.LoopRecordReplace = vm.Transport.LoopRecordReplace;
vm.Settings.Save();
};
- Timeline.Waveform = (WaveformStyle)Math.Clamp(vm.Settings.Current.ArrangementWaveform, 0, 1);
+ Timeline.Waveform = (WaveformStyle)Math.Clamp(vm.Settings.Current.ArrangementWaveform, 0, 2);
InitSnapGrid();
// Settings → Appearance can switch the waveform style while the arrangement is open.
- vm.Settings.Changed += () => Timeline.Waveform = (WaveformStyle)Math.Clamp(vm.Settings.Current.ArrangementWaveform, 0, 1);
+ vm.Settings.Changed += () => Timeline.Waveform = (WaveformStyle)Math.Clamp(vm.Settings.Current.ArrangementWaveform, 0, 2);
Browser.SetViewModel(vm.Browser);
InitPalette(); // the command palette (⌘⇧P) indexes the library and the registry
Browser.ProjectTempo = () => (double)vm.Transport.Bpm; // the Files filter's "project" shortcuts
diff --git a/src/managed/Nota.App/PreferencesWindow.cs b/src/managed/Nota.App/PreferencesWindow.cs
index f7399e85..609a0563 100644
--- a/src/managed/Nota.App/PreferencesWindow.cs
+++ b/src/managed/Nota.App/PreferencesWindow.cs
@@ -1158,14 +1158,15 @@ public sealed partial class PreferencesWindow : NotaWindow
}
}
- // Bars / Solid for the arrangement's audio-clip waveforms and the browser preview. Saving
+ // Smooth / Solid / Bars for the arrangement's audio-clip waveforms (Solid and Bars also set
+ // the browser preview). Saving
// fires Settings.Changed, which the lanes and the preview apply at once.
private static Control WaveformPicker()
{
var settings = App.Services.GetRequiredService<ISettingsService>();
var strip = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 2 };
var buttons = new List<(int Style, ToggleButton Btn)>();
- foreach (var (style, label) in new[] { (0, "Bars"), (1, "Solid") })
+ foreach (var (style, label) in new[] { (0, "Smooth"), (1, "Solid"), (2, "Bars") })
{
var st = style;
var btn = new ToggleButton { Classes = { "seg" }, FontSize = 12, Content = label, IsChecked = settings.Current.ArrangementWaveform == st };
@@ -1295,7 +1296,7 @@ public sealed partial class PreferencesWindow : NotaWindow
TopRow("Colour theme", ThemePicker()),
Row("", Caption("Themes change colours only. Follow system switches between your dark-mode and light-mode theme with the OS appearance.")),
Row("Waveform", WaveformPicker()),
- Row("", Caption("How audio clips draw on the arrangement, and samples in the browser's preview: Bars spaces the peaks out so the rhythm reads; Solid draws every pixel.")),
+ Row("", Caption("How audio clips draw on the arrangement: Smooth outlines the peaks around the RMS level; Solid draws every pixel; Bars spaces the peaks out so the rhythm reads. Solid and Bars also set the browser's preview.")),
Row("Interface scale", ScalePicker()),
Row("", Caption("Makes the whole interface larger or smaller. Timeline, piano roll and audio editor zoom work on top of it."))),
Section("AI control (MCP)", 12, enable, details));
diff --git a/src/managed/Nota.App/PreviewPlayer.cs b/src/managed/Nota.App/PreviewPlayer.cs
index abbad2f4..a11dab8b 100644
--- a/src/managed/Nota.App/PreviewPlayer.cs
+++ b/src/managed/Nota.App/PreviewPlayer.cs
@@ -259,7 +259,7 @@ public sealed class PreviewPlayer : UserControl
_fxTrack = track == AuditionTrackIds.Sample || audition.Tracks.Any(t => t.Id == track) ? track : AuditionTrackIds.Auto;
SetSpectrum(settings.Current.BrowserPreviewSpectrum, persist: false);
// The Appearance → Waveform choice draws the well too, and follows it live (#107).
- void ApplyWaveform() => _wave.Style = (WaveformStyle)Math.Clamp(settings.Current.ArrangementWaveform, 0, 1);
+ void ApplyWaveform() => _wave.Style = (WaveformStyle)Math.Clamp(settings.Current.ArrangementWaveform, 0, 2);
ApplyWaveform();
settings.Changed += ApplyWaveform;
}
@@ -920,7 +920,7 @@ public sealed class PreviewWaveform : Control
public void SetPeaks(float[]? peaks) { _peaks = peaks; InvalidateVisual(); }
- /// <summary>Bars (spaced strokes) or Solid (one column per pixel), as Appearance → Waveform sets.</summary>
+ /// <summary>Solid (one column per pixel) or spaced strokes for the other styles, as Appearance → Waveform sets.</summary>
public WaveformStyle Style
{
get => _style;
diff --git a/src/managed/Nota.App/WaveformPainter.cs b/src/managed/Nota.App/WaveformPainter.cs
new file mode 100644
index 00000000..0444fb05
--- /dev/null
+++ b/src/managed/Nota.App/WaveformPainter.cs
@@ -0,0 +1,184 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.
+
+using System;
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Media;
+
+namespace Nota.App;
+
+/// <summary>
+/// The default waveform look for audio clips on the lanes and in the clip editor (#267): the
+/// min/max peak envelope as one anti-aliased outline in a lighter ink, the RMS body inside it in
+/// the full ink. Peak buckets are folded into device-pixel columns (every bucket under a column
+/// counts, so nothing aliases away when zoomed out) and buckets wider than a column become one
+/// vertex at their centre, joined by straight edges, so a zoomed-in wave slopes instead of
+/// stepping. One instance per view; it reuses its buffers across repaints.
+/// </summary>
+internal sealed class WaveformPainter
+{
+ // Peak envelope over the clip body: ink at this alpha, the body at full ink.
+ private const byte PeakAlpha = 0x8C;
+
+ private double[] _x = new double[512];
+ private float[] _lo = new float[512], _hi = new float[512], _rms = new float[512];
+ private int _n;
+ private double _col = 1;
+ private bool _hasRms;
+ private double _minX, _maxX;
+
+ private bool _open;
+ private long _key;
+ private double _cx0, _cx1, _cSq, _cW;
+ private float _cLo, _cHi;
+
+ /// <summary>The ink for the peak envelope around a body drawn in <paramref name="ink"/>.</summary>
+ public static IBrush PeakInk(IBrush ink) => ink is SolidColorBrush s ? NotaPalette.Wash(s, PeakAlpha) : ink;
+
+ /// <summary>Device pixels per DIP a control renders at: the screen's scaling (2 on a Retina
+ /// display) times the interface scale, which enlarges everything through a LayoutTransform the
+ /// RenderScaling doesn't include (at 200 % one DIP is twice as many device pixels).</summary>
+ public static double Scale(Visual v) => (TopLevel.GetTopLevel(v)?.RenderScaling ?? 1.0) * NotaUiScale.Factor;
+
+ public void Begin(double renderScaling)
+ {
+ _col = 1.0 / Math.Max(0.25, renderScaling);
+ _n = 0;
+ _open = false;
+ _hasRms = true;
+ _minX = double.MaxValue;
+ _maxX = double.MinValue;
+ }
+
+ /// <summary>One peak bucket spanning x0..x1 (DIPs), gain already applied. Buckets arrive
+ /// in screen order, left→right or right→left. A negative rms means none is known: the
+ /// wave then draws its envelope only.</summary>
+ public void Add(double x0, double x1, float min, float max, float rms)
+ {
+ if (x1 < x0) (x0, x1) = (x1, x0);
+ if (min > max) return; // "no data" bucket
+ if (rms < 0) _hasRms = false;
+ _minX = Math.Min(_minX, x0);
+ _maxX = Math.Max(_maxX, x1);
+ double w = x1 - x0;
+ if (w >= _col)
+ {
+ Flush();
+ Emit((x0 + x1) / 2, min, max, rms);
+ return;
+ }
+ long key = (long)Math.Floor((x0 + x1) / 2 / _col);
+ if (_open && key != _key) Flush();
+ if (!_open)
+ {
+ (_open, _key, _cx0, _cx1, _cLo, _cHi, _cSq, _cW) = (true, key, x0, x1, min, max, 0, 0);
+ }
+ else
+ {
+ _cx0 = Math.Min(_cx0, x0); _cx1 = Math.Max(_cx1, x1);
+ _cLo = Math.Min(_cLo, min); _cHi = Math.Max(_cHi, max);
+ }
+ double ww = Math.Max(w, 1e-9);
+ _cSq += (double)rms * rms * ww;
+ _cW += ww;
+ }
+
+ /// <summary>Fills what was added: the envelope in <paramref name="peakInk"/>, the RMS body
+ /// in <paramref name="bodyInk"/>, about <paramref name="mid"/> with ±1 at ±<paramref name="amp"/>.</summary>
+ public void Fill(DrawingContext ctx, double mid, double amp, IBrush peakInk, IBrush bodyInk)
+ {
+ Flush();
+ if (_n == 0 || amp <= 0) return;
+ if (_x[0] > _x[_n - 1]) Reverse();
+ // Hold the outermost buckets out to their edges, so the wave starts and ends where the
+ // audio does rather than half a bucket in.
+ if (_minX < _x[0] - 1e-6) Insert(0, _minX);
+ if (_maxX > _x[_n - 1] + 1e-6) Insert(_n, _maxX);
+
+ // Never thinner than a device pixel: silence still reads as a line.
+ double minSpan = _col / amp;
+ for (int i = 0; i < _n; i++)
+ {
+ double span = _hi[i] - _lo[i];
+ if (span >= minSpan) continue;
+ double c = (_hi[i] + _lo[i]) / 2;
+ _lo[i] = (float)(c - minSpan / 2);
+ _hi[i] = (float)(c + minSpan / 2);
+ }
+
+ var peak = new StreamGeometry();
+ using (var g = peak.Open())
+ {
+ g.BeginFigure(new Point(_x[0], mid - _hi[0] * amp), true);
+ for (int i = 1; i < _n; i++) g.LineTo(new Point(_x[i], mid - _hi[i] * amp));
+ for (int i = _n - 1; i >= 0; i--) g.LineTo(new Point(_x[i], mid - _lo[i] * amp));
+ g.EndFigure(true);
+ }
+ ctx.DrawGeometry(peakInk, null, peak);
+ if (!_hasRms) return;
+
+ // The body is ±RMS about the centre line, cut to the bucket's own min..max: a bucket of a
+ // few samples on one side of zero (zoomed to the samples) then thins to the trace
+ // instead of filling down to the centre.
+ var body = new StreamGeometry();
+ using (var g = body.Open())
+ {
+ g.BeginFigure(new Point(_x[0], mid - Up(0) * amp), true);
+ for (int i = 1; i < _n; i++) g.LineTo(new Point(_x[i], mid - Up(i) * amp));
+ for (int i = _n - 1; i >= 0; i--) g.LineTo(new Point(_x[i], mid - Down(i) * amp));
+ g.EndFigure(true);
+ }
+ ctx.DrawGeometry(bodyInk, null, body);
+ }
+
+ private double Up(int i) => Math.Clamp(_rms[i], _lo[i], _hi[i]);
+ private double Down(int i) => Math.Clamp(-_rms[i], _lo[i], _hi[i]);
+
+ private void Flush()
+ {
+ if (!_open) return;
+ _open = false;
+ Emit((_cx0 + _cx1) / 2, _cLo, _cHi, (float)Math.Sqrt(_cSq / Math.Max(_cW, 1e-12)));
+ }
+
+ private void Emit(double x, float lo, float hi, float rms)
+ {
+ if (_n == _x.Length) Grow();
+ _x[_n] = x; _lo[_n] = lo; _hi[_n] = hi; _rms[_n] = Math.Max(0f, rms);
+ _n++;
+ }
+
+ private void Insert(int at, double x)
+ {
+ int from = at == 0 ? 0 : _n - 1;
+ float lo = _lo[from], hi = _hi[from], rms = _rms[from];
+ if (_n == _x.Length) Grow();
+ if (at < _n)
+ {
+ Array.Copy(_x, at, _x, at + 1, _n - at);
+ Array.Copy(_lo, at, _lo, at + 1, _n - at);
+ Array.Copy(_hi, at, _hi, at + 1, _n - at);
+ Array.Copy(_rms, at, _rms, at + 1, _n - at);
+ }
+ _x[at] = x; _lo[at] = lo; _hi[at] = hi; _rms[at] = rms;
+ _n++;
+ }
+
+ private void Reverse()
+ {
+ Array.Reverse(_x, 0, _n);
+ Array.Reverse(_lo, 0, _n);
+ Array.Reverse(_hi, 0, _n);
+ Array.Reverse(_rms, 0, _n);
+ }
+
+ private void Grow()
+ {
+ int n = _x.Length * 2;
+ Array.Resize(ref _x, n);
+ Array.Resize(ref _lo, n);
+ Array.Resize(ref _hi, n);
+ Array.Resize(ref _rms, n);
+ }
+}
diff --git a/src/managed/Nota.App/WaveformView.cs b/src/managed/Nota.App/WaveformView.cs
deleted file mode 100644
index e3db3889..00000000
--- a/src/managed/Nota.App/WaveformView.cs
+++ /dev/null
@@ -1,52 +0,0 @@
-// SPDX-License-Identifier: AGPL-3.0-only
-// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.
-
-using Avalonia;
-using Avalonia.Controls;
-using Avalonia.Media;
-
-namespace Nota.App;
-
-/// <summary>
-/// Draws a clip's min/max waveform peaks. Peaks are fetched once from the engine
-/// (message thread) and cached; rendering uses Avalonia's Skia-backed
-/// DrawingContext (NFR-4).
-/// </summary>
-public sealed class WaveformView : Control
-{
- private float[]? _peaks;
- private int _buckets;
-
- // Design tokens (see DESIGN.md): a waveform at rest is neutral viz ink on the well.
- private static readonly IBrush Background = NotaPalette.BgSunken;
- private static readonly IPen WavePen = new Pen(NotaPalette.VizInk, 1);
- private static readonly IPen MidPen = new Pen(NotaPalette.Rule, 1);
-
- public void SetPeaks(float[] minMax, int buckets)
- {
- _peaks = minMax;
- _buckets = buckets;
- InvalidateVisual();
- }
-
- public override void Render(DrawingContext context)
- {
- var bounds = new Rect(Bounds.Size);
- context.FillRectangle(Background, bounds);
-
- double w = bounds.Width, h = bounds.Height, mid = h / 2.0;
- context.DrawLine(MidPen, new Point(0, mid), new Point(w, mid));
-
- if (_peaks is null || _buckets <= 0) return;
-
- for (int i = 0; i < _buckets; i++)
- {
- double x = i * w / _buckets;
- float mn = _peaks[i * 2];
- float mx = _peaks[i * 2 + 1];
- double y1 = mid - mx * mid;
- double y2 = mid - mn * mid;
- context.DrawLine(WavePen, new Point(x, y1), new Point(x, y2));
- }
- }
-}
diff --git a/src/managed/Nota.Application/Engine/IAudioEngine.cs b/src/managed/Nota.Application/Engine/IAudioEngine.cs
index 770c5af3..72f87cf5 100644
--- a/src/managed/Nota.Application/Engine/IAudioEngine.cs
+++ b/src/managed/Nota.Application/Engine/IAudioEngine.cs
@@ -368,15 +368,16 @@ public interface IAudioEngine : IDisposable
/// <summary>Restores a frozen track's audio blob and marks it frozen.</summary>
void SetFreezeState(int trackId, byte[] data);
- int GetClipPeaks(int trackId, int clipIndex, float[] outMinMax, int maxPoints);
+ // Each peaks call also fills outRms (one RMS level per bucket, the waveform's body) when given.
+ int GetClipPeaks(int trackId, int clipIndex, float[] outMinMax, int maxPoints, float[]? outRms = null);
/// <summary>Peaks over the whole sample (ignores the trimmed region) for the clip editor's Start/End brackets.</summary>
- int GetClipSourcePeaks(int trackId, int clipIndex, float[] outMinMax, int maxPoints);
+ int GetClipSourcePeaks(int trackId, int clipIndex, float[] outMinMax, int maxPoints, float[]? outRms = null);
/// <summary>Peaks over the full warped material (ignores the trim window) for the warped-clip Start/End brackets.</summary>
- int GetClipWarpFullPeaks(int trackId, int clipIndex, float[] outMinMax, int maxPoints);
+ int GetClipWarpFullPeaks(int trackId, int clipIndex, float[] outMinMax, int maxPoints, float[]? outRms = null);
/// <summary>Peaks over warped beats [beat0, beat1] of the full material, file order (≤ 8192 points) — the zoomed clip editor's detail.</summary>
- int GetClipWarpPeaksRange(int trackId, int clipIndex, double beat0, double beat1, float[] outMinMax, int maxPoints);
+ int GetClipWarpPeaksRange(int trackId, int clipIndex, double beat0, double beat1, float[] outMinMax, int maxPoints, float[]? outRms = null);
/// <summary>Peaks over source frames [frame0, frame1) of the whole sample (≤ 8192 points) — the zoomed clip editor's detail.</summary>
- int GetClipSourcePeaksRange(int trackId, int clipIndex, double frame0, double frame1, float[] outMinMax, int maxPoints);
+ int GetClipSourcePeaksRange(int trackId, int clipIndex, double frame0, double frame1, float[] outMinMax, int maxPoints, float[]? outRms = null);
// --- Instrument tracks, MIDI clips & notes -----------------------------
int AddInstrumentTrack();
diff --git a/src/managed/Nota.Application/Settings.cs b/src/managed/Nota.Application/Settings.cs
index cc00886a..bb01c116 100644
--- a/src/managed/Nota.Application/Settings.cs
+++ b/src/managed/Nota.Application/Settings.cs
@@ -162,7 +162,9 @@ public sealed class Settings
/// <summary>Show the song-structure (sections) lane over the ruler.</summary>
public bool ArrangementShowSections { get; set; } = true;
/// <summary>How audio clips draw their waveform on the lanes (Settings → Appearance):
- /// 0 bars — spaced peak strokes (default), 1 solid — one column per pixel.</summary>
+ /// 0 smooth — the peak outline around its RMS body (default; was bars before #267, so a
+ /// saved 0 moves to the new default), 1 solid — one column per pixel, 2 bars — spaced
+ /// peak strokes.</summary>
public int ArrangementWaveform { get; set; }
/// <summary>Interface scale in percent (Settings → Appearance, spec 027): one of
/// <see cref="Application.InterfaceScale.Presets"/>; anything else reads as 100.</summary>
diff --git a/src/managed/Nota.Infrastructure/Interop/NativeMethods.Tracks.cs b/src/managed/Nota.Infrastructure/Interop/NativeMethods.Tracks.cs
index 0b651744..64741d61 100644
--- a/src/managed/Nota.Infrastructure/Interop/NativeMethods.Tracks.cs
+++ b/src/managed/Nota.Infrastructure/Interop/NativeMethods.Tracks.cs
@@ -373,6 +373,13 @@ internal static partial class NativeMethods
internal static partial int ClipGetSourcePeaksRange(IntPtr engine, int trackId, int clipIndex, double frame0, double frame1,
[Out] float[] outMinMax, int maxPoints);
+ internal const int ClipLevelsPlayed = 0, ClipLevelsSource = 1, ClipLevelsWarpFull = 2,
+ ClipLevelsWarpRange = 3, ClipLevelsSourceRange = 4; // NOTA_CLIP_LEVELS_*
+
+ [LibraryImport(Lib, EntryPoint = "nota_clip_get_levels")]
+ internal static partial int ClipGetLevels(IntPtr engine, int trackId, int clipIndex, int view, double a, double b,
+ [Out] float[] outMinMax, [Out] float[] outRms, int maxPoints);
+
[LibraryImport(Lib, EntryPoint = "nota_engine_add_instrument_track")]
internal static partial int AddInstrumentTrack(IntPtr engine);
diff --git a/src/managed/Nota.Infrastructure/Interop/NotaEngine.Tracks.cs b/src/managed/Nota.Infrastructure/Interop/NotaEngine.Tracks.cs
index 47e1d8dc..b57f5354 100644
--- a/src/managed/Nota.Infrastructure/Interop/NotaEngine.Tracks.cs
+++ b/src/managed/Nota.Infrastructure/Interop/NotaEngine.Tracks.cs
@@ -605,40 +605,55 @@ public sealed partial class NotaEngine
}
/// <summary>Fetches waveform peaks (min,max pairs) for a clip. Returns the number of buckets written.</summary>
- public int GetClipPeaks(int trackId, int clipIndex, float[] outMinMax, int maxPoints)
+ public int GetClipPeaks(int trackId, int clipIndex, float[] outMinMax, int maxPoints, float[]? outRms = null)
{
ThrowIfDisposed();
- return NativeMethods.ClipGetPeaks(_handle, trackId, clipIndex, outMinMax, maxPoints);
+ return outRms is null
+ ? NativeMethods.ClipGetPeaks(_handle, trackId, clipIndex, outMinMax, maxPoints)
+ : Levels(NativeMethods.ClipLevelsPlayed, trackId, clipIndex, 0, 0, outMinMax, maxPoints, outRms);
}
/// <summary>Fetches peaks over the whole sample (ignores the clip's trimmed region) for the clip editor.</summary>
- public int GetClipSourcePeaks(int trackId, int clipIndex, float[] outMinMax, int maxPoints)
+ public int GetClipSourcePeaks(int trackId, int clipIndex, float[] outMinMax, int maxPoints, float[]? outRms = null)
{
ThrowIfDisposed();
- return NativeMethods.ClipGetSourcePeaks(_handle, trackId, clipIndex, outMinMax, maxPoints);
+ return outRms is null
+ ? NativeMethods.ClipGetSourcePeaks(_handle, trackId, clipIndex, outMinMax, maxPoints)
+ : Levels(NativeMethods.ClipLevelsSource, trackId, clipIndex, 0, 0, outMinMax, maxPoints, outRms);
}
/// <summary>Fetches peaks over the full warped material (ignores the trim window) for the clip editor.</summary>
- public int GetClipWarpFullPeaks(int trackId, int clipIndex, float[] outMinMax, int maxPoints)
+ public int GetClipWarpFullPeaks(int trackId, int clipIndex, float[] outMinMax, int maxPoints, float[]? outRms = null)
{
ThrowIfDisposed();
- return NativeMethods.ClipGetWarpFullPeaks(_handle, trackId, clipIndex, outMinMax, maxPoints);
+ return outRms is null
+ ? NativeMethods.ClipGetWarpFullPeaks(_handle, trackId, clipIndex, outMinMax, maxPoints)
+ : Levels(NativeMethods.ClipLevelsWarpFull, trackId, clipIndex, 0, 0, outMinMax, maxPoints, outRms);
}
/// <summary>Peaks over warped beats [beat0, beat1] of the full material (zoomed clip editor).</summary>
- public int GetClipWarpPeaksRange(int trackId, int clipIndex, double beat0, double beat1, float[] outMinMax, int maxPoints)
+ public int GetClipWarpPeaksRange(int trackId, int clipIndex, double beat0, double beat1, float[] outMinMax, int maxPoints, float[]? outRms = null)
{
ThrowIfDisposed();
- return NativeMethods.ClipGetWarpPeaksRange(_handle, trackId, clipIndex, beat0, beat1, outMinMax, maxPoints);
+ return outRms is null
+ ? NativeMethods.ClipGetWarpPeaksRange(_handle, trackId, clipIndex, beat0, beat1, outMinMax, maxPoints)
+ : Levels(NativeMethods.ClipLevelsWarpRange, trackId, clipIndex, beat0, beat1, outMinMax, maxPoints, outRms);
}
/// <summary>Peaks over source frames [frame0, frame1) of the whole sample (zoomed clip editor).</summary>
- public int GetClipSourcePeaksRange(int trackId, int clipIndex, double frame0, double frame1, float[] outMinMax, int maxPoints)
+ public int GetClipSourcePeaksRange(int trackId, int clipIndex, double frame0, double frame1, float[] outMinMax, int maxPoints, float[]? outRms = null)
{
ThrowIfDisposed();
- return NativeMethods.ClipGetSourcePeaksRange(_handle, trackId, clipIndex, frame0, frame1, outMinMax, maxPoints);
+ return outRms is null
+ ? NativeMethods.ClipGetSourcePeaksRange(_handle, trackId, clipIndex, frame0, frame1, outMinMax, maxPoints)
+ : Levels(NativeMethods.ClipLevelsSourceRange, trackId, clipIndex, frame0, frame1, outMinMax, maxPoints, outRms);
}
+ // Both buffers must hold maxPoints buckets; the native side writes past neither.
+ private int Levels(int view, int trackId, int clipIndex, double a, double b, float[] outMinMax, int maxPoints, float[] outRms)
+ => NativeMethods.ClipGetLevels(_handle, trackId, clipIndex, view, a, b, outMinMax, outRms,
+ System.Math.Min(maxPoints, System.Math.Min(outMinMax.Length / 2, outRms.Length)));
+
// --- Instrument tracks, MIDI clips & notes -----------------------------
/// <summary>Adds an instrument track with the built-in Nota Synth. Returns its id.</summary>
diff --git a/src/native/nota.engine/include/nota/nota_engine.h b/src/native/nota.engine/include/nota/nota_engine.h
index bae9b599..2b0dd4ad 100644
--- a/src/native/nota.engine/include/nota/nota_engine.h
+++ b/src/native/nota.engine/include/nota/nota_engine.h
@@ -609,6 +609,19 @@ NOTA_API int32_t nota_clip_get_source_peaks_range(const NotaEngine* engine, int3
int32_t clip_index, double frame0, double frame1,
float* out_min_max, int32_t max_points);
+/* Waveform levels: the same min/max buckets as the matching *_peaks call above, plus each
+ * bucket's RMS of the stereo mid (0..1) in out_rms[max_points] — the waveform's body.
+ * view picks the call; a and b are its range (beats for WARP_RANGE, frames for
+ * SOURCE_RANGE) and are ignored by the others. Returns the number of buckets written. */
+#define NOTA_CLIP_LEVELS_PLAYED 0 /* nota_clip_get_peaks */
+#define NOTA_CLIP_LEVELS_SOURCE 1 /* nota_clip_get_source_peaks */
+#define NOTA_CLIP_LEVELS_WARP_FULL 2 /* nota_clip_get_warp_full_peaks */
+#define NOTA_CLIP_LEVELS_WARP_RANGE 3 /* nota_clip_get_warp_peaks_range */
+#define NOTA_CLIP_LEVELS_SOURCE_RANGE 4 /* nota_clip_get_source_peaks_range */
+NOTA_API int32_t nota_clip_get_levels(const NotaEngine* engine, int32_t track_id, int32_t clip_index,
+ int32_t view, double a, double b, float* out_min_max,
+ float* out_rms, int32_t max_points);
+
/* ---- Background audio import -------------------------------------------- */
/* Decodes a WAV/FLAC/MP3 block by block on ANY thread (it touches no engine state), so
* the UI stays responsive and can draw the waveform as it fills in. One job is not
diff --git a/src/native/nota.engine/src/abi/nota_engine_track.cpp b/src/native/nota.engine/src/abi/nota_engine_track.cpp
index 638d8d64..f34fbfda 100644
--- a/src/native/nota.engine/src/abi/nota_engine_track.cpp
+++ b/src/native/nota.engine/src/abi/nota_engine_track.cpp
@@ -128,6 +128,23 @@ int32_t nota_clip_get_source_peaks_range(const NotaEngine* e, int32_t track_id,
if (!e) return 0;
return CENG(e)->getClipSourcePeaksRange(track_id, clip_index, frame0, frame1, out_min_max, max_points);
}
+int32_t nota_clip_get_levels(const NotaEngine* e, int32_t track_id, int32_t clip_index, int32_t view, double a,
+ double b, float* out_min_max, float* out_rms, int32_t max_points) {
+ if (!e || !out_min_max || max_points <= 0) return 0;
+ auto* eng = CENG(e);
+ switch (view) {
+ case NOTA_CLIP_LEVELS_PLAYED: return eng->getClipPeaks(track_id, clip_index, out_min_max, max_points, out_rms);
+ case NOTA_CLIP_LEVELS_SOURCE:
+ return eng->getClipSourcePeaks(track_id, clip_index, out_min_max, max_points, out_rms);
+ case NOTA_CLIP_LEVELS_WARP_FULL:
+ return eng->getClipWarpFullPeaks(track_id, clip_index, out_min_max, max_points, out_rms);
+ case NOTA_CLIP_LEVELS_WARP_RANGE:
+ return eng->getClipWarpPeaksRange(track_id, clip_index, a, b, out_min_max, max_points, out_rms);
+ case NOTA_CLIP_LEVELS_SOURCE_RANGE:
+ return eng->getClipSourcePeaksRange(track_id, clip_index, a, b, out_min_max, max_points, out_rms);
+ default: return 0;
+ }
+}
// ---- Instrument tracks, MIDI clips & notes (M2) ---------------------------
diff --git a/src/native/nota.engine/src/engine/Engine.h b/src/native/nota.engine/src/engine/Engine.h
index 2e5e1250..ed679e4d 100644
--- a/src/native/nota.engine/src/engine/Engine.h
+++ b/src/native/nota.engine/src/engine/Engine.h
@@ -442,13 +442,17 @@ class Engine {
float trackSend(int32_t trackId, int32_t bus) const;
int32_t returnTrackCount() const; // number of return buses in use
int32_t trackReturnIndex(int32_t trackId) const; // bus slot for a return track, else -1
- int32_t getClipPeaks(int32_t trackId, int32_t clipIndex, float* outMinMax, int32_t maxPoints) const;
- int32_t getClipSourcePeaks(int32_t trackId, int32_t clipIndex, float* outMinMax, int32_t maxPoints) const;
- int32_t getClipWarpFullPeaks(int32_t trackId, int32_t clipIndex, float* outMinMax, int32_t maxPoints) const;
- int32_t getClipWarpPeaksRange(
- int32_t trackId, int32_t clipIndex, double beat0, double beat1, float* outMinMax, int32_t maxPoints) const;
- int32_t getClipSourcePeaksRange(
- int32_t trackId, int32_t clipIndex, double frame0, double frame1, float* outMinMax, int32_t maxPoints) const;
+ // Waveform buckets: min/max pairs, plus each bucket's RMS when outRms is given.
+ int32_t getClipPeaks(
+ int32_t trackId, int32_t clipIndex, float* outMinMax, int32_t maxPoints, float* outRms = nullptr) const;
+ int32_t getClipSourcePeaks(
+ int32_t trackId, int32_t clipIndex, float* outMinMax, int32_t maxPoints, float* outRms = nullptr) const;
+ int32_t getClipWarpFullPeaks(
+ int32_t trackId, int32_t clipIndex, float* outMinMax, int32_t maxPoints, float* outRms = nullptr) const;
+ int32_t getClipWarpPeaksRange(int32_t trackId, int32_t clipIndex, double beat0, double beat1, float* outMinMax,
+ int32_t maxPoints, float* outRms = nullptr) const;
+ int32_t getClipSourcePeaksRange(int32_t trackId, int32_t clipIndex, double frame0, double frame1, float* outMinMax,
+ int32_t maxPoints, float* outRms = nullptr) const;
// --- incremental warp-cache build (project load, with a progress bar) ---
void setDeferWarpBuild(bool defer); // load path: skip cache builds, fill them via warpBuildStep
diff --git a/src/native/nota.engine/src/engine/Engine_Tracks.cpp b/src/native/nota.engine/src/engine/Engine_Tracks.cpp
index 16e65311..cff78391 100644
--- a/src/native/nota.engine/src/engine/Engine_Tracks.cpp
+++ b/src/native/nota.engine/src/engine/Engine_Tracks.cpp
@@ -1039,8 +1039,8 @@ int32_t Engine::trackReturnIndex(int32_t id) const {
// Peak-pick a warped clip's source envelope over a beat range [beat0, beat1] via the
// marker map (time-stretch preserves the amplitude envelope). Shared by the played
// window (getClipPeaks) and the full-material view (getClipWarpFullPeaks).
-static int32_t warpPeaksRange(
- const AudioClip& clip, float* out, int32_t maxPoints, double beat0, double beat1, int32_t cap = 2048) {
+static int32_t warpPeaksRange(const AudioClip& clip, float* out, float* outRms, int32_t maxPoints, double beat0,
+ double beat1, int32_t cap = 2048) {
if (!out || maxPoints <= 0 || !clip.sample) return 0;
const auto& m = clip.warpMarkers;
if (m.size() < 2) return 0;
@@ -1067,20 +1067,23 @@ static int32_t warpPeaksRange(
sb.peakRange(s0, s1 + 1, mn, mx);
out[b * 2] = mn;
out[b * 2 + 1] = mx;
+ if (outRms) outRms[b] = sb.rmsRange(s0, s1 + 1);
}
return buckets;
}
// Flip a min/max peak array end-to-end (each bucket's own min/max is unchanged) so a
// reversed clip draws the waveform it actually plays.
-static void reversePeaks(float* peaks, int32_t count) {
+static void reversePeaks(float* peaks, float* rms, int32_t count) {
for (int32_t a = 0, b = count - 1; a < b; ++a, --b) {
std::swap(peaks[a * 2], peaks[b * 2]);
std::swap(peaks[a * 2 + 1], peaks[b * 2 + 1]);
+ if (rms) std::swap(rms[a], rms[b]);
}
}
-int32_t Engine::getClipPeaks(int32_t trackId, int32_t clipIndex, float* outMinMax, int32_t maxPoints) const {
+int32_t Engine::getClipPeaks(
+ int32_t trackId, int32_t clipIndex, float* outMinMax, int32_t maxPoints, float* outRms) const {
if (!outMinMax || maxPoints <= 0) return 0;
auto t = findTrackAuthoring(trackId);
if (!t || !audioClipRef(*t, clipIndex)) return 0;
@@ -1097,8 +1100,8 @@ int32_t Engine::getClipPeaks(int32_t trackId, int32_t clipIndex, float* outMinMa
const bool warped = clip.warpEnabled && m.size() >= 2 && clip.warpBeats > 0.0;
if (warped) { // peaks over the PLAYED window (what the arrangement shows/plays)
- const int32_t n = warpPeaksRange(clip, outMinMax, maxPoints, clip.warpPlayStart, clip.warpPlayEndEff());
- if (clip.reversed) reversePeaks(outMinMax, n);
+ const int32_t n = warpPeaksRange(clip, outMinMax, outRms, maxPoints, clip.warpPlayStart, clip.warpPlayEndEff());
+ if (clip.reversed) reversePeaks(outMinMax, outRms, n);
return n;
}
@@ -1113,8 +1116,9 @@ int32_t Engine::getClipPeaks(int32_t trackId, int32_t clipIndex, float* outMinMa
sb.peakRange(begin, begin + per, mn, mx);
outMinMax[b * 2] = mn;
outMinMax[b * 2 + 1] = mx;
+ if (outRms) outRms[b] = sb.rmsRange(begin, begin + per);
}
- if (clip.reversed) reversePeaks(outMinMax, buckets);
+ if (clip.reversed) reversePeaks(outMinMax, outRms, buckets);
return buckets;
}
@@ -1123,7 +1127,8 @@ int32_t Engine::getClipPeaks(int32_t trackId, int32_t clipIndex, float* outMinMa
// reveal audio that was trimmed off. Unwarped only (warped uses getClipPeaks). Always in
// FILE order: the editor draws this view together with source-frame brackets, so it
// mirrors the two as one when the clip is reversed rather than flipping peaks here.
-int32_t Engine::getClipSourcePeaks(int32_t trackId, int32_t clipIndex, float* outMinMax, int32_t maxPoints) const {
+int32_t Engine::getClipSourcePeaks(
+ int32_t trackId, int32_t clipIndex, float* outMinMax, int32_t maxPoints, float* outRms) const {
if (!outMinMax || maxPoints <= 0) return 0;
auto t = findTrackAuthoring(trackId);
if (!t || !audioClipRef(*t, clipIndex)) return 0;
@@ -1139,6 +1144,7 @@ int32_t Engine::getClipSourcePeaks(int32_t trackId, int32_t clipIndex, float* ou
sb.peakRange(b * per, (b + 1) * per, mn, mx);
outMinMax[b * 2] = mn;
outMinMax[b * 2 + 1] = mx;
+ if (outRms) outRms[b] = sb.rmsRange(b * per, (b + 1) * per);
}
return buckets;
}
@@ -1147,31 +1153,32 @@ int32_t Engine::getClipSourcePeaks(int32_t trackId, int32_t clipIndex, float* ou
// clip editor draws the whole warp so the Start/End brackets can reveal trimmed beats.
// In marker (file) order — the editor mirrors this view and its markers together when the
// clip is reversed, so flipping the peaks alone here would desync them.
-int32_t Engine::getClipWarpFullPeaks(int32_t trackId, int32_t clipIndex, float* outMinMax, int32_t maxPoints) const {
+int32_t Engine::getClipWarpFullPeaks(
+ int32_t trackId, int32_t clipIndex, float* outMinMax, int32_t maxPoints, float* outRms) const {
auto t = findTrackAuthoring(trackId);
if (!t || !audioClipRef(*t, clipIndex)) return 0;
const AudioClip& clip = (*audioClipRef(*t, clipIndex));
if (!(clip.warpEnabled && clip.warpBeats > 0.0)) return 0;
- return warpPeaksRange(clip, outMinMax, maxPoints, 0.0, clip.warpBeats);
+ return warpPeaksRange(clip, outMinMax, outRms, maxPoints, 0.0, clip.warpBeats);
}
// The clip editor's zoomed-in detail: peaks over just the visible slice, so zooming
// re-resolves the waveform instead of magnifying the whole-clip overview into blocks.
constexpr int32_t kRangePeaksCap = 8192;
-int32_t Engine::getClipWarpPeaksRange(
- int32_t trackId, int32_t clipIndex, double beat0, double beat1, float* outMinMax, int32_t maxPoints) const {
+int32_t Engine::getClipWarpPeaksRange(int32_t trackId, int32_t clipIndex, double beat0, double beat1, float* outMinMax,
+ int32_t maxPoints, float* outRms) const {
auto t = findTrackAuthoring(trackId);
if (!t || !audioClipRef(*t, clipIndex)) return 0;
const AudioClip& clip = (*audioClipRef(*t, clipIndex));
if (!(clip.warpEnabled && clip.warpBeats > 0.0)) return 0;
beat0 = std::clamp(beat0, 0.0, clip.warpBeats);
beat1 = std::clamp(beat1, 0.0, clip.warpBeats);
- return warpPeaksRange(clip, outMinMax, maxPoints, beat0, beat1, kRangePeaksCap);
+ return warpPeaksRange(clip, outMinMax, outRms, maxPoints, beat0, beat1, kRangePeaksCap);
}
-int32_t Engine::getClipSourcePeaksRange(
- int32_t trackId, int32_t clipIndex, double frame0, double frame1, float* outMinMax, int32_t maxPoints) const {
+int32_t Engine::getClipSourcePeaksRange(int32_t trackId, int32_t clipIndex, double frame0, double frame1,
+ float* outMinMax, int32_t maxPoints, float* outRms) const {
if (!outMinMax || maxPoints <= 0) return 0;
auto t = findTrackAuthoring(trackId);
if (!t || !audioClipRef(*t, clipIndex)) return 0;
@@ -1191,6 +1198,7 @@ int32_t Engine::getClipSourcePeaksRange(
sb.peakRange(f0, f1, mn, mx);
outMinMax[b * 2] = mn;
outMinMax[b * 2 + 1] = mx;
+ if (outRms) outRms[b] = sb.rmsRange(f0, f1);
}
return buckets;
}
diff --git a/src/native/nota.engine/src/media/SampleBuffer.cpp b/src/native/nota.engine/src/media/SampleBuffer.cpp
index 14a94f20..c95e8909 100644
--- a/src/native/nota.engine/src/media/SampleBuffer.cpp
+++ b/src/native/nota.engine/src/media/SampleBuffer.cpp
@@ -5,6 +5,8 @@
#include "SampleBuffer.h"
+#include <cmath>
+
namespace nota {
int64_t SampleBuffer::nextId() {
@@ -31,18 +33,21 @@ void SampleBuffer::buildPeakTable() {
}
void SampleBuffer::updatePeakTable(int64_t f0, int64_t f1) {
- if (!hasPeakTable()) {
+ if (!hasPeakTable() || !hasRmsTable()) {
peakTable.assign(static_cast<size_t>(peakBlocks() * 2), 0.0f);
+ rmsTable.assign(static_cast<size_t>(peakBlocks()), 0.0f);
fillSentinel(0, peakBlocks());
}
f0 = std::max<int64_t>(0, f0);
f1 = std::min(f1, frames);
if (f1 <= f0) return;
for (int64_t b = f0 / kPeakBlock; b <= (f1 - 1) / kPeakBlock; ++b) {
+ const int64_t s0 = b * kPeakBlock, s1 = std::min(frames, (b + 1) * kPeakBlock);
float mn, mx;
- scanRange(b * kPeakBlock, std::min(frames, (b + 1) * kPeakBlock), mn, mx);
+ scanRange(s0, s1, mn, mx);
peakTable[b * 2] = mn;
peakTable[b * 2 + 1] = mx;
+ rmsTable[b] = static_cast<float>(scanSquares(s0, s1) / static_cast<double>(s1 - s0));
}
}
@@ -50,6 +55,7 @@ void SampleBuffer::fillSentinel(int64_t b0, int64_t b1) {
for (int64_t b = b0; b < b1; ++b) {
peakTable[b * 2] = 1.0f;
peakTable[b * 2 + 1] = -1.0f;
+ if (hasRmsTable()) rmsTable[b] = 0.0f;
}
}
@@ -81,6 +87,32 @@ void SampleBuffer::peakRange(int64_t f0, int64_t f1, float& mn, float& mx) const
if (mn > mx) mn = mx = 0.0f;
}
+float SampleBuffer::rmsRange(int64_t f0, int64_t f1) const {
+ f0 = std::max<int64_t>(0, f0);
+ f1 = std::min(f1, frames);
+ if (f1 <= f0) return 0.0f;
+ double sum;
+ if (f1 - f0 < 4 * kPeakBlock || !hasRmsTable()) {
+ sum = scanSquares(f0, f1);
+ } else {
+ const int64_t b0 = (f0 + kPeakBlock - 1) / kPeakBlock, b1 = f1 / kPeakBlock; // whole blocks
+ sum = scanSquares(f0, b0 * kPeakBlock) + scanSquares(b1 * kPeakBlock, f1);
+ for (int64_t b = b0; b < b1; ++b) sum += static_cast<double>(rmsTable[b]) * kPeakBlock;
+ }
+ return static_cast<float>(std::sqrt(sum / static_cast<double>(f1 - f0)));
+}
+
+double SampleBuffer::scanSquares(int64_t f0, int64_t f1) const {
+ double sum = 0.0;
+ for (int64_t f = f0; f < f1; ++f) {
+ float l, r;
+ readStereo(f, l, r);
+ const double mid = 0.5 * (static_cast<double>(l) + r);
+ sum += mid * mid;
+ }
+ return sum;
+}
+
void SampleBuffer::scanRange(int64_t f0, int64_t f1, float& mn, float& mx) const {
mn = 1.0f;
mx = -1.0f;
diff --git a/src/native/nota.engine/src/media/SampleBuffer.h b/src/native/nota.engine/src/media/SampleBuffer.h
index 8b71a80c..bd034363 100644
--- a/src/native/nota.engine/src/media/SampleBuffer.h
+++ b/src/native/nota.engine/src/media/SampleBuffer.h
@@ -44,9 +44,13 @@ struct SampleBuffer {
// scans frames. Blocks not computed yet hold the (1,-1) "no data" sentinel.
static constexpr int64_t kPeakBlock = 512;
std::vector<float> peakTable;
+ // Mean square of the stereo mid per block, alongside peakTable, for the waveform's RMS
+ // body. Not part of the peak cache: a seeded table has none until the decode finishes.
+ std::vector<float> rmsTable;
int64_t peakBlocks() const { return (frames + kPeakBlock - 1) / kPeakBlock; }
bool hasPeakTable() const { return static_cast<int64_t>(peakTable.size()) == peakBlocks() * 2; }
+ bool hasRmsTable() const { return static_cast<int64_t>(rmsTable.size()) == peakBlocks(); }
void buildPeakTable();
@@ -60,8 +64,12 @@ struct SampleBuffer {
// exact frame scans for the partial blocks at either end. (0,0) for an empty range.
void peakRange(int64_t f0, int64_t f1, float& mn, float& mx) const;
+ // RMS of the stereo mid over frames [f0, f1), read the same way. 0 for an empty range.
+ float rmsRange(int64_t f0, int64_t f1) const;
+
private:
void scanRange(int64_t f0, int64_t f1, float& mn, float& mx) const;
+ double scanSquares(int64_t f0, int64_t f1) const;
};
} // namespace nota
diff --git a/tests/Nota.SmokeTest/Program.cs b/tests/Nota.SmokeTest/Program.cs
index 0fede6c9..2e771367 100644
--- a/tests/Nota.SmokeTest/Program.cs
+++ b/tests/Nota.SmokeTest/Program.cs
@@ -15041,6 +15041,26 @@ Console.WriteLine("-- background audio import --");
Check(sn == 64 && err < 1e-6, $"range peaks: source sub-range matches a full scan (max err {err:E1})");
var tiny = new float[100 * 2];
Check(ie.GetClipSourcePeaksRange(ct, cc, 5000, 5010, tiny, 100) == 100, "range peaks: sub-frame buckets read single frames");
+
+ // The waveform's RMS body (#267): the same min/max as without it, and each bucket's
+ // RMS matches a scan — over short spans (frame scans) and long ones (block table).
+ double ScanRms(long f0, long f1) { double s = 0; for (long f = f0; f < f1; f++) { double m = Mid(f); s += m * m; } return Math.Sqrt(s / (f1 - f0)); }
+ var sub2 = new float[64 * 2]; var subRms = new float[64];
+ ie.GetClipSourcePeaksRange(ct, cc, 1000, 1000 + 64 * 64, sub2, 64, subRms);
+ double rErr = 0;
+ for (int b = 0; b < 64; b++) rErr = Math.Max(rErr, Math.Abs(ScanRms(1000 + b * 64, 1000 + (b + 1) * 64) - subRms[b]));
+ Check(sub2.SequenceEqual(sub) && rErr < 1e-5, $"waveform rms: short buckets match a scan (max err {rErr:E1})");
+ var whole = new float[8 * 2]; var wholeRms = new float[8];
+ int wn = ie.GetClipSourcePeaks(ct, cc, whole, 8, wholeRms);
+ long per = psi.Frames / Math.Max(1, wn);
+ rErr = 0;
+ for (int b = 0; b < wn; b++) rErr = Math.Max(rErr, Math.Abs(ScanRms(b * per, (b + 1) * per) - wholeRms[b]));
+ Check(wn == 8 && rErr < 1e-4, $"waveform rms: long buckets read from the block table match a scan (max err {rErr:E1})");
+ var fullRms = new float[256]; var full2 = new float[256 * 2];
+ ie.GetClipWarpFullPeaks(ct, cc, full2, 256, fullRms);
+ bool inside = true;
+ for (int b = 0; b < 256; b++) inside &= fullRms[b] >= 0 && fullRms[b] <= Math.Max(Math.Abs(full2[b * 2]), Math.Abs(full2[b * 2 + 1])) + 1e-6;
+ Check(full2.SequenceEqual(full) && inside && fullRms.Any(v => v > 0.001f), "waveform rms: warped buckets keep their peaks, RMS inside them");
}
// Background warp build: a deferred marker edit keeps the old cache playing (not