diff --git a/audio/src/conn.rs b/audio/src/conn.rs index d155471..529ba48 100644 --- a/audio/src/conn.rs +++ b/audio/src/conn.rs @@ -248,8 +248,10 @@ impl Conn { synth.set_sample_rate(self.framerate); drop(synth); - // Enqueue note events. let mut midi_event_queue = self.midi_event_queue.lock(); + // Clear the queue before adding new events. + midi_event_queue.clear(); + // Enqueue note events. for track in state.music.get_playable_tracks().iter() { for note in track.get_playback_notes(state.time.playback) { // Note-on event. diff --git a/audio/src/midi_event_queue.rs b/audio/src/midi_event_queue.rs index 17fd99c..f7dfade 100644 --- a/audio/src/midi_event_queue.rs +++ b/audio/src/midi_event_queue.rs @@ -39,4 +39,9 @@ impl MidiEventQueue { } midi_events } + + /// Clear the queue. + pub(crate) fn clear(&mut self) { + self.events.clear() + } } diff --git a/changelog.md b/changelog.md index ee9027a..82b91e1 100644 --- a/changelog.md +++ b/changelog.md @@ -4,6 +4,8 @@ - Fixed: There was an input bug where the play/start key (spacebar) was sometimes unresponsive for the first few presses. This is because audio was still decaying from a previous play, meaning that technically the previous play was still ongoing. - Fixed: When a new file is created or when a new save file loaded, the app didn't reset correctly. +- Fixed: If you try to play music and there are no tracks or no playable notes, the app starts playing music and then immediately stops. +- Fixed: If you're playing music and then load a save file, the save file can't play music because the synthesizer still has MIDI events from the previous music. ## 0.2.1 diff --git a/io/src/lib.rs b/io/src/lib.rs index 94fa381..67036d6 100644 --- a/io/src/lib.rs +++ b/io/src/lib.rs @@ -423,7 +423,15 @@ impl IO { // Get the focused panel. let panel = self.get_panel(&state.panels[state.focus.get()]); // Play music. - if panel.allow_play_music() && input.happened(&InputEvent::PlayStop) { + if input.happened(&InputEvent::PlayStop) + && panel.allow_play_music() + && !state.music.midi_tracks.is_empty() + && state + .music + .get_playable_tracks() + .iter() + .any(|t| !t.get_playback_notes(state.time.playback).is_empty()) + { conn.set_music(state); } // We're not done yet.