-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
100 lines (93 loc) · 2.86 KB
/
index.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
var range = document.getElementById('range');
noUiSlider.create(range, {
start: [3, 4],
step: 1,
connect: true,
range: {
'min': 0,
'max': 8
},
tooltips: true,
format: wNumb({
decimals: 0
}),
});
// const synth = new Tone.Synth().toDestination();
const synth = new Tone.Sampler({
urls: {
A0: "A0.mp3",
C1: "C1.mp3",
"D#1": "Ds1.mp3",
"F#1": "Fs1.mp3",
A1: "A1.mp3",
C2: "C2.mp3",
"D#2": "Ds2.mp3",
"F#2": "Fs2.mp3",
A2: "A2.mp3",
C3: "C3.mp3",
"D#3": "Ds3.mp3",
"F#3": "Fs3.mp3",
A3: "A3.mp3",
C4: "C4.mp3",
"D#4": "Ds4.mp3",
"F#4": "Fs4.mp3",
A4: "A4.mp3",
C5: "C5.mp3",
"D#5": "Ds5.mp3",
"F#5": "Fs5.mp3",
A5: "A5.mp3",
C6: "C6.mp3",
"D#6": "Ds6.mp3",
"F#6": "Fs6.mp3",
A6: "A6.mp3",
C7: "C7.mp3",
"D#7": "Ds7.mp3",
"F#7": "Fs7.mp3",
A7: "A7.mp3",
C8: "C8.mp3"
},
release: 1,
baseUrl: "https://tonejs.github.io/audio/salamander/"
}).toDestination();
function run() {
try {
const inputArray = document.getElementById("input").value.split(" ");
const code = DoReMi.fromString(document.getElementById("code").value, inputArray);
if (!document.getElementById("stringOutput").checked)
document.getElementById("output").value = code.output.join(" ")
else
document.getElementById("output").value = DoReMi.convertOutputToString(code.output);
}
catch (err) {
alert(err)
}
}
function toFormat(min, max, number) {
if (number < min) number = min;
if (number > max) number = max;
return number;
}
function play() {
try {
const inputArray = document.getElementById("input").value.split(" ");
const code = DoReMi.fromString(document.getElementById("code").value, inputArray, false);
let now = Tone.now();
if (!document.getElementById("iterative").checked)
for (let note of code.notes) {
synth.triggerAttackRelease(`${note.note}${note.alteration | ""}${note.mood | ""}${note.octave ?
toFormat(range.noUiSlider.get()[0], range.noUiSlider.get()[1], note.octave) : "4"}`, "4n", now);
now += 0.20;
}
else {
const notes = code.run(true);
for (let note of notes) {
synth.triggerAttackRelease(`${note.note}${note.alteration | ""}${note.mood | ""}${note.octave ?
toFormat(range.noUiSlider.get()[0], range.noUiSlider.get()[1], note.octave) : "4"}`, "4n", now);
now += 0.20;
}
}
}
catch (err) {
alert(err)
}
}