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);
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 {