diff --git a/neothesia/src/scene/playing_scene/midi_player.rs b/neothesia/src/scene/playing_scene/midi_player.rs index 1cee79ac..eba8a9d5 100644 --- a/neothesia/src/scene/playing_scene/midi_player.rs +++ b/neothesia/src/scene/playing_scene/midi_player.rs @@ -3,7 +3,6 @@ use midi_file::midly::{num::u4, MidiMessage}; use crate::{ output_manager::OutputConnection, song::{PlayerConfig, Song}, - target::Target, }; use std::{ collections::{HashSet, VecDeque}, @@ -19,7 +18,7 @@ pub struct MidiPlayer { impl MidiPlayer { pub fn new( - target: &Target, + output: OutputConnection, song: Song, user_keyboard_range: piano_math::KeyboardRange, ) -> Self { @@ -28,7 +27,7 @@ impl MidiPlayer { Duration::from_secs(3), song.file.tracks.clone(), ), - output: target.output_manager.connection().clone(), + output, play_along: PlayAlong::new(user_keyboard_range), song, }; @@ -36,7 +35,7 @@ impl MidiPlayer { // for timestamp 0 most likely all programs will be 0, so this should clean any leftovers // from previous songs player.send_midi_programs_for_timestamp(&player.playback.time()); - player.update(target, Duration::ZERO); + player.update(Duration::ZERO); player } @@ -44,12 +43,10 @@ impl MidiPlayer { /// When playing: returns midi events /// /// When paused: returns None - pub fn update(&mut self, target: &Target, delta: Duration) -> Vec<&midi_file::MidiEvent> { + pub fn update(&mut self, delta: Duration) -> Vec<&midi_file::MidiEvent> { self.play_along.update(); - let elapsed = (delta / 10) * (target.config.speed_multiplier * 10.0) as u32; - - let events = self.playback.update(elapsed); + let events = self.playback.update(delta); events.iter().for_each(|event| { let config = &self.song.config.tracks[event.track_id]; diff --git a/neothesia/src/scene/playing_scene/mod.rs b/neothesia/src/scene/playing_scene/mod.rs index c69d33d7..c3262234 100644 --- a/neothesia/src/scene/playing_scene/mod.rs +++ b/neothesia/src/scene/playing_scene/mod.rs @@ -55,7 +55,11 @@ impl PlayingScene { keyboard_layout.clone(), ); - let player = MidiPlayer::new(target, song, keyboard_layout.range.clone()); + let player = MidiPlayer::new( + target.output_manager.connection().clone(), + song, + keyboard_layout.range.clone(), + ); notes.update(&target.gpu.queue, player.time_without_lead_in()); Self { @@ -94,7 +98,8 @@ impl Scene for PlayingScene { self.rewind_controler.update(&mut self.player, target); if self.player.play_along().are_required_keys_pressed() { - let midi_events = self.player.update(target, delta); + let delta = (delta / 10) * (target.config.speed_multiplier * 10.0) as u32; + let midi_events = self.player.update(delta); self.keyboard.file_midi_events(&target.config, &midi_events); }