Skip to main content

Synth

Trait Synth 

Source
pub trait Synth {
    // Required methods
    fn current_time(&self) -> u32;
    fn play_msg_at(&mut self, msg: u32, time: u32) -> bool;
    fn play_sysex_at(&mut self, sysex: &[u8], time: u32) -> bool;
    fn render(&mut self, out: &mut [Frame]);

    // Provided methods
    fn play_msg(&mut self, msg: u32) -> bool { ... }
    fn play_sysex(&mut self, sysex: &[u8]) -> bool { ... }
}
Expand description

Interface for MIDI synthesizers.

MIDI messages must be added in time-ascending order, otherwise they will be ignored during rendering.

Required Methods§

Source

fn current_time(&self) -> u32

Returns the number of frames rendered so far.

Source

fn play_msg_at(&mut self, msg: u32, time: u32) -> bool

Enqueues one MIDI message at a specific frame.

A MIDI baud rate transfer delay is added to time before enqueuing: 24 frames for 3-byte messages, 16 frames for 2-byte messages (program change and channel pressure).

Source

fn play_sysex_at(&mut self, sysex: &[u8], time: u32) -> bool

Enqueues one MIDI System Exclusive message at a specific frame.

No transfer delay is added; the message is processed at exactly the given frame.

Source

fn render(&mut self, out: &mut [Frame])

Renders audio samples into a slice of frames.

The output slice is filled with stereo audio frames. Each Frame is comprised of two 16-bit, native-endian, signed PCM audio samples.

The internal clock is advanced by the number of frames rendered.

Provided Methods§

Source

fn play_msg(&mut self, msg: u32) -> bool

Enqueues one MIDI message starting from the current frame.

Equivalent to play_msg_at(msg, current_time()). The message is processed after the MIDI baud rate transfer delay (16 or 24 frames), not at the current frame itself.

Source

fn play_sysex(&mut self, sysex: &[u8]) -> bool

Enqueues one MIDI System Exclusive message at the current frame.

Equivalent to play_sysex_at(sysex, current_time()). The message is processed immediately at the current frame.

Implementors§