diff options
Diffstat (limited to 'audio')
| -rw-r--r-- | audio/src/data.rs | 13 | ||||
| -rw-r--r-- | audio/src/lib.rs | 1 | ||||
| -rw-r--r-- | audio/src/parse/macros.rs | 4 | ||||
| -rw-r--r-- | audio/src/program.rs | 22 |
4 files changed, 31 insertions, 9 deletions
diff --git a/audio/src/data.rs b/audio/src/data.rs index 2d1bdc5..e63254d 100644 --- a/audio/src/data.rs +++ b/audio/src/data.rs @@ -11,20 +11,29 @@ macro_rules! load_asm { Program::parse(&src, true)? } }}; - ($first:tt, $($arg:tt)*) => { + ($first:tt, $($arg:tt),*) => { load_asm!($first)$(.merge(load_asm!($arg)))* }; } pub struct Data { + pub explore: Program, pub megalovania: Program, } impl Data { pub fn load() -> crate::Result<Self> { + let explore = load_asm!( + "assets/asm/explore_melody.asm", + "assets/asm/explore_harmony1.asm", + "assets/asm/explore_harmony2.asm" + ); let megalovania = load_asm!( "assets/asm/megalovania_melody.asm", "assets/asm/megalovania_base.asm" ); - Ok(Self { megalovania }) + Ok(Self { + explore, + megalovania, + }) } } diff --git a/audio/src/lib.rs b/audio/src/lib.rs index b2d3e87..97121f5 100644 --- a/audio/src/lib.rs +++ b/audio/src/lib.rs @@ -85,6 +85,7 @@ impl Audio { pub fn update(&mut self) { if self.last.elapsed() >= TIME_SLICE { + self.data.explore.exec(&mut self.channels); self.data.megalovania.exec(&mut self.channels); self.last = Instant::now(); } diff --git a/audio/src/parse/macros.rs b/audio/src/parse/macros.rs index 1dc33eb..d33208a 100644 --- a/audio/src/parse/macros.rs +++ b/audio/src/parse/macros.rs @@ -75,7 +75,9 @@ fn fill_macro(contents: &mut Vec<Cow<'_, str>>, name: &str, body: &str) -> usize break; } let line = &contents[idx]; - if line.starts_with(name) { + if line.starts_with(name) + && matches!(line.chars().nth(name.len()), None | Some(' ')) + { fill_macro_once(contents, idx, body); count += 1; } 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; } |