mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-21 18:48:36 +00:00
anonymous patterns + muting with _
This commit is contained in:
parent
e0c4997f1e
commit
93d151b943
@ -54,10 +54,12 @@ export function repl({
|
|||||||
const scheduler =
|
const scheduler =
|
||||||
sync && typeof SharedWorker != 'undefined' ? new NeoCyclist(schedulerOptions) : new Cyclist(schedulerOptions);
|
sync && typeof SharedWorker != 'undefined' ? new NeoCyclist(schedulerOptions) : new Cyclist(schedulerOptions);
|
||||||
let pPatterns = {};
|
let pPatterns = {};
|
||||||
|
let anonymousIndex = 0;
|
||||||
let allTransform;
|
let allTransform;
|
||||||
|
|
||||||
const hush = function () {
|
const hush = function () {
|
||||||
pPatterns = {};
|
pPatterns = {};
|
||||||
|
anonymousIndex = 0;
|
||||||
allTransform = undefined;
|
allTransform = undefined;
|
||||||
return silence;
|
return silence;
|
||||||
};
|
};
|
||||||
@ -82,6 +84,15 @@ export function repl({
|
|||||||
// set pattern methods that use this repl via closure
|
// set pattern methods that use this repl via closure
|
||||||
const injectPatternMethods = () => {
|
const injectPatternMethods = () => {
|
||||||
Pattern.prototype.p = function (id) {
|
Pattern.prototype.p = function (id) {
|
||||||
|
if (id.startsWith('_') || id.endsWith('_')) {
|
||||||
|
// allows muting a pattern x with x_ or _x
|
||||||
|
return silence;
|
||||||
|
}
|
||||||
|
if (id === '$') {
|
||||||
|
// allows adding anonymous patterns with $:
|
||||||
|
id = `$${anonymousIndex}`;
|
||||||
|
anonymousIndex++;
|
||||||
|
}
|
||||||
pPatterns[id] = this;
|
pPatterns[id] = this;
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user