mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-22 11:08:35 +00:00
fixed indexdb
This commit is contained in:
parent
1fd9ba5dbf
commit
bf7fe2bf75
@ -99,7 +99,7 @@ export const connectToDestination = (input, channels = [0, 1]) => {
|
|||||||
//This upmix can be removed if correct channel counts are set throughout the app,
|
//This upmix can be removed if correct channel counts are set throughout the app,
|
||||||
// and then strudel could theoretically support surround sound audio files
|
// and then strudel could theoretically support surround sound audio files
|
||||||
const stereoMix = new StereoPannerNode(ctx);
|
const stereoMix = new StereoPannerNode(ctx);
|
||||||
input.connect(stereoMix);
|
input?.connect(stereoMix);
|
||||||
|
|
||||||
const splitter = new ChannelSplitterNode(ctx, {
|
const splitter = new ChannelSplitterNode(ctx, {
|
||||||
numberOfOutputs: stereoMix.channelCount,
|
numberOfOutputs: stereoMix.channelCount,
|
||||||
|
|||||||
@ -26,19 +26,7 @@ function clearIDB() {
|
|||||||
// queries the DB, and registers the sounds so they can be played
|
// queries the DB, and registers the sounds so they can be played
|
||||||
export function registerSamplesFromDB(config = userSamplesDBConfig, onComplete = () => {}) {
|
export function registerSamplesFromDB(config = userSamplesDBConfig, onComplete = () => {}) {
|
||||||
openDB(config, (objectStore) => {
|
openDB(config, (objectStore) => {
|
||||||
// const keys = objectStore.getAllKeys();
|
const query = objectStore.getAll();
|
||||||
|
|
||||||
// keys.onsuccess = (e) => {
|
|
||||||
// console.log(e);
|
|
||||||
// const result = e.target.result[0];
|
|
||||||
// console.log(result);
|
|
||||||
|
|
||||||
// const q = objectStore.get(result);
|
|
||||||
// q.onerror = (e) => console.error(e.target.error);
|
|
||||||
// q.onsuccess = (e) => console.log(e);
|
|
||||||
// };
|
|
||||||
|
|
||||||
let query = objectStore.getAll();
|
|
||||||
query.onerror = (e) => {
|
query.onerror = (e) => {
|
||||||
logger('User Samples failed to load ', 'error');
|
logger('User Samples failed to load ', 'error');
|
||||||
onComplete();
|
onComplete();
|
||||||
@ -50,32 +38,36 @@ export function registerSamplesFromDB(config = userSamplesDBConfig, onComplete =
|
|||||||
if (!soundFiles?.length) {
|
if (!soundFiles?.length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log(soundFiles);
|
|
||||||
const sounds = new Map();
|
const sounds = new Map();
|
||||||
[...soundFiles]
|
|
||||||
.sort((a, b) => a.title.localeCompare(b.title, undefined, { numeric: true, sensitivity: 'base' }))
|
|
||||||
.forEach((soundFile, i) => {
|
|
||||||
const title = soundFile.title;
|
|
||||||
if (!isAudioFile(title)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const splitRelativePath = soundFile.id.split('/');
|
|
||||||
let parentDirectory =
|
|
||||||
//fallback to file name before period and seperator if no parent directory
|
|
||||||
splitRelativePath[splitRelativePath.length - 2] ?? soundFile.id.split(/\W+/)[0] ?? 'user';
|
|
||||||
|
|
||||||
const soundPath = blobToDataUrl(soundFile.blob);
|
Promise.all(
|
||||||
|
[...soundFiles]
|
||||||
|
.sort((a, b) => a.title.localeCompare(b.title, undefined, { numeric: true, sensitivity: 'base' }))
|
||||||
|
.map((soundFile, i) => {
|
||||||
|
const title = soundFile.title;
|
||||||
|
if (!isAudioFile(title)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const splitRelativePath = soundFile.id.split('/');
|
||||||
|
let parentDirectory =
|
||||||
|
//fallback to file name before period and seperator if no parent directory
|
||||||
|
splitRelativePath[splitRelativePath.length - 2] ?? soundFile.id.split(/\W+/)[0] ?? 'user';
|
||||||
|
const blob = soundFile.blob;
|
||||||
|
|
||||||
// const soundPath = soundFile.blob;
|
// Files used to be uploaded as base64 strings, After Jan 1 2025 this check can be safely deleted
|
||||||
const soundPaths = sounds.get(parentDirectory) ?? new Set();
|
if (typeof blob === 'string') {
|
||||||
soundPaths.add(soundPath);
|
return blob;
|
||||||
sounds.set(parentDirectory, soundPaths);
|
}
|
||||||
});
|
|
||||||
|
|
||||||
sounds.forEach((soundPaths, key) => {
|
return blobToDataUrl(blob).then((soundPath) => {
|
||||||
const paths = Array.from(soundPaths);
|
const soundPaths = sounds.get(parentDirectory) ?? new Set();
|
||||||
Promise.all(paths).then((value) => {
|
soundPaths.add(soundPath);
|
||||||
// console.log({ value });
|
sounds.set(parentDirectory, soundPaths);
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
).then(() => {
|
||||||
|
sounds.forEach((soundPaths, key) => {
|
||||||
|
const value = Array.from(soundPaths);
|
||||||
registerSound(key, (t, hapValue, onended) => onTriggerSample(t, hapValue, onended, value), {
|
registerSound(key, (t, hapValue, onended) => onTriggerSample(t, hapValue, onended, value), {
|
||||||
type: 'sample',
|
type: 'sample',
|
||||||
samples: value,
|
samples: value,
|
||||||
@ -84,26 +76,12 @@ export function registerSamplesFromDB(config = userSamplesDBConfig, onComplete =
|
|||||||
tag: undefined,
|
tag: undefined,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
logger('imported sounds registered!', 'success');
|
|
||||||
onComplete();
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
|
||||||
// creates a blob from a buffer that can be read
|
|
||||||
async function bufferToDataUrl(buf) {
|
|
||||||
return new Promise((resolve) => {
|
|
||||||
var blob = new Blob([buf], { type: 'application/octet-binary' });
|
|
||||||
var reader = new FileReader();
|
|
||||||
reader.onload = function (event) {
|
|
||||||
resolve(event.target.result);
|
|
||||||
};
|
|
||||||
reader.readAsDataURL(blob);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function bufferToBlob(buf) {
|
logger('imported sounds registered!', 'success');
|
||||||
return new Blob([buf], { type: 'application/octet-binary' });
|
onComplete();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function blobToDataUrl(blob) {
|
async function blobToDataUrl(blob) {
|
||||||
@ -172,15 +150,11 @@ async function processFilesForIDB(files) {
|
|||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
title,
|
title,
|
||||||
// buf,
|
|
||||||
blob,
|
blob,
|
||||||
id,
|
id,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
//create a url base64 containing all of the buffer data
|
|
||||||
// const base64 = await bufferToDataUrl(buf);
|
|
||||||
})
|
})
|
||||||
.filter(Boolean),
|
.filter(Boolean),
|
||||||
).catch((error) => {
|
).catch((error) => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user