diff options
Diffstat (limited to 'audio/src/program.rs')
| -rw-r--r-- | audio/src/program.rs | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/audio/src/program.rs b/audio/src/program.rs index 28a5f41..d8ece2c 100644 --- a/audio/src/program.rs +++ b/audio/src/program.rs @@ -41,19 +41,20 @@ const fn map_volume(volume: u8) -> f32 { pub struct Program { ins: Vec<Instruction>, pc: usize, - looping: bool, pause_cnt: u32, pause_len: u32, + looping: bool, + playing: bool, } impl Program { pub const fn new(ins: Vec<Instruction>, looping: bool) -> Self { - let pc = ins.len(); Self { ins, - pc, - looping, + pc: 0, pause_cnt: 0, pause_len: 4, + looping, + playing: false, } } @@ -150,6 +151,9 @@ impl Program { } pub fn exec(&mut self, channels: &mut Channels) { + if !self.playing { + return; + } if self.pause_cnt > 0 { self.pause_cnt -= 1; } @@ -157,10 +161,11 @@ impl Program { if self.pause_cnt > 0 { break; } - if self.finished() { + if self.is_finished() { if self.looping { self.pc = 0; } else { + self.playing = false; break; } } @@ -170,11 +175,16 @@ impl Program { } } - pub const fn finished(&self) -> bool { + pub const fn is_finished(&self) -> bool { self.pc >= self.ins.len() } + pub const fn is_playing(&self) -> bool { + self.playing + } + pub const fn play(&mut self) { + self.playing = true; self.pc = 0; } |