-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandom_note_script.js
More file actions
41 lines (36 loc) · 1.43 KB
/
random_note_script.js
File metadata and controls
41 lines (36 loc) · 1.43 KB
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
const note_sets = {
basic: ["A", "B", "C", "D", "E", "F", "G"],
sharps: ["A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#"],
sharps_flats: ["A", "A#", "Bb", "B", "C", "C#", "Db", "D", "D#", "Eb", "E", "F", "F#", "Gb", "G", "G#","Ab"]
};
let current_set = null;
let current_index = null;
let current_notes = null;
function newCurrentSet() {
const selected_set = document.querySelector("#note_set").value;
current_set = selected_set;
// Shuffle notes from current set
current_notes = note_sets[current_set].slice().sort(() => Math.random() - 0.5);
current_index = 0;
}
document.querySelector("#note_set").addEventListener("change", newCurrentSet);
newCurrentSet();
function updateNote() {
const selected_strings = 6; //parseInt(document.querySelector("#string_set").value);
let selected_string = null;
if(selected_strings != 6) {
// Random string between selected string and 6
selected_string = Math.floor(Math.random() * (7 - selected_strings)) + selected_strings;
}
const contentDiv = document.querySelector("#content");
contentDiv.textContent = current_notes[current_index];
if(selected_string) {
contentDiv.innerHTML += "<br>(on " + selected_string + ")";
}
current_index++;
if (current_index >= current_notes.length) {
newCurrentSet();
}
setTimeout(updateNote, (document.querySelector("#duration").value || 5) * 1000);
}
updateNote();