-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
118 lines (109 loc) · 4.36 KB
/
script.js
File metadata and controls
118 lines (109 loc) · 4.36 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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
var html_template = "<!doctype html>"
html_template = html_template + "<html><head><link rel='stylesheet' href='styles.css'/><\/head><body><div class='play-arrow' id='playArrow'>"
html_template = html_template + "</div><button onclick='play()'>Play<\/button>"
html_template = html_template + "<script> @@@PLAY_CODE <\/script>"
html_template = html_template + "<\/body><\/html>"
var code_output = ""
var compiled_code = document.getElementById("compiledCode");
function play_notes(){
song = document.getElementById("textBox").value;
bg = document.getElementById("textBg");
playArrow = document.getElementById("playArrow");
playArrow.classList.add('play');
bg.style.top = "4.5em";
bg.style.display = "block";
console.log(song);
lines = song.split(/\r?\n/);
console.log(lines);
sound_delay = 0;
code_output = "function play(){document.getElementById('playArrow').classList.add('play');";
for(i = 0; i < lines.length; ++i)
{
console.log(lines[i]);
sound_delay = (1000 * i);
var bg_pos = bg.offsetTop;
if(lines[i][0] == 'E')
{
console.log("Play E");
setTimeout(function() {
new Audio('sounds/E.wav').play();
}, sound_delay);
code_output = code_output + "setTimeout(function() {"
code_output = code_output + "new Audio('sounds/E.wav').play()"
code_output = code_output +"}, " + sound_delay + ");";
}
if(lines[i][1] == 'A')
{
console.log("Play A")
setTimeout(function() {
new Audio('sounds/A.wav').play();
}, sound_delay);
code_output = code_output + "setTimeout(function() {"
code_output = code_output + "new Audio('sounds/A.wav').play()"
code_output = code_output +"}, " + sound_delay + ");";
}
if(lines[i][2] == 'D')
{
console.log("Play D")
setTimeout(function() {
new Audio('sounds/D.wav').play();
}, sound_delay);
code_output = code_output + "setTimeout(function() {"
code_output = code_output + "new Audio('sounds/D.wav').play()"
code_output = code_output +"}, " + sound_delay + ");";
}
if(lines[i][3] == 'G')
{
console.log("Play G")
setTimeout(function() {
new Audio('sounds/G.wav').play();
}, sound_delay);
code_output = code_output + "setTimeout(function() {"
code_output = code_output + "new Audio('sounds/G.wav').play()"
code_output = code_output +"}, " + sound_delay + ");";
}
if(lines[i][4] == 'F')
{
console.log("Play F")
setTimeout(function() {
new Audio('sounds/F.wav').play();
}, sound_delay);
code_output = code_output + "setTimeout(function() {"
code_output = code_output + "new Audio('sounds/F.wav').play()"
code_output = code_output +"}, " + sound_delay + ");";
}
if(lines[i][5] == 'C')
{
console.log("Play C")
setTimeout(function() {
new Audio('sounds/C.wav').play();
}, sound_delay);
code_output = code_output + "setTimeout(function() {"
code_output = code_output + "new Audio('sounds/C.wav').play()"
code_output = code_output +"}, " + sound_delay + ");";
}
}
bg.style.transition = i + "s linear";
bg.style.top = 4.5 + (i*1.4) + "em";
setTimeout(function() {
bg.style.top = "4.5em";
bg.style.transition = "0.5s linear";
bg.style.display = "none";
playArrow.classList.remove('play');
}, sound_delay);
code_output = code_output + "setTimeout(function() {document.getElementById('playArrow').classList.remove('play')}, ";
code_output = code_output + sound_delay + ");";
code_output = code_output + "}";
compiled_code.value = html_template.replace("@@@PLAY_CODE", code_output);
}
function clear_music(){
document.getElementById("textBox").value = "";
}
document.addEventListener('DOMContentLoaded', function() {
new Audio('sounds/E.wav');
new Audio('sounds/A.wav');
new Audio('sounds/D.wav');
new Audio('sounds/G.wav');
new Audio('sounds/F.wav');
new Audio('sounds/C.wav');
}, false);