-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
458 lines (423 loc) · 9.7 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
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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
<!doctype html>
<html>
<head>
<title>Mozfest Locales</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/tabletop.js/1.1.0/tabletop.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
</head>
<body>
<p>
The music you hear is composed in
<a href="https://docs.google.com/spreadsheet/ccc?key=0Ao5u1U6KYND7dC1wekE1bThiaXF6dnBpMVBoV1VmR3c#gid=0">this spreadsheet</a>
</p>
<audio id="kick" src="808/bass (6).WAV" />
<audio id="hi-hat" src="808/hi hat (6).wav" />
<audio id="snare" src="808/snare (6).WAV" />
<script src="app.js" type="text/javascript"></script>
<script type="text/javascript">
</script>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function() {
var gData
var KEY = "0Ao5u1U6KYND7dC1wekE1bThiaXF6dnBpMVBoV1VmR3c"
Tabletop.init( { key: KEY, callback: main, simpleSheet: true } )
})
///////////////////////////////////////////////
// notes and scales
var ACOUSTIC_SCALE = [0, 2, 4, 6, 7, 9, 10];
var ADONAI_MALAKH = [0, 2, 4, 5, 7, 8, 10];
var AEOLIAN_MODE = [0, 2, 3, 5, 7, 8, 10];
var ALGERIAN_SCALE = [0, 2, 3, 6, 7, 8, 11];
var ALTERED_SCALE = [0, 1, 3, 4, 6, 8, 10];
var AUGMENTED_SCALE = [0, 3, 4, 7, 8, 11];
var BEBOP_DOMINANT = [0, 2, 4, 5, 7, 9, 10, 11];
var BLUES_SCALE = [0, 3, 5, 6, 7, 10];
var DORIAN_MODE = [0, 2, 3, 5, 7, 9, 10];
var DOUBLE_HARMONIC_SCALE = [0, 1, 4, 5, 7, 8, 11];
var ENIGMATIC_SCALE = [0, 1, 4, 6, 8, 10, 11];
var FLAMENCO_MODE = [0, 1, 4, 5, 7, 8, 11];
var GYPSY_SCALE = [0, 2, 3, 6, 7, 8, 10];
var HALF_DIMINISHED_SCALE = [0, 2, 3, 5, 6, 8, 10];
var HARMONIC_MAJOR_SCALE = [0, 2, 4, 5, 7, 8, 11];
var HARMONIC_MINOR_SCALE = [0, 2, 3, 5, 7, 8, 11];
var HIRAJOSHI_SCALE = [0, 4, 6, 7, 11];
var HUNGARIAN_GYPSY_SCALE = [0, 2, 3, 6, 7, 8, 11];
var INSEN_SCALE = [0, 1, 5, 7, 10];
var IONIAN_MODE = [0, 2, 4, 5, 7, 9, 11];
var IWATO_SCALE = [0, 1, 5, 6, 11];
var LOCRIAN_MODE = [0, 1, 3, 5, 6, 8, 10];
var LYDIAN_AUGMENTED_SCALE = [0, 2, 4, 6, 8, 9, 11];
var LYDIAN_MODE = [0, 2, 4, 6, 7, 9, 11];
var MAJOR_LOCRIAN = [0, 2, 4, 5, 6, 8, 10];
var MELODIC_MINOR_SCALE = [0, 2, 3, 5, 7, 9, 11];
var MIXOLYDIAN_MODE = [0, 2, 4, 5, 7, 9, 10];
var NEAPOLITAN_MAJOR_SCALE = [0, 1, 3, 5, 7, 9, 11];
var NEAPOLITAN_MINOR_SCALE = [0, 1, 3, 5, 7, 8, 11];
var PERSIAN_SCALE = [0, 1, 4, 5, 6, 8, 11];
var PHRYGIAN_MODE = [0, 1, 3, 5, 7, 8, 10];
var PROMETHEUS_SCALE = [0, 2, 4, 6, 9, 10];
var TRITONE_SCALE = [0, 1, 4, 6, 7, 10];
var UKRAINIAN_DORIAN_SCALE = [0, 2, 3, 6, 7, 9, 10];
var WHOLE_TONE_SCALE = [0, 2, 4, 6, 8, 10];
var MAJOR = [0, 2, 4, 5, 7, 9, 11];
var MINOR = [0, 2, 3, 5, 7, 8, 10];
var CHROMATIC = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
var chordLookup = {
"maj": [0,4,7],
"maj_no_fifth": [0,4],
"power": [0,7],
"sus": [0,5,7],
"sus2": [0,2,7],
"maj_six": [0,4,7,9],
"maj_six_no_fifth": [0,4,9],
"maj_six_nine": [0,4,9, 14],
"min": [0,3,7],
"min_no_fifth": [0,3],
"min_six": [0,3,7,9],
"min_six_no_fifth": [0,3,9],
"min_six_nine": [0,3,9, 14],
"dim": [0,3,6],
"aug": [0,4,8],
"maj7": [0,4,7,11],
"maj7_no_fifth": [0,4,11]
};
var noteLookup = {
"C-1": 0,
"C#-1": 1,
"Db-1": 1,
"D-1": 2,
"D#-1": 3,
"Eb-1": 3,
"E-1": 4,
"F-1": 5,
"F#-1": 6,
"Gb-1": 6,
"G-1": 7,
"G#-1": 8,
"Ab-1": 8,
"A-1": 9,
"A#-1": 10,
"Bb-1": 10,
"B-1": 11,
"C0": 12,
"C#0": 13,
"Db0": 13,
"D0": 14,
"D#0": 15,
"Eb0": 15,
"E0": 16,
"F0": 17,
"F#0": 18,
"Gb0": 18,
"G0": 19,
"G#0": 20,
"Ab0": 20,
"A0": 21,
"A#0": 22,
"Bb0": 22,
"B0": 23,
"C1": 24,
"C#1": 25,
"Db1": 25,
"D1": 26,
"D#1": 27,
"Eb1": 27,
"E1": 28,
"F1": 29,
"F#1": 30,
"Gb1": 30,
"G1": 31,
"G#1": 32,
"Ab1": 32,
"A1": 33,
"A#1": 34,
"Bb1": 34,
"B1": 35,
"C2": 36,
"C#2": 37,
"Db2": 37,
"D2": 38,
"D#2": 39,
"Eb2": 39,
"E2": 40,
"F2": 41,
"F#2": 42,
"Gb2": 42,
"G2": 43,
"G#2": 44,
"Ab2": 44,
"A2": 45,
"A#2": 46,
"Bb2": 46,
"B2": 47,
"C3": 48,
"C#3": 49,
"Db3": 49,
"D3": 50,
"D#3": 51,
"Eb3": 51,
"E3": 52,
"F3": 53,
"F#3": 54,
"Gb3": 54,
"G3": 55,
"G#3": 56,
"Ab3": 56,
"A3": 57,
"A#3": 58,
"Bb3": 58,
"B3": 59,
"C4": 60,
"C#4": 61,
"Db4": 61,
"D4": 62,
"D#4": 63,
"Eb4": 63,
"E4": 64,
"F4": 65,
"F#4": 66,
"Gb4": 66,
"G4": 67,
"G#4": 68,
"Ab4": 68,
"A4": 69,
"A#4": 70,
"Bb4": 70,
"B4": 71,
"C5": 72,
"C#5": 73,
"Db5": 73,
"D5": 74,
"D#5": 75,
"Eb5": 75,
"E5": 76,
"F5": 77,
"F#5": 78,
"Gb5": 78,
"G5": 79,
"G#5": 80,
"Ab5": 80,
"A5": 81,
"A#5": 82,
"Bb5": 82,
"B5": 83,
"C6": 84,
"C#6": 85,
"Db6": 85,
"D6": 86,
"D#6": 87,
"Eb6": 87,
"E6": 88,
"F6": 89,
"F#6": 90,
"Gb6": 90,
"G6": 91,
"G#6": 92,
"Ab6": 92,
"A6": 93,
"A#6": 94,
"Bb6": 94,
"B6": 95,
"C7": 96,
"C#7": 97,
"Db7": 97,
"D7": 98,
"D#7": 99,
"Eb7": 99,
"E7": 100,
"F7": 101,
"F#7": 102,
"Gb7": 102,
"G7": 103,
"G#7": 104,
"Ab7": 104,
"A7": 105,
"A#7": 106,
"Bb7": 106,
"B7": 107,
"C8": 108,
"C#8": 109,
"Db8": 109,
"D8": 110,
"D#8": 111,
"Eb8": 111,
"E8": 112,
"F8": 113,
"F#8": 114,
"Gb8": 114,
"G8": 115,
"G#8": 116,
"Ab8": 116,
"A8": 117,
"A#8": 118,
"Bb8": 118,
"B8": 119,
"C9": 120,
"C#9": 121,
"Db9": 121,
"D9": 122,
"D#9": 123,
"Eb9": 123,
"E9": 124,
"F9": 125,
"F#9": 126,
"Gb9": 126,
"G9": 127
};
var rootLookup = {
"C": 0,
"C#": 1,
"Db": 1,
"D": 2,
"D#": 3,
"Eb": 3,
"E": 4,
"F": 5,
"F#": 6,
"Gb": 6,
"G": 7,
"G#": 8,
"Ab": 8,
"A": 9,
"A#": 10,
"Bb": 10,
"B": 11
};
// Helper Functions
function frequencyFromNoteName( noteName ) {
var note = noteLookup[noteName];
return 440 * Math.pow(2,(note-69)/12);
}
function frequencyFromNoteNumber( noteNumber ) {
return 440 * Math.pow(2,(noteNumber - 69)/12);
}
function sortNumber(a,b) {
return a - b;
}
function initSound(arrayBuffer) {
context.decodeAudioData(arrayBuffer, function(buffer) {
// audioBuffer is global to reuse the decoded audio later.
audioBuffer = buffer;
}, function(e) {
console.log('Error decoding file', e);
});
}
// Load file from a URL as an ArrayBuffer.
// Example: loading via xhr2: loadSoundFile('sounds/test.mp3');
function loadSoundFile(url) {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'arraybuffer';
xhr.onload = function(e) {
initSound(this.response); // this.response is an ArrayBuffer.
};
xhr.send();
}
function buildScale(keyName, scale, minNote, maxNote) {
var key = rootLookup[keyName];
var minNote = noteLookup[minNote];
var maxNote = noteLookup[maxNote];
scale = scale.map(function(s) {return s + key});
console.log(key, minNote, maxNote, scale);
var newScale = [];
for (var i=0; i < scale.length; i++) {
for (var j=0; j<12; j++) {
var note = scale[i] + (12 * j);
if (note >= minNote && note <= maxNote) {
newScale.push(note);
}
}
}
sortedScale = newScale.sort(sortNumber)
return sortedScale;
}
// Initialize audio
var context;
window.addEventListener('load', init, false);
function init() {
try {
// Fix up for prefixing
window.AudioContext = window.AudioContext||window.webkitAudioContext;
context = new AudioContext();
}
catch(e) {
alert('Web Audio API is not supported in this browser');
}
}
init()
var lowpassFilter = context.createBiquadFilter();
var gainNode = context.createGain();
var waveShaper = context.createWaveShaper();
var panner = context.createPanner();
var compressor = context.createDynamicsCompressor();
var reverb = context.createConvolver();
var myScale = buildScale(
keyName = 'E',
scale = [0,4,5,7,9],
minNote = 'E1',
maxNote = 'E9'
);
// var startTime = 0;
// var eighthNoteTime = 0.1;
// //play beat
var kick = document.getElementById('kick');
var snare = document.getElementById('snare');
var hi_hat = document.getElementById('hi-hat');
// for (var bar = 0; bar < 2; bar++) {
// var time = startTime + bar * 8 * eighthNoteTime;
// // Play the bass (kick) drum on beats 1, 5
// playSound(kick, time);
// playSound(kick, time + 4 * eighthNoteTime);
// // Play the snare drum on beats 3, 7
// playSound(snare, time + 2 * eighthNoteTime);
// playSound(snare, time + 6 * eighthNoteTime);
// // Play the hi-hat every eighth note.
// for (var i = 0; i < 8; ++i) {
// playSound(hihat, time + i * eighthNoteTime);
// }
// }
// window.onload = init;
// var context;
// var bufferLoader;
// function init() {
// // Fix up prefixing
// window.AudioContext = window.AudioContext || window.webkitAudioContext;
// context = new AudioContext();
// bufferLoader = new BufferLoader(
// context,
// [
// '808/clap (6).WAV',
// '../sounds/hyper-reality/laughter.wav',
// ],
// finishedLoading
// );
// bufferLoader.load();
// }
// function finishedLoading(bufferList) {
// // Create two sources and play them both together.
// var source1 = context.createBufferSource();
// var source2 = context.createBufferSource();
// source1.buffer = bufferList[0];
// source2.buffer = bufferList[1];
// source1.connect(context.destination);
// source2.connect(context.destination);
// source1.start(0);
// source2.start(0);
// }
var t = 0;
var BPM = 40;
document.ready = function() {
for (var i=0; i < myScale.length; i++) {
oscillator = context.createOscillator();
oscillator.frequency.value = frequencyFromNoteNumber(myScale[i]);
oscillator.connect(gainNode);
gainNode.connect(context.destination);
gainNode.gain.value = 1;
oscillator.start(t);
// playSound(hi_hat, t * 1000 / BPM)
t += 0.1;
}
}
</script>
</body>
</html>