-
Notifications
You must be signed in to change notification settings - Fork 0
/
chord_quiz.js
46 lines (37 loc) · 1.21 KB
/
chord_quiz.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//TODO add slash chords
let kind, base = null;
let chord_found;
let chord_array;
let chord_held = []; // notes currently held by the user, treated as a set
function random_chord(){
if ( (chord = chords.get_random()) == null) return;
if ( (base = notes.get_random()) == null) return;
last_chord = chord;
last_base = base;
chord_array = addConstantModulo12(chord.notes, base.number)
cprint(base.name + chord.name);
}
function chord_callback(event){
[type, key, intensity] = event.data;
chord_held = [... new Set(addConstantModulo12(notes_down, 0))]
if (haveSameElements(addConstantModulo12(chord_held, 0), chord_array)){
chord_held.forEach((note) => {
green_key(note);
});
chord_found = true;
}
// a little sloppy but it feels more right than just the name changing
// while the correct previous chord is still being held
if (type == KEYUP && chord_found){
chord_held.forEach((note) => {
unlight_key(note);
});
chord_found = false;
random_chord();
}
}
function init_chord(){
canvas.style.display = 'none';
init_quiz(random_chord, chord_callback)
}
add_game_button('chords', init_chord);