Merge pull request #1102 from daslyfe/upload_individual_samples
Samples tab improvements
This commit is contained in:
commit
def5bc858f
3 changed files with 15 additions and 7 deletions
|
|
@ -40,8 +40,10 @@ export const registerSamplesFromDB = (config = userSamplesDBConfig, onComplete =
|
||||||
if (!isAudioFile(title)) {
|
if (!isAudioFile(title)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const splitRelativePath = soundFile.id?.split('/');
|
const splitRelativePath = soundFile.id.split('/');
|
||||||
const parentDirectory = splitRelativePath[splitRelativePath.length - 2];
|
const 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 = soundFile.blob;
|
const soundPath = soundFile.blob;
|
||||||
const soundPaths = sounds.get(parentDirectory) ?? new Set();
|
const soundPaths = sounds.get(parentDirectory) ?? new Set();
|
||||||
soundPaths.add(soundPath);
|
soundPaths.add(soundPath);
|
||||||
|
|
@ -114,6 +116,7 @@ const processFilesForIDB = async (files) => {
|
||||||
Array.from(files)
|
Array.from(files)
|
||||||
.map(async (s) => {
|
.map(async (s) => {
|
||||||
const title = s.name;
|
const title = s.name;
|
||||||
|
|
||||||
if (!isAudioFile(title)) {
|
if (!isAudioFile(title)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -121,12 +124,14 @@ const processFilesForIDB = async (files) => {
|
||||||
const sUrl = URL.createObjectURL(s);
|
const sUrl = URL.createObjectURL(s);
|
||||||
//fetch the sound and turn it into a buffer array
|
//fetch the sound and turn it into a buffer array
|
||||||
const buf = await fetch(sUrl).then((res) => res.arrayBuffer());
|
const buf = await fetch(sUrl).then((res) => res.arrayBuffer());
|
||||||
//create a url blob containing all of the buffer data
|
//create a url base64 containing all of the buffer data
|
||||||
const base64 = await bufferToDataUrl(buf);
|
const base64 = await bufferToDataUrl(buf);
|
||||||
|
const path = s.webkitRelativePath;
|
||||||
|
const id = path?.length ? path : title;
|
||||||
return {
|
return {
|
||||||
title,
|
title,
|
||||||
blob: base64,
|
blob: base64,
|
||||||
id: s.webkitRelativePath,
|
id,
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
.filter(Boolean),
|
.filter(Boolean),
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ export default function ImportSoundsButton({ onComplete }) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setIsUploading(true);
|
setIsUploading(true);
|
||||||
|
|
||||||
await uploadSamplesToDB(userSamplesDBConfig, fileUploadRef.current.files).then(() => {
|
await uploadSamplesToDB(userSamplesDBConfig, fileUploadRef.current.files).then(() => {
|
||||||
registerSamplesFromDB(userSamplesDBConfig, () => {
|
registerSamplesFromDB(userSamplesDBConfig, () => {
|
||||||
onComplete();
|
onComplete();
|
||||||
|
|
@ -32,7 +33,7 @@ export default function ImportSoundsButton({ onComplete }) {
|
||||||
directory=""
|
directory=""
|
||||||
webkitdirectory=""
|
webkitdirectory=""
|
||||||
multiple
|
multiple
|
||||||
accept="audio/*"
|
accept="audio/*, .wav, .mp3, .m4a, .flac"
|
||||||
onChange={() => {
|
onChange={() => {
|
||||||
onChange();
|
onChange();
|
||||||
}}
|
}}
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,9 @@ export function SoundsTab() {
|
||||||
const sounds = useStore(soundMap);
|
const sounds = useStore(soundMap);
|
||||||
const { soundsFilter } = useSettings();
|
const { soundsFilter } = useSettings();
|
||||||
const soundEntries = useMemo(() => {
|
const soundEntries = useMemo(() => {
|
||||||
let filtered = Object.entries(sounds).filter(([key]) => !key.startsWith('_'));
|
let filtered = Object.entries(sounds)
|
||||||
|
.filter(([key]) => !key.startsWith('_'))
|
||||||
|
.sort((a, b) => a[0].localeCompare(b[0]));
|
||||||
if (!sounds) {
|
if (!sounds) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
@ -43,7 +45,7 @@ export function SoundsTab() {
|
||||||
});
|
});
|
||||||
return (
|
return (
|
||||||
<div id="sounds-tab" className="px-4 flex flex-col w-full h-full dark:text-white text-stone-900">
|
<div id="sounds-tab" className="px-4 flex flex-col w-full h-full dark:text-white text-stone-900">
|
||||||
<div className="pb-2 flex shrink-0 overflow-auto">
|
<div className="pb-2 flex shrink-0 flex-wrap">
|
||||||
<ButtonGroup
|
<ButtonGroup
|
||||||
value={soundsFilter}
|
value={soundsFilter}
|
||||||
onChange={(value) => settingsMap.setKey('soundsFilter', value)}
|
onChange={(value) => settingsMap.setKey('soundsFilter', value)}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue