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