diff --git a/changelog.md b/changelog.md index 3663790..6bc710b 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,7 @@ ## 0.2.4 +- Fixed: If note is played via a qwerty key press, and then an octave is changed via a qwerty key press, there won't be a note-off event. - Fixed: Cacophony can't found files (saves, soundfonts, etc.) if the file extension contains uppercase characters. - Fixed clippy warnings for Rust 1.78 - The GitHub workflow for building Cacophony now uses the latest version of Rust. diff --git a/input/src/lib.rs b/input/src/lib.rs index d8f8bfc..d2ba7f4 100644 --- a/input/src/lib.rs +++ b/input/src/lib.rs @@ -70,9 +70,9 @@ pub struct Input { events: Vec, /// The MIDI connection. midi_conn: Option, - // Note-on MIDI messages. These will be sent immediately to the synthesizer to be played. + /// Note-on MIDI messages. These will be sent immediately to the synthesizer to be played. pub note_on_messages: Vec<[u8; 3]>, - // Note-off MIDI messages. These will be sent immediately to the synthesizer. + /// Note-off MIDI messages. These will be sent immediately to the synthesizer. pub note_off_keys: Vec, /// Note-on events that don't have corresponding off events. note_on_events: Vec, @@ -206,10 +206,12 @@ impl Input { } // Octave up. if events.contains(&InputEvent::OctaveUp) && self.qwerty_octave < MAX_OCTAVE { + self.clear_notes_on_qwerty_octave(); self.qwerty_octave += 1; } // Octave down. if events.contains(&InputEvent::OctaveDown) && self.qwerty_octave > 0 { + self.clear_notes_on_qwerty_octave(); self.qwerty_octave -= 1; } // Qwerty note-off. @@ -420,6 +422,14 @@ impl Input { (9 - self.qwerty_octave) * 12 + note } + /// When a qwerty note is pressed, followed by an octave change, clear all note-on events. + fn clear_notes_on_qwerty_octave(&mut self) { + // Qwerty note-off. + for (_, qwerty_note_off) in QWERTY_NOTE_EVENTS.iter() { + self.note_off_keys.push(self.get_pitch(*qwerty_note_off)); + } + } + #[cfg(debug_assertions)] fn listen_for_note_offs(&mut self) { if self.happened(&InputEvent::NotesOff) {