mirror of
https://github.com/eliasstepanik/strudel.git
synced 2026-01-10 05:08:33 +00:00
fix: use full repl in web package
This commit is contained in:
parent
65856409b6
commit
3cd31b2290
@ -6,9 +6,9 @@ export * from '@strudel/mini';
|
|||||||
export * from '@strudel/tonal';
|
export * from '@strudel/tonal';
|
||||||
export * from '@strudel/webaudio';
|
export * from '@strudel/webaudio';
|
||||||
import { Pattern, evalScope, setTime } from '@strudel/core';
|
import { Pattern, evalScope, setTime } from '@strudel/core';
|
||||||
import { initAudioOnFirstClick, registerSynthSounds, webaudioScheduler } from '@strudel/webaudio';
|
import { initAudioOnFirstClick, registerSynthSounds, webaudioRepl } from '@strudel/webaudio';
|
||||||
// import { registerSoundfonts } from '@strudel/soundfonts';
|
// import { registerSoundfonts } from '@strudel/soundfonts';
|
||||||
import { evaluate as _evaluate } from '@strudel/transpiler';
|
import { evaluate as _evaluate, transpiler } from '@strudel/transpiler';
|
||||||
import { miniAllStrings } from '@strudel/mini';
|
import { miniAllStrings } from '@strudel/mini';
|
||||||
|
|
||||||
// init logic
|
// init logic
|
||||||
@ -27,19 +27,18 @@ export async function defaultPrebake() {
|
|||||||
// when this function finishes, everything is initialized
|
// when this function finishes, everything is initialized
|
||||||
let initDone;
|
let initDone;
|
||||||
|
|
||||||
let scheduler;
|
let repl;
|
||||||
export function initStrudel(options = {}) {
|
export function initStrudel(options = {}) {
|
||||||
initAudioOnFirstClick();
|
initAudioOnFirstClick();
|
||||||
miniAllStrings();
|
options.miniAllStrings !== false && miniAllStrings();
|
||||||
const { prebake, ...schedulerOptions } = options;
|
const { prebake, ...replOptions } = options;
|
||||||
|
repl = webaudioRepl({ ...replOptions, transpiler });
|
||||||
scheduler = webaudioScheduler(schedulerOptions);
|
|
||||||
initDone = (async () => {
|
initDone = (async () => {
|
||||||
await defaultPrebake();
|
await defaultPrebake();
|
||||||
await prebake?.();
|
await prebake?.();
|
||||||
return scheduler;
|
return repl;
|
||||||
})();
|
})();
|
||||||
setTime(() => scheduler.now());
|
setTime(() => repl.scheduler.now());
|
||||||
return initDone;
|
return initDone;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,22 +46,21 @@ window.initStrudel = initStrudel;
|
|||||||
|
|
||||||
// this method will play the pattern on the default scheduler
|
// this method will play the pattern on the default scheduler
|
||||||
Pattern.prototype.play = function () {
|
Pattern.prototype.play = function () {
|
||||||
if (!scheduler) {
|
if (!repl) {
|
||||||
throw new Error('.play: no scheduler found. Have you called init?');
|
throw new Error('.play: no repl found. Have you called initStrudel?');
|
||||||
}
|
}
|
||||||
initDone.then(() => {
|
initDone.then(() => {
|
||||||
scheduler.setPattern(this, true);
|
repl.setPattern(this, true);
|
||||||
});
|
});
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
// stop playback
|
// stop playback
|
||||||
export function hush() {
|
export function hush() {
|
||||||
scheduler.stop();
|
repl.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
// evaluate and play the given code using the transpiler
|
// evaluate and play the given code using the transpiler
|
||||||
export async function evaluate(code, autoplay = true) {
|
export async function evaluate(code, autoplay = true) {
|
||||||
const { pattern } = await _evaluate(code);
|
return repl.evaluate(code, autoplay);
|
||||||
autoplay && pattern.play();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,7 @@ This program is free software: you can redistribute it and/or modify it under th
|
|||||||
|
|
||||||
import * as strudel from '@strudel/core';
|
import * as strudel from '@strudel/core';
|
||||||
import { superdough, getAudioContext, setLogger, doughTrigger } from 'superdough';
|
import { superdough, getAudioContext, setLogger, doughTrigger } from 'superdough';
|
||||||
const { Pattern, logger } = strudel;
|
const { Pattern, logger, repl } = strudel;
|
||||||
|
|
||||||
setLogger(logger);
|
setLogger(logger);
|
||||||
|
|
||||||
@ -24,17 +24,13 @@ Pattern.prototype.webaudio = function () {
|
|||||||
return this.onTrigger(webaudioOutputTrigger);
|
return this.onTrigger(webaudioOutputTrigger);
|
||||||
};
|
};
|
||||||
|
|
||||||
export function webaudioScheduler(options = {}) {
|
export function webaudioRepl(options = {}) {
|
||||||
options = {
|
options = {
|
||||||
getTime: () => getAudioContext().currentTime,
|
getTime: () => getAudioContext().currentTime,
|
||||||
defaultOutput: webaudioOutput,
|
defaultOutput: webaudioOutput,
|
||||||
...options,
|
...options,
|
||||||
};
|
};
|
||||||
const { defaultOutput, getTime } = options;
|
return repl(options);
|
||||||
return new strudel.Cyclist({
|
|
||||||
...options,
|
|
||||||
onTrigger: strudel.getTrigger({ defaultOutput, getTime }),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Pattern.prototype.dough = function () {
|
Pattern.prototype.dough = function () {
|
||||||
|
|||||||
@ -649,7 +649,7 @@
|
|||||||
"/packages/webaudio/webaudio.mjs": [
|
"/packages/webaudio/webaudio.mjs": [
|
||||||
"webaudioOutputTrigger",
|
"webaudioOutputTrigger",
|
||||||
"webaudioOutput",
|
"webaudioOutput",
|
||||||
"webaudioScheduler"
|
"webaudioRepl"
|
||||||
],
|
],
|
||||||
"/packages/webaudio/scope.mjs": [
|
"/packages/webaudio/scope.mjs": [
|
||||||
"drawTimeScope",
|
"drawTimeScope",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user