From fb0da4b5ffc5cf15287565bb46534f383dd9135b Mon Sep 17 00:00:00 2001 From: Huck Boles Date: Sat, 8 Jul 2023 18:40:24 -0500 Subject: [PATCH] fixed: modulo by zero error in note generator --- src/midi.rs | 5 +++++ src/music.rs | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) 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 { -- 2.45.2