dynamic sequencer support

This commit is contained in:
sigil-03 2025-11-05 19:42:44 -07:00
parent 7d93cd8977
commit 9e67026345
3 changed files with 144 additions and 22 deletions

View file

@ -11,6 +11,8 @@ const SQUARE_WAVETABLE: [u8; 2] = [0, 100];
pub struct SynthesizerService {
pub synth: SimpleWavetableSynthesizer<SimpleWavetable<'static, u8>>,
pub enabled: bool,
pub need_service: bool,
}
impl SynthesizerService {
@ -18,19 +20,29 @@ impl SynthesizerService {
let square_wt = SimpleWavetable::new(&SQUARE_WAVETABLE);
let synth = SimpleWavetableSynthesizer::new(square_wt, clock_freq_hz);
Self { synth }
Self {
synth,
enabled: true,
need_service: false,
}
}
pub fn tick(&mut self) {
self.synth.tick();
if self.enabled {
self.synth.tick();
}
}
pub fn need_service(&self) -> bool {
self.synth.has_new_output()
self.need_service || self.synth.has_new_output()
}
pub fn service(&mut self) -> u8 {
self.synth.get_output()
pub fn service(&mut self) -> Option<u8> {
if self.enabled {
Some(self.synth.get_output())
} else {
None
}
}
}
@ -40,10 +52,14 @@ impl SynthesizerService {
}
pub fn enable(&mut self) {
self.enabled = true;
self.need_service = true;
// TODO: write the enable function
}
pub fn disable(&mut self) {
self.enabled = false;
self.need_service = true;
// TODO: write the disable function
}
}