Skip to content

Commit e26c236

Browse files
authored
More play along improvements (#46)
* Don't clear user pressed keys on playback pause * Ignore drums and keys out of range in play along
1 parent 45ef0e0 commit e26c236

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

neothesia-core/src/render/keyboard/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ impl KeyboardRenderer {
4747
pub fn reset_notes(&mut self) {
4848
for key in self.key_states.iter_mut() {
4949
key.pressed_by_file_off();
50-
key.set_pressed_by_user(false);
5150
}
5251
self.queue_reupload();
5352
}

neothesia/src/scene/playing_scene/midi_player.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub struct MidiPlayer {
2222
}
2323

2424
impl MidiPlayer {
25-
pub fn new(target: &mut Target) -> Self {
25+
pub fn new(target: &mut Target, user_keyboard_range: piano_math::KeyboardRange) -> Self {
2626
let midi_file = target.midi_file.as_ref().unwrap();
2727

2828
let mut player = Self {
@@ -33,7 +33,7 @@ impl MidiPlayer {
3333
rewind_controller: RewindController::None,
3434
output_manager: target.output_manager.clone(),
3535
midi_file: midi_file.clone(),
36-
play_along: PlayAlong::default(),
36+
play_along: PlayAlong::new(user_keyboard_range),
3737
};
3838
player.update(target, Duration::ZERO);
3939

@@ -58,6 +58,10 @@ impl MidiPlayer {
5858
events.iter().for_each(|event| {
5959
self.output_manager.borrow_mut().midi_event(event);
6060

61+
if event.channel == 9 {
62+
return;
63+
}
64+
6165
use midi_file::midly::MidiMessage;
6266
match event.message {
6367
MidiMessage::NoteOn { key, .. } => {
@@ -192,8 +196,10 @@ struct UserPress {
192196
note_id: u8,
193197
}
194198

195-
#[derive(Debug, Default)]
199+
#[derive(Debug)]
196200
pub struct PlayAlong {
201+
user_keyboard_range: piano_math::KeyboardRange,
202+
197203
required_notes: HashSet<u8>,
198204

199205
// List of user key press events that happened in last 500ms,
@@ -202,6 +208,14 @@ pub struct PlayAlong {
202208
}
203209

204210
impl PlayAlong {
211+
fn new(user_keyboard_range: piano_math::KeyboardRange) -> Self {
212+
Self {
213+
user_keyboard_range,
214+
required_notes: Default::default(),
215+
user_pressed_recently: Default::default(),
216+
}
217+
}
218+
205219
fn update(&mut self) {
206220
// Instead of calling .elapsed() per item let's fetch `now` once, and substract it ourselfs
207221
let now = Instant::now();
@@ -247,6 +261,10 @@ impl PlayAlong {
247261
}
248262

249263
pub fn press_key(&mut self, src: KeyPressSource, note_id: u8, active: bool) {
264+
if !self.user_keyboard_range.contains(note_id) {
265+
return;
266+
}
267+
250268
match src {
251269
KeyPressSource::User => self.user_press_key(note_id, active),
252270
KeyPressSource::File => self.file_press_key(note_id, active),

neothesia/src/scene/playing_scene/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl PlayingScene {
6161
keyboard_layout.clone(),
6262
);
6363

64-
let player = MidiPlayer::new(target);
64+
let player = MidiPlayer::new(target, keyboard_layout.range.clone());
6565
notes.update(&target.gpu.queue, player.time_without_lead_in());
6666

6767
Self {

0 commit comments

Comments
 (0)