mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-25 12:38:35 +00:00
cleanup constructor
This commit is contained in:
parent
1182d0e45d
commit
733994f9b5
@ -239,7 +239,9 @@ export const magicSofa = `stack(
|
|||||||
.every(2, fast(2))
|
.every(2, fast(2))
|
||||||
.voicings(),
|
.voicings(),
|
||||||
"<c2 f2 g2> <d2 g2 a2 e2>"
|
"<c2 f2 g2> <d2 g2 a2 e2>"
|
||||||
).slow(1).transpose.slowcat(0, 2, 3, 4)`;
|
).slow(1).transpose(slowcat(0, 2, 3, 4))`;
|
||||||
|
// below doesn't work anymore due to constructor cleanup
|
||||||
|
// ).slow(1).transpose.slowcat(0, 2, 3, 4)`;
|
||||||
|
|
||||||
export const confusedPhone = `"[g2 ~@1.3] [c3 ~@1.3]"
|
export const confusedPhone = `"[g2 ~@1.3] [c3 ~@1.3]"
|
||||||
.superimpose(
|
.superimpose(
|
||||||
|
|||||||
41
strudel.mjs
41
strudel.mjs
@ -262,23 +262,6 @@ class Pattern {
|
|||||||
// the following functions will get patternFactories as nested functions:
|
// the following functions will get patternFactories as nested functions:
|
||||||
constructor(query) {
|
constructor(query) {
|
||||||
this.query = query;
|
this.query = query;
|
||||||
// the following code will assign `patternFactories` as child functions to all methods of Pattern that don't start with '_'
|
|
||||||
const proto = Object.getPrototypeOf(this);
|
|
||||||
// proto.patternified is defined below Pattern class. You can add more patternified functions from outside.
|
|
||||||
proto.patternified.forEach((prop) => {
|
|
||||||
// patternify function
|
|
||||||
this[prop] = (...args) => this._patternify(Pattern.prototype['_' + prop])(...args);
|
|
||||||
// with the following, you can do, e.g. `stack(c3).fast.slowcat(1, 2, 4, 8)` instead of `stack(c3).fast(slowcat(1, 2, 4, 8))`
|
|
||||||
Object.assign(
|
|
||||||
this[prop],
|
|
||||||
Object.fromEntries(
|
|
||||||
Object.entries(Pattern.prototype.factories).map(([type, func]) => [
|
|
||||||
type,
|
|
||||||
(...args) => this[prop](func(...args)),
|
|
||||||
])
|
|
||||||
)
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_splitQueries() {
|
_splitQueries() {
|
||||||
@ -1019,7 +1002,7 @@ Pattern.prototype.define('hush', (pat) => pat.hush(), { patternified: false, com
|
|||||||
Pattern.prototype.define('bypass', (pat) => pat.bypass(on), { patternified: true, composable: true });
|
Pattern.prototype.define('bypass', (pat) => pat.bypass(on), { patternified: true, composable: true });
|
||||||
|
|
||||||
// call this after all Patter.prototype.define calls have been executed! (right before evaluate)
|
// call this after all Patter.prototype.define calls have been executed! (right before evaluate)
|
||||||
Pattern.prototype.bootstrap = () => {
|
Pattern.prototype.bootstrap = function() {
|
||||||
// makeComposable(Pattern.prototype);
|
// makeComposable(Pattern.prototype);
|
||||||
const bootstrapped = Object.fromEntries(Object.entries(Pattern.prototype.composable).map(([functionName, composable]) => {
|
const bootstrapped = Object.fromEntries(Object.entries(Pattern.prototype.composable).map(([functionName, composable]) => {
|
||||||
if(Pattern.prototype[functionName]) {
|
if(Pattern.prototype[functionName]) {
|
||||||
@ -1028,6 +1011,28 @@ Pattern.prototype.bootstrap = () => {
|
|||||||
}
|
}
|
||||||
return [functionName, curry(composable, makeComposable)];
|
return [functionName, curry(composable, makeComposable)];
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
// note: this === Pattern.prototypetgh6z
|
||||||
|
this.patternified.forEach((prop) => {
|
||||||
|
// the following will patternify all functions in Pattern.prototype.patternified
|
||||||
|
Pattern.prototype[prop] = function(...args) {
|
||||||
|
return this._patternify(Pattern.prototype['_' + prop])(...args)
|
||||||
|
}
|
||||||
|
// with the following, you can do, e.g. `stack(c3).fast.slowcat(1, 2, 4, 8)` instead of `stack(c3).fast(slowcat(1, 2, 4, 8))`
|
||||||
|
// TODO: find a way to implement below outside of constructor (code only worked there)
|
||||||
|
/* Object.assign(
|
||||||
|
Pattern.prototype[prop],
|
||||||
|
Object.fromEntries(
|
||||||
|
Object.entries(Pattern.prototype.factories).map(([type, func]) => [
|
||||||
|
type,
|
||||||
|
function(...args) {
|
||||||
|
console.log('this', this);
|
||||||
|
return this[prop](func(...args))
|
||||||
|
}
|
||||||
|
])
|
||||||
|
)
|
||||||
|
); */
|
||||||
|
});
|
||||||
return bootstrapped;
|
return bootstrapped;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user