Skip to main content
← PSoXide SDK guides and examples · SDK 80d1c329e977 · All Cargo features enabled; check feature gates before use.

Sequencer

Struct Sequencer 

Source
pub struct Sequencer<'a, const P: usize, const N: usize> { /* private fields */ }
Expand description

The sequencer: P players sharing N voices.

Players are independent songs (background music, a fanfare over it, an overlay); each has its own tempo, IO ports and fade, and they compete for the same N voices by note priority.

Implementations§

Source§

impl<'a, const P: usize, const N: usize> Sequencer<'a, P, N>

Source

pub fn note_on( &mut self, hw: &mut impl Hw, font_id: u8, instrument: u8, key: u8, velocity: u8, pan: u8, priority: u8, ) -> Option<NoteHandle>

Start a note: instrument of the soundfont whose original id is font_id (it must be in the loaded bank), at semitone key, with MIDI-like velocity and pan (0 left, 64 centre, 127 right) and a note priority (1 to 15, larger is more important; it takes a free voice, then an old decaying one, then the least important sounding note below it). Returns None when no voice can be had.

let mut seq: Sequencer<'_, 1, 4> = Sequencer::new(0b1111);
let mut hw = Recorder::<8>::new();
// no bank loaded: nothing to play
assert!(seq.note_on(&mut hw, 0, 0, 60, 100, 64, 9).is_none());
Source

pub fn note_alive(&self, h: NoteHandle) -> bool

Whether the note is still sounding.

Source

pub fn note_bend(&mut self, h: NoteHandle, bend_q16: u32) -> bool

Bend the note’s pitch by bend_q16 (65536 = none, 131072 = an octave up). Returns whether the handle was live.

Source

pub fn note_vibrato(&mut self, h: NoteHandle, depth: u8, rate: u8) -> bool

Give the note vibrato, with the depth and rate units of the vibdepth and vibfreq channel opcodes (0 turns it off).

Source

pub fn note_velocity(&mut self, h: NoteHandle, velocity: u8) -> bool

Change a held note’s loudness (velocity as in note_on).

Source

pub fn note_off(&mut self, h: NoteHandle) -> bool

Let the note go: it decays at its instrument’s release rate.

Source§

impl<'a, const P: usize, const N: usize> Sequencer<'a, P, N>

Source

pub fn new(voice_mask: u32) -> Self

A sequencer over the voices set in voice_mask, which must have exactly N bits set.

The sequencer is several kilobytes: a game that keeps one in a static should build it in place with Sequencer::init_at and not pass this return value through its stack.

§Panics

If voice_mask does not have N bits set.

Source

pub unsafe fn init_at(slot: *mut Self, voice_mask: u32)

Build a sequencer over the voices set in voice_mask (exactly N bits) directly in slot, field by field, without a copy of it on the stack.

§Safety

slot must be valid for writes of a Sequencer and aligned for one; whatever it held is overwritten without being read or dropped.

§Panics

If voice_mask does not have N bits set.

Source

pub fn set_bank(&mut self, bank: Bank<'a>, spu_base: u32)

Use bank for instruments. spu_base is where its ADPCM region was uploaded in SPU RAM.

Source

pub fn start( &mut self, player: usize, song: &'a mut [u8], ) -> Result<(), StartError>

Start song on player. song is the whole container as loaded; songs that patch themselves need it in RAM.

Source

pub fn stop(&mut self, player: usize, fade_updates: u16)

Stop player, fading its volume to nothing over fade_updates updates first (0 stops now; held notes release at their own rate).

Source

pub fn is_playing(&self, player: usize) -> bool

Is player still running its song?

Source

pub fn voices_in_use(&self) -> u32

Voices that are not free.

Source

pub fn unsupported_ops(&self) -> u32

Opcodes met so far that this engine does not implement.

Source

pub fn set_player_io(&mut self, player: usize, port: usize, value: u8)

Write a sequence-level IO port (what ldio in the song reads).

Source

pub fn player_io(&self, player: usize, port: usize) -> Option<u8>

Read back a sequence-level IO port (what stio in the song wrote).

Source

pub fn set_channel_io( &mut self, player: usize, channel: usize, port: usize, value: u8, )

Write a channel IO port.

Source

pub fn channel_io( &self, player: usize, channel: usize, port: usize, ) -> Option<u8>

Read back a channel IO port.

Source

pub fn set_channel_mute(&mut self, player: usize, mask: u16)

Mute (set bits) or unmute channels of player. Muted channels start no new notes.

Source

pub fn fade_to(&mut self, player: usize, target_q15: u16, updates: u16)

Fade player’s volume to target_q15 (32768 = full) over updates.

Source

pub fn set_master(&mut self, q12: u16)

Set the output gain applied to every voice (4096 = 1.0). The game passes the music volume times the duck gain from psx_sfx::master.

Source

pub fn set_player_muted(&mut self, player: usize, muted: bool)

Mute or unmute a whole player (what the pause menu does). Behaviour follows the song’s mute settings: by default notes stop and the rest is softened.

Source

pub fn pump(&mut self, hw: &mut impl Hw, now: u32)

Run the updates due at now (a count of UPDATE_HZ updates on the caller’s clock). The first call only sets the clock.

Source

pub fn update(&mut self, hw: &mut impl Hw)

Run exactly one update.

Source

pub fn silence(&mut self, hw: &mut impl Hw)

Key off every voice and forget all notes (before overwriting the sample region in SPU RAM).

Source

pub fn song_flags(bytes: &[u8]) -> Result<u16, FormatError>

Whether the song header says flag.

Auto Trait Implementations§

§

impl<'a, const P: usize, const N: usize> Freeze for Sequencer<'a, P, N>

§

impl<'a, const P: usize, const N: usize> RefUnwindSafe for Sequencer<'a, P, N>

§

impl<'a, const P: usize, const N: usize> Send for Sequencer<'a, P, N>

§

impl<'a, const P: usize, const N: usize> Sync for Sequencer<'a, P, N>

§

impl<'a, const P: usize, const N: usize> Unpin for Sequencer<'a, P, N>

§

impl<'a, const P: usize, const N: usize> UnsafeUnpin for Sequencer<'a, P, N>

§

impl<'a, const P: usize, const N: usize> !UnwindSafe for Sequencer<'a, P, N>

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.