-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandom-note.js
More file actions
46 lines (34 loc) · 1.33 KB
/
Copy pathrandom-note.js
File metadata and controls
46 lines (34 loc) · 1.33 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
42
43
44
45
46
function swapNote() {
let nextNote = noteSet.pop()
if (nextNote === undefined) {
noteSet = shuffle(baseSet)
nextNote = noteSet.pop()
}
noteElement.textContent = nextNote + (chordCheckbox.checked ? get_random(chordTypes) : "")
}
function useSet(set) {
baseSet = set
noteSet = shuffle(baseSet)
}
const shuffle = ([...array]) => {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
return array;
};
function get_random(arr) {
return arr[Math.floor((Math.random() * arr.length))];
}
const noteElement = document.getElementById("current_note");
const chordCheckbox = document.querySelector("#chords");
const naturals = ["A", "B", "C", "D", "E", "F", "G"]
const sharps = ["A", "A#", "B", "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#"]
const flats = ["Ab", "A", "Bb", "B", "C", "Db", "D", "Eb", "E", "F", "Gb", "G"]
const both = ["A", "A#", "Ab", "B", "Bb", "C", "C#", "D", "D#", "Db", "E", "Eb", "F", "F#", "G", "G#", "Gb"]
const chordTypes = ["7M", "m7", "7", "°", "m(7M)", "ø", "7M(#5)"]
let baseSet = naturals
let noteSet = shuffle(baseSet);
let intervalms = 3000;
swapNote(noteSet)
setInterval(function () { swapNote(noteSet) }, intervalms)