@@ -4,57 +4,30 @@ extends Control
44signal clear_highlighted_keys
55
66# Node references
7+ @onready var hand_dropdown = $ HBoxContainer/HandDropdown
78@onready var exercise_type_dropdown = $ HBoxContainer/ExerciseTypeDropdown
89@onready var music_key_dropdown = $ HBoxContainer/KeyDropdown
910@onready var sequence_manager = get_parent ().get_node ("SequenceManager" )
1011
1112# Load exercises
12- @onready var scales = load ("res://scripts/exercises/scales_major.gd" ).new ()
13- @onready var chords = load ("res://scripts/exercises/chords_major.gd" ).new ()
14- @onready var arpeggios = load ("res://scripts/exercises/arpeggios_major.gd" ).new ()
15-
16- # Named entity for exercise map
17- class ExerciseMap :
18- var scales : Array
19- var chords : Array
20- var arpeggios : Array
21-
22- func _init (_scales : Array , _chords : Array , _arpeggios : Array ):
23- scales = _scales
24- chords = _chords
25- arpeggios = _arpeggios
26-
27- # Helper method to create exercise maps
28- func create_exercise_map (key : String ) -> ExerciseMap :
29- return ExerciseMap .new (
30- scales .get (key .to_snake_case () + "_major_rh_1oct" ),
31- chords .get (key .to_snake_case () + "_major_rh_inversions" ),
32- arpeggios .get (key .to_snake_case () + "_major_rh_arpeggios" )
33- )
34-
35- # Key to exercise mapping
36- @onready var key_to_exercises = {
37- "C" : create_exercise_map ("c" ),
38- "G" : create_exercise_map ("g" ),
39- "D" : create_exercise_map ("d" ),
40- "A" : create_exercise_map ("a" ),
41- "E" : create_exercise_map ("e" ),
42- "B" : create_exercise_map ("b" ),
43- "F#" : create_exercise_map ("f_sharp" ),
44- "C#" : create_exercise_map ("c_sharp" ),
45- "F" : create_exercise_map ("f" ),
46- "Bb" : create_exercise_map ("b_flat" ),
47- "Eb" : create_exercise_map ("e_flat" ),
48- "Ab" : create_exercise_map ("a_flat" )
49- }
13+ @onready var scales = preload ("res://scripts/exercises/scales_major.gd" ).new ()
14+ @onready var chords = preload ("res://scripts/exercises/chords_major.gd" ).new ()
15+ @onready var arpeggios = preload ("res://scripts/exercises/arpeggios_major.gd" ).new ()
5016
5117func _ready ():
18+ hand_dropdown .connect ("item_selected" , _on_hand_selected )
5219 exercise_type_dropdown .connect ("item_selected" , _on_exercise_type_selected )
5320 music_key_dropdown .connect ("item_selected" , _on_key_selected )
5421 _initialize_dropdowns ()
5522 call_deferred ("_update_exercise" )
5623
5724func _initialize_dropdowns ():
25+ # Initialize hand selection
26+ hand_dropdown .clear ()
27+ hand_dropdown .add_item ("Right Hand" )
28+ hand_dropdown .add_item ("Left Hand" )
29+
30+ # Initialize exercise types
5831 exercise_type_dropdown .clear ()
5932 exercise_type_dropdown .add_item ("Scales" )
6033 exercise_type_dropdown .add_item ("Chords" )
@@ -64,9 +37,8 @@ func _initialize_dropdowns():
6437
6538func _update_key_dropdown ():
6639 music_key_dropdown .clear ()
67- var music_keys = ["C" , "G" , "D" , "A" , "E" , "B" , "F#" , "C#" , "F" , "Bb" , "Eb" , "Ab" ]
68- for music_key in music_keys :
69- music_key_dropdown .add_item (music_key )
40+ for key in MusicalConstants .MusicKey .values ():
41+ music_key_dropdown .add_item (MusicalConstants .MUSIC_KEY_STRINGS [key ])
7042
7143func _on_exercise_type_selected (index ):
7244 _update_key_dropdown ()
@@ -75,12 +47,24 @@ func _on_exercise_type_selected(index):
7547func _on_key_selected (index ):
7648 _update_exercise ()
7749
50+ func _on_hand_selected (index ):
51+ _update_exercise ()
52+
7853func _update_exercise ():
7954 emit_signal ("clear_highlighted_keys" )
8055
8156 var exercise_type = exercise_type_dropdown .get_item_text (exercise_type_dropdown .selected )
82- var music_key = music_key_dropdown .get_item_text (music_key_dropdown .selected )
83- print (exercise_type , music_key )
57+ var music_key_str = music_key_dropdown .get_item_text (music_key_dropdown .selected )
58+ var music_key = null
59+ for key in MusicalConstants .MusicKey .values ():
60+ if MusicalConstants .MUSIC_KEY_STRINGS [key ] == music_key_str :
61+ music_key = key
62+ break
63+
64+ var hand = MusicalConstants .Hand .RIGHT if hand_dropdown .get_item_text (hand_dropdown .selected ).begins_with ("Right" ) else MusicalConstants .Hand .LEFT
65+ var hand_name = "right_hand" if hand == MusicalConstants .Hand .RIGHT else "left_hand"
66+
67+ print (exercise_type , music_key_str , hand_name )
8468 var exercises = {
8569 "Scales" : "create_scale" ,
8670 "Chords" : "create_chord_inversions" ,
@@ -89,45 +73,42 @@ func _update_exercise():
8973
9074 if exercises .has (exercise_type ):
9175 var exercise_method = exercises [exercise_type ]
92- var exercise_sequence = self .call (exercise_method , music_key )
76+ var exercise_sequence = self .call (exercise_method , music_key , hand_name , hand )
9377 sequence_manager .set_sequence (exercise_sequence )
9478
9579# Exercise creation methods
96- func create_scale (music_key : String ) -> PracticeSequence :
80+ func create_scale (music_key : MusicalConstants . MusicKey , hand_name : String , hand : MusicalConstants . Hand ) -> PracticeSequence :
9781 var practice_sequence = PracticeSequence .new ()
9882 practice_sequence .exercise_type = "scale"
99-
100- var scale_notes = key_to_exercises [music_key ].scales
10183
84+ var scale_notes = scales .get_exercise (music_key , hand_name )
10285 for note_data in scale_notes :
103- var note = PianoNote .new (note_data [0 ], "R" , note_data [1 ])
86+ var note = PianoNote .new (note_data [0 ], hand , note_data [1 ])
10487 practice_sequence .add_position ([note ])
10588
10689 return practice_sequence
10790
108- func create_chord_inversions (music_key : String ) -> PracticeSequence :
91+ func create_chord_inversions (music_key : MusicalConstants . MusicKey , hand_name : String , hand : MusicalConstants . Hand ) -> PracticeSequence :
10992 var practice_sequence = PracticeSequence .new ()
11093 practice_sequence .exercise_type = "chord_inversions"
11194
112- var chord_notes = key_to_exercises [music_key ].chords
113-
95+ var chord_notes = chords .get_exercise (music_key , hand_name )
11496 for chord in chord_notes :
11597 var chord_position : Array [PianoNote ] = []
11698 for note_data in chord :
117- var note = PianoNote .new (note_data [0 ], "R" , note_data [1 ])
99+ var note = PianoNote .new (note_data [0 ], hand , note_data [1 ])
118100 chord_position .append (note )
119101 practice_sequence .add_position (chord_position )
120102
121103 return practice_sequence
122104
123- func create_arpeggios (music_key : String ) -> PracticeSequence :
105+ func create_arpeggios (music_key : MusicalConstants . MusicKey , hand_name : String , hand : MusicalConstants . Hand ) -> PracticeSequence :
124106 var practice_sequence = PracticeSequence .new ()
125107 practice_sequence .exercise_type = "arpeggio"
126108
127- var arpeggio_notes = key_to_exercises [music_key ].arpeggios
128-
109+ var arpeggio_notes = arpeggios .get_exercise (music_key , hand_name )
129110 for note_data in arpeggio_notes :
130- var note = PianoNote .new (note_data [0 ], "R" , note_data [1 ])
111+ var note = PianoNote .new (note_data [0 ], hand , note_data [1 ])
131112 practice_sequence .add_position ([note ])
132113
133114 return practice_sequence
0 commit comments