-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample-browser.html
More file actions
156 lines (144 loc) · 10.3 KB
/
Copy pathsample-browser.html
File metadata and controls
156 lines (144 loc) · 10.3 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Dato DRUM — sample browser</title>
<style>
#select-prev, #select-next, #drumpad {
cursor: pointer;
/* equivalent of box-shadow: 0 4px 0 rgba(0,0,0,0.1) — offset pre-rotated
for the -45deg group, in user units (380 units = 300px) */
filter: drop-shadow(-3.58px 3.58px 0 rgba(0, 0, 0, 0.1));
}
</style>
</head>
<body>
<svg id="widget" xmlns="http://www.w3.org/2000/svg" width="300" viewBox="1446 386 380 380">
<g transform="rotate(-45 1636 576)">
<path id="select-prev" d="M1504.37,455.485c-1.99,-7.436 4.81,-14.24 12.25,-12.248l33.46,8.966c7.43,1.992 9.92,11.287 4.48,16.73l-24.49,24.495c-5.45,5.443 -14.74,2.953 -16.73,-4.483l-8.97,-33.46Z" style="fill-rule:nonzero;" />
<path id="select-next" d="M1755.4,706.507c7.44,1.992 14.24,-4.812 12.25,-12.247l-8.97,-33.461c-1.99,-7.436 -11.29,-9.926 -16.73,-4.483l-24.49,24.495c-5.45,5.443 -2.96,14.738 4.48,16.73l33.46,8.966Z" style="fill-rule:nonzero;" />
<g id="drumpad">
<path id="pad-body" d="M1508.02,561.437l113.137,-113.138c7.805,-7.805 20.479,-7.805 28.284,0l113.137,113.138c7.805,7.805 7.805,20.479 0,28.284l-113.137,113.137c-7.805,7.805 -20.479,7.805 -28.284,0l-113.137,-113.137c-7.805,-7.805 -7.805,-20.479 0,-28.284Z" style="fill:#ddd;" />
<g class="pad-mask" id="mask-track-0" transform="translate(-0.95,0.95) rotate(180 1636.23 574.63)">
<path d="M1644.17,575.097c1.23,1.227 3.22,1.227 4.44,0c1.23,-1.226 1.23,-3.214 0,-4.44c-1.23,-1.227 -3.21,-1.227 -4.44,-0.001c-1.23,1.226 -1.23,3.215 0,4.441Z" style="fill-rule:nonzero;" />
<path d="M1635.03,565.959c1.23,1.227 3.21,1.226 4.44,-0c1.23,-1.227 1.23,-3.214 0,-4.441c-1.23,-1.226 -3.21,-1.227 -4.44,-0.001c-1.23,1.227 -1.23,3.215 0,4.442Z" style="fill-rule:nonzero;" />
<path d="M1523.12,574.629l113.204,113.149l113.027,-113.149l-113.124,-113.127l-113.107,113.127Zm111.565,-32.007c0.65,-0.002 1.24,0.26 1.66,0.685c0.43,0.425 0.69,1.009 0.69,1.658l0,7.117c5.31,0.235 10.55,2.353 14.6,6.406c4.05,4.054 6.17,9.294 6.41,14.602l7.11,0.002c0.65,-0 1.24,0.261 1.66,0.685c0.43,0.425 0.69,1.012 0.69,1.658c0,1.295 -1.05,2.344 -2.35,2.344l-7.4,-0.002c-0.74,4.345 -2.77,8.514 -6.12,11.868c-8.6,8.603 -22.55,8.603 -31.16,-0.001c-8.6,-8.603 -8.6,-22.553 0,-31.156c3.36,-3.355 7.53,-5.382 11.87,-6.121l0,-7.402c0,-1.293 1.05,-2.345 2.34,-2.343Z" style="fill-rule:nonzero;" />
</g>
<g class="pad-mask" id="mask-track-1" transform="translate(-0.95,0.95) rotate(90 1636.23 574.63) translate(-0.1,-1061.87)">
<path d="M1628.19,1639.33c-1.23,1.23 -1.23,3.22 0,4.44c1.23,1.23 3.21,1.23 4.44,0c1.23,-1.22 1.23,-3.21 0,-4.44c-1.23,-1.23 -3.21,-1.22 -4.44,0Z" style="fill-rule:nonzero;" />
<path d="M1637.33,1630.19c-1.23,1.23 -1.23,3.22 0,4.44c1.23,1.23 3.21,1.23 4.44,0c1.23,-1.22 1.23,-3.21 0,-4.44c-1.23,-1.23 -3.21,-1.22 -4.44,0Z" style="fill-rule:nonzero;" />
<path d="M1636.32,1523.53l-113.343,113.337l113.352,112.623l113.279,-112.513l-113.288,-113.447Zm17.478,101.108c2.38,2.38 2.38,6.24 -0,8.62l-5.04,5.04l4.74,4.75c0.92,0.91 0.92,2.4 -0,3.31c-0.92,0.92 -2.4,0.92 -3.32,-0l-4.74,-4.74l-5.82,5.82l4.74,4.74c0.92,0.92 0.92,2.4 -0,3.32c-0.91,0.92 -2.4,0.92 -3.31,-0l-4.75,-4.74l-5.04,5.04c-2.38,2.38 -6.24,2.38 -8.62,-0l-9.38,-9.38c-2.38,-2.38 -2.38,-6.24 -0,-8.62l22.54,-22.54c2.38,-2.38 6.24,-2.38 8.62,-0l9.38,9.38Z" style="fill-rule:nonzero;" />
</g>
<g class="pad-mask" id="mask-track-2" transform="translate(-0.95,0.95) translate(1061.83,-1062.0)">
<path d="M583.072,1636.2c-1.226,-1.22 -3.214,-1.22 -4.44,0c-1.228,1.23 -1.227,3.22 -0.001,4.44c1.227,1.23 3.215,1.23 4.442,0c1.227,-1.22 1.226,-3.21 -0.001,-4.44Z" style="fill-rule:nonzero;" />
<path d="M573.932,1627.06c-1.227,-1.22 -3.215,-1.22 -4.441,0c-1.227,1.23 -1.227,3.22 0,4.44c1.226,1.23 3.214,1.23 4.441,0c1.227,-1.22 1.226,-3.21 0,-4.44Z" style="fill-rule:nonzero;" />
<path d="M687.536,1636.77l-113.339,-113.291l-112.9,113.1l113.094,113.176l113.145,-112.985Zm-101.604,18.176l-3.285,-0.41c-2.406,-0.29 -4.832,0.36 -6.768,1.82l-2.643,1.99c-3.271,2.47 -7.988,1.2 -9.587,-2.57l-1.292,-3.05c-0.946,-2.23 -2.722,-4 -4.954,-4.95l-3.049,-1.29c-3.77,-1.6 -5.034,-6.32 -2.568,-9.59l1.993,-2.64c1.46,-1.94 2.111,-4.36 1.815,-6.77l-0.406,-3.29c-0.5,-4.06 2.953,-7.51 7.018,-7.01l3.286,0.4c2.406,0.3 4.832,-0.35 6.768,-1.81l2.643,-2c3.271,-2.46 7.986,-1.2 9.587,2.57l1.292,3.05c0.946,2.23 2.722,4.01 4.954,4.95l3.048,1.3c3.77,1.6 5.035,6.31 2.568,9.58l-1.993,2.65c-1.459,1.93 -2.11,4.36 -1.814,6.76l0.406,3.29c0.5,4.06 -2.953,7.52 -7.019,7.02Z" style="fill-rule:nonzero;" />
</g>
<g class="pad-mask" id="mask-track-3" transform="translate(-0.95,0.95) rotate(-90 1636.23 574.63) translate(1061.86,-0.04)">
<path d="M588.935,580.797c1.227,-1.227 1.227,-3.215 -0,-4.442c-1.226,-1.226 -3.214,-1.225 -4.441,0.001c-1.226,1.227 -1.227,3.214 -0,4.441c1.226,1.226 3.215,1.227 4.441,0Z" style="fill-rule:nonzero;" />
<path d="M581.787,587.945c1.227,-1.226 1.226,-3.215 0,-4.441c-1.227,-1.227 -3.214,-1.226 -4.44,0c-1.227,1.227 -1.228,3.215 -0.002,4.441c1.227,1.226 3.216,1.227 4.442,0Z" style="fill-rule:nonzero;" />
<path d="M574.281,687.717l113.274,-112.97l-113.265,-113.114l-113.096,112.988l113.087,113.096Zm-13.98,-103.721l10.687,-10.687l-6.379,-6.379l-10.224,-0.002c-1.295,0.002 -2.343,-1.051 -2.343,-2.343c-0,-0.649 0.26,-1.233 0.685,-1.658c0.424,-0.425 1.011,-0.688 1.658,-0.685l8.855,0.001l-0.001,-8.856c-0,-0.648 0.26,-1.233 0.685,-1.658c0.425,-0.424 1.01,-0.685 1.658,-0.685c1.295,-0.002 2.346,1.049 2.343,2.343l0.003,10.23l6.376,6.376l10.69,-10.69c4.005,-4.005 10.83,-0.859 10.384,4.788l-1.806,22.887c-0.237,2.987 -2.609,5.359 -5.595,5.596l-22.888,1.805c-5.646,0.446 -8.793,-6.378 -4.788,-10.383Z" style="fill-rule:nonzero;" />
</g>
</g>
</g>
</svg>
<script type="module">
const samples = [
{ note: 30, color: '#FF0040', file: '30_kick_disco.wav' },
{ note: 31, color: '#FF0060', file: '31_kick_pattern.wav' },
{ note: 32, color: '#FF1010', file: '32_kick_big.wav' },
{ note: 33, color: '#FF1020', file: '33_kick_cr78.wav' },
{ note: 34, color: '#FF2040', file: '34_kick_808_long.wav' },
{ note: 35, color: '#FF2060', file: '35_kick_gabber.wav' },
{ note: 36, color: '#FF0000', file: '36_kick_808.wav' },
{ note: 37, color: '#FF0020', file: '37_kick_deep.wav' },
{ note: 38, color: '#0000FF', file: '38_snare_cr78.wav' },
{ note: 39, color: '#0028FF', file: '39_snare_808.wav' },
{ note: 40, color: '#0050FF', file: '40_snare_disco.wav' },
{ note: 41, color: '#0078FF', file: '41_snare_straw.wav' },
{ note: 42, color: '#1010FF', file: '42_snare_garage.wav' },
{ note: 43, color: '#1028FF', file: '43_snare_heimzap.wav' },
{ note: 44, color: '#2050FF', file: '44_snare_machine.wav' },
{ note: 45, color: '#3078FF', file: '45_snare_backbone.wav' },
{ note: 46, color: '#00FF00', file: '46_var_clap.wav' },
{ note: 47, color: '#00FF1E', file: '47_var_pop.wav' },
{ note: 48, color: '#00FF3C', file: '48_var_wood.wav' },
{ note: 49, color: '#00FF5A', file: '49_var_snap.wav' },
{ note: 50, color: '#10FF10', file: '50_var_sepp.wav' },
{ note: 51, color: '#10FF1E', file: '51_var_pow.wav' },
{ note: 52, color: '#10FF3C', file: '52_var_ah.wav' },
{ note: 53, color: '#20FF5A', file: '53_var_rim.wav' },
{ note: 54, color: '#FFFF00', file: '54_hat_cr78.wav' },
{ note: 55, color: '#FFE100', file: '55_hat_808.wav' },
{ note: 56, color: '#FFC300', file: '56_hat_maraca.wav' },
{ note: 57, color: '#FFA500', file: '57_hat_909_open.wav' },
{ note: 58, color: '#FFFF20', file: '58_hat_shaker.wav' },
{ note: 59, color: '#FFE120', file: '59_hat_electro.wav' },
{ note: 60, color: '#FFC320', file: '60_hat_second.wav' },
{ note: 61, color: '#FFA520', file: '61_hat_backbone.wav' },
];
const padBody = document.getElementById('pad-body');
const pad = document.getElementById('drumpad');
const prevBtn = document.getElementById('select-prev');
const nextBtn = document.getElementById('select-next');
const audioCtx = new (window.AudioContext || window.webkitAudioContext)();
const buffers = new Array(samples.length).fill(null);
async function loadSample(index) {
if (buffers[index]) return buffers[index];
const response = await fetch(`samples/factory_kit/${samples[index].file}`);
buffers[index] = await audioCtx.decodeAudioData(await response.arrayBuffer());
return buffers[index];
}
let current = 0;
const masks = [0, 1, 2, 3].map(t => document.getElementById(`mask-track-${t}`));
function showColor(index) {
padBody.style.fill = samples[index].color;
const track = Math.floor(index / 8);
masks.forEach((mask, t) => { mask.style.display = t === track ? '' : 'none'; });
}
showColor(current);
// Flash toward white on trigger (like the instrument): mix white into the
// selected color, then ease the mix back down linearly over 0.5s.
const FLASH_DURATION = 500;
const FLASH_WHITE_AMOUNT = 0.8;
let flashRaf = null;
function mixWithWhite(hex, amount) {
const channels = [1, 3, 5].map(i => {
const c = parseInt(hex.slice(i, i + 2), 16);
return Math.round(c + (255 - c) * amount);
});
return `rgb(${channels.join(',')})`;
}
function flash() {
cancelAnimationFrame(flashRaf);
const color = samples[current].color;
const start = performance.now();
padBody.style.fill = mixWithWhite(color, FLASH_WHITE_AMOUNT);
const frame = now => {
const t = Math.min((now - start) / FLASH_DURATION, 1);
padBody.style.fill = mixWithWhite(color, FLASH_WHITE_AMOUNT * (1 - t));
if (t < 1) flashRaf = requestAnimationFrame(frame);
};
flashRaf = requestAnimationFrame(frame);
}
async function play(index) {
flash();
if (audioCtx.state === 'suspended') await audioCtx.resume();
const buffer = await loadSample(index);
const source = audioCtx.createBufferSource();
source.buffer = buffer;
source.connect(audioCtx.destination);
source.start();
}
function select(step) {
current = (current + step + samples.length) % samples.length;
showColor(current);
play(current);
}
pad.addEventListener('pointerdown', () => { showColor(current); play(current); });
prevBtn.addEventListener('pointerdown', () => select(-1));
nextBtn.addEventListener('pointerdown', () => select(1));
</script>
</body>
</html>