fix: freeze the scope when the transport is stopped

FL keeps calling process() with silence while stopped/paused, so the scope
scrolled silence instead of holding. Gate the plot's bucket advance on
context.transport().playing, so it freezes on stop/pause and resumes on play.
Bar meters still fall to silence as before. Update README thread-safety notes
for the ScopeRing feed and transport gating.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Mikkeli Matlock
2026-06-24 16:25:08 +09:00
parent 9a60b0ea72
commit 514fd964f6
2 changed files with 34 additions and 18 deletions
+9 -3
View File
@@ -256,9 +256,15 @@ NIH-plug provides `Smoother` — use it for all gain/threshold params to avoid z
### Thread safety
Params are atomics. The editor and audio thread communicate only through params and a shared
`Arc<Meters>` of **lock-free atomics** (`meters.rs`) — never a mutex on the audio path. `process()`
publishes one value per meter per block (gated on the editor being open); the editor reads them
each frame. Never pass DSP state to the UI directly.
`Arc<Meters>` (`meters.rs`) — never a mutex on the audio path. Two lock-free feeds, both gated on
the editor being open:
- **Bar meters** — decayed atomic scalars, one store per block; the editor reads them each frame.
- **Scrolling plot** — a single-producer/single-consumer `ScopeRing` of buckets clocked at
~200 Hz, so the plot's horizontal resolution is decoupled from the ~60 fps repaint. The editor
drains all new buckets each frame. The scope is **transport-gated** (advances only while playing)
so it freezes rather than scrolling silence when the host is stopped/paused.
Never pass DSP state to the UI directly.
### VST3 licensing
You must accept Steinberg's VST3 SDK licence before distributing VST3 binaries.
+11 -1
View File
@@ -171,7 +171,7 @@ impl Plugin for Codename206 {
&mut self,
buffer: &mut Buffer,
_aux: &mut AuxiliaryBuffers,
_context: &mut impl ProcessContext<Self>,
context: &mut impl ProcessContext<Self>,
) -> ProcessStatus {
let lookahead = self.lookahead_samples();
@@ -198,6 +198,9 @@ impl Plugin for Codename206 {
// Only do the (cheap) metering work when the editor is actually open.
let metering = self.params.editor_state.is_open();
// The host keeps calling process() with silence while stopped/paused (FL does), so the
// scope is gated on the transport actually playing — otherwise it would scroll silence.
let playing = context.transport().playing;
let num_samples = buffer.samples();
let mut lvl_l = [0.0f32; meters::NUM_CHANNELS];
let mut lvl_r = [0.0f32; meters::NUM_CHANNELS];
@@ -246,11 +249,13 @@ impl Plugin for Codename206 {
lvl_l[b] = lvl_l[b].max(out_l);
lvl_r[b] = lvl_r[b].max(out_r);
gr[b] = gr[b].max(g);
if playing {
self.scope_in[b] = self.scope_in[b].max(in_mono);
self.scope_out[b] = self.scope_out[b].max(out_l.max(out_r));
self.scope_gr[b] = self.scope_gr[b].max(g);
}
}
}
// 'All' aggregate channel over the summed bands (driven before its compressor).
let all_pre = util::db_to_gain(self.params.all.pre_gain_db.smoothed.next());
@@ -272,6 +277,10 @@ impl Plugin for Codename206 {
lvl_r[ALL] = lvl_r[ALL].max(out_r);
gr[ALL] = gr[ALL].max(g);
lim_gr = lim_gr.max(self.limiter.gain_reduction_db());
// Only advance the scope while the transport is playing, so it freezes (rather than
// scrolling silence) when the host is paused/stopped but still calling process().
if playing {
self.scope_in[ALL] = self.scope_in[ALL].max(in_mono);
self.scope_out[ALL] = self.scope_out[ALL].max(out_l.max(out_r));
self.scope_gr[ALL] = self.scope_gr[ALL].max(g);
@@ -286,6 +295,7 @@ impl Plugin for Codename206 {
self.scope_samples = 0;
}
}
}
for ch in 0..n {
*frame.get_mut(ch).unwrap() = lim_frame[ch];