]> git.huck.website - cellseq.git/commitdiff
fixed: modulo by zero error in note generator
authorHuck Boles <huck@huck.website>
Sat, 8 Jul 2023 23:40:24 +0000 (18:40 -0500)
committerHuck Boles <huck@huck.website>
Sat, 8 Jul 2023 23:40:24 +0000 (18:40 -0500)
src/midi.rs
src/music.rs

index 74a8b6b68f2a823a606cf52737f0f9e9acd8a9ff..1181daac2b0978ccdb2a88057d31ee08a5808f78 100644 (file)
@@ -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);
index eeb3e966f0ea27cc059c78917f239fe59189fa4c..2867e225aed9f4b4fbb9d5413e6907c47c56ed6b 100644 (file)
@@ -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::<u8>() % info.octave.range;
+    let oct_mod = if info.octave.range != 0 {
+        random::<u8>() % info.octave.range
+    } else {
+        0
+    };
+
     let octave = if random::<bool>() {
         info.octave.center.saturating_add(oct_mod)
     } else {