Skip to content

Commit

Permalink
fix(instrument): retrigger on special 255 instrument
Browse files Browse the repository at this point in the history
  • Loading branch information
nenikitov committed Oct 5, 2024
1 parent 4aaf12b commit 13b5f2a
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions engine/src/asset/sound/dat/mixer_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl AudioSamplePoint for i16 {
}
}

#[derive(Default, Clone)]
#[derive(Default, Clone, Debug)]
struct PlayerChannelNote {
finetune: Option<FineTune>,
finetune_initial: Option<FineTune>,
Expand Down Expand Up @@ -140,22 +140,28 @@ impl PlayerChannel {
T::from_normalized_f32(current_sample)
}

fn change_instrument(&mut self, instrument: Option<Rc<TInstrument>>) {
// In tracker music, every instrument change is a state reset
fn trigger_note(&mut self) {
// Previous state is kept to subtly blend in notes to remove clicks.

// Disregard previous state before `self.clone` so we don't have a fully recursive structure.
self.previous = None;
self.previous = Some((Box::new(self.clone()), 0.));

self.pos_reset();
}

fn change_instrument(&mut self, instrument: Option<Rc<TInstrument>>) {
if let Some(instrument) = instrument {
self.instrument = Some(instrument);
self.pos_reset();

self.trigger_note();
} else {
// TODO(nenikitov): Idk honestly, figure this out
self.note_cut();
self.instrument = None;
self.sample = None;
if self.instrument.is_none() {
// TODO(nenikitov): Idk honestly, figure this out
self.note_cut();
self.instrument = None;
self.sample = None;
}
}

Check warning on line 165 in engine/src/asset/sound/dat/mixer_new.rs

View workflow job for this annotation

GitHub Actions / clippy

this `else { if .. }` block can be collapsed

warning: this `else { if .. }` block can be collapsed --> engine/src/asset/sound/dat/mixer_new.rs:158:16 | 158 | } else { | ________________^ 159 | | if self.instrument.is_none() { 160 | | // TODO(nenikitov): Idk honestly, figure this out 161 | | self.note_cut(); ... | 164 | | } 165 | | } | |_________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_else_if = note: `#[warn(clippy::collapsible_else_if)]` on by default help: collapse nested if block | 158 ~ } else if self.instrument.is_none() { 159 + // TODO(nenikitov): Idk honestly, figure this out 160 + self.note_cut(); 161 + self.instrument = None; 162 + self.sample = None; 163 + } |
}

Expand Down Expand Up @@ -276,7 +282,7 @@ impl<'a> Player<'a> {
.map(|c| c.generate_sample::<S>(step))
.map(|c| c.into_normalized_f32())
//.enumerate()
//.filter_map(|(i, s)| (i == 4).then_some(s))
//.filter_map(|(i, s)| (i == 8).then_some(s))
.sum::<f32>();
S::from_normalized_f32(sample * self.volume_global * self.volume_amplification)
}
Expand Down

0 comments on commit 13b5f2a

Please sign in to comment.