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.

(fix) Less CPU while idle: redraw only what changed, pace the Linux pump (#66)

Egor Khindikaynenc3fbc559799c
diff --git a/.specify/bugs/linux-idle-cpu/assessment.md b/.specify/bugs/linux-idle-cpu/assessment.md
new file mode 100644
index 00000000..3662c17c
--- /dev/null
+++ b/.specify/bugs/linux-idle-cpu/assessment.md
@@ -0,0 +1,141 @@
+# Bug Assessment: Linux — Nota's process CPU is well above other DAWs, also when idle
+
+- **Slug**: linux-idle-cpu
+- **Created**: 2026-10-15
+- **Source**: https://github.com/nota-daw/nota/issues/55 (host: github.com — allowlisted)
+- **Verdict**: likely valid, needs reproduction
+- **Severity**: medium
+
+## Report (summarized)
+
+Issue #55, "Linux: Nota uses 20–30 % more CPU than other DAWs" (filed by the maintainer on behalf
+of a user). On 64-bit Linux the system monitor shows Nota at 35–45 % CPU on average during a
+session; two other DAWs on the same machine sit at 15–25 %. The user called this the main thing left
+to fix. Expected: comparable CPU, and close to idle when nothing is playing. The issue already names
+leads: the Linux-only 10 ms JUCE pump timer and UI polling/repaint timers that never stop. The
+in-app CPU meter reading lower than the system monitor is tracked separately in #54.
+
+## Symptom
+
+Process CPU on Linux sits at roughly 35–45 % throughout a session, about 20 percentage points above
+comparable DAWs. Expected: similar to other DAWs while playing, and near idle when stopped or
+minimized.
+
+## Reproduction
+
+1. Linux x86_64, open a project that uses only built-in instruments.
+2. Measure process CPU (`top -p <pid>` / `pidstat -t -p <pid> 1`) in three states: stopped, playing,
+ and with the window minimized.
+3. Compare with the same project on macOS / Windows.
+
+[NEEDS CLARIFICATION: the user's project size (tracks/devices), distro, X11 vs Wayland, GPU/driver,
+and whether the number was taken while playing or stopped.]
+
+## Suspected Code Paths
+
+- `src/managed/Nota.Presentation/ViewModels/MainWindowViewModel.cs:90` — `_clock` fires `OnTick`
+ every 33 ms for the app's whole life. It never pauses when the transport is stopped, nothing
+ changed, or the window is minimized/hidden.
+- `src/managed/Nota.App/MainWindow.axaml.cs:269` — the `PlayheadUpdated` handler does a lot of work
+ each tick: master meter, `Timeline.SetPlayhead`, `Timeline.UpdateMeters`, mixer meters,
+ `_deviceChain.RefreshSynthLive`, editor playheads, the CPU indicator (sets `Width`/`Background`/`Text`
+ every tick), MIDI learn, plus the extra subscribers in `MainWindow.Remote.cs:35` and
+ `MainWindow.Gamepad.cs:49`.
+- `src/managed/Nota.App/ArrangementView.cs:553` `SetPlayhead` — calls `InvalidateVisual()` on the
+ ruler, sections lane, overlay and footer lanes **every** tick, even when `beats` is unchanged
+ (stopped). That is a steady ~30 fps redraw of the arrangement chrome while idle.
+- `src/managed/Nota.App/Controls/MeterBar.cs:39` `Push` — calls `InvalidateVisual()` unconditionally,
+ even when the level and hold are unchanged (e.g. 0 → 0 in silence). `ArrangementView.UpdateMeters`
+ (`ArrangementView.cs:664`) pushes to the header **and** footer meter of every track, plus the master.
+ So N tracks give 2N+2 meter redraws per tick, forever.
+- `src/managed/Nota.App/DeviceChainView.Instruments.cs:111` `RefreshSynthLive` — re-reads every
+ device param over P/Invoke and runs the instrument's graph refresher (`_instLiveViz`) each tick
+ while the device chain is visible. Whether the graphs redraw only on change was not verified.
+- `src/managed/Nota.App/App.axaml.cs:114` — the Linux-only 10 ms `DispatcherTimer` that calls
+ `NotaEngine.PumpPluginHost()`. Its native side (`src/native/nota.engine/pluginhost/PluginHost.cpp:90`)
+ returns at once when no plugin GUI exists, so the cost is ~100 dispatcher wake-ups plus P/Invokes
+ per second. That is real but small; not the main suspect for built-in-only projects.
+- `src/native/nota.engine/src/Engine_Render.cpp:327` `Engine::render` → `processBlock` — the whole
+ graph (every instrument, effect, rack) is processed every block, even when stopped. Nothing skips
+ silent tracks or devices. Same on every OS, so it does not explain a Linux-only gap by itself, but
+ it adds to the idle baseline.
+
+## Root Cause Hypothesis
+
+Most of the excess is most likely UI work, not DSP. A single 33 ms clock drives unconditional
+`InvalidateVisual()` calls on the arrangement chrome and 2N+2 meters, plus per-tick property sets
+(CPU indicator) and P/Invoke polling. So the app redraws at ~30 fps even when stopped and nothing has
+changed, and it keeps doing so when minimized. On Linux, Avalonia (`UsePlatformDetect`, no explicit
+`X11PlatformOptions`) often ends up on software Skia rendering or a weaker GL path. That would make
+the same redraw rate far more expensive than on macOS/Windows and explain why only Linux stands out.
+The 10 ms JUCE pump and the always-on graph processing add smaller constant costs. Confidence:
+**medium**. The code clearly does idle redraws, but nobody has measured how the reported 35–45 %
+splits between UI, audio and pump.
+
+## Proposed Remediation
+
+**Preferred**: make the UI tick do nothing when nothing changed, and back off when the window can't be seen.
+1. `MeterBar.Push`: store the last drawn values and call `InvalidateVisual()` only when a level or
+ hold actually changed (with a small epsilon). Do the same in other `Push`-style meter controls.
+2. `ArrangementView.SetPlayhead`: return early (skip all invalidations) when `beats`, the loop state
+ and the scroll are unchanged since the last tick.
+3. Main-window CPU indicator: update `Width`/`Background`/`Text` only when the rounded percentage
+ changes.
+4. `MainWindowViewModel._clock`: when the window is minimized/hidden, either stop the visual part of
+ the tick or drop it to a slow interval (~250 ms). Keep `Engine.Poll()`, gamepad, MIDI learn and
+ Remote serviced. Add `IsVisible`/`WindowState` checks in the `PlayheadUpdated` handler, or split
+ the handler into a "service" part and a "paint" part.
+5. Linux JUCE pump: start the 10 ms timer only after the first plugin GUI/instance exists (or make
+ it lazy: slow it to e.g. 50 ms while `nota_pluginhost_pump` keeps returning 0, then go back to
+ 10 ms on activity).
+
+Before changing anything, measure on Linux (stopped / playing / minimized; `perf top -p`,
+`dotnet-counters`, per-thread `top -H`) to confirm how the cost splits. Also check which Avalonia
+render backend is active, e.g. by logging `AvaloniaLocator`/`IPlatformGraphics` or forcing
+`X11PlatformOptions { RenderingMode = [Glx, Egl, Software] }`.
+
+**Alternatives**:
+- Engine-side idle skip: skip `process` for tracks whose instrument has no active voices, no
+ input/MIDI and whose effect tails have decayed below a threshold. Bigger win on large projects and
+ on every OS, but it touches the audio thread and every device's tail logic. Treat it as a separate
+ feature (spec-driven), not part of this fix.
+- Slowing the global clock to 60–100 ms while stopped. Simpler, but MIDI-learn and gamepad latency
+ get worse unless those move to their own timer.
+
+**Files likely to change**:
+- `src/managed/Nota.App/Controls/MeterBar.cs` (and sibling meter controls in `Controls/`)
+- `src/managed/Nota.App/ArrangementView.cs`
+- `src/managed/Nota.App/MainWindow.axaml.cs`
+- `src/managed/Nota.Presentation/ViewModels/MainWindowViewModel.cs`
+- `src/managed/Nota.App/App.axaml.cs`
+
+**Tests to add or update**:
+- Headless Avalonia test: with the transport stopped and silent meters, N ticks of the UI clock
+ cause no further render passes on the arrangement/meters after the first (count `Render` calls or
+ invalidations).
+- `MeterBar` unit test: pushing the same reading twice invalidates once.
+- Smoke test (`tests/Nota.SmokeTest`): `PumpPluginHost` still returns 0 safely with no plugin. That
+ check already exists at `Program.cs:14646`; keep it passing if the pump becomes lazy.
+- Manual Linux measurement before/after (stopped, playing, minimized), recorded in the fix notes.
+
+## Risks & Considerations
+
+- Skipping invalidations can leave stale visuals if some state change doesn't go through the
+ compared fields (theme switch, resize, zoom). Those paths must still invalidate explicitly.
+- Meter peak-hold decay: if any meter animates a fall-off over time, "no change" detection must
+ account for it.
+- Lazy JUCE pump: hosted plugin editors/timers on Linux must still start promptly. The black/
+ unclosable window bug (`.specify/bugs/linux-plugin-black-window`) is the regression to watch.
+- MIDI learn / gamepad / Nota Remote ride the same tick; throttling while minimized must not stall
+ them (a pad note-off must still arrive).
+- Related but separate: #54 (in-app CPU meter only measures DSP time, so it reads lower than the
+ system monitor).
+
+## Open Questions
+
+- [NEEDS CLARIFICATION: Was the 35–45 % measured while playing or while stopped? Window minimized?]
+- [NEEDS CLARIFICATION: Project size and devices used; X11 or Wayland; GPU/driver (software
+ rendering suspected).]
+- [NEEDS CLARIFICATION: Was any third-party plugin loaded (turns the JUCE pump into real work)?]
+- Is "% CPU" in the user's monitor per-core (top-style) or of the total machine? This changes how big
+ the gap really is.
diff --git a/.specify/bugs/linux-idle-cpu/fix.md b/.specify/bugs/linux-idle-cpu/fix.md
new file mode 100644
index 00000000..d8758713
--- /dev/null
+++ b/.specify/bugs/linux-idle-cpu/fix.md
@@ -0,0 +1,85 @@
+# Bug Fix: Linux — Nota's process CPU is well above other DAWs, also when idle
+
+- **Slug**: linux-idle-cpu
+- **Fixed**: 2026-10-15
+- **Assessment**: ./assessment.md
+- **Status**: applied
+
+## Summary
+
+The UI no longer redraws when nothing changed. Meters repaint only when a level or hold moved,
+the arrangement playhead chrome repaints only when the playhead, the loop or the follow-scroll
+moved, and the CPU read-out updates only when its percentage changes. While the main window is
+minimized (and no floating Devices/Clip window is shown), the tick keeps servicing MIDI learn and
+scene tempo but skips all visual work. On Linux, the JUCE message pump backs off from 10 ms to
+100 ms once its queue has stayed empty for ~0.25 s, and snaps back on the first handled message.
+
+The assessment's verdict was "likely valid, needs reproduction" with open questions. The user
+chose to go ahead with the fix without a Linux measurement first.
+
+## Changes
+
+| File | Change | Notes |
+|------|--------|-------|
+| `src/managed/Nota.App/Controls/MeterBar.cs` | modified | `Push` returns early when level and hold are unchanged; covers track headers, footer, mixer and master meters |
+| `src/managed/Nota.App/ArrangementView.cs` | modified | `SetPlayhead` invalidates ruler/sections/overlay/footer/overview only when the playhead moved, the loop changed or follow-scroll moved the view; the auto-baseline check still runs every tick |
+| `src/managed/Nota.App/MainWindow.axaml.cs` | modified | the `PlayheadUpdated` handler returns after MIDI learn + scene tempo while the window is minimized; the CPU read-out updates only on a changed percentage; `SyncSceneTempo` moved above the early return |
+| `src/managed/Nota.Application/Engine/PumpPacer.cs` | added | pure pacing logic for the Linux pump (Fast 10 ms / Slow 100 ms after 25 empty pumps) |
+| `src/managed/Nota.App/App.axaml.cs` | modified | the Linux pump timer re-times itself from `PumpPacer.Next(handled)` |
+| `tests/Nota.SmokeTest/PumpPacerTests.cs` | added test | pacing rules |
+| `tests/Nota.SmokeTest/Program.cs` | modified | runs `PumpPacerTests` next to the existing pump check |
+| `CHANGELOG.md` | modified | `[Unreleased] → Fixed` entry |
+
+## Diff Highlights
+
+```csharp
+// MeterBar.Push
+if (l == _levelL && r == _levelR && hl == _holdL && hr == _holdR) return;
+
+// ArrangementView.SetPlayhead
+if (!moved && !scrolled && !loopChanged) return;
+
+// MainWindow PlayheadUpdated
+if (WindowState == WindowState.Minimized
+ && _detailWindow is not { IsVisible: true, WindowState: not WindowState.Minimized }) return;
+```
+
+## Tests Added or Updated
+
+- `tests/Nota.SmokeTest/PumpPacerTests.cs` — the pacer starts fast, stays fast through a short
+ idle run, backs off after `IdlePumpsBeforeSlow` empty pumps, stays slow, and snaps back to fast
+ on one handled message (with the back-off counting from zero again).
+- The existing "plugin host pump: exported, non-blocking no-op" check still passes.
+
+## Local Verification
+
+- Commands run: `dotnet build Nota.sln` → succeeded; `scripts/build.sh` (macOS arm64: native
+ + managed + full smoke test) → `SMOKE TEST PASSED`, exit 0, all new pacer checks PASS.
+- Manual checks: none yet. The app was not launched, and CPU was not measured on Linux.
+
+## Deviations from Assessment
+
+- **No headless render-count test.** The smoke test has no Avalonia/`Nota.App` reference, and
+ adding Avalonia.Headless is a new test dependency the assessment didn't call for. The
+ meter/playhead early returns are covered by the build only; the pump pacing logic was extracted
+ into `Nota.Application` so it could be tested instead.
+- **The `_clock` in `MainWindowViewModel` was left untouched.** Minimized throttling lives in the
+ view's tick handler instead. That keeps `Engine.Poll`, transport, gamepad and Remote at full rate
+ (a pad note-off or a phone fader must not wait), and skips only the visual work.
+- **Pump slow rate is 100 ms**, not the 50 ms the assessment sketched. Any handled message
+ (X11 input over a plugin window, a plugin timer) brings it back to 10 ms immediately.
+- `RefreshSynthLive`, mixer and session updates were not given their own change detection.
+ Their redraws go through controls that mostly already compare values (faders check `> 1e-3`);
+ they are skipped while minimized.
+
+## Follow-ups
+
+- Measure on Linux (stopped / playing / minimized; `top -H`, `perf top -p`) before and after,
+ and record which Avalonia render backend is active. If it's software Skia, consider explicit
+ `X11PlatformOptions { RenderingMode = … }`.
+- Manually check in the app: meters still fall to zero on stop, peak-hold click clears, loop
+ toggles from the transport bar show in the ruler, theme switch/resize repaint the ruler, plugin
+ editors on Linux still open and respond at once (`linux-plugin-black-window` regression).
+- Engine-side skipping of silent tracks/devices when stopped: a separate spec-driven feature.
+- Ask the reporter for the open questions in the assessment (playing vs. stopped, project size,
+ X11/Wayland, GPU).
diff --git a/.specify/bugs/linux-idle-cpu/test.md b/.specify/bugs/linux-idle-cpu/test.md
new file mode 100644
index 00000000..73a4df9d
--- /dev/null
+++ b/.specify/bugs/linux-idle-cpu/test.md
@@ -0,0 +1,74 @@
+# Bug Verification: Linux — Nota's process CPU is well above other DAWs, also when idle
+
+- **Slug**: linux-idle-cpu
+- **Tested**: 2026-10-15
+- **Assessment**: ./assessment.md
+- **Fix**: ./fix.md
+- **Result**: partial
+
+## Summary
+
+On macOS, a headless run of the real `MainWindow` (12 tracks, stopped) shows the fix cuts the
+UI-thread cost of the main tick plus a rendered frame by about 3× (≈2.0 → ≈0.6 ms per tick). The
+cost also drops when minimized (≈1.4 → ≈0.45 ms). The full build and smoke test pass, including
+the new pump-pacing checks. The original symptom (process CPU on Linux vs. other DAWs) was **not**
+reproduced or re-measured: no Linux machine was available. That is why the result is `partial`,
+not `verified`.
+
+## Checks Performed
+
+| Check | Command / Action | Result | Notes |
+|-------|------------------|--------|-------|
+| Reproduction on Linux (post-fix) | process CPU via `top`/`perf` on Linux x86_64 | not-run | no Linux machine in this session |
+| Idle UI cost, before vs. after (macOS, headless proxy) | `/tmp/idlecpuharness` (fix) vs. the same harness on a `git worktree` of `HEAD` 097af5d (baseline), 3 runs each | pass | see excerpts; same native dylib on both sides (the fix has no native changes) |
+| New tests (pump pacer) | `scripts/build.sh` → smoke test `-- plugin host pump --` | pass | 6 new checks + the existing pump no-op check |
+| Regression suite | `scripts/build.sh` (native + managed + full smoke test, macOS arm64) | pass | `SMOKE TEST PASSED`, exit 0 (run during `/speckit-bug-fix`; sources unchanged since) |
+| Build / type-check | `dotnet build Nota.sln` | pass | no new warnings in the changed files |
+| Linux JUCE pump in practice (plugin editor opens/responds) | Linux, hosted VST3 with editor | not-run | needs Linux; pacing logic covered by unit checks only |
+| Visual regressions (meters fall on stop, peak-hold click, loop toggle on ruler, theme switch) | manual in the app | not-run | GUI launch not performed; harness measures cost, not visuals |
+
+## Output Excerpts
+
+Harness: the real `MainWindow` + `MainWindowViewModel` from `App.Services`, Avalonia.Headless +
+Skia (real drawing), 1600×1000, 4 template tracks + 8 instrument tracks with MIDI clips, transport
+stopped. The VM's own 33 ms timer is stopped. Each step = reflected `OnTick()` + `RunJobs()` +
+`CaptureRenderedFrame()`. After a 60-step warm-up, 600 steps are timed per state. UI-thread
+wall time per step:
+
+| Run | Baseline shown | Fix shown | Baseline minimized | Fix minimized |
+|-----|----------------|-----------|--------------------|---------------|
+| 1 | 2.156 ms | 0.718 ms | 1.494 ms | 0.530 ms |
+| 2 | 1.958 ms | 0.667 ms | 1.341 ms | 0.433 ms |
+| 3 | 1.915 ms | 0.516 ms | 1.320 ms | 0.421 ms |
+
+```
+-- plugin host pump --
+ [PASS] plugin host pump: exported, non-blocking no-op with no plugin loaded
+ [PASS] pump pacer starts at the fast rate
+ [PASS] a short run of empty pumps stays fast
+ [PASS] a long run of empty pumps backs off to the slow rate
+ [PASS] an idle pump stays slow
+SMOKE TEST PASSED
+```
+
+## Residual Risks
+
+- **Not measured on Linux.** The ~3× drop is a macOS headless proxy for UI-thread work. It
+ doesn't show how much of the reported 35–45 % process CPU goes away. If the Linux cost is
+ dominated by the render backend (software Skia) or by DSP, the gain may be smaller.
+- The headless renderer doesn't model the real compositor or vsync; on a real window, the
+ savings from fewer invalidations may be larger or smaller.
+- Visual correctness of the early returns (meters, ruler/overlay after loop/theme/resize
+ changes) was reasoned through in code but not checked on screen.
+- Linux pump back-off is checked only as logic. Plugin editor responsiveness on Linux (the
+ `linux-plugin-black-window` regression) is unverified.
+- The playing case was not measured. When playing, the playhead moves every tick, so savings
+ come only from meters and the CPU read-out.
+
+## Recommendation
+
+Hold the issue open. The fix measurably reduces idle UI work and nothing regressed in the smoke
+test, so it is fine to merge. But #55 is about Linux process CPU, and that wasn't measured. Before
+closing: on Linux x86_64, compare process CPU (stopped / playing / minimized) on `develop` vs. this
+change, and note the Avalonia render backend in use. Also open a hosted plugin's editor to confirm
+the paced JUCE pump still responds at once. Quickly check the meters and loop ruler on screen.
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7f625912..ed53ac02 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -82,6 +82,10 @@ Entry categories: `Added`, `Changed`, `Fixed`, `Removed`.
chain.
### Fixed
+- **Less CPU while idle:** Nota no longer redraws its meters, playhead and CPU read-out
+ ~30 times a second when nothing on them has changed. It skips them entirely while the
+ window is minimized, and on Linux the plug-in message pump slows down when no plug-in
+ needs it. Most noticeable on Linux, where Nota used much more CPU than other DAWs.
- **New tracks scroll into view:** a track added to a full arrangement was drawn under the
pinned Return and Master rows. The arrangement now scrolls to show it, and the pinned
rows sit on a line of their own.
diff --git a/src/managed/Nota.App/App.axaml.cs b/src/managed/Nota.App/App.axaml.cs
index b4853493..27e241cd 100644
--- a/src/managed/Nota.App/App.axaml.cs
+++ b/src/managed/Nota.App/App.axaml.cs
@@ -111,10 +111,17 @@ public partial class App : Avalonia.Application
// Linux: JUCE's message loop isn't shared with Avalonia's (it is on macOS/Windows),
// so hosted plugins' editors and timers only run when we service it. Without this,
// plugin windows stay black and unclosable and plugins stay silent.
+ // Paced: 10 ms while plugins post messages, 100 ms once the queue stays empty (#55).
if (OperatingSystem.IsLinux())
{
- var pump = new Avalonia.Threading.DispatcherTimer(TimeSpan.FromMilliseconds(10),
- Avalonia.Threading.DispatcherPriority.Normal, (_, _) => NotaEngine.PumpPluginHost());
+ var pacer = new PumpPacer();
+ Avalonia.Threading.DispatcherTimer? pump = null;
+ pump = new Avalonia.Threading.DispatcherTimer(PumpPacer.Fast,
+ Avalonia.Threading.DispatcherPriority.Normal, (_, _) =>
+ {
+ var next = pacer.Next(NotaEngine.PumpPluginHost());
+ if (pump!.Interval != next) pump.Interval = next;
+ });
pump.Start();
}
diff --git a/src/managed/Nota.App/ArrangementView.cs b/src/managed/Nota.App/ArrangementView.cs
index 87d6edcd..fc778430 100644
--- a/src/managed/Nota.App/ArrangementView.cs
+++ b/src/managed/Nota.App/ArrangementView.cs
@@ -552,6 +552,7 @@ public sealed partial class ArrangementView : UserControl
public void SetPlayhead(double beats)
{
+ bool moved = beats != _playheadBeats;
_playheadBeats = beats;
// While following, the view scrolls under the playhead — the lane surface (clips /
// waveforms) must repaint along with the ruler+overlay, not just the overlay.
@@ -559,12 +560,20 @@ public sealed partial class ArrangementView : UserControl
if (scrolled) _lanes.InvalidateVisual();
// Converge the loop highlight with the engine (~30 Hz) so transport-bar
// toggles/changes reflect here too — except mid-drag, where we show a preview.
+ bool loopChanged = false;
if (!_loopDragging && _engine is { } eng)
{
bool on = eng.LoopEnabled; double s = eng.LoopStart, e = eng.LoopEnd;
if (on != _loopActive || s != _loopS || e != _loopE)
- { _loopActive = on; _loopS = s; _loopE = e; }
+ { _loopActive = on; _loopS = s; _loopE = e; loopChanged = true; }
}
+ // Automation mode: an empty lane draws a baseline at the param's live value, so it must
+ // follow a knob turned in the device. Redraw the lanes only when a visible empty lane's
+ // baseline actually changed (params with points are automation-driven — no baseline).
+ if (_automationMode) RefreshAutoBaselines();
+ // Stopped with nothing moving: the playhead chrome is already right — repainting it
+ // every tick kept the whole window redrawing ~30×/s while idle (#55).
+ if (!moved && !scrolled && !loopChanged) return;
// Only the overlay (playhead + loop band) moves each tick — the lane surface
// beneath is unchanged, so leave it be to avoid a full clip/waveform repaint.
_ruler.InvalidateVisual();
@@ -572,11 +581,6 @@ public sealed partial class ArrangementView : UserControl
_overlay.InvalidateVisual();
_footerLanes.InvalidateVisual();
TickOverviewPlayhead(); // only when the marker crossed a pixel of the strip
-
- // Automation mode: an empty lane draws a baseline at the param's live value, so it must
- // follow a knob turned in the device. Redraw the lanes only when a visible empty lane's
- // baseline actually changed (params with points are automation-driven — no baseline).
- if (_automationMode) RefreshAutoBaselines();
}
// Repaint the lane surface when a visible un-automated (empty-lane) target's live value
diff --git a/src/managed/Nota.App/Controls/MeterBar.cs b/src/managed/Nota.App/Controls/MeterBar.cs
index 3612b2a8..ec04dd71 100644
--- a/src/managed/Nota.App/Controls/MeterBar.cs
+++ b/src/managed/Nota.App/Controls/MeterBar.cs
@@ -38,10 +38,12 @@ public sealed class MeterBar : Control
/// <summary>Feed a fresh reading. The bar takes the value at once; the hold keeps the maximum.</summary>
public void Push(NotaMeter m)
{
- _levelL = MeterScale.Norm(m.PeakL);
- _levelR = MeterScale.Norm(m.PeakR);
- _holdL = Math.Max(_holdL, _levelL);
- _holdR = Math.Max(_holdR, _levelR);
+ double l = MeterScale.Norm(m.PeakL), r = MeterScale.Norm(m.PeakR);
+ double hl = Math.Max(_holdL, l), hr = Math.Max(_holdR, r);
+ // Readings arrive at the UI clock even in silence: repaint only when something moved,
+ // or every meter redraws ~30×/s while idle (#55).
+ if (l == _levelL && r == _levelR && hl == _holdL && hr == _holdR) return;
+ _levelL = l; _levelR = r; _holdL = hl; _holdR = hr;
InvalidateVisual();
}
diff --git a/src/managed/Nota.App/MainWindow.axaml.cs b/src/managed/Nota.App/MainWindow.axaml.cs
index 1595d177..0c2f95ed 100644
--- a/src/managed/Nota.App/MainWindow.axaml.cs
+++ b/src/managed/Nota.App/MainWindow.axaml.cs
@@ -266,9 +266,15 @@ public partial class MainWindow : Window
var cpuGreen = (IBrush?)NotaPalette.Success;
var cpuAmber = (IBrush?)NotaPalette.Warning;
var cpuRed = (IBrush?)NotaPalette.Danger;
+ int cpuShown = -1; // the CPU read-out's last percentage, so an unchanged one isn't re-laid-out
vm.PlayheadUpdated += beats =>
{
_learn?.Tick(); // apply incoming MIDI mappings / capture a learn message
+ SyncSceneTempo(); // a launched scene set tempo / signature
+ // Nothing of the window can be seen: keep servicing MIDI and scenes, skip the
+ // meters, playheads and live knobs — they'd redraw ~30×/s for nobody (#55).
+ if (WindowState == WindowState.Minimized
+ && _detailWindow is not { IsVisible: true, WindowState: not WindowState.Minimized }) return;
LearnOverlay.Refresh(); // keep highlights over rebuilt cards while armed
Timeline.SetPlayhead(beats);
_masterMeter?.Push(vm.Engine.MasterMeter());
@@ -276,7 +282,6 @@ public partial class MainWindow : Window
Timeline.RefreshAutomationLive(); // show writes live (M9-C)
SyncReenableAutomation(); // "a control is overriding its lane"
if (_session?.IsVisible == true) _session.UpdateStates(); // live launch/queue/play
- SyncSceneTempo(); // a launched scene set tempo / signature
if (_mixer?.IsVisible == true) _mixer.UpdateMeters(); // Mixer tab strips
if (_modular?.IsVisible == true) _modular.Tick(vm.Engine.IsPlaying); // graph knobs follow automation + edge pulse
if (DetailBody.Content is MixerView mx && mx.IsEffectivelyVisible) mx.UpdateMeters(); // 1f strips
@@ -296,9 +301,14 @@ public partial class MainWindow : Window
_patternView.SetPlayhead(beats - ppi.StartBeat, vm.Engine.IsPlaying);
double load = Math.Clamp(vm.Engine.CpuLoad, 0, 1); // live DSP load (Phase 11)
- CpuFill.Width = load * 52;
- CpuFill.Background = load > 0.9 ? cpuRed : load > 0.7 ? cpuAmber : cpuGreen;
- CpuText.Text = "CPU " + (int)Math.Round(load * 100) + "%";
+ int pct = (int)Math.Round(load * 100);
+ if (pct != cpuShown)
+ {
+ cpuShown = pct;
+ CpuFill.Width = pct * 0.52;
+ CpuFill.Background = pct > 90 ? cpuRed : pct > 70 ? cpuAmber : cpuGreen;
+ CpuText.Text = "CPU " + pct + "%";
+ }
SyncMidiDot();
};
// Recording tick fires ~60 Hz: refresh clip data + lane drawing only, WITHOUT
diff --git a/src/managed/Nota.Application/Engine/PumpPacer.cs b/src/managed/Nota.Application/Engine/PumpPacer.cs
new file mode 100644
index 00000000..69a2c735
--- /dev/null
+++ b/src/managed/Nota.Application/Engine/PumpPacer.cs
@@ -0,0 +1,29 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.
+
+namespace Nota.Application;
+
+/// <summary>Paces the Linux JUCE message pump (see App.axaml.cs): fast while hosted plugins
+/// are posting messages, slow once the queue has stayed empty for a while — so a session
+/// with no plugin (or a quiet one) isn't woken 100×/s for nothing (#55). One handled
+/// message snaps it back to the fast rate.</summary>
+public sealed class PumpPacer
+{
+ public static readonly TimeSpan Fast = TimeSpan.FromMilliseconds(10);
+ public static readonly TimeSpan Slow = TimeSpan.FromMilliseconds(100);
+ /// <summary>Empty pumps in a row (at the fast rate) before backing off: ~0.25 s.</summary>
+ public const int IdlePumpsBeforeSlow = 25;
+
+ private int _idle;
+
+ /// <summary>The current interval.</summary>
+ public TimeSpan Interval { get; private set; } = Fast;
+
+ /// <summary>Feed the number of messages the last pump handled; returns the next interval.</summary>
+ public TimeSpan Next(int handled)
+ {
+ if (handled > 0) _idle = 0;
+ else if (_idle < IdlePumpsBeforeSlow) _idle++;
+ return Interval = _idle >= IdlePumpsBeforeSlow ? Slow : Fast;
+ }
+}
diff --git a/tests/Nota.SmokeTest/Program.cs b/tests/Nota.SmokeTest/Program.cs
index d739b5ad..db2e1fac 100644
--- a/tests/Nota.SmokeTest/Program.cs
+++ b/tests/Nota.SmokeTest/Program.cs
@@ -14645,6 +14645,7 @@ foreach (var (ok, label) in PanLawTests.Run()) Check(ok, label);
Console.WriteLine("-- plugin host pump --");
Check(NotaEngine.PumpPluginHost() == 0 && NotaEngine.PumpPluginHost() == 0,
"plugin host pump: exported, non-blocking no-op with no plugin loaded");
+foreach (var (ok, label) in PumpPacerTests.Run()) Check(ok, label);
Console.WriteLine("-- mix undo --");
foreach (var (ok, label) in MixUndoTests.Run()) Check(ok, label);
diff --git a/tests/Nota.SmokeTest/PumpPacerTests.cs b/tests/Nota.SmokeTest/PumpPacerTests.cs
new file mode 100644
index 00000000..2163b0d3
--- /dev/null
+++ b/tests/Nota.SmokeTest/PumpPacerTests.cs
@@ -0,0 +1,31 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.
+//
+// The Linux JUCE pump's pacing (.specify/bugs/linux-idle-cpu): it starts fast, backs off
+// only after a run of empty pumps, and one handled message brings it straight back.
+
+using Nota.Application;
+
+namespace Nota.SmokeTest;
+
+internal static class PumpPacerTests
+{
+ public static IEnumerable<(bool Ok, string Label)> Run()
+ {
+ var p = new PumpPacer();
+ yield return (p.Interval == PumpPacer.Fast, "pump pacer starts at the fast rate");
+
+ TimeSpan last = p.Interval;
+ for (int i = 0; i < PumpPacer.IdlePumpsBeforeSlow - 1; i++) last = p.Next(0);
+ yield return (last == PumpPacer.Fast, "a short run of empty pumps stays fast");
+
+ last = p.Next(0);
+ yield return (last == PumpPacer.Slow, "a long run of empty pumps backs off to the slow rate");
+
+ for (int i = 0; i < 1000; i++) last = p.Next(0);
+ yield return (last == PumpPacer.Slow, "an idle pump stays slow");
+
+ yield return (p.Next(3) == PumpPacer.Fast, "one handled message snaps back to fast");
+ yield return (p.Next(0) == PumpPacer.Fast, "…and the back-off starts over");
+ }
+}