summaryrefslogtreecommitdiff
path: root/graphics/src/audio/program.rs
diff options
context:
space:
mode:
Diffstat (limited to 'graphics/src/audio/program.rs')
-rw-r--r--graphics/src/audio/program.rs49
1 files 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) {