From 89f3385f1f091415d7e7ef553f6da6f503a0db92 Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Sat, 22 Nov 2025 01:25:54 -0500 Subject: audio: fix merge --- graphics/src/audio/program.rs | 49 +++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/graphics/src/audio/program.rs b/graphics/src/audio/program.rs index b5cc363..f5decd6 100644 --- a/graphics/src/audio/program.rs +++ b/graphics/src/audio/program.rs @@ -63,35 +63,44 @@ impl Program { } pub fn merge(self, other: Self) -> Self { - let mut l_ins = self.ins; - let r_ins = other.ins; + let mut res = vec![]; + let mut l = 0; let mut r = 0; + let l_ins = self.ins; + let r_ins = other.ins; + loop { - if r >= r_ins.len() { + if l >= l_ins.len() && r >= r_ins.len() { + // were done here break; } - let ins = r_ins[r]; - if ins == Instruction::Pause { - // inc l until even - loop { - if l == l_ins.len() { - l_ins.push(Instruction::Pause); - break; - } - if l_ins[l] == Instruction::Pause { - l += 1; - break; - } - l += 1; + + let mut has_pause = false; + while l < l_ins.len() { + let ins = l_ins[l]; + l += 1; + if matches!(ins, Instruction::Pause) { + has_pause = true; + break; + } + res.push(ins); + } + while r < r_ins.len() { + let ins = r_ins[r]; + r += 1; + if matches!(ins, Instruction::Pause) { + has_pause = true; + break; } - } else { - l_ins.insert(l, ins); + res.push(ins); + } + if has_pause { + res.push(Instruction::Pause); } - r += 1; } - Self::new(l_ins, self.looping) + Self::new(res, self.looping) } fn exec_ins(&mut self, channels: &mut Channels, ins: Instruction) { -- cgit v1.2.3-freya