Better sample loading
This commit is contained in:
parent
92d3fe496d
commit
daea207aff
5 changed files with 33 additions and 15 deletions
|
|
@ -42,9 +42,9 @@ const extensions = {
|
||||||
isMultiCursorEnabled: (on) =>
|
isMultiCursorEnabled: (on) =>
|
||||||
on
|
on
|
||||||
? [
|
? [
|
||||||
EditorState.allowMultipleSelections.of(true),
|
EditorState.allowMultipleSelections.of(true),
|
||||||
EditorView.clickAddsSelectionRange.of((ev) => ev.metaKey || ev.ctrlKey),
|
EditorView.clickAddsSelectionRange.of((ev) => ev.metaKey || ev.ctrlKey),
|
||||||
]
|
]
|
||||||
: [],
|
: [],
|
||||||
};
|
};
|
||||||
const compartments = Object.fromEntries(Object.keys(extensions).map((key) => [key, new Compartment()]));
|
const compartments = Object.fromEntries(Object.keys(extensions).map((key) => [key, new Compartment()]));
|
||||||
|
|
@ -264,9 +264,9 @@ export class StrudelMirror {
|
||||||
console.warn('first frame could not be painted');
|
console.warn('first frame could not be painted');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async evaluate(autoplay = true) {
|
async evaluate(autostart = true) {
|
||||||
this.flash();
|
this.flash();
|
||||||
await this.repl.evaluate(this.code, autoplay);
|
await this.repl.evaluate(this.code, autostart);
|
||||||
}
|
}
|
||||||
async stop() {
|
async stop() {
|
||||||
this.repl.scheduler.stop();
|
this.repl.scheduler.stop();
|
||||||
|
|
|
||||||
|
|
@ -289,7 +289,7 @@ export async function onTriggerSample(t, value, onended, bank, resolveUrl) {
|
||||||
const { bufferSource, sliceDuration, offset } = await getSampleBufferSource(value, bank, resolveUrl);
|
const { bufferSource, sliceDuration, offset } = await getSampleBufferSource(value, bank, resolveUrl);
|
||||||
|
|
||||||
// asny stuff above took too long?
|
// asny stuff above took too long?
|
||||||
if (ac.currentTime > t) {
|
if (ac.currentTime > t && !(ac instanceof OfflineAudioContext)) {
|
||||||
logger(`[sampler] still loading sound "${s}:${n}"`, 'highlight');
|
logger(`[sampler] still loading sound "${s}:${n}"`, 'highlight');
|
||||||
// console.warn('sample still loading:', s, n);
|
// console.warn('sample still loading:', s, n);
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -562,7 +562,7 @@ export const superdough = async (value, t, hapDuration, cps = 0.5, cycle = 0.5)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ac.currentTime > t) {
|
if (ac.currentTime > t && !(ac instanceof OfflineAudioContext)) {
|
||||||
logger('[webaudio] skip hap: still loading', ac.currentTime - t);
|
logger('[webaudio] skip hap: still loading', ac.currentTime - t);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,11 +22,14 @@ import {
|
||||||
setMaxPolyphony,
|
setMaxPolyphony,
|
||||||
setMultiChannelOrbits,
|
setMultiChannelOrbits,
|
||||||
resetGlobalEffects,
|
resetGlobalEffects,
|
||||||
|
getDefaultValue,
|
||||||
} from 'superdough';
|
} from 'superdough';
|
||||||
import './supradough.mjs';
|
import './supradough.mjs';
|
||||||
import { workletUrl } from 'supradough';
|
import { workletUrl } from 'supradough';
|
||||||
import { SuperdoughAudioController } from 'superdough/superdoughoutput.mjs';
|
import { SuperdoughAudioController } from 'superdough/superdoughoutput.mjs';
|
||||||
|
import { loadModules } from '@src/repl/util.mjs';
|
||||||
|
import { prebake } from '@src/repl/prebake.mjs';
|
||||||
|
import { getFontBufferSource, getFontPitch } from 'node_modules/@strudel/soundfonts/fontloader.mjs';
|
||||||
registerWorklet(workletUrl);
|
registerWorklet(workletUrl);
|
||||||
|
|
||||||
const { Pattern, logger, repl } = strudel;
|
const { Pattern, logger, repl } = strudel;
|
||||||
|
|
@ -56,7 +59,9 @@ export async function renderPatternAudio(pattern, cps, begin, end, sampleRate, d
|
||||||
logger('[webaudio] start rendering');
|
logger('[webaudio] start rendering');
|
||||||
|
|
||||||
let haps = pattern.queryArc(begin, end, { _cps: cps });
|
let haps = pattern.queryArc(begin, end, { _cps: cps });
|
||||||
await Promise.all(
|
await Promise.all([
|
||||||
|
loadModules(),
|
||||||
|
prebake(),
|
||||||
haps.map(async (h) => {
|
haps.map(async (h) => {
|
||||||
let s;
|
let s;
|
||||||
if (h.value.s) {
|
if (h.value.s) {
|
||||||
|
|
@ -65,13 +70,26 @@ export async function renderPatternAudio(pattern, cps, begin, end, sampleRate, d
|
||||||
} else {
|
} else {
|
||||||
s = h.value.s;
|
s = h.value.s;
|
||||||
}
|
}
|
||||||
let bank = getSound(s).data.samples;
|
// let bank = getSound(s).data.samples;
|
||||||
if (bank) {
|
let sample = getSound(s);
|
||||||
let { url: sampleUrl, label } = getSampleInfo(h.value, bank);
|
if (sample.data.type == "soundfont") {
|
||||||
await loadBuffer(sampleUrl, audioContext, label);
|
sample.data.fonts.forEach(async (font) => {
|
||||||
|
await getFontBufferSource(font, h.value, audioContext)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
if (sample.data.type == "sample") {
|
||||||
|
let url;
|
||||||
|
if (Array.isArray(sample)) {
|
||||||
|
url = sample.data.samples[i % sample.data.samples.length];
|
||||||
|
} else if (typeof sample === 'object') {
|
||||||
|
console.log(sample.data.samples)
|
||||||
|
url = Object.values(sample.data.samples).flat()[getDefaultValue("i") % Object.values(sample.data.samples).length];
|
||||||
|
}
|
||||||
|
await loadBuffer(url, audioContext, s, 0);
|
||||||
|
} // TODO: waveform
|
||||||
}
|
}
|
||||||
}),
|
})
|
||||||
|
],
|
||||||
);
|
);
|
||||||
haps.forEach(async (hap) => {
|
haps.forEach(async (hap) => {
|
||||||
if (hap.hasOnset()) {
|
if (hap.hasOnset()) {
|
||||||
|
|
|
||||||
|
|
@ -206,7 +206,7 @@ export function useReplContext() {
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleExport = async (begin, end, sampleRate, downloadName = undefined) => {
|
const handleExport = async (begin, end, sampleRate, downloadName = undefined) => {
|
||||||
await editorRef.current.evaluate(true);
|
await editorRef.current.evaluate(false);
|
||||||
editorRef.current.repl.scheduler.stop();
|
editorRef.current.repl.scheduler.stop();
|
||||||
await renderPatternAudio(
|
await renderPatternAudio(
|
||||||
editorRef.current.repl.state.pattern,
|
editorRef.current.repl.state.pattern,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue