This repository was archived by the owner on Jan 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
196 lines (177 loc) · 4.54 KB
/
index.html
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>CodeX.Music</title>
<script src="dist/index.js"></script>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
font-size: 14px;
line-height: 1.5em;
margin: 0;
padding: 50px;
}
header h1 {
font-size: 32px;
font-weight: 800;
margin-bottom: 8px;
}
.value {
display: inline-block;
background: #eee;
padding: 5px 10px;
border-radius: 5px;
}
fieldset {
box-shadow: 0 1px 5px rgba(0, 0, 0, 0.11), 0 16px 10px -10px rgba(0, 0, 0, 0.08);
border-radius: 7px;
border: 0;
}
table:empty::before {
content: 'No Tracks added';
color: #888;
background: #eee;
display: block;
border-radius: 7px;
padding: 10px 25px
}
table:empty + button {
display: none;
}
td {
padding: 5px 0;
}
</style>
</head>
<body>
<header>
<h1>
CodeX Music
</h1>
Dehumanised engine for generating Chillout music
</header>
<table cellpadding="0" cellspacing="0" width="100%" vspace="50" id="tracks"></table>
<button onclick="playAll(this)" style="margin-bottom: 50px">
Play All
</button>
<fieldset style="padding: 25px">
<h3 style="margin: 0">
Add track
</h3>
<table cellpadding="0" cellspacing="0" width="100%" vspace="16">
<tr>
<td>
Instrument
<select id="instrument">
<option value="SineWave">Sine wave</option>
<option value="Horn">Horn</option>
</select>
</td>
<td>
Melody
<input id="melody" placeholder="A4 E4 F4" required>
</td>
<td>
Interval, sec
<input id="interval" placeholder="2" required>
</td>
<td>
Volume, %
<input id="volume" type="range" min="0" max="1" step="0.01" oninput="showValue(this)">
<span class="value">
50 %
</span>
</td>
<td>
Effect
<select></select>
</td>
</tr>
</table>
<button onclick="addTrack()">Add</button>
</fieldset>
<script>
const music = new CodexMusic();
const $ = (id) => document.getElementById(id);
function addTrack(){
const instrument = $('instrument');
const melody = $('melody');
const interval = $('interval');
const volume = $('volume');
const trackId = music.addTrack({
instrument: instrument.value,
melody: melody.value,
interval: interval.value,
volume: volume.value,
});
const track = `
<tr>
<td>
<button class="play" onclick="playTrack('${trackId}')">Play</button>
<button class="stop" onclick="stopTrack('${trackId}')">Stop</button>
</td>
<td>
Instrument
<span class="value">
${instrument.value}
</span>
</td>
<td>
Melody
<span class="value">
${melody.value}
</span>
</td>
<td>
Interval
<span class="value">
${interval.value} sec
</span>
</td>
<td>
Volume
<input class="new-volume" type="range" min="0" max="1" step="0.01" value="${volume.value}" oninput="changeVolume(this, '${trackId}')">
<span class="value">
${volume.value * 100} %
</span>
</td>
<td>
Effect
<span class="value">
—
</span>
</td>
</tr>
`;
$('tracks').insertAdjacentHTML('beforeend', track);
melody.value = '';
interval.value = '';
}
function showValue(volumeRangeElement) {
volumeRangeElement.nextElementSibling.innerText = parseInt(volume.value * 100) + " %";
}
function changeVolume(volumeRangeElement, trackId) {
volumeRangeElement.nextElementSibling.innerText = parseInt(volumeRangeElement.value * 100) + " %";
music.changeTrackVolume(trackId, volumeRangeElement.value);
}
function playTrack(id){
music.play(id);
}
function stopTrack(id){
music.stop(id);
}
function playAll(button){
const isPlaying = button.dataset.playing === 'true';
if (!isPlaying){
music.play();
button.textContent = 'Stop all';
} else {
music.stop();
button.textContent = 'Play all';
}
button.dataset.playing = !isPlaying;
}
</script>
</body>
</html>