Skip to main content

QuiverEngine

Struct QuiverEngine 

Source
pub struct QuiverEngine { /* private fields */ }
Available on crate feature wasm only.
Expand description

Main WASM interface for Quiver audio engine

Implementations§

Source§

impl QuiverEngine

Source

pub fn new(sample_rate: f64) -> Self

Create a new Quiver engine

Source

pub fn sample_rate(&self) -> f64

Get the sample rate

Source

pub fn get_catalog(&self) -> Result<JsValue, JsValue>

Get the full module catalog

Source

pub fn search_modules(&self, query: &str) -> Result<JsValue, JsValue>

Search modules by query string

Source

pub fn get_modules_by_category( &self, category: &str, ) -> Result<JsValue, JsValue>

Get modules by category

Source

pub fn get_categories(&self) -> Result<JsValue, JsValue>

Get all categories

Source

pub fn get_signal_colors(&self) -> Result<JsValue, JsValue>

Get default signal colors

Source

pub fn check_compatibility( &self, from: &str, to: &str, ) -> Result<JsValue, JsValue>

Check port compatibility between two signal kinds

Source

pub fn load_patch(&mut self, patch_json: JsValue) -> Result<(), JsValue>

Load a patch from JSON

Source

pub fn save_patch(&self, name: &str) -> Result<JsValue, JsValue>

Save the current patch to JSON

Source

pub fn validate_patch(&self, patch_json: JsValue) -> Result<JsValue, JsValue>

Validate a patch definition

Source

pub fn clear_patch(&mut self)

Clear the current patch

Source

pub fn add_module(&mut self, type_id: &str, name: &str) -> Result<(), JsValue>

Add a module to the patch

Source

pub fn remove_module(&mut self, name: &str) -> Result<(), JsValue>

Remove a module from the patch

Source

pub fn set_module_position( &mut self, name: &str, x: f32, y: f32, ) -> Result<(), JsValue>

Set module position for UI layout

Source

pub fn get_module_position(&self, name: &str) -> Result<JsValue, JsValue>

Get module position

Source

pub fn module_count(&self) -> usize

Get the number of modules in the patch

Source

pub fn cable_count(&self) -> usize

Get the number of cables in the patch

Source

pub fn set_output(&mut self, name: &str) -> Result<(), JsValue>

Set the output module (required for audio output)

The specified module’s outputs will be read as the patch’s stereo output. Port 0 is left channel, port 1 is right channel.

Source

pub fn connect(&mut self, from: &str, to: &str) -> Result<usize, JsValue>

Connect two ports (format: “module.port”).

Returns the new cable’s stable CableId as a number. Hold onto it and pass it to disconnect_cable to remove exactly this connection later, even after other cables change.

Source

pub fn connect_attenuated( &mut self, from: &str, to: &str, attenuation: f64, ) -> Result<usize, JsValue>

Connect with attenuation. Returns the new cable’s stable CableId.

Source

pub fn connect_modulated( &mut self, from: &str, to: &str, attenuation: f64, offset: f64, ) -> Result<usize, JsValue>

Connect with full modulation (attenuation and offset). Returns the new cable’s stable CableId.

Source

pub fn disconnect_cable(&mut self, cable_id: usize) -> Result<(), JsValue>

Disconnect a cable by its stable CableId.

This is the id returned by connect and friends. It stays valid regardless of how many other cables have been removed since.

Source

pub fn disconnect_by_index(&mut self, cable_index: usize) -> Result<(), JsValue>

Disconnect the cable at the given position in the cable list.

Convenience for callers that track cables positionally. Resolves the position to the cable’s stable CableId and removes it, so the underlying removal is id-based (never off-by-one after prior removals).

Source

pub fn disconnect(&mut self, from: &str, to: &str) -> Result<(), JsValue>

Disconnect two ports (format: “module.port”)

Source

pub fn get_module_names(&self) -> Result<JsValue, JsValue>

Get all module names in the patch

Source

pub fn get_params(&self, node_name: &str) -> Result<JsValue, JsValue>

Get parameters for a module

Note: This returns metadata about the module’s type from the registry, not the current parameter values. Use get_param for values.

Source

pub fn set_param( &mut self, node_name: &str, param_index: u32, value: f64, ) -> Result<(), JsValue>

Set a parameter value by numeric index

Source

pub fn get_param( &self, node_name: &str, param_index: u32, ) -> Result<f64, JsValue>

