From cf9d6fb699220d9a1c4d681f0f96ad5f1ebb9ecf Mon Sep 17 00:00:00 2001 From: alex Date: Sun, 6 Feb 2022 21:34:57 +0000 Subject: [PATCH] rebuild --- docs/CNAME | 2 +- docs/_snowpack/link/strudel.js | 72 +++++++++++++++++++++++++--------- docs/dist/logo.svg.proxy.js | 2 +- docs/dist/tunes.js | 10 ++--- docs/index.html | 6 +-- 5 files changed, 63 insertions(+), 29 deletions(-) diff --git a/docs/CNAME b/docs/CNAME index cb0753a2..63687b2b 100644 --- a/docs/CNAME +++ b/docs/CNAME @@ -1 +1 @@ -strudel.tidalcycles.org \ No newline at end of file +strudel.tidalcycles.org diff --git a/docs/_snowpack/link/strudel.js b/docs/_snowpack/link/strudel.js index 636f8060..3934b8e4 100644 --- a/docs/_snowpack/link/strudel.js +++ b/docs/_snowpack/link/strudel.js @@ -6,6 +6,17 @@ function flatten(arr) { return [].concat(...arr); } var id = (a) => a; +function curry(func) { + return function curried(...args) { + if (args.length >= func.length) { + return func.apply(this, args); + } else { + return function(...args2) { + return curried.apply(this, args.concat(args2)); + }; + } + }; +} Fraction.prototype.sam = function() { return Fraction(Math.floor(this)); }; @@ -27,6 +38,9 @@ Fraction.prototype.lte = function(other) { Fraction.prototype.gte = function(other) { return this.compare(other) >= 0; }; +Fraction.prototype.eq = function(other) { + return this.compare(other) == 0; +}; Fraction.prototype.max = function(other) { return this.gt(other) ? this : other; }; @@ -36,6 +50,9 @@ Fraction.prototype.min = function(other) { Fraction.prototype.show = function() { return this.n + "/" + this.d; }; +Fraction.prototype.or = function(other) { + return this.eq(0) ? other : this; +}; class TimeSpan { constructor(begin, end) { this.begin = Fraction(begin); @@ -141,6 +158,9 @@ class Pattern { withEventTime(func) { return this.withEventSpan((span) => span.withTime(func)); } + _withEvents(func) { + return new Pattern((span) => func(this.query(span))); + } withValue(func) { return new Pattern((span) => this.query(span).map((hap) => hap.withValue(func))); } @@ -220,6 +240,9 @@ class Pattern { get firstCycle() { return this.query(new TimeSpan(Fraction(0), Fraction(1))); } + _sortEventsByPart() { + return this._withEvents((events) => events.sort((a, b) => a.part.begin.sub(b.part.begin).or(a.part.end.sub(b.part.end)).or(a.whole.begin.sub(b.whole.begin).or(a.whole.end.sub(b.whole.end))))); + } _opleft(other, func) { return this.fmap(func).appLeft(reify(other)); } @@ -241,7 +264,7 @@ class Pattern { var match = function(a) { return func(a.value).query(a.part).map((b) => withWhole(a, b)); }; - return flatten(pat_val.query(span).map(match)); + return flatten(pat_val.query(span).map((a) => match(a))); }; return new Pattern(query2); } @@ -288,16 +311,13 @@ class Pattern { var false_pat = binary_pat._filterValues((val) => !val); var with_pat = true_pat.fmap((_) => (y) => y).appRight(func(this)); var without_pat = false_pat.fmap((_) => (y) => y).appRight(this); - return stack([with_pat, without_pat]); + return stack(with_pat, without_pat); } off(time_pat, func) { return stack([this, func(this._early(time_pat))]); } - off(time_pat, func) { - return stack(this, func(this.early(time_pat))); - } every(n, func) { - const pats = Array(n - 1).fill(this); + var pats = Array(n - 1).fill(this); pats.unshift(this); return slowcat(...pats); } @@ -334,12 +354,7 @@ class Pattern { return stack([left, func(right)]); } } -function reify(thing) { - if (thing.constructor.name == "Pattern") { - return thing; - } - return pure(thing); -} +const silence = new Pattern((_) => []); function pure(value) { function query2(span) { return span.spanCycles.map((subspan) => new Hap(Fraction(subspan.begin).wholeCycle(), subspan, value)); @@ -349,8 +364,14 @@ function pure(value) { function steady(value) { return new Pattern((span) => Hap(void 0, span, value)); } +function reify(thing) { + if (thing.constructor.name == "Pattern") { + return thing; + } + return pure(thing); +} function stack(...pats) { - pats = pats.map(reify); + var pats = pats.map((pat) => reify(pat)); var query2 = function(span) { return flatten(pats.map((pat) => pat.query(span))); }; @@ -373,7 +394,7 @@ function cat(...pats) { function _sequenceCount(x) { if (Array.isArray(x)) { if (x.length == 0) { - return [silence(), 0]; + return [silence, 0]; } if (x.length == 1) { return _sequenceCount(x[0]); @@ -386,9 +407,9 @@ function sequence(...xs) { return _sequenceCount(xs)[0]; } function polymeter(steps = 0, ...args) { - var seqs = args.map(_sequenceCount); + var seqs = args.map((a) => _sequenceCount(a)); if (seqs.length == 0) { - return silence(); + return silence; } if (steps == 0) { steps = seqs[0][1]; @@ -406,8 +427,18 @@ function polymeter(steps = 0, ...args) { } return stack(pats); } -function silence() { - return new Pattern((_) => []); +function pm(args) { + polymeter(args); +} +function polyrhythm(...xs) { + var seqs = xs.map((a) => sequence(a)); + if (seqs.length == 0) { + return silence; + } + return stack(...seqs); +} +function pr(args) { + polyrhythm(args); } export { Fraction, @@ -415,12 +446,15 @@ export { Hap, Pattern, pure, - reify, stack, slowcat, fastcat, cat, sequence, polymeter, + pm, + polyrhythm, + pr, + reify, silence }; diff --git a/docs/dist/logo.svg.proxy.js b/docs/dist/logo.svg.proxy.js index 73f6fe7f..aed9da04 100644 --- a/docs/dist/logo.svg.proxy.js +++ b/docs/dist/logo.svg.proxy.js @@ -1 +1 @@ -export default "/strudel/dist/logo.svg"; \ No newline at end of file +export default "/dist/logo.svg"; \ No newline at end of file diff --git a/docs/dist/tunes.js b/docs/dist/tunes.js index e8b14702..3e9dd75d 100644 --- a/docs/dist/tunes.js +++ b/docs/dist/tunes.js @@ -1,12 +1,12 @@ export const tetris = `stack(sequence( 'e5', sequence('b4', 'c5'), 'd5', sequence('c5', 'b4'), 'a4', sequence('a4', 'c5'), 'e5', sequence('d5', 'c5'), - 'b4', sequence(silence(), 'c5'), 'd5', 'e5', - 'c5', 'a4', 'a4', silence(), - sequence(silence(), 'd5'), sequence(silence(), 'f5'), 'a5', sequence('g5', 'f5'), - 'e5', sequence(silence(), 'c5'), 'e5', sequence('d5', 'c5'), + 'b4', sequence(silence, 'c5'), 'd5', 'e5', + 'c5', 'a4', 'a4', silence, + sequence(silence, 'd5'), sequence(silence, 'f5'), 'a5', sequence('g5', 'f5'), + 'e5', sequence(silence, 'c5'), 'e5', sequence('d5', 'c5'), 'b4', sequence('b4', 'c5'), 'd5', 'e5', - 'c5', 'a4', 'a4', silence()), + 'c5', 'a4', 'a4', silence), sequence( 'e2', 'e3', 'e2', 'e3', 'e2', 'e3', 'e2', 'e3', 'a2', 'a3', 'a2', 'a3', 'a2', 'a3', 'a2', 'a3', diff --git a/docs/index.html b/docs/index.html index 507724ce..0e7db17b 100644 --- a/docs/index.html +++ b/docs/index.html @@ -2,8 +2,8 @@ - - + + Strudel REPL @@ -11,6 +11,6 @@
- +