pub struct LivePoly { /* private fields */ }Expand description
A polyphonic live instrument over one patch.
Implementations§
Source§impl LivePoly
impl LivePoly
Sourcepub fn new(
tree_json: &str,
sample_rate: f64,
n_voices: usize,
) -> Result<LivePoly, JsValue>
pub fn new( tree_json: &str, sample_rate: f64, n_voices: usize, ) -> Result<LivePoly, JsValue>
Build an n_voices-voice instrument from a PatchTree JSON.
Sourcepub fn set_meter(&mut self, on: bool) -> usize
pub fn set_meter(&mut self, on: bool) -> usize
Turn interior metering on or off.
On, every module in the patch gets a Level subscription and
Self::meter_ptr carries its RMS in dB; off, nothing is subscribed
and the render loop does no metering work at all. Returns the number of
taps, which is the length of both Self::meter_keys and the level
buffer.
Nothing here needs sync_output_keepalive. That call pins ports with
no consumer so a module implementing tick_masked still produces them,
and it dirties the patch — a recompile that would have to be staged
around the audio thread the way patch swaps are. It is not needed
because the genome is a typed tree: every module’s output feeds
exactly one parent, so quiver is already computing every value metered
here. Metering costs no recompile and cannot glitch the audio.
Sourcepub fn meter_keys(&self) -> String
pub fn meter_keys(&self) -> String
The term keys the level buffer is indexed by, as a JSON array.
Read once after Self::set_meter rather than per quantum — this
allocates, and the order is fixed until the next patch swap.
Sourcepub fn meter_ptr(&self) -> *const f32
pub fn meter_ptr(&self) -> *const f32
Pointer to the RMS dB per tap, in Self::meter_keys order.
The same zero-allocation contract as Self::process_ptr: a view into
wasm memory, overwritten in place, valid until the next patch swap
resizes it. A tap that has not filled a buffer yet reads
f32::NEG_INFINITY — silence, not zero dB.
Sourcepub fn meter_len(&self) -> usize
pub fn meter_len(&self) -> usize
How many taps Self::meter_ptr holds.
Sourcepub fn set_patch(&mut self, tree_json: &str) -> bool
pub fn set_patch(&mut self, tree_json: &str) -> bool
Queue a patch swap. Parses eagerly (false = bad JSON, nothing changes); the actual voice rebuild is amortized over the next few silent quanta. Held notes are re-pressed on the new patch.
Sourcepub fn poll_event(&mut self) -> u32
pub fn poll_event(&mut self) -> u32
Poll the latest swap event (0 = none, 1 = patched, 2 = error). Clears on read.
Sourcepub fn last_error(&self) -> String
pub fn last_error(&self) -> String
The message of the last patch error.
Sourcepub fn note_on(&mut self, note: u8, vel: f64)
pub fn note_on(&mut self, note: u8, vel: f64)
Press a MIDI note (60 = C4) with velocity 0..1. Retriggers if already held; otherwise takes a parked voice, else steals the oldest. With the arp on, the note joins the held set and the arp presses it.
Sourcepub fn note_off(&mut self, note: u8)
pub fn note_off(&mut self, note: u8)
Release a MIDI note (the voice keeps ringing through its tail).
Sourcepub fn set_bend(&mut self, semitones: f64)
pub fn set_bend(&mut self, semitones: f64)
Pitch bend in semitones (smoothed on the audio thread).
Sourcepub fn set_unison(&mut self, on: bool, detune: f64, spread: f64)
pub fn set_unison(&mut self, on: bool, detune: f64, spread: f64)
Unison mode: every voice plays the same note, detuned/panned apart.
Sourcepub fn set_arp(
&mut self,
on: bool,
mode: u32,
div: f64,
bpm: f64,
gate: f64,
octaves: u32,
swing: f64,
)
pub fn set_arp( &mut self, on: bool, mode: u32, div: f64, bpm: f64, gate: f64, octaves: u32, swing: f64, )
Configure the arpeggiator. mode: 0 up, 1 down, 2 up-down, 3 random.
div: steps per beat. gate: note length as a fraction of the step
(0.05 staccato … 1.0; at or above [ARP_TIE] the pattern is tied and
slides between pitches instead of retriggering). octaves: how many
octaves the pattern climbs before wrapping (1–4). swing: 0–0.75, which
lengthens every even step and shortens the odd one after it, leaving the
pair’s total duration unchanged.
Turning it off re-presses the held chord; turning it on hands the held notes to the scheduler.
Sourcepub fn set_param(&mut self, addr: &str, value: f64) -> bool
pub fn set_param(&mut self, addr: &str, value: f64) -> bool
Set a knob target in the site’s own units. The value ramps in over
~25 ms on the audio thread (no zipper) — no recompilation: filter
and delay state survive. Returns false for addresses with no live
handle (the remaining enums, structure) — those need set_patch.
“The site’s own units” is new, and it is the whole reason table and
oct can be here at all: they send a category index, and the blanket
clamp(0.0, 1.0) this used to apply would have folded all eight
wavetables onto the first two and every octave onto −2 and −1.
Sourcepub fn set_makeup(&mut self, gain: f64)
pub fn set_makeup(&mut self, gain: f64)
Loudness makeup gain (linear). Applied immediately when idle, or deferred to swap completion when a patch swap is pending (so the outgoing patch fades at its own level).
Sourcepub fn process_ptr(&mut self, frames: usize) -> *const f32
pub fn process_ptr(&mut self, frames: usize) -> *const f32
Render frames frames into the internal interleaved-stereo buffer
and return a pointer into wasm memory — the zero-allocation worklet
path ([l0, r0, l1, r1, …], frames * 2 floats).
Trait Implementations§
Source§impl FromWasmAbi for LivePoly
impl FromWasmAbi for LivePoly
Source§impl IntoWasmAbi for LivePoly
impl IntoWasmAbi for LivePoly
Source§impl LongRefFromWasmAbi for LivePoly
impl LongRefFromWasmAbi for LivePoly
Source§impl OptionFromWasmAbi for LivePoly
impl OptionFromWasmAbi for LivePoly
Source§impl OptionIntoWasmAbi for LivePoly
impl OptionIntoWasmAbi for LivePoly
Source§impl RefFromWasmAbi for LivePoly
impl RefFromWasmAbi for LivePoly
Source§type Abi = WasmPtr<WasmRefCell<LivePoly>>
type Abi = WasmPtr<WasmRefCell<LivePoly>>
Self are recovered from.Source§impl RefMutFromWasmAbi for LivePoly
impl RefMutFromWasmAbi for LivePoly
Source§impl TryFromJsValue for LivePoly
impl TryFromJsValue for LivePoly
Source§impl VectorFromWasmAbi for LivePoly
impl VectorFromWasmAbi for LivePoly
Source§impl VectorIntoWasmAbi for LivePoly
impl VectorIntoWasmAbi for LivePoly
impl SupportsConstructor for LivePoly
impl SupportsInstanceProperty for LivePoly
impl SupportsStaticProperty for LivePoly
Auto Trait Implementations§
impl Freeze for LivePoly
impl !RefUnwindSafe for LivePoly
impl Send for LivePoly
impl Sync for LivePoly
impl Unpin for LivePoly
impl UnsafeUnpin for LivePoly
impl !UnwindSafe for LivePoly
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
Source§type Abi = <T as IntoWasmAbi>::Abi
type Abi = <T as IntoWasmAbi>::Abi
IntoWasmAbi::AbiSource§fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
IntoWasmAbi::into_abi, except that it may throw and never
return in the case of Err.