Get a parameter value

Source

pub fn set_param_by_name( &mut self, node_name: &str, param_name: &str, value: f64, ) -> Result<(), JsValue>

Set a parameter value by name

This is a convenience method that looks up the parameter index by name.

Source

pub fn subscribe(&mut self, targets: JsValue) -> Result<(), JsValue>

Subscribe to real-time value updates

Source

pub fn unsubscribe(&mut self, target_ids: JsValue) -> Result<(), JsValue>

Unsubscribe from real-time value updates

Source

pub fn clear_subscriptions(&mut self)

Clear all subscriptions

Source

pub fn poll_updates(&mut self) -> Result<JsValue, JsValue>

Poll for pending updates (called from requestAnimationFrame)

Source

pub fn pending_update_count(&self) -> usize

Get the number of pending updates

Source

pub fn tick(&mut self) -> Box<[f64]>

Process a single sample and return stereo output as a Float64Array [left, right].

Source

pub fn process_block(&mut self, num_samples: usize) -> Float32Array

Process a block of num_samples frames and return the interleaved stereo result as a Float32Array of length num_samples * 2 ([l0, r0, l1, r1, ...]).

§Zero-allocation

The engine keeps preallocated, reused L/R and interleaved buffers (grown on demand). Rendering uses the allocation-free Patch::tick_block, so a steady-state render quantum performs no per-sample or per-block heap allocation. Output is safety-clamped to ±10V to prevent speaker/hearing damage from runaway signals.

§Ownership rule (important)

The returned Float32Array is a view into WASM linear memory, valid only until the next call into this engine (which reuses/grows the buffer) or free. Read it immediately — e.g. copy into your own array with Array.from(...) or myBuffer.set(...) — before calling any other engine method. Do not retain the returned object.

Source

pub fn set_observer_interval(&mut self, blocks: u32)

Set how often the state observer collects values, in blocks.

1 collects on every process_block; higher values decimate collection (default 8). Clamped to a minimum of 1.

Source

pub fn reset(&mut self)

Reset all module state

Source

pub fn compile(&mut self) -> Result<(), JsValue>

Compile the patch (required after adding/removing modules or cables)

Source

pub fn add_midi_inputs(&mut self)

Inject the engine-owned MIDI CV source modules into the current patch.

Adds five ExternalInput modules the user can cable from to make MIDI actually drive audio:

Module nameSignalFed by
midi_voctV/Octmidi_note_on (pitch)
midi_gateGate (0/5V)midi_note_on / midi_note_off
midi_velocityCV unipolar 0–1midi_note_on (velocity)
midi_modCV unipolar 0–1midi_cc(1, ...) (mod wheel)
midi_bendCV bipolar V/Octmidi_pitch_bend

Each exposes a single out port (e.g. cable midi_voct.out -> vco.voct). Idempotent: modules already present (by name) are left untouched, so it is safe to call after building or loading a patch. Marks the patch dirty.

Note: these modules are engine-managed and are not in the module registry, so a patch saved while they are present cannot be re-instantiated by load_patch on a fresh engine — call add_midi_inputs() again after loading.

Source

pub fn midi_note_on(&mut self, note: u8, velocity: u8) -> Result<(), JsValue>

Handle a MIDI Note On message.

Updates both the scalar getters and the shared midi_voct / midi_gate / midi_velocity CV sources (see add_midi_inputs), so a cabled patch responds on the next processed sample.

The shared CV sources are monophonic, so overlapping notes follow last-note priority: the newly pressed note becomes the sounding note and is pushed onto the held-note stack (see midi_note_off).

Source

pub fn midi_note_off(&mut self, note: u8, _velocity: u8) -> Result<(), JsValue>

Handle a MIDI Note Off message.

The midi_* CV sources are monophonic and shared, so releasing a note only closes the gate when it is the last held note. With overlapping notes (a chord, or legato where the next note-on precedes the previous note-off), releasing an inner note keeps the gate open and re-points pitch/velocity to the most recently pressed note still held (last-note priority). This preserves the documented “Gate: 5.0 while a note is held” contract instead of dropping the gate — and prematurely releasing every cabled envelope — on the first release.

Source

pub fn midi_note(&self) -> f64

Get the current MIDI note as V/Oct (for connecting to VCO)

Source

pub fn midi_velocity(&self) -> f64

Get the current MIDI velocity (0-1)

Source

pub fn midi_gate(&self) -> bool

