pub struct AtomicParameterBridge { /* private fields */ }Expand description
Lock-free bridge for passing parameter values from the WebSocket thread to the audio thread.
Constructed once at startup with one Arc<AtomicF32> per parameter. The
inner HashMap is never mutated after construction — only the atomic
values change. This makes reads fully lock-free and real-time safe.
Implementations§
Source§impl AtomicParameterBridge
impl AtomicParameterBridge
Sourcepub fn new(parameters: &[ParameterInfo]) -> Self
pub fn new(parameters: &[ParameterInfo]) -> Self
Create a new bridge from parameter metadata.
Each parameter gets an AtomicF32 initialized to its default value.
Sourcepub fn parameter_count(&self) -> usize
pub fn parameter_count(&self) -> usize
Returns the dense plain-value parameter count in generation order.
Sourcepub fn write(&self, id: &str, value: f32)
pub fn write(&self, id: &str, value: f32)
Write a parameter value (called from WebSocket thread).
Uses Ordering::Relaxed — no synchronization guarantee beyond
eventual visibility. The audio thread will see the update at the
next block boundary.
Sourcepub fn read(&self, id: &str) -> Option<f32>
pub fn read(&self, id: &str) -> Option<f32>
Read a parameter value (called from audio thread — RT-safe).
Returns None if the parameter ID is unknown. Uses
Ordering::Relaxed — single atomic load, no allocation.
Sourcepub fn copy_all_to(&self, output: &mut [f32]) -> usize
pub fn copy_all_to(&self, output: &mut [f32]) -> usize
Copy all parameters into output in stable generation order.
Returns the number of copied values (min(output.len(), parameter_count())).
This is real-time safe and allocation-free, suitable for audio callback use.