From: Huck Boles Date: Sat, 8 Jul 2023 23:40:24 +0000 (-0500) Subject: fixed: modulo by zero error in note generator X-Git-Url: https://git.huck.website/?a=commitdiff_plain;h=fb0da4b5ffc5cf15287565bb46534f383dd9135b;p=cellseq.git fixed: modulo by zero error in note generator --- diff --git a/src/midi.rs b/src/midi.rs index 74a8b6b..1181daa 100644 --- a/src/midi.rs +++ b/src/midi.rs @@ -91,6 +91,11 @@ impl MidiLink { if self.notes_on.len() > info.voices.into() { if let Some(elem) = self.notes_on.iter().next().cloned() { self.notes_on.remove(&elem); + self.buffer.push(MidiMessage::Off { + note: elem, + velocity: generate_velocity(info.velocity), + channel: info.channel, + }); } } self.notes_on.insert(note); diff --git a/src/music.rs b/src/music.rs index eeb3e96..2867e22 100644 --- a/src/music.rs +++ b/src/music.rs @@ -247,7 +247,12 @@ impl Display for Scale { pub fn generate_note(info: &MidiInfo) -> u8 { let root: u8 = info.root.into(); - let oct_mod = random::() % info.octave.range; + let oct_mod = if info.octave.range != 0 { + random::() % info.octave.range + } else { + 0 + }; + let octave = if random::() { info.octave.center.saturating_add(oct_mod) } else {