@@ -22,7 +22,7 @@ pub struct MidiPlayer {
22
22
}
23
23
24
24
impl MidiPlayer {
25
- pub fn new ( target : & mut Target ) -> Self {
25
+ pub fn new ( target : & mut Target , user_keyboard_range : piano_math :: KeyboardRange ) -> Self {
26
26
let midi_file = target. midi_file . as_ref ( ) . unwrap ( ) ;
27
27
28
28
let mut player = Self {
@@ -33,7 +33,7 @@ impl MidiPlayer {
33
33
rewind_controller : RewindController :: None ,
34
34
output_manager : target. output_manager . clone ( ) ,
35
35
midi_file : midi_file. clone ( ) ,
36
- play_along : PlayAlong :: default ( ) ,
36
+ play_along : PlayAlong :: new ( user_keyboard_range ) ,
37
37
} ;
38
38
player. update ( target, Duration :: ZERO ) ;
39
39
@@ -58,6 +58,10 @@ impl MidiPlayer {
58
58
events. iter ( ) . for_each ( |event| {
59
59
self . output_manager . borrow_mut ( ) . midi_event ( event) ;
60
60
61
+ if event. channel == 9 {
62
+ return ;
63
+ }
64
+
61
65
use midi_file:: midly:: MidiMessage ;
62
66
match event. message {
63
67
MidiMessage :: NoteOn { key, .. } => {
@@ -192,8 +196,10 @@ struct UserPress {
192
196
note_id : u8 ,
193
197
}
194
198
195
- #[ derive( Debug , Default ) ]
199
+ #[ derive( Debug ) ]
196
200
pub struct PlayAlong {
201
+ user_keyboard_range : piano_math:: KeyboardRange ,
202
+
197
203
required_notes : HashSet < u8 > ,
198
204
199
205
// List of user key press events that happened in last 500ms,
@@ -202,6 +208,14 @@ pub struct PlayAlong {
202
208
}
203
209
204
210
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
+
205
219
fn update ( & mut self ) {
206
220
// Instead of calling .elapsed() per item let's fetch `now` once, and substract it ourselfs
207
221
let now = Instant :: now ( ) ;
@@ -247,6 +261,10 @@ impl PlayAlong {
247
261
}
248
262
249
263
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
+
250
268
match src {
251
269
KeyPressSource :: User => self . user_press_key ( note_id, active) ,
252
270
KeyPressSource :: File => self . file_press_key ( note_id, active) ,
0 commit comments