add prepare() to superdough

This commit is contained in:
prezmop
2025-04-26 17:47:27 +09:00
parent 7cc44a8829
commit af27364c45
2 changed files with 31 additions and 9 deletions
+16 -7
View File
@@ -265,19 +265,28 @@ export const samples = async (sampleMap, baseUrl = sampleMap._base || '', option
processSampleMap(
sampleMap,
(key, bank) =>
registerSound(key, (t, hapValue, onended) => onTriggerSample(t, hapValue, onended, bank), {
type: 'sample',
samples: bank,
baseUrl,
prebake,
tag,
}),
registerSound(
key,
(t, hapValue, onended) => onTriggerSample(t, hapValue, onended, bank),
{
type: 'sample',
samples: bank,
baseUrl,
prebake,
tag,
},
(hapValue) => onPrepareSample(hapValue, bank),
),
baseUrl,
);
};
const cutGroups = [];
export async function onPrepareSample(hapValue, bank, resolveUrl) {
await getSampleBuffer(hapValue, bank, resolveUrl);
}
export async function onTriggerSample(t, value, onended, bank, resolveUrl) {
let {
s,
+15 -2
View File
@@ -23,9 +23,10 @@ export function setMaxPolyphony(polyphony) {
}
export const soundMap = map();
export function registerSound(key, onTrigger, data = {}) {
export function registerSound(key, onTrigger, data = {}, onPrepare = (() => {})) {
key = key.toLowerCase().replace(/\s+/g, '_');
soundMap.setKey(key, { onTrigger, data });
soundMap.setKey(key, { onTrigger, data, onPrepare });
}
function aliasBankMap(aliasMap) {
@@ -721,3 +722,15 @@ export const superdough = async (value, t, hapDuration) => {
export const superdoughTrigger = (t, hap, ct, cps) => {
superdough(hap, t - ct, hap.duration / cps, cps);
};
export const prepare = (value) => {
const {
onPrepare,
} = getSound(value.s);
if (onPrepare) {
if (value.bank && value.s) {
value.s = `${value.bank}_${value.s}`;
}
onPrepare(value);
}
}