1
1
extends Control
2
2
3
+ const Hand = preload ("res://scripts/constants/hand.gd" ).Hand
4
+ const FingeredNote = preload ("res://scripts/models/fingered_note.gd" )
5
+ const NotePosition = preload ("res://scripts/models/note_position.gd" )
6
+
3
7
# Signals
4
8
signal clear_highlighted_keys
5
9
signal exercise_sequence_created (sequence : PracticeSequence )
6
10
signal sequence_updated (current_position : int )
7
11
signal sequence_completed
8
12
signal note_validated (success : bool )
9
- signal highlight_note_by_name (note_name : String , hand : MusicalConstants . Hand )
13
+ signal highlight_note_by_name (note_name : String , hand : Hand )
10
14
signal unhighlight_note_by_name (note_name : String )
11
15
signal clear_finger_indicators
12
- signal add_finger_indicator (note : PianoNote , is_current : bool )
16
+ signal add_finger_indicator (note : FingeredNote , is_current : bool )
13
17
14
18
# Node references
15
19
@onready var hand_dropdown = $ HBoxContainer/HandDropdown
@@ -63,29 +67,38 @@ func _on_hand_selected(index):
63
67
_update_exercise ()
64
68
65
69
func _update_exercise ():
66
- print ("Updating exercise" )
67
70
emit_signal ("clear_highlighted_keys" )
68
71
69
- var exercise_type = exercise_type_dropdown .get_item_text (exercise_type_dropdown .selected )
72
+ var exercise_type_str = exercise_type_dropdown .get_item_text (exercise_type_dropdown .selected )
73
+ var exercise_type : PracticeSequence .ExerciseType
74
+
75
+ if exercise_type_str == "Scales" :
76
+ exercise_type = PracticeSequence .ExerciseType .SCALES
77
+ elif exercise_type_str == "Chords" :
78
+ exercise_type = PracticeSequence .ExerciseType .CHORDS
79
+ elif exercise_type_str == "Arpeggios" :
80
+ exercise_type = PracticeSequence .ExerciseType .ARPEGGIOS
81
+ else :
82
+ exercise_type = PracticeSequence .ExerciseType .SCALES
83
+
70
84
var music_key_str = music_key_dropdown .get_item_text (music_key_dropdown .selected )
71
85
var music_key = null
72
86
for key in MusicalConstants .MusicKey .values ():
73
87
if MusicalConstants .MUSIC_KEY_STRINGS [key ] == music_key_str :
74
88
music_key = key
75
89
break
76
90
77
- var hand = MusicalConstants .Hand .RIGHT if hand_dropdown .get_item_text (hand_dropdown .selected ).begins_with ("Right" ) else MusicalConstants .Hand .LEFT
78
- var hand_name = "right_hand" if hand == MusicalConstants .Hand .RIGHT else "left_hand"
91
+ var hand = Hand .RIGHT_HAND if hand_dropdown .get_item_text (hand_dropdown .selected ).begins_with ("Right" ) else Hand .LEFT_HAND
79
92
80
93
var exercises = {
81
- "Scales" : "create_scale" ,
82
- "Chords" : "create_chord_inversions" ,
83
- "Arpeggios" : "create_arpeggios"
94
+ PracticeSequence . ExerciseType . SCALES : "create_scale" ,
95
+ PracticeSequence . ExerciseType . CHORDS : "create_chord_inversions" ,
96
+ PracticeSequence . ExerciseType . ARPEGGIOS : "create_arpeggios"
84
97
}
85
98
86
99
if exercises .has (exercise_type ):
87
100
var exercise_method = exercises [exercise_type ]
88
- var exercise_sequence = self .call (exercise_method , music_key , hand_name , hand )
101
+ var exercise_sequence = self .call (exercise_method , music_key , hand )
89
102
set_sequence (exercise_sequence )
90
103
91
104
# Set a new sequence and reset state
@@ -106,7 +119,7 @@ func validate_input(midi_notes: Array[int]) -> bool:
106
119
if not current_sequence or current_position >= current_sequence .sequence .size ():
107
120
return false
108
121
109
- var current_notes = current_sequence .sequence [current_position ]
122
+ var current_notes = current_sequence .sequence [current_position ]. notes
110
123
# First validate that all played notes are part of the expected chord
111
124
for midi_note in midi_notes :
112
125
var note_valid = false
@@ -146,7 +159,7 @@ func advance_sequence():
146
159
147
160
if current_position < current_sequence .sequence .size () - 1 :
148
161
current_position += 1
149
- var current_notes = current_sequence .sequence [current_position ]
162
+ var current_notes = current_sequence .sequence [current_position ]. notes
150
163
var note_names = []
151
164
for note in current_notes :
152
165
note_names .append (note .pitch )
@@ -166,21 +179,21 @@ func update_display():
166
179
emit_signal ("clear_finger_indicators" )
167
180
168
181
if current_position < current_sequence .sequence .size ():
169
- var current_notes = current_sequence .sequence [current_position ]
182
+ var current_notes = current_sequence .sequence [current_position ]. notes
170
183
for note in current_notes :
171
184
emit_signal ("add_finger_indicator" , note , true )
172
185
173
186
# Highlight current chord notes
174
187
func highlight_current_note ():
175
188
if current_position < current_sequence .sequence .size ():
176
- var current_notes = current_sequence .sequence [current_position ]
189
+ var current_notes = current_sequence .sequence [current_position ]. notes
177
190
for note in current_notes :
178
191
emit_signal ("highlight_note_by_name" , note .pitch , note .hand )
179
192
180
193
# Remove highlighting from current chord notes
181
194
func unhighlight_current_note ():
182
195
if current_position < current_sequence .sequence .size ():
183
- var current_notes = current_sequence .sequence [current_position ]
196
+ var current_notes = current_sequence .sequence [current_position ]. notes
184
197
for note in current_notes :
185
198
emit_signal ("unhighlight_note_by_name" , note .pitch )
186
199
@@ -199,38 +212,32 @@ func midi_to_note_name(midi_note: int) -> String:
199
212
return MusicalConstants .MIDI_TO_NOTE_PREFERRED [note_index ] + str (octave )
200
213
201
214
# Exercise creation methods
202
- func create_scale (music_key : MusicalConstants .MusicKey , hand_name : String , hand : MusicalConstants . Hand ) -> PracticeSequence :
215
+ func create_scale (music_key : MusicalConstants .MusicKey , hand : Hand ) -> PracticeSequence :
203
216
var practice_sequence = PracticeSequence .new ()
204
- practice_sequence .exercise_type = "scale"
217
+ practice_sequence .exercise_type = PracticeSequence . ExerciseType . SCALES
205
218
206
- var scale_notes = scales .get_exercise (music_key , hand_name )
207
- for note_data in scale_notes :
208
- var note = PianoNote .new (note_data [0 ], hand , note_data [1 ])
209
- practice_sequence .add_position ([note ])
219
+ var exercise = scales .get_exercise (music_key , hand )
220
+ for position in exercise :
221
+ practice_sequence .add_position (position )
210
222
211
223
return practice_sequence
212
224
213
- func create_chord_inversions (music_key : MusicalConstants .MusicKey , hand_name : String , hand : MusicalConstants . Hand ) -> PracticeSequence :
225
+ func create_chord_inversions (music_key : MusicalConstants .MusicKey , hand : Hand ) -> PracticeSequence :
214
226
var practice_sequence = PracticeSequence .new ()
215
- practice_sequence .exercise_type = "chord_inversions"
227
+ practice_sequence .exercise_type = PracticeSequence . ExerciseType . CHORDS
216
228
217
- var chord_notes = chords .get_exercise (music_key , hand_name )
218
- for chord in chord_notes :
219
- var chord_position : Array [PianoNote ] = []
220
- for note_data in chord :
221
- var note = PianoNote .new (note_data [0 ], hand , note_data [1 ])
222
- chord_position .append (note )
223
- practice_sequence .add_position (chord_position )
229
+ var exercise = chords .get_exercise (music_key , hand )
230
+ for position in exercise :
231
+ practice_sequence .add_position (position )
224
232
225
233
return practice_sequence
226
234
227
- func create_arpeggios (music_key : MusicalConstants .MusicKey , hand_name : String , hand : MusicalConstants . Hand ) -> PracticeSequence :
235
+ func create_arpeggios (music_key : MusicalConstants .MusicKey , hand : Hand ) -> PracticeSequence :
228
236
var practice_sequence = PracticeSequence .new ()
229
- practice_sequence .exercise_type = "arpeggio"
237
+ practice_sequence .exercise_type = PracticeSequence . ExerciseType . ARPEGGIOS
230
238
231
- var arpeggio_notes = arpeggios .get_exercise (music_key , hand_name )
232
- for note_data in arpeggio_notes :
233
- var note = PianoNote .new (note_data [0 ], hand , note_data [1 ])
234
- practice_sequence .add_position ([note ])
239
+ var exercise = arpeggios .get_exercise (music_key , hand )
240
+ for position in exercise :
241
+ practice_sequence .add_position (position )
235
242
236
243
return practice_sequence
0 commit comments