summaryrefslogtreecommitdiff
path: root/audio/src/program.rs
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2025-11-22 16:00:35 -0500
committerFreya Murphy <freya@freyacat.org>2025-11-22 16:29:28 -0500
commitfbfb3ad0f70ebbc5db9e5d5fc41c53c15b082d9d (patch)
treea41968431e016403aa3956bbdc075dd4a2203e1e /audio/src/program.rs
parentaudio: refactor into seperate crate (diff)
downloadDungeonCrawl-fbfb3ad0f70ebbc5db9e5d5fc41c53c15b082d9d.tar.gz
DungeonCrawl-fbfb3ad0f70ebbc5db9e5d5fc41c53c15b082d9d.tar.bz2
DungeonCrawl-fbfb3ad0f70ebbc5db9e5d5fc41c53c15b082d9d.zip
audio: some changes
Diffstat (limited to 'audio/src/program.rs')
-rw-r--r--audio/src/program.rs22
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;
}