From dfdd918ea04d4ca8c9e03c5fbe070bfd177095aa Mon Sep 17 00:00:00 2001 From: alex Date: Thu, 22 Sep 2022 22:52:02 +0100 Subject: [PATCH] attempt at fixing #216 --- packages/core/pattern.mjs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/core/pattern.mjs b/packages/core/pattern.mjs index 2950d015..932e9ca4 100644 --- a/packages/core/pattern.mjs +++ b/packages/core/pattern.mjs @@ -645,12 +645,15 @@ export class Pattern { return this._trigJoin(true); } + // Like the other joins above, joins a pattern of patterns of values, into a flatter + // pattern of values. In this case it takes whole cycles of the inner pattern to fit each event + // in the outer pattern. _squeezeJoin() { const pat_of_pats = this; function query(state) { const haps = pat_of_pats.discreteOnly().query(state); function flatHap(outerHap) { - const pat = outerHap.value._compressSpan(outerHap.wholeOrPart().cycleArc()); + const pat = outerHap.value._focusSpan(outerHap.wholeOrPart().cycleArc()); const innerHaps = pat.query(state.setSpan(outerHap.part)); function munge(outer, inner) { let whole = undefined; @@ -735,6 +738,7 @@ export class Pattern { return this.withQuerySpan(qf).withHapSpan(ef)._splitQueries(); } + // Compress each cycle into the given timespan, leaving a gap _compress(b, e) { if (b.gt(e) || b.gt(1) || e.gt(1) || b.lt(0) || e.lt(0)) { return silence; @@ -746,6 +750,17 @@ export class Pattern { return this._compress(span.begin, span.end); } + // Similar to compress, but doesn't leave gaps, and the 'focus' can be + // bigger than a cycle + _focus(b, e) { + const factor = Fraction(1).div(e.sub(b)); + return this._fast(factor).late(b) + } + + _focusSpan(span) { + return this._focus(span.begin, span.end); + } + /** * Speed up a pattern by the given factor. Used by "*" in mini notation. *