Get the current MIDI gate state

Source

pub fn midi_cc(&mut self, cc: u8, value: u8) -> Result<(), JsValue>

Handle a MIDI Control Change message.

All CCs are stored for retrieval via get_midi_cc. CC1 (mod wheel) additionally drives the shared midi_mod CV source.

Source

pub fn get_midi_cc(&self, cc: u8) -> f64

Get a MIDI CC value (0-1 normalized)

Source

pub fn midi_pitch_bend(&mut self, value: f64) -> Result<(), JsValue>

Handle a MIDI Pitch Bend message (value in -1..1).

Drives the shared midi_bend CV source as a V/Oct offset of ±2 semitones at full deflection. The pitch_bend getter still returns the raw -1..1 value.

Source

pub fn pitch_bend(&self) -> f64

Get the current pitch bend value (-1 to 1)

Source

pub fn get_port_spec(&self, type_id: &str) -> Result<JsValue, JsValue>

Get port specification for a module type

Trait Implementations§

Source§

impl From<QuiverEngine> for JsValue

Source§

fn from(value: QuiverEngine) -> Self

Converts to this type from the input type.
Source§

impl FromWasmAbi for QuiverEngine

Source§

type Abi = u32

The Wasm ABI type that this converts from when coming back out from the ABI boundary.
Source§

unsafe fn from_abi(js: u32) -> Self

Recover a Self from Self::Abi. Read more
Source§

impl IntoWasmAbi for QuiverEngine

Source§

type Abi = u32

The Wasm ABI type that this converts into when crossing the ABI boundary.
Source§

fn into_abi(self) -> u32

Convert self into Self::Abi so that it can be sent across the wasm ABI boundary.
Source§

impl LongRefFromWasmAbi for QuiverEngine

Source§

type Abi = u32

Same as RefFromWasmAbi::Abi
Source§

type Anchor = RcRef<QuiverEngine>

Same as RefFromWasmAbi::Anchor
Source§

unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor

Same as RefFromWasmAbi::ref_from_abi
Source§

impl OptionFromWasmAbi for QuiverEngine

Source§

fn is_none(abi: &Self::Abi) -> bool

Tests whether the argument is a “none” instance. If so it will be deserialized as None, and otherwise it will be passed to FromWasmAbi.
Source§

impl OptionIntoWasmAbi for QuiverEngine

Source§

fn none() -> Self::Abi

Returns an ABI instance indicating “none”, which JS will interpret as the None branch of this option. Read more
Source§

impl RefFromWasmAbi for QuiverEngine

Source§

type Abi = u32

The Wasm ABI type references to Self are recovered from.
Source§

type Anchor = RcRef<QuiverEngine>

The type that holds the reference to Self for the duration of the invocation of the function that has an &Self parameter. This is required to ensure that the lifetimes don’t persist beyond one function call, and so that they remain anonymous.
Source§

unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor

Recover a Self::Anchor from Self::Abi. Read more
Source§

impl RefMutFromWasmAbi for QuiverEngine

Source§

type Abi = u32

Same as RefFromWasmAbi::Abi
Source§

type Anchor = RcRefMut<QuiverEngine>

Same as RefFromWasmAbi::Anchor
Source§

unsafe fn ref_mut_from_abi(js: Self::Abi) -> Self::Anchor

Same as RefFromWasmAbi::ref_from_abi
Source§

impl SupportsConstructor for QuiverEngine

Source§

impl SupportsInstanceProperty for QuiverEngine

Source§

impl SupportsStaticProperty for QuiverEngine

Source§

impl TryFromJsValue for QuiverEngine

Source§

fn try_from_js_value(value: JsValue) -> Result<Self, JsValue>

Performs the conversion.
Source§

fn try_from_js_value_ref(value: &JsValue) -> Option<Self>

Performs the conversion.
Source§

impl VectorFromWasmAbi for QuiverEngine

Source§

impl VectorIntoWasmAbi for QuiverEngine

Source§

impl WasmDescribe for QuiverEngine

Source§

impl WasmDescribeVector for QuiverEngine

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ReturnWasmAbi for T
where T: IntoWasmAbi,

Source§

type Abi = <T as IntoWasmAbi>::Abi

Same as IntoWasmAbi::Abi
Source§

fn return_abi(self) -> <T as ReturnWasmAbi>::Abi

Same as IntoWasmAbi::into_abi, except that it may throw and never return in the case of Err.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.