Skip to content

Commit 0444e39

Browse files
authored
Merge pull request #10 from Absulit/dev
Dev
2 parents bd5fef7 + 4d0e250 commit 0444e39

4 files changed

Lines changed: 53 additions & 9 deletions

File tree

index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<meta name="Description"
1010
content="Audio Visualizer made with WebGPU and JavaScript">
1111

12-
<meta property="og:title" content=">Gravity Pull Audio Visualizer by absulit" />
12+
<meta property="og:title" content="Gravity Pull Audio Visualizer by absulit" />
1313
<meta property="og:type" content="website" />
1414
<meta property="og:url" content="https://absulit.github.io/Gravity-Pull/" />
1515
<meta property="og:image" content="https://absulit.github.io/Gravity-Pull/docs/example1.webp" />
@@ -18,7 +18,7 @@
1818
<meta name="twitter:card" content="summary_large_image" />
1919
<meta name="twitter:site" content="@absulit" />
2020
<meta name="twitter:creator" content="@absulit" />
21-
<meta name="twitter:title" content=">Gravity Pull Audio Visualizer by absulit" />
21+
<meta name="twitter:title" content="Gravity Pull Audio Visualizer by absulit" />
2222
<meta name="twitter:description" content="Audio Visualizer made in WebGPU" />
2323
<meta name="twitter:image" content="https://absulit.github.io/Gravity-Pull/docs/example1.webp" />
2424

src/main.js

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const folderSongs = gui.addFolder('songs');
1717

1818
let audio = null;
1919
let loop = false;
20+
let pauseClickTimeout = null;
2021

2122
const options = {
2223
volume: 0.500,
@@ -35,7 +36,10 @@ const colorSchemes = {
3536
Artwork: 2,
3637
Negative: 3
3738
}
38-
folderOptions.add(selectedScheme, 'Color Scheme', colorSchemes).onChange(v => points.setUniform('colorScheme', v));
39+
folderOptions.add(selectedScheme, 'Color Scheme', colorSchemes).onChange(v => {
40+
points.setUniform('colorScheme', v)
41+
saveOption('scheme', v);
42+
});
3943

4044
function clickSong() {
4145
playSong(this)
@@ -231,11 +235,35 @@ songs.forEach(async (song, index) => {
231235
})
232236

233237
//------------------------------------
238+
async function saveOption(key, value) {
239+
await db.options.put({ key, value });
240+
}
241+
242+
async function getOption(key) {
243+
const option = await db.options.get(key);
244+
return option ? option.value : null;
245+
}
246+
247+
234248

235249
const db = new Dexie('bhdb');
236250
db.version(1).stores({
237-
songs: '++id, file'
251+
songs: '++id, file',
252+
options: 'key'
238253
});
254+
const volume = await getOption('volume');
255+
if (volume) {
256+
options.volume = volume;
257+
}
258+
259+
const scheme = await getOption('scheme');
260+
console.log(scheme);
261+
262+
if (scheme) {
263+
selectedScheme['Color Scheme'] = scheme;
264+
points.setUniform('colorScheme', scheme)
265+
folderOptions.updateDisplay();
266+
}
239267

240268
const songsFromDB = await db.songs
241269
.toArray();
@@ -269,7 +297,10 @@ Object.keys(options).forEach(key => {
269297
}
270298
})
271299

272-
volumeSlider.onChange(value => audio.volume = value);
300+
volumeSlider.onChange(value => {
301+
audio.volume = value;
302+
saveOption('volume', value);
303+
});
273304

274305
folderOptions.open();
275306
folderSongs.open();
@@ -303,7 +334,20 @@ await points.init(renderPasses);
303334

304335
points.fitWindow = true;
305336

306-
document.addEventListener('dblclick', _ => points.fullscreen = !points.fullscreen);
337+
points.canvas.addEventListener('click', _ => {
338+
if (pauseClickTimeout) {
339+
return;
340+
}
341+
pauseClickTimeout = setTimeout(() => {
342+
audio?.paused ? audio?.play() : audio?.pause();
343+
pauseClickTimeout = null;
344+
}, 300);
345+
});
346+
document.addEventListener('dblclick', _ => {
347+
clearTimeout(pauseClickTimeout);
348+
pauseClickTimeout = null;
349+
points.fullscreen = !points.fullscreen;
350+
});
307351

308352
setInterval(_ => {
309353
console.log('---- 10s');

src/renderpasses/renderpass0/frag.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,11 @@ fn main(
217217
var stringMask2 = 0.;
218218
let textScale = 2.476 * ratio.y + c0;
219219
let textUVR = uvr / textScale;
220+
let spaceRatio = .0017 * ratio.x;
220221
for (var index = 0; index < NUMCHARS; index++) {
221222
let charIndex = u32(chars[index]);
222223
let charPosition = charSizeF32 * vec2(f32(index), 0);
223-
let space = .002261 * vec2(f32(index), 0);
224+
let space = spaceRatio * vec2(f32(index), 0);
224225
stringMask += sprite(font, textImageSampler, space + fontPosition + charPosition, textUVR, charIndex - charOffset, charSize).x;
225226
stringMask2 += sprite(font, textImageSampler, space + fontPosition + charPosition, textUVR + .0005, charIndex - charOffset, charSize).x;
226227
}

src/utils.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export async function countImageColors(src) {
2323
const side = 16;
2424
canvas.width = side;
2525
canvas.height = side;
26-
ctx.drawImage(img, 0, 0,side,side);
26+
ctx.drawImage(img, 0, 0, side, side);
2727

2828

2929

@@ -59,5 +59,4 @@ export async function countImageColors(src) {
5959
};
6060

6161
});
62-
6362
}

0 commit comments

Comments
 (0)