Skip to content

Commit

Permalink
attempt at fixing #216
Browse files Browse the repository at this point in the history
  • Loading branch information
yaxu committed Sep 22, 2022
1 parent cc54da5 commit dfdd918
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion packages/core/pattern.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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.
*
Expand Down

0 comments on commit dfdd918

Please sign in to comment.