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>
impl<'a, const P: usize, const N: usize> Sequencer<'a, P, N>
Sourcepub fn note_on(
&mut self,
hw: &mut impl Hw,
font_id: u8,
instrument: u8,
key: u8,
velocity: u8,
pan: u8,
priority: u8,
) -> Option<NoteHandle>
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());Sourcepub fn note_alive(&self, h: NoteHandle) -> bool
pub fn note_alive(&self, h: NoteHandle) -> bool
Whether the note is still sounding.
Sourcepub fn note_bend(&mut self, h: NoteHandle, bend_q16: u32) -> bool
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.
Sourcepub fn note_vibrato(&mut self, h: NoteHandle, depth: u8, rate: u8) -> bool
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).
Sourcepub fn note_velocity(&mut self, h: NoteHandle, velocity: u8) -> bool
pub fn note_velocity(&mut self, h: NoteHandle, velocity: u8) -> bool
Change a held note’s loudness (velocity as in note_on).
Sourcepub fn note_off(&mut self, h: NoteHandle) -> bool
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>
impl<'a, const P: usize, const N: usize> Sequencer<'a, P, N>
Sourcepub fn new(voice_mask: u32) -> Self
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.
Sourcepub unsafe fn init_at(slot: *mut Self, voice_mask: u32)
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.
Sourcepub fn set_bank(&mut self, bank: Bank<'a>, spu_base: u32)
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.
Sourcepub fn start(
&mut self,
player: usize,
song: &'a mut [u8],
) -> Result<(), StartError>
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.
Sourcepub fn stop(&mut self, player: usize, fade_updates: u16)
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).
Sourcepub fn is_playing(&self, player: usize) -> bool
pub fn is_playing(&self, player: usize) -> bool
Is player still running its song?
Sourcepub fn voices_in_use(&self) -> u32
pub fn voices_in_use(&self) -> u32
Voices that are not free.
Sourcepub fn unsupported_ops(&self) -> u32
pub fn unsupported_ops(&self) -> u32
Opcodes met so far that this engine does not implement.
Sourcepub fn set_player_io(&mut self, player: usize, port: usize, value: u8)
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).
Sourcepub fn player_io(&self, player: usize, port: usize) -> Option<u8>
pub fn player_io(&self, player: usize, port: usize) -> Option<u8>
Read back a sequence-level IO port (what stio in the song wrote).
Sourcepub fn set_channel_io(
&mut self,
player: usize,
channel: usize,
port: usize,
value: u8,
)
pub fn set_channel_io( &mut self, player: usize, channel: usize, port: usize, value: u8, )
Write a channel IO port.
Sourcepub fn channel_io(
&self,
player: usize,
channel: usize,
port: usize,
) -> Option<u8>
pub fn channel_io( &self, player: usize, channel: usize, port: usize, ) -> Option<u8>
Read back a channel IO port.
Sourcepub fn set_channel_mute(&mut self, player: usize, mask: u16)
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.
Sourcepub fn fade_to(&mut self, player: usize, target_q15: u16, updates: u16)
pub fn fade_to(&mut self, player: usize, target_q15: u16, updates: u16)
Fade player’s volume to target_q15 (32768 = full) over updates.
Sourcepub fn set_master(&mut self, q12: u16)
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.
Sourcepub fn set_player_muted(&mut self, player: usize, muted: bool)
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.
Sourcepub fn pump(&mut self, hw: &mut impl Hw, now: u32)
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.
Sourcepub fn silence(&mut self, hw: &mut impl Hw)
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).
Sourcepub fn song_flags(bytes: &[u8]) -> Result<u16, FormatError>
pub fn song_flags(bytes: &[u8]) -> Result<u16, FormatError>
Whether the song header says flag.