-
Notifications
You must be signed in to change notification settings - Fork 0
/
builder.html
338 lines (287 loc) · 9.4 KB
/
builder.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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>mu-tune tuning configuration</title>
<link rel="manifest" href="./manifest.json">
<link href="https://fonts.googleapis.com/css?family=Roboto:100,200,300,400,500,600,700,800,900&display=swap"
rel="stylesheet">
<style>
html, body {
margin: 0 !important;
padding: 0 !important;
color: white;
background: black;
font-family: Roboto, sans-serif;
font-size: 28px;
font-weight: 300;
}
.row {
margin: auto;
padding: 0.3rem 1rem;
}
@media all and (max-width: 480px) {
html, body {
font-size: 24px;
}
}
@media all and (min-width: 481px) {
.row {
width: 70vw;
left: 30vw;
}
}
.logo {
font-weight: 300;
color: #ffaa55;
width: calc(100% - 1rem);
text-align: center;
}
.medium {
font-size: 80%;
}
.small {
font-size: 53%;
font-weight: 400;
}
.smalldiv {
font-size: 53%;
font-weight: 400;
margin-top: 0.5rem;
}
.grey {
color: #bbaa99;
}
.err {
font-size: 60%;
color: #ff7744;
}
hr {
border-color: #ff7744;
width: 86vw;
}
input {
background: #331a00;
color: white;
font-family: Roboto, sans-serif;
font-weight: 400;
font-size: 1rem;
border-width: 0;
border-color: #ff7744;
border-bottom-width: 2px;
padding: 5px;
}
#steps {
text-align: right;
}
#interval {
width: 3rem;
}
#scale-pattern {
width: 80vw;
max-width: 10rem;
}
#offset {
width: 3rem;
}
#start {
background: #ff7744;
color: black;
padding: 0.5rem 3rem;
margin-bottom: 1rem;
text-align: center;
font-size: 2rem;
}
</style>
</head>
<body>
<div class="row logo">μuτune <span style="color: white"> v 1.9 </span></div>
<hr>
<div class="row">
<input type="number" id="steps" min="1" max="400" step="1" value="12">
<span>ED</span>
<input type="text" id="interval" value="2">
<br>
<span class="small grey">math expressions are allowed for interval (eg. 5 ED 5/4)</span>
<br>
<span id="steps-err" class="err"></span>
</div>
<div class="row">
<span class="medium">base frequency: </span>
<input type="number" id="base-freq" min="16" max="22050" value="440">
<span>Hz</span>
<br>
<span id="base-freq-err" class="err"></span>
</div>
<div class="row">
<span class="medium">scale pattern: </span>
<input type="text" id="scale-pattern" value="2 2 1 2 2 2 1">
<br>
<span id="scale-pattern-err" class="err"></span>
</div>
<div class="row">
<span class="medium">offset:</span>
<input type="number" id="offset" step="1" value="3">
<br>
<div class="smalldiv grey">
no. of steps the root note of the scale differs from the base frequency <br>
(eg. 440Hz is A, C is 3 steps above from A in 12ED2)
</div>
<span id="offset-err" class="err"></span>
</div>
<br>
<div class="row">
<div id="start"> start</div>
</div>
<script
src="https://code.jquery.com/jquery-3.4.1.min.js"
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
crossorigin="anonymous"></script>
<script>
window.onload = () => {
let $steps = $('#steps');
let $interval = $('#interval');
let $stepsErr = $('#steps-err');
let $baseFreq = $('#base-freq');
let $baseFreqErr = $('#base-freq-err');
let $scalePattern = $('#scale-pattern');
let $scalePatternErr = $('#scale-pattern-err');
let $offset = $('#offset');
let $offsetErr = $('#offset-err');
let stepsOk = true,
intervalOk = true,
baseFreqOk = true,
scalePatternOk = true,
offsetOk = true;
if (location.hash.trim().length !== 0) {
try {
let configStr = location.hash.substr(1);
let [divisionsStr, baseFreqStr, scaleStr, offsetStr] = configStr.split(",");
let [stepsStr, repeatingIntervalStr] = divisionsStr.split(/ed/i);
$steps.val(stepsStr);
$interval.val(repeatingIntervalStr);
$baseFreq.val(baseFreqStr);
$scalePattern.val(scaleStr.replace(/-/g, ' '));
$offset.val(offsetStr);
} catch {
location.hash = '';
}
}
$steps.change(() => {
let s = parseInt($steps.val());
if (isNaN(s)) {
$stepsErr.text('steps must be an integer from 1 - 400');
stepsOk = false;
return;
}
if (s < 1)
$steps.val(1);
else if (s > 400)
$steps.val(400);
else
$steps.val(s);
stepsOk = true;
$stepsErr.text('');
// Also check if the scale pattern matches up with the new steps count.
let sp = $scalePattern.val();
let sum = sp.split(/\s+/).map(x => parseInt(x)).reduce((a, b) => a + b);
if (isNaN(sum)) {
$scalePatternErr.text('Invalid format. e.g. format: 2 2 1 2 2 2 1');
scalePatternOk = false;
return;
}
if (sum !== parseInt($steps.val())) {
$scalePatternErr.text(
`Pattern has ${sum} steps, expected ${parseInt($steps.val())}`);
scalePatternOk = false;
} else {
$scalePatternErr.text('');
scalePatternOk = true;
}
});
$interval.change(() => {
try {
let s = eval($interval.val());
if (s === undefined) {
$stepsErr.text(`Interval must evaluate to a positive number`);
} else if (typeof (s) !== 'number' || isNaN(s) || s <= 0) {
$stepsErr.text(`${$interval.val()} must evaluate to a positive number`);
intervalOk = false;
} else {
intervalOk = true;
$stepsErr.text('');
}
} catch {
$stepsErr.text(`${$interval.val()} is not a valid expression`);
intervalOk = false;
}
});
$baseFreq.change(() => {
let b = parseFloat($baseFreq.val());
if (isNaN(b)) {
$baseFreqErr.text('base freq must be a number from 16 - 22050');
baseFreqOk = false;
return;
}
if (b < 16)
$baseFreq.val(16);
else if (b > 22050)
$baseFreq.val(22050);
baseFreqOk = true;
$baseFreqErr.text('');
});
$scalePattern.change(() => {
let s = $scalePattern.val();
let sum = s.split(/\s+/).map(x => parseInt(x)).reduce((a, b) => a + b);
if (isNaN(sum)) {
$scalePatternErr.text('Invalid format. e.g. format: 2 2 1 2 2 2 1');
scalePatternOk = false;
return;
}
if (sum !== parseInt($steps.val())) {
$scalePatternErr.text(
`Pattern has ${sum} steps, expected ${parseInt($steps.val())}`);
scalePatternOk = false;
} else {
$scalePatternErr.text('');
scalePatternOk = true;
}
});
$offset.change(() => {
let s = parseInt($offset.val());
if (isNaN(s)) {
$offsetErr.text('offset must be an integer');
offsetOk = false;
return;
}
$offset.val(s);
offsetOk = true;
$offsetErr.text('');
});
$('input').change(() => {
console.log('input change', scalePatternOk, baseFreqOk, intervalOk, offsetOk, stepsOk);
if ((scalePatternOk && baseFreqOk && intervalOk && offsetOk && stepsOk) === false) {
$('#start').css({
background: '#888888'
});
} else {
$('#start').css({
background: '#ff7744'
});
}
});
$('#start').click(() => {
if (scalePatternOk && baseFreqOk && intervalOk && offsetOk && stepsOk) {
let steps = $('#steps').val();
let interval = $('#interval').val();
let baseFreq = $('#base-freq').val();
let scalePattern = $('#scale-pattern').val().replace(/\s+/g, '-');
let offset = $('#offset').val();
location.href = `index.html#${steps}ed${interval},${baseFreq},${scalePattern},${offset}`;
}
});
};
</script>
</body>
</html>