add eslint + fix lint errors
This commit is contained in:
parent
e1a532500e
commit
e2898ee5bf
19 changed files with 938 additions and 92 deletions
|
|
@ -15,6 +15,7 @@ import drawLine from './drawLine.mjs';
|
|||
import { logger } from './logger.mjs';
|
||||
|
||||
let stringParser;
|
||||
|
||||
// parser is expected to turn a string into a pattern
|
||||
// if set, the reify function will parse all strings with it
|
||||
// intended to use with mini to automatically interpret all strings as mini notation
|
||||
|
|
@ -32,10 +33,9 @@ export class Pattern {
|
|||
this.query = query;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Haskell-style functor, applicative and monadic operations
|
||||
|
||||
|
||||
/**
|
||||
* Returns a new pattern, with the function applied to the value of
|
||||
* each hap. It has the alias {@link Pattern#fmap}.
|
||||
|
|
@ -164,7 +164,6 @@ export class Pattern {
|
|||
return new Pattern(query);
|
||||
}
|
||||
|
||||
|
||||
bindWhole(choose_whole, func) {
|
||||
const pat_val = this;
|
||||
const query = function (state) {
|
||||
|
|
@ -205,7 +204,7 @@ export class Pattern {
|
|||
}
|
||||
|
||||
outerBind(func) {
|
||||
return this.bindWhole((a, _) => a, func);
|
||||
return this.bindWhole((a) => a, func);
|
||||
}
|
||||
|
||||
outerJoin() {
|
||||
|
|
@ -313,7 +312,7 @@ export class Pattern {
|
|||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Utility methods mainly for internal use
|
||||
|
||||
|
||||
/**
|
||||
* Query haps inside the given time span.
|
||||
*
|
||||
|
|
@ -534,7 +533,7 @@ export class Pattern {
|
|||
// removes continuous haps that don't have a 'whole' timespan
|
||||
return this.filterHaps((hap) => hap.whole);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Queries the pattern for the first cycle, returning Haps. Mainly of use when
|
||||
* debugging a pattern.
|
||||
|
|
@ -940,8 +939,8 @@ export class Pattern {
|
|||
//binary_pat = sequence(binary_pat)
|
||||
const true_pat = binary_pat.filterValues(id);
|
||||
const false_pat = binary_pat.filterValues((val) => !val);
|
||||
const with_pat = true_pat.fmap((_) => (y) => y).appRight(func(this));
|
||||
const without_pat = false_pat.fmap((_) => (y) => y).appRight(this);
|
||||
const with_pat = true_pat.fmap(() => (y) => y).appRight(func(this));
|
||||
const without_pat = false_pat.fmap(() => (y) => y).appRight(this);
|
||||
return stack(with_pat, without_pat);
|
||||
}
|
||||
|
||||
|
|
@ -1007,7 +1006,7 @@ export class Pattern {
|
|||
every(n, func) {
|
||||
return this.firstOf(n, func);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns a new pattern where every other cycle is played once, twice as
|
||||
* fast, and offset in time by one quarter of a cycle. Creates a kind of
|
||||
|
|
@ -1051,7 +1050,6 @@ export class Pattern {
|
|||
return this.every(2, rev);
|
||||
}
|
||||
|
||||
|
||||
juxBy(by, func) {
|
||||
by /= 2;
|
||||
const elem_or = function (dict, key, dflt) {
|
||||
|
|
@ -1184,8 +1182,12 @@ export class Pattern {
|
|||
* note("0 1 2 3".scale('A minor')).iter(4)
|
||||
*/
|
||||
_iter(times, back = false) {
|
||||
times = Fraction(times)
|
||||
return slowcat(...listRange(0, times.sub(1)).map((i) => (back ? this.late(Fraction(i).div(times)) : this.early(Fraction(i).div(times)))));
|
||||
times = Fraction(times);
|
||||
return slowcat(
|
||||
...listRange(0, times.sub(1)).map((i) =>
|
||||
back ? this.late(Fraction(i).div(times)) : this.early(Fraction(i).div(times)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1231,10 +1233,10 @@ export class Pattern {
|
|||
on = Boolean(parseInt(on));
|
||||
return on ? silence : this;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Control-related methods, which manipulate patterns of objects
|
||||
|
||||
|
||||
/**
|
||||
* Cuts each sample into the given number of parts, allowing you to explore a technique known as 'granular synthesis'.
|
||||
* It turns a pattern of samples into a pattern of parts of samples.
|
||||
|
|
@ -1282,17 +1284,11 @@ export class Pattern {
|
|||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Context methods - ones that deal with metadata
|
||||
|
||||
|
||||
_color(color) {
|
||||
return this.withContext((context) => ({ ...context, color }));
|
||||
}
|
||||
|
||||
log() {
|
||||
return this.withHap((e) => {
|
||||
return e.setContext({ ...e.context, logs: (e.context?.logs || []).concat([e.show()]) });
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Sets the velocity from 0 to 1. Is multiplied together with gain.
|
||||
|
|
@ -1363,7 +1359,6 @@ export class Pattern {
|
|||
_legato(value) {
|
||||
return this.withHapSpan((span) => new TimeSpan(span.begin, span.begin.add(span.end.sub(span.begin).mul(value))));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// TODO - adopt value.mjs fully..
|
||||
|
|
@ -1388,7 +1383,7 @@ function _composeOp(a, b, func) {
|
|||
// pattern composers
|
||||
const composers = {
|
||||
set: [(a, b) => b],
|
||||
keep: [(a, b) => a],
|
||||
keep: [(a) => a],
|
||||
keepif: [(a, b) => (b ? a : undefined)],
|
||||
|
||||
// numerical functions
|
||||
|
|
@ -1488,21 +1483,21 @@ function _composeOp(a, b, func) {
|
|||
}
|
||||
if (how === 'In') {
|
||||
// set 'in' to default, but with magic properties to pick a different 'how'
|
||||
Object.defineProperty(Pattern.prototype, what, {
|
||||
// a getter that returns a function, so 'pat' can be
|
||||
// accessed by closures that are methods of that function..
|
||||
get: function() {
|
||||
const pat = this;
|
||||
// wrap the 'in' function as default behaviour
|
||||
const wrapper = (...other) => pat[what + "In"](...other);
|
||||
// add methods to that function to pick alternative behaviours
|
||||
for (const wraphow of hows) {
|
||||
Object.defineProperty(Pattern.prototype, what, {
|
||||
// a getter that returns a function, so 'pat' can be
|
||||
// accessed by closures that are methods of that function..
|
||||
get: function () {
|
||||
const pat = this;
|
||||
// wrap the 'in' function as default behaviour
|
||||
const wrapper = (...other) => pat[what + 'In'](...other);
|
||||
// add methods to that function to pick alternative behaviours
|
||||
for (const wraphow of hows) {
|
||||
wrapper[wraphow.toLowerCase()] = (...other) => pat[what + wraphow](...other);
|
||||
}
|
||||
|
||||
return wrapper;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return wrapper;
|
||||
},
|
||||
});
|
||||
} else {
|
||||
// default what to 'set', e.g. squeeze = setSqueeze
|
||||
if (what === 'set') {
|
||||
|
|
@ -1580,7 +1575,7 @@ Pattern.prototype.factories = {
|
|||
// Elemental patterns
|
||||
|
||||
// Nothing
|
||||
export const silence = new Pattern((_) => []);
|
||||
export const silence = new Pattern(() => []);
|
||||
|
||||
/** A discrete value that repeats once per cycle.
|
||||
*
|
||||
|
|
@ -1598,13 +1593,16 @@ export function pure(value) {
|
|||
export function isPattern(thing) {
|
||||
// thing?.constructor?.name !== 'Pattern' // <- this will fail when code is mangled
|
||||
const is = thing instanceof Pattern || thing?._Pattern;
|
||||
if (!thing instanceof Pattern) {
|
||||
// TODO: find out how to check wrong core dependency. below will never work !thing === 'undefined'
|
||||
// wrapping it in (..) will result other checks to log that warning (e.g. isPattern('kalimba'))
|
||||
/* if (!thing instanceof Pattern) {
|
||||
console.warn(
|
||||
`Found Pattern that fails "instanceof Pattern" check.
|
||||
This may happen if you are using multiple versions of @strudel.cycles/core.
|
||||
Please check by running "npm ls @strudel.cycles/core".`,
|
||||
);
|
||||
}
|
||||
console.log(thing);
|
||||
} */
|
||||
return is;
|
||||
}
|
||||
|
||||
|
|
@ -1758,7 +1756,7 @@ export function polymeterSteps(steps, ...args) {
|
|||
const pats = [];
|
||||
for (const seq of seqs) {
|
||||
if (seq[1] == 0) {
|
||||
next;
|
||||
continue;
|
||||
}
|
||||
if (steps == seq[1]) {
|
||||
pats.push(seq[0]);
|
||||
|
|
@ -1916,10 +1914,9 @@ Pattern.prototype.bootstrap = function () {
|
|||
this.patternified.forEach((prop) => {
|
||||
// the following will patternify all functions in Pattern.prototype.patternified
|
||||
Pattern.prototype[prop] = function (...args) {
|
||||
return this.patternify(x => x.innerJoin(), Pattern.prototype['_' + prop])(...args);
|
||||
return this.patternify((x) => x.innerJoin(), Pattern.prototype['_' + prop])(...args);
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*
|
||||
const func = Pattern.prototype['_' + prop];
|
||||
Pattern.prototype[prop] = function (...args) {
|
||||
|
|
@ -1945,7 +1942,7 @@ Pattern.prototype.bootstrap = function () {
|
|||
}
|
||||
});
|
||||
*/
|
||||
|
||||
|
||||
// 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(
|
||||
|
|
@ -1978,4 +1975,4 @@ Pattern.prototype.define = (name, func, options = {}) => {
|
|||
|
||||
// Pattern.prototype.define('early', (a, pat) => pat.early(a), { patternified: true, composable: true });
|
||||
Pattern.prototype.define('hush', (pat) => pat.hush(), { patternified: false, composable: true });
|
||||
Pattern.prototype.define('bypass', (pat) => pat.bypass(on), { patternified: true, composable: true });
|
||||
Pattern.prototype.define('bypass', (pat) => pat.bypass(1), { patternified: true, composable: true });
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue