+ add hush

+ add the ability to evaluate without clearing
This commit is contained in:
Felix Roos 2023-11-16 07:17:59 +01:00
parent a7b799f154
commit f43f627037
2 changed files with 15 additions and 8 deletions

View file

@ -1975,9 +1975,9 @@ export const press = register('press', function (pat) {
* s("hh*3") * s("hh*3")
* ) * )
*/ */
export const hush = register('hush', function (pat) { Pattern.prototype.hush = function () {
return silence; return silence;
}); };
/** /**
* Applies `rev` to a pattern every other cycle, so that the pattern alternates between forwards and backwards. * Applies `rev` to a pattern every other cycle, so that the pattern alternates between forwards and backwards.

View file

@ -26,25 +26,31 @@ export function repl({
}); });
let pPatterns = {}; let pPatterns = {};
let allTransform; let allTransform;
const hush = function () {
pPatterns = {};
allTransform = undefined;
return silence;
};
const setPattern = (pattern, autostart = true) => { const setPattern = (pattern, autostart = true) => {
pattern = editPattern?.(pattern) || pattern; pattern = editPattern?.(pattern) || pattern;
scheduler.setPattern(pattern, autostart); scheduler.setPattern(pattern, autostart);
}; };
setTime(() => scheduler.now()); // TODO: refactor? setTime(() => scheduler.now()); // TODO: refactor?
const evaluate = async (code, autostart = true) => { const evaluate = async (code, autostart = true, shouldHush = true) => {
if (!code) { if (!code) {
throw new Error('no code to evaluate'); throw new Error('no code to evaluate');
} }
try { try {
await beforeEval?.({ code }); await beforeEval?.({ code });
pPatterns = {}; shouldHush && hush();
allTransform = undefined;
let { pattern, meta } = await _evaluate(code, transpiler); let { pattern, meta } = await _evaluate(code, transpiler);
if (Object.keys(pPatterns).length) { if (Object.keys(pPatterns).length) {
pattern = stack(...Object.values(pPatterns)); pattern = stack(...Object.values(pPatterns));
if (allTransform) { }
pattern = allTransform(pattern); if (allTransform) {
} pattern = allTransform(pattern);
} }
if (!isPattern(pattern)) { if (!isPattern(pattern)) {
const message = `got "${typeof evaluated}" instead of pattern`; const message = `got "${typeof evaluated}" instead of pattern`;
@ -105,6 +111,7 @@ export function repl({
loopAt, loopAt,
fit, fit,
all, all,
hush,
setCps, setCps,
setcps: setCps, setcps: setCps,
setCpm, setCpm,