-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
394 lines (364 loc) · 17.4 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Over the Kit</title>
<script type="text/javascript" src="https://unpkg.com/[email protected]/releases/vexflow-min.js"></script>
<script type="text/javascript" src="js/fraction.min.js"></script>
<script type="text/javascript" src="js/bufferLoader.js"></script>
<script type="text/javascript" src="js/drumsetAudioBuffers.js"></script>
<script type="text/javascript" src="js/GrooveGenerator.js"></script>
<script type="text/javascript" src="js/StickingPadder.js"></script>
<script type="text/javascript" src="js/Orchestrator.js"></script>
<script type="text/javascript" src="js/Player.js"></script>
<script type="text/javascript" src="js/Notator.js"></script>
<link rel="stylesheet" href="https://unpkg.com/tailwindcss@^1.5/dist/base.min.css">
<link rel="stylesheet" href="https://unpkg.com/tailwindcss@^1.5/dist/components.min.css">
<link rel="stylesheet" href="https://unpkg.com/@tailwindcss/[email protected]/dist/typography.min.css">
<link rel="stylesheet" href="https://unpkg.com/tailwindcss@^1.5/dist/utilities.min.css">
</head>
<body class="bg-gray-200">
<div class="container mx-auto prose text-center py-10">
<div class="shadow-md rounded bg-white py-12 px-10 md:px-16 prose-lg">
<h1>🥁 Over the Kit</h1>
<div class="bg-orange-100 border-l-4 border-orange-500 text-orange-700 p-4 mb-10 md:hidden" role="alert">
<span class="font-bold">On a mobile device?</span>
<span>Remember to turn off silent mode!</span>
</div>
<div class="flex flex-col space-y-10">
<div class="mw-1/2">Discover a new chop to practice!</div>
<form id="shuffleForm" class="my-4 space-y-10 md:space-y-4">
<div class="md:flex md:items-center md:justify-center">
<div class="md:w-1/3">
<label class="block text-gray-500 font-bold md:text-right mb-1 md:mb-0 pr-4" for="sticking">
Sticking:
</label>
</div>
<div class="md:w-2/3">
<input
id="sticking"
value="RLRLK"
maxlength="16"
minlength="3"
class="bg-gray-200 appearance-none border-2 border-gray-200 rounded w-full py-3 px-4 text-gray-700 leading-tight focus:outline-none focus:bg-white focus:border-purple-500"
type="text"
>
</div>
</div>
<div class="md:flex md:items-start">
<div class="md:w-1/3">
<label class="block text-gray-500 font-bold md:text-right mb-1 md:mb-0 pr-4" for="sticking">
Orchestrations:
</label>
</div>
<div class="md:w-2/3 pl-2 text-left">
<div class="mb-2 flex">
<div class="w-1/2">
<label class="md:w-full block text-gray-500 font-bold">
<input id="hihatCheckbox" class="mr-2 leading-tight" checked type="checkbox">
<span class="text-sm">
Hi-Hat
</span>
</label>
</div>
<div class="w-1/2">
<label class="md:w-full block text-gray-500 font-bold">
<input id="snareCheckbox" class="mr-2 leading-tight" checked type="checkbox">
<span class="text-sm">
Snare
</span>
</label>
</div>
</div>
<div class="mb-2 flex">
<div class="w-1/2">
<label class="md:w-full block text-gray-500 font-bold">
<input id="hiTomCheckbox" class="mr-2 leading-tight" checked type="checkbox">
<span class="text-sm">
Hi-Tom
</span>
</label>
</div>
<div class="w-1/2">
<label class="md:w-full block text-gray-500 font-bold">
<input id="midTomCheckbox" class="mr-2 leading-tight" type="checkbox">
<span class="text-sm">
Mid-Tom
</span>
</label>
</div>
</div>
<div class="mb-2 flex">
<div class="w-1/2">
<label class="md:w-full block text-gray-500 font-bold">
<input id="floorTomCheckbox" class="mr-2 leading-tight" checked type="checkbox">
<span class="text-sm">
Floor-Tom
</span>
</label>
</div>
<div class="w-1/2">
<label class="md:w-full block text-gray-500 font-bold">
<input class="mr-2 leading-tight" type="checkbox" checked disabled>
<span class="text-sm">
Kick
</span>
</label>
</div>
</div>
</div>
</div>
<div class="md:flex md:items-center md:justify-center">
<div class="md:w-1/3">
<label class="block text-gray-500 font-bold md:text-right mb-1 md:mb-0 pr-4" for="sticking">
Tempo:
</label>
</div>
<div class="md:w-2/3 mb-4 md:mb-auto">
<input
id="tempo"
value="120"
max="400"
type="number"
class="bg-gray-200 appearance-none border-2 border-gray-200 rounded w-full py-3 px-4 text-gray-700 leading-tight focus:outline-none focus:bg-white focus:border-purple-500"
>
</div>
</div>
<div class="md:flex md:items-center">
<div class="md:w-1/3 hidden md:block"> </div>
<div class="md:w-2/3 text-left">
<button class="shadow bg-purple-500 hover:bg-purple-400 focus:shadow-outline focus:outline-none text-white font-bold py-2 px-4 rounded w-full md:w-auto inline-flex items-center justify-center" type="submit">
<svg class="fill-current w-4 h-4 mr-2" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path class="heroicon-ui" d="M6 18.7V21a1 1 0 0 1-2 0v-5a1 1 0 0 1 1-1h5a1 1 0 1 1 0 2H7.1A7 7 0 0 0 19 12a1 1 0 1 1 2 0 9 9 0 0 1-15 6.7zM18 5.3V3a1 1 0 0 1 2 0v5a1 1 0 0 1-1 1h-5a1 1 0 0 1 0-2h2.9A7 7 0 0 0 5 12a1 1 0 1 1-2 0 9 9 0 0 1 15-6.7z"/></svg>
<span>Generate</span>
</button>
</div>
</div>
</form>
<div class="border-solid border-t border-gray-300">
<h2>Fill (16th Notes)</h2>
<div id="fill16" class="flex justify-center mb-4"></div>
<button id="fill16Play" class="shadow bg-purple-200 hover:bg-purple-100 focus:shadow-outline focus:outline-none text-purple-600 font-bold py-2 px-4 rounded w-full md:w-auto inline-flex items-center justify-center md:ml-2 mt-2 md:mt-auto" type="button">
<svg class="fill-current w-4 h-4 mr-2" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path class="heroicon-ui" d="M8 14.54V6a1 1 0 0 1 .76-.97l12-3A1 1 0 0 1 22 3v12a4 4 0 1 1-2-3.46V4.28l-10 2.5V18a4 4 0 1 1-2-3.46zM6 20a2 2 0 1 0 0-4 2 2 0 0 0 0 4zm12-3a2 2 0 1 0 0-4 2 2 0 0 0 0 4z"/></svg>
<span>Play</span>
</button>
</div>
<div class="border-solid border-t border-gray-300">
<h2>One Bar Fill (16th Notes)</h2>
<div id="1BarFill16" class="flex justify-center"></div>
<button id="1BarFill16Play" class="shadow bg-purple-200 hover:bg-purple-100 focus:shadow-outline focus:outline-none text-purple-600 font-bold py-2 px-4 rounded w-full md:w-auto inline-flex items-center justify-center md:ml-2 mt-2 md:mt-auto" type="button">
<svg class="fill-current w-4 h-4 mr-2" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path class="heroicon-ui" d="M8 14.54V6a1 1 0 0 1 .76-.97l12-3A1 1 0 0 1 22 3v12a4 4 0 1 1-2-3.46V4.28l-10 2.5V18a4 4 0 1 1-2-3.46zM6 20a2 2 0 1 0 0-4 2 2 0 0 0 0 4zm12-3a2 2 0 1 0 0-4 2 2 0 0 0 0 4z"/></svg>
<span>Play</span>
</button>
</div>
<div class="border-solid border-t border-gray-300">
<h2>One Bar Fill (16th Note Triplets)</h2>
<div id="1BarFill16Triplets" class="flex justify-center"></div>
<button id="1BarFill16TripletsPlay" class="shadow bg-purple-200 hover:bg-purple-100 focus:shadow-outline focus:outline-none text-purple-600 font-bold py-2 px-4 rounded w-full md:w-auto inline-flex items-center justify-center md:ml-2 mt-2 md:mt-auto" type="button">
<svg class="fill-current w-4 h-4 mr-2" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path class="heroicon-ui" d="M8 14.54V6a1 1 0 0 1 .76-.97l12-3A1 1 0 0 1 22 3v12a4 4 0 1 1-2-3.46V4.28l-10 2.5V18a4 4 0 1 1-2-3.46zM6 20a2 2 0 1 0 0-4 2 2 0 0 0 0 4zm12-3a2 2 0 1 0 0-4 2 2 0 0 0 0 4z"/></svg>
<span>Play</span>
</button>
</div>
</div>
</div>
<div class="text-gray-500 px-10 md:px-16">
<h2>👋<span class="ml-2 text-gray-600">Hey there!</span></h2>
<p class="text-center">
If you enjoyed this and have a suggestion, or want to be notified as I add more features, please drop a note <a class="underline hover:text-gray-700" href="https://forms.gle/R4ZryX4fbvmBrz5TA" target="_blank" rel="noopener noreferrer">here</a>.
</p>
<h3><span class="text-gray-600">Roadmap:</span></h3>
<div>Generate different stickings</div>
<div>Over-the-bar / sub-bar patterns</div>
<div>Save and share patterns</div>
<div>More orchestrations / flavours e.g. rests, accents</div>
<div>👉<em class="ml-2">Your idea here?</em></div>
<p>
<small>
a project by <a href="https://github.com/wasabigeek">wasabigeek</a>
</small>
</p>
</div>
</div>
<script type="text/javascript">
window.onload = init;
var audioContext;
var drumset;
DURATION_SIXTEENTH = '1/16';
DURATION_SIXTEENTH_TRIPLET = '1/24';
DURATION_EIGHTH = '1/8';
DURATION_QUARTER = '1/4';
var scores = {
'fill16': new Score(),
'1BarFill16': new Score(),
'1BarFill16Triplets': new Score(),
}
var getOrchestrations = function() {
var orchestrations = [];
// this is coupled to the UI / instruments for simplicity, might want to relook this
if (document.getElementById('hihatCheckbox').checked) { orchestrations.push(drumset.hihat) }
if (document.getElementById('snareCheckbox').checked) { orchestrations.push(drumset.snare) }
if (document.getElementById('hiTomCheckbox').checked) { orchestrations.push(drumset.tom1) }
if (document.getElementById('midTomCheckbox').checked) { orchestrations.push(drumset.tom2) }
if (document.getElementById('floorTomCheckbox').checked) { orchestrations.push(drumset.tom3) }
return orchestrations;
}
function Score(noteGroups = [], options = {}) {
this.noteGroups = noteGroups;
this.options = options; // for copying
this.timeSignature = options.timeSignature || '4/4';
this.getBeatValue = function() {
return new Fraction(1 / Number(this.timeSignature.split('/')[1]));
}
this.slice = function(start, end) {
return new Score(this.noteGroups.slice(start, end), this.options);
}
this.sliceDuration = function(start, end) {
start = new Fraction(start);
end = new Fraction(end);
var sliced = [];
var copy = this.noteGroups.slice();
var cumulativeDuration = new Fraction(0);
while(cumulativeDuration < end && copy.length > 0) {
var next = copy.shift();
// have we reached the end?
if (next && (end.sub(cumulativeDuration)) >= next.duration) {
// is this from the start that we wanted to slice?
if (cumulativeDuration >= start) {
sliced.push(next);
}
cumulativeDuration = cumulativeDuration.add(next.duration);
}
}
return new Score(sliced, this.options);
}
this.concat = function(score) {
return new Score(this.noteGroups.slice().concat(score.noteGroups), this.options);
}
this.forEach = function(fn) {
this.noteGroups.forEach(fn);
}
this.push = function(noteGroup) {
this.noteGroups.push(noteGroup);
}
this.sumDuration = function() {
return this.noteGroups.reduce(function(acc, noteGroup) {
return acc.add(noteGroup.duration);
}, new Fraction(0));
}
}
function Note(options) {
this.instrument = options.instrument;
this.volume = options.volume;
this.verticalPosition = this.instrument.verticalPosition;
// this has to be lazily retrieved now because the AudioContext needs to load
this.getSound = this.instrument.sound;
}
function NoteGroup(notes, duration) {
this.notes = notes;
this.duration = new Fraction(duration);
this.setDuration = function(duration) {
this.duration = new Fraction(duration);
}
}
function Drumset(audioBuffers, positions) {
this.snare = { verticalPosition: positions.SNARE, sound: audioBuffers.snareSound };
this.hihat = { verticalPosition: positions.CLOSED_HIHAT, sound: audioBuffers.hihatSound };
this.kick = { verticalPosition: positions.KICK, sound: audioBuffers.kickSound };
this.tom1 = { verticalPosition: positions.HI_TOM, sound: audioBuffers.tom1Sound };
this.tom2 = { verticalPosition: positions.MID_TOM, sound: audioBuffers.tom2Sound };
this.tom3 = { verticalPosition: positions.FLOOR_TOM, sound: audioBuffers.tom3Sound };
}
/**
* Determines how the sticking is interpreted.
*/
function StickingContext(params = {}) {
this.pipeline = params.pipeline;
var generate = function(sticking, options = {}) {
return this.pipeline.reduce(function(output, processingFunction) {
return processingFunction(output);
}, sticking);
}
this.generate = generate.bind(this);
}
function init() {
// Audio setup
window.AudioContext = window.AudioContext || window.webkitAudioContext;
audioContext = new AudioContext();
var drumsetAudioBuffers = new DrumsetAudioBuffers(audioContext);
drumset = new Drumset(drumsetAudioBuffers, NOTATOR_POSITIONS);
var stickingContexts = {
'fill16': new StickingContext({
pipeline: [
new Orchestrator({ drumset: drumset }).orchestrate,
function(score) {
score.forEach(function(grouping) { grouping.setDuration(DURATION_SIXTEENTH) });
return score;
},
function(score) {
var groove = new GrooveGenerator({ drumset: drumset }).generate({ duration: 1 - score.sumDuration() });
return groove.concat(score);
}
]
}),
'1BarFill16': new StickingContext({
pipeline: [
new StickingPadder().pad,
new Orchestrator({ drumset: drumset }).orchestrate,
function(score) {
score.forEach(function(grouping) { grouping.setDuration(DURATION_SIXTEENTH) });
return score;
},
function(score) {
var groove = new GrooveGenerator({ drumset: drumset }).generate({ duration: 2 - score.sumDuration() });
return groove.concat(score);
}
]
}),
'1BarFill16Triplets': new StickingContext({
pipeline: [
new StickingPadder({ desiredLength: 24 }).pad,
new Orchestrator({ drumset: drumset }).orchestrate,
function(score) {
score.forEach(function(grouping) { grouping.setDuration(DURATION_SIXTEENTH_TRIPLET) });
return score;
},
function(score) {
var groove = new GrooveGenerator({ drumset: drumset }).generate({ duration: 2 - score.sumDuration() });
return groove.concat(score);
}
]
}),
}
var notators = {
'fill16': new Notator({ elementId: 'fill16' }),
'1BarFill16': new Notator({ elementId: '1BarFill16', height: 300 }),
'1BarFill16Triplets': new Notator({ elementId: '1BarFill16Triplets', width: 500, height: 300 }),
}
var player = new Player({ audioContext: audioContext })
function generateContexts() {
var newSticking = document.getElementById('sticking').value;
for (var scoreKey in scores) {
scores[scoreKey] = stickingContexts[scoreKey].generate(newSticking);
notators[scoreKey].generateNotation(scores[scoreKey]);
}
}
// empty state
generateContexts();
// events
var createClickHandler = function(scoreKey) {
return function(e) {
var tempo = document.getElementById('tempo').value;
player.play(scores[scoreKey], { tempo: tempo })
}
}
for (var scoreKey in scores) {
document.getElementById(scoreKey + 'Play').onclick = createClickHandler(scoreKey); // scope scoreKey to the function
}
document.getElementById('shuffleForm').onsubmit = function(e) {
e.preventDefault();
generateContexts();
}
}
</script>
</body>
</html>