Merge pull request #1059 from tidalcycles/dollar-colon

anonymous patterns + muting
This commit is contained in:
Felix Roos 2024-04-19 00:05:08 +02:00 committed by GitHub
commit f427b56062
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -54,10 +54,12 @@ export function repl({
const scheduler =
sync && typeof SharedWorker != 'undefined' ? new NeoCyclist(schedulerOptions) : new Cyclist(schedulerOptions);
let pPatterns = {};
let anonymousIndex = 0;
let allTransform;
const hush = function () {
pPatterns = {};
anonymousIndex = 0;
allTransform = undefined;
return silence;
};
@ -82,6 +84,15 @@ export function repl({
// set pattern methods that use this repl via closure
const injectPatternMethods = () => {
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;
return this;
};