-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathview.js
More file actions
69 lines (65 loc) · 2.66 KB
/
Copy pathview.js
File metadata and controls
69 lines (65 loc) · 2.66 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import Synthesizer from './synthesizer.js'
export default class View {
constructor() {
this.synthesizer = Synthesizer.getInstance()
this.checkboxes = []
this.startnote = 57 //57 220 Hz, 69 440 Hz, 81 880 Hz
this.writeFifths()
this.checkFifths()
this.allOff()
}
writeFifths() {
let notes = ['A', 'A#', 'B', 'C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#']
for (let i = 0; i <= 36; i++) {
fifths.innerHTML +=
'<tr><th><input type="checkbox" name="checkbox"></th><th>' +
notes[(this.startnote - 9 + i) % 12] +
((this.startnote - 27 + i) / 12).toFixed(0) +
'</th><th>' +
this.synthesizer.tuningEqual[i + this.startnote].toFixed(2) +
'</th><th>' +
this.synthesizer.tuningCircleOfFifth[i + this.startnote].toFixed(2) +
'</th><th>' +
(
(100 *
(this.synthesizer.tuningCircleOfFifth[i + this.startnote] -
this.synthesizer.tuningEqual[i + this.startnote])) /
this.synthesizer.tuningEqual[i + this.startnote]
).toFixed(2) +
' %</th></tr>'
}
}
checkFifths() {
this.checkboxes = document.querySelectorAll('input[name="checkbox"]')
for (let i = 0; i < this.checkboxes.length; i++) {
this.checkboxes[i].onclick = () => {
if (this.checkboxes[i].checked) {
if (document.querySelector('input[name="all0"]').checked)
this.synthesizer.noteOn(i + this.startnote, 0)
if (document.querySelector('input[name="all1"]').checked)
this.synthesizer.noteOn(i + this.startnote, 1)
} else {
this.synthesizer.noteOff(i + this.startnote, 0)
this.synthesizer.noteOff(i + this.startnote, 1)
}
}
}
}
allOff = () => {
let allOff = document.querySelector('input[name="allOff"]')
allOff.onclick = () => {
if (allOff.checked) {
for (let i = 0; i < this.checkboxes.length; i++) {
if (this.checkboxes[i].checked) {
this.checkboxes[i].checked = false
this.synthesizer.noteOff(i + this.startnote, 0)
this.synthesizer.noteOff(i + this.startnote, 1)
}
}
setTimeout(() => {
allOff.checked = false
}, 300)
}
}
}
}