-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
312 lines (290 loc) · 18 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<title>web Intonation</title>
<script defer src="https://cdn.jsdelivr.net/npm/@alpinejs/persist@3.x.x/dist/cdn.min.js"></script>
<script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/keyboard-css@1.2.4/dist/css/main.min.css" />
<script src="https://cdn.jsdelivr.net/npm/mathjs@12.3.0/lib/browser/math.min.js"></script>
<script src="https://cdn.plot.ly/plotly-2.29.1.min.js"></script>
<script src="https://unpkg.com/@tonejs/midi"></script>
<meta name="description" content="Free online simulator for hearing and developing musical tunings, temperaments and tunings" />
<meta property="og:type" content="website" />
<meta property="og:url" content="https://flappix.github.io/web_intonation/" />
<script type="text/javascript" src="app.js"></script>
<link rel="stylesheet" href="style.css" />
</head>
<body x-data="ScaleApp()" x-on:keydown="key_check_on" x-on:keyup="key_check_off">
<div style="display: flex; justify-content: space-between; align-items: start;">
<div style="font-weight: bold; font-size: 2em;">
Musical Tuing Simulator
<span style="display: none;">Free online simulator for exploring musical tunings and temperaments. Supports just intonation, equal temperament, pythtagoreian tuning, meantone temperament</span>
</div>
<div style="width: 70vw;">
<div style="display: flex; margin-bottom: 0px; margin-left: 0.5em; position: relative;">
<div class="tab" :style="{'z-index': tab == 'tuning' ? 2 : 0, 'background-color': tab == 'tuning' ? 'white' : '#F0F0F0'}" x-on:click="tab = 'tuning'">Tuning</div>
<div class="tab" :style="{'z-index': tab == 'synth' ? 2 : 0, 'background-color': tab == 'synth' ? 'white' : '#F0F0F0'}" x-on:click="tab = 'synth'">Synthesizer</div>
<div class="tab" :style="{'z-index': tab == 'midi' ? 2 : 0, 'background-color': tab == 'midi' ? 'white' : '#F0F0F0'}" x-on:click="tab = 'midi'">Midi (<i>experimental</i>)</div>
</div>
<div style="border: 1px solid black; padding: 0.5em; margin: 0.5em; margin-top: 0; z-index: 1; position: relative; border-radius: 0 0.5em 0.5em 0.5em;" class="box" x-show="tab == 'tuning'">
<div style="display: flex; align-items: center; flex-wrap: wrap;">
<div class="setting">
<span style="margin-right: 0.2em;">Tuning</span>
<select x-model="curr_tuning" x-on:change="curr_notes = createFromTemplate (curr_tuning, curr_scale)">
<template x-for="name in Object.keys ( filterObj (tunings, t => t[1].scalable) )">
<option x-html="name" ></option>
</template>
<option disabled>────</option>
<template x-for="name in Object.keys ( filterObj (tunings, t => !t[1].scalable) )">
<option x-html="name" ></option>
</template>
</select>
</div>
<div class="setting">
<span style="margin-right: 0.2em;">Scale</span>
<select x-model="curr_scale" x-on:change="curr_notes = createFromTemplate (curr_tuning, curr_scale)">
<template x-for="name in Object.keys (scales)">
<option x-html="name" :disabled="!tunings[curr_tuning].scalable && name != 'chromatic'" :selected="name == 'chromatic'"></option>
</template>
</select>
</div>
<div class="setting">
<span style="margin-right: 0.2em;">Root</span>
<select x-model="root.note" x-on:change="root.freq = note2freqMap[root.note];" style="margin-right: 0.2em;">
<template x-for="key in midi.scaleNotes">
<option x-html="key" :selected="key == root.note"></option>
</template>
<option x-html="''"></option>
</select>
<input type="number" x-model="root.freq" style="width: 4em; margin-right: 0.2em;" x-on:change="root.note = Object.keys (note2freqMap).find (key => note2freqMap[key] == root.freq) ?? ''" /> Hz
</div>
<div class="setting">
<span style="margin-right: 0.2em;">Keyboard</span>
<select x-model="curr_keymap">
<template x-for="name in Object.keys (key_maps)">
<option x-html="name"></option>
</template>
</select>
</div>
<!--<div>
<span>Scale Type</span>:
<span x-html="tunings[curr_tuning].type"></span>
</div>-->
<div class="setting">
<span style="margin-right: 0.2em;">Volume</span>
<input type="range" min="0" max="0.1" step="0.001" x-model="volume" />
</div>
</div>
<button x-on:click="curr_notes = createFromTemplate (curr_tuning, curr_scale)" style="margin-left: 0.5em;">reset</button>
<button x-on:click="curr_notes = [1]" style="margin-left: 0.5em;">clear</button>
</div>
<div style="border: 1px solid black; padding: 0.5em; margin: 0.5em; margin-top: 0; z-index: 1; position: relative; border-radius: 0 0.5em 0.5em 0.5em; display: none;" class="box" x-show="tab == 'synth'">
<div style="display: flex;">
<div class="setting">
<span style="margin-right: 0.2em;">Harmonics</span>
<input type="number" min="0" step="1" x-model="harmonics" style="width: 3em;" />
</div>
<div class="setting">
<span style="margin-right: 0.2em; cursor: help;" title="Volume of the n-th harmonic = (this facor ^ n) * master volume. For a realistic sound set this value between 0 and 1.">Harmonics volume reduction</span>
<input type="number" x-model="reduction" step="0.1" style="width: 3em;" />
</div>
</div>
</div>
<div style="border: 1px solid black; padding: 0.5em; margin: 0.5em; margin-top: 0; z-index: 1; position: relative; border-radius: 0 0.5em 0.5em 0.5em; display: none;" class="box" x-show="tab == 'midi'">
<div style="display: flex; align-items: center; flex-wrap:flex;">
<div class="setting">
<input type="file" x-on:change="readMidiFile ($el)" style="border: 1px solid black; border-radius: 0.5em; margin: 1em;" />
<span x-show="midi.error != null" x-html="midi.error" style="color: red; margin: 1em;"></span>
</div>
<div class="setting">
<span style="white-space: nowrap; cursor: help;" title="Make sure this settings matches the root note of the key signature in your midi file. E.g. if your piece is in C major set this setting to C. If your piece is in D minor set this setting to D. Multiple key signatures in one midi file is currently not supported.">
Root <span style="background-color: #838383; border-radius: 1em; padding: 0.2em; color: white;">?</span>
</span>
<select x-model="midi.root" x-on:change="calcNoteOffset(); root.note = midi.root; root.freq = note2freqMap[root.note];">
<template x-for="key in midi.scaleNotes">
<option x-html="key" :selected="key == midi.root"></option>
</template>
</select>
</div>
<div class="setting">
<span style="white-space: nowrap;">Reference freq</span>
<select x-model="root.note" x-on:change="root.freq = note2freqMap[root.note];">
<template x-for="key in midi.scaleNotes">
<option x-html="key" :selected="key == root.note"></option>
</template>
<option x-html="''"></option>
</select>
<input type="number" x-model="root.freq" style="width: 4em; margin-right: 0.2em;" x-on:change="root.note = Object.keys (note2freqMap).find (key => note2freqMap[key] == root.freq) ?? ''" /> Hz
</div>
<div class="setting">
Tempo <input type="range" min="0.1" max="5" step="0.1" x-model="midi.tempo" /> × <span x-html="midi.tempo"></span>
</div>
<button x-on:click="midi_play()" :disabled="!midi.loaded" x-show="midi.scheduledNotes.length == 0" style="margin: 1em;">► play</button>
<button x-on:click="midi_stop()" :disabled="!midi.loaded" style="margin: 1em;" x-show="midi.scheduledNotes.length > 0">⏹ stop</button>
<div x-show="curr_notes.length != 12" style="color: #BE4747;">
<u>Warning</u>: You current system does not have 12 scale degrees. This will lead to unexpected results in playback. Set scale to <i>chromatic</i> in <i>Tuning</i>-tab.
</div>
</div>
</div>
</div>
<div style="display: flex; align-items: stretch;">
<a href="https://github.com/flappix/web_intonation" class="link" title="this project on github"><svg style="width: 2.5em;" aria-hidden="true" viewBox="0 0 16 16" version="1.1" width="32" data-view-component="true" class="octicon octicon-mark-github v-align-middle color-fg-default"><path d="M8 0c4.42 0 8 3.58 8 8a8.013 8.013 0 0 1-5.45 7.59c-.4.08-.55-.17-.55-.38 0-.27.01-1.13.01-2.2 0-.75-.25-1.23-.54-1.48 1.78-.2 3.65-.88 3.65-3.95 0-.88-.31-1.59-.82-2.15.08-.2.36-1.02-.08-2.12 0 0-.67-.22-2.2.82-.64-.18-1.32-.27-2-.27-.68 0-1.36.09-2 .27-1.53-1.03-2.2-.82-2.2-.82-.44 1.1-.16 1.92-.08 2.12-.51.56-.82 1.28-.82 2.15 0 3.06 1.86 3.75 3.64 3.95-.23.2-.44.55-.51 1.07-.46.21-1.61.55-2.33-.66-.15-.24-.6-.83-1.23-.82-.67.01-.27.38.01.53.34.19.73.9.82 1.13.16.45.68 1.31 2.69.94 0 .67.01 1.3.01 1.49 0 .21-.15.45-.55.38A7.995 7.995 0 0 1 0 8c0-4.42 3.58-8 8-8Z"></path></svg></a>
<a href="https://flappix.github.io/webchords/" class="link" style="font-weight: bold; color: black; text-decoration: none;" title="Online tool for creating and looping jazzy chord progressions on the fly">WebChords</a>
<a href="https://soundcloud.com/user-21721742" class="link" title="my music on soundcloud"><img style="width: 3em;" src="https://d21buns5ku92am.cloudfront.net/26628/images/419677-sc-logo-vertical-black%20%281%29-81a8fc-medium-1645807040.png" /></a>
</div>
</div>
<div>
<span x-on:click="filter = toggleList (filter, 'scale')"
style="font-weight: bold; cursor: pointer;"
:style="{color: filter.includes ('scale') ? 'black' : 'gray'}">👁 Scale</span>
<div x-show="filter.includes ('scale')">
<div style="display: flex; width: 100%; flex-wrap: wrap; align-self: stretch; justify-content: stretch;">
<template x-for="(note, n) in curr_notes" :key="n">
<div style="border: 1px solid black; margin: 0.5em; padding: 0.5em; width: 10%;"
class="box shadow"
:style="{
'animation': marker == n ? 'myAnim 1s ease-in-out 0s 1 normal forwards' : 'none',
'background-color': playing.map (p => mod ( Number (p), curr_notes.length ) ).includes (n) ? colors[n] : 'none'
}">
<!--<div x-html="n"></div>
<div x-html="n % tunings[curr_tuning].notes.length"></div>
<div x-html="JSON.stringify ( playing.map (p => p % tunings[curr_tuning].notes.length))"></div>
<div x-html="JSON.stringify (playing.includes (n))"></div>
<div x-html="JSON.stringify (marker)"></div>-->
<div style="display: flex; justify-content: space-between;">
<div style="border: 1px solid black; padding: 0.5em;"
:style="{'background-color': colors[n]}"
x-html="n + 1"></div>
<i x-show="n > 0 && isPure (n)">pure</i>
<div style="display: flex; flex-wrap: nowrap; align-items: center; margin: 0; padding: 0;">
<div style="margin-right: 0.5em; cursor: pointer; height: fit-content;"
:style="{'color': !graph_show_degrees.includes (n) ? '#A1A1A1' : 'black'}"
x-on:click="toggleGrapShowDegree (n)"
title="show/hide graph trace"> ~👁 </div> <!-- eye -->
<button x-on:click="curr_notes.splice (n, 1);" title="delete" style="font-family: monospace;" x-show="n > 0">×</button>
<div>
<button x-on:click="dropdown.show = n" style=" margin-left: 0.2em;" title="add scale degree">+</button>
<div style="position: absolute; padding: 1em; z-index: 999;" class="box shadowStrong" x-show="dropdown.show === n" x-on:click.outside="dropdown.show = null;">
Select preset
<div class="setting">
<span style="margin-right: 0.2em;">Tuning</span>
<select x-model="dropdown.tuning">
<template x-for="name in Object.keys ( filterObj (tunings, t => t[1].scalable) )">
<option x-html="name" ></option>
</template>
<option disabled>────</option>
<template x-for="name in Object.keys ( filterObj (tunings, t => !t[1].scalable) )">
<option x-html="name" ></option>
</template>
</select>
</div>
<div class="setting">
<span style="margin-right: 0.2em;">Scale</span>
<select x-model="dropdown.scale">
<template x-for="name in Object.keys (scales)">
<option x-html="name"></option>
</template>
</select>
</div>
<div class="setting">
<span style="margin-right: 0.2em;">Degree</span>
<select x-model="dropdown.degree">
<template x-for="degree in Object.keys (scales[dropdown.scale])" :key="degree">
<option x-html="Number (degree) + 1" :value="degree"></option>
</template>
</select>
</div>
<div style="display: flex; justify-content: end;">
<button x-on:click="dropdown.show = null">cancel</button>
<button x-on:click="add_scale_degree (n)">add</button>
</div>
</div>
</div>
</div>
</div>
<div style="display: flex;">
<span style="margin-right: 0.5em;">ratio</span>
<!--<input type="number"
x-model="tunings[curr_tuning].notes[n]"
step="0.01"
:max="n < tunings[curr_tuning].notes.length ? tunings[curr_tuning].notes[n + 1]: 1"
style="width: 50%;" />-->
<input type="text"
x-model="curr_notes[n]"
style="width: 80%; text-align: end;" :style="{'background-color': getFreq (n) == null ? 'red' : 'none'}" />
</div>
<div style="display: flex; align-items: center; justify-content: space-between;">
<span style="width: 50%; cursor: help;" :title="`root × ratio = ${formatFreq (n)}Hz`">freq</span>
<span style="font-family: monospace;" x-html="formatFreq (n)"></span> Hz
</div>
<!--<input type="text" x-model="key_maps[curr_keymap][n]" />-->
</div>
</template>
<button x-on:click="dropdown.show = curr_notes.length - 1" style="cursor: pointer; margin: 0.5em;" title="add scale degree">+</button>
</div>
</div>
<div style="margin-top: 1em;">
<span x-on:click="filter = toggleList (filter, 'inter_scale_ratios')"
style="font-weight: bold; cursor: pointer;"
:style="{color: filter.includes ('inter_scale_ratios') ? 'black' : 'gray'}">👁 Inter-scale ratios</span>
<template x-if="filter.includes ('inter_scale_ratios')" x-transition x-transition.duration.500ms >
<div style="display: flex;">
<template x-for="rows in getInterScaleRatios()">
<div style="margin-right: 1em; padding: 1em; background-color: #FAFAFA;" class="box">
<template x-for="ratio in rows">
<div style="margin-right: 1em; margin-top: 1em; line-height: 2em;">
<span style="padding: 0.5em; border-radius: 0.5em;" :style="{'background-color': colors[ratio.i2]}">f<sub x-html="ratio.i2 + 1"></sub></span> /
<span style="padding: 0.5em; border-radius: 0.5em;" :style="{'background-color': colors[ratio.i1]}">f<sub x-html="ratio.i1 + 1"></sub></span> =
<span style="padding: 0.5em; background-color: #CFCFCF; border-radius: 0.5em;" x-html="ratio.resolved"></span> ≈
<span style="padding: 0.5em; background-color: #CFCFCF; border-radius: 0.5em; font-family: monospace;" x-html="ratio.approx"></span>
</div>
</template>
</div>
</template>
<template x-if="getInterScaleRatios().length == 0">
<i>Select ( ~👁) or play at leat 2 scale degrees</i>
</template>
</div>
</template>
</div>
<div style="margin-top: 1em;">
<span x-on:click="filter = toggleList (filter, 'keyboard')"
style="font-weight: bold; cursor: pointer;"
:style="{color: filter.includes ('keyboard') ? 'black' : 'gray'}">👁 Keyboard</span>
<div x-show="filter.includes ('keyboard')">
<span>press key to play note<br />
click on key to edit</span>
<div style="display: flex; width: 100%; flex-wrap: wrap;">
<template x-for="(key, k) in key_maps[curr_keymap]">
<div style="border: 1px solid black; margin: 0.5em; padding: 0.5em; width: 10%;"
class="box shadow"
:style="{'background-color': playing.map (p => Number (p)).includes ( Number (k) ) ? colors[mod (k, curr_notes.length)] : 'none'}">
<div style="display: flex; justify-content: space-between;">
<div style="border: 1px solid black; padding: 5px; margin-bottom: 5px;" :style="{'background-color': colors[mod (k, curr_notes.length)]}" x-html="parseInt (k) + 1"></div>
<input type="text"
class="kbc-button"
x-model="key_maps[curr_keymap][k]"
style="width: 3em; text-align: center;" />
<div x-on:click="delete key_maps[curr_keymap][k]" title="delete" style="cursor: pointer; font-family: monospace;">[×]</div>
</div>
<!--<input type="text" x-model="key_maps[curr_keymap][k]" />-->
</div>
</template>
<button x-on:click="add_keymap_degree()" style="cursor: pointer; margin: 0.5em;" title="add keyboard key">+</button>
</div>
</div>
</div>
<div style="margin-top: 1em;">
<span x-on:click="filter = toggleList (filter, 'graph')"
style="font-weight: bold; cursor: pointer;"
:style="{color: filter.includes ('graph') ? 'black' : 'gray'}">👁 Graph</span>
<div x-show="filter.includes ('graph')"
style="width: 90vw; height: 400px; margin: 0px auto; border: 1px solid black; padding: 0.5em; background-color: white;"
class="shadow">
<input type="number" min="1" step="1" x-model="graph_periods" x-on:change="updatePeriods()" style="width: 30px;" /> periods
<div id="graph" style="100%; height: 90%;" x-ignore></div>
</div>
</div>
</div>
</body>
</html>