diff --git a/docs/_snowpack/link/strudel.js b/docs/_snowpack/link/strudel.js index eb531426..96cc10c8 100644 --- a/docs/_snowpack/link/strudel.js +++ b/docs/_snowpack/link/strudel.js @@ -294,6 +294,29 @@ class Pattern { }; return patterned; } + _fastGap(factor) { + const qf = function(span) { + const cycle = span.begin.sam(); + const begin = cycle.add(span.begin.sub(cycle).mul(factor).min(1)); + const end = cycle.add(span.end.sub(cycle).mul(factor).min(1)); + return new TimeSpan(begin, end); + }; + const ef = function(span) { + const cycle = span.begin.sam(); + const begin = cycle.add(span.begin.sub(cycle).div(factor).min(1)); + const end = cycle.add(span.end.sub(cycle).div(factor).min(1)); + return new TimeSpan(begin, end); + }; + return this.withQuerySpan(qf).withEventSpan(ef)._splitQueries(); + } + _compressSpan(span) { + const b = span.begin; + const e = span.end; + if (b > e || b > 1 || e > 1 || b < 0 || e < 0) { + return silence; + } + return this._fastGap(Fraction(1).div(e.sub(b)))._late(b); + } _fast(factor) { const fastQuery = this.withQueryTime((t) => t.mul(factor)); return fastQuery.withEventTime((t) => t.div(factor)); @@ -405,6 +428,17 @@ function fastcat(...pats) { function cat(...pats) { return fastcat(...pats); } +function timeCat(...timepats) { + const total = timepats.map((a) => a[0]).reduce((a, b) => a.add(b), Fraction(0)); + let begin = Fraction(0); + const pats = []; + for (const [time, pat] of timepats) { + const end = begin.add(time); + pats.push(reify(pat)._compressSpan(new TimeSpan(begin.div(total), end.div(total)))); + begin = end; + } + return stack(...pats); +} function _sequenceCount(x) { if (Array.isArray(x)) { if (x.length == 0) { @@ -469,6 +503,7 @@ export { slowcat, fastcat, cat, + timeCat, sequence, polymeter, pm, diff --git a/docs/dist/parse.js b/docs/dist/parse.js index 5b930bcd..f68f3942 100644 --- a/docs/dist/parse.js +++ b/docs/dist/parse.js @@ -5,7 +5,21 @@ import "./tone.js"; import "./midi.js"; import * as toneStuff from "./tone.js"; import shapeshifter from "./shapeshifter.js"; -const {pure, stack, slowcat, fastcat, cat, sequence, polymeter, pm, polyrhythm, pr, silence, Fraction} = strudel; +const { + pure, + stack, + slowcat, + fastcat, + cat, + sequence, + polymeter, + pm, + polyrhythm, + pr, + silence, + Fraction, + timeCat +} = strudel; const {autofilter, filter, gain} = toneStuff; function reify(thing) { if (thing?.constructor?.name === "Pattern") { diff --git a/docs/dist/tunes.js b/docs/dist/tunes.js index cd479660..4eef72c4 100644 --- a/docs/dist/tunes.js +++ b/docs/dist/tunes.js @@ -1,3 +1,11 @@ +export const timeCat = `stack( + timeCat([3, c3], [1, stack(eb3, g3, m(c4, d4).slow(2))]), + m(c2, g2), + sequence( + timeCat([5, eb4], [3, m(f4, eb4, d4)]), + m(eb4, c4).slow(2) + ).slow(4) +)`; export const shapeShifted = `stack( sequence( e5, [b4, c5], d5, [c5, b4],