-
Notifications
You must be signed in to change notification settings - Fork 0
/
scale_degrees.js
43 lines (35 loc) · 1.01 KB
/
scale_degrees.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
// ex: 6th note of F# major
// easy to implement
let index, note_to_guess;
const ordinal = {
0: '1st',
1: '2nd',
2: '3rd',
3: '4th',
4: '5th',
5: '6th',
6: '7th',
}
function random_scale_degree(){
if ( (scale_base = notes.get_random() ) == null) return;
if ( (scale = scales.get_random() ) == null) return;
index = rand_index(scale.notes);
scale_array = addConstantModulo12(scale.notes, scale_base.number);
note_to_guess = scale_array[index]%12;
cprint ( ordinal[index] + ' note of ' + scale_base.name + ' ' + scale.name);
}
function scale_degree_callback(event){
[type, key, intensity] = event.data;
if (key % 12 == note_to_guess){
green_key(key);
}
if (type == KEYUP && key % 12 == note_to_guess){
unlight_key(key);
random_scale_degree();
}
}
function init_scale_degree(){
canvas.style.display = 'none';
init_quiz(random_scale_degree, scale_degree_callback)
}
add_game_button('scale degrees', init_scale_degree);