Skip to content

Commit

Permalink
focus tweak for squeezeJoin - another go at fixing #216
Browse files Browse the repository at this point in the history
  • Loading branch information
yaxu committed Sep 24, 2022
1 parent 5b56fbe commit 6279d94
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
16 changes: 13 additions & 3 deletions packages/core/pattern.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -649,12 +649,22 @@ export class Pattern {
// pattern of values. In this case it takes whole cycles of the inner pattern to fit each event
// in the outer pattern.
_squeezeJoin() {
// A pattern of patterns, which we call the 'outer' pattern, with patterns
// as values which we call the 'inner' patterns.
const pat_of_pats = this;
function query(state) {
// Get the events with the inner patterns. Ignore continuous events (without 'wholes')
const haps = pat_of_pats.discreteOnly().query(state);
// A function to map over the events from the outer pattern.
function flatHap(outerHap) {
const pat = outerHap.value._focusSpan(outerHap.wholeOrPart());
const innerHaps = pat.query(state.setSpan(outerHap.part));
// Get the inner pattern, slowed and shifted so that the 'whole'
// timespan of the outer event corresponds to the first cycle of the
// inner event
const inner_pat = outerHap.value._focusSpan(outerHap.wholeOrPart());
// Get the inner events, from the timespan of the outer event's part
const innerHaps = inner_pat.query(state.setSpan(outerHap.part));
// A function to map over the inner events, to combine them with the
// outer event
function munge(outer, inner) {
let whole = undefined;
if (inner.whole && outer.whole) {
Expand Down Expand Up @@ -753,7 +763,7 @@ export class Pattern {
// Similar to compress, but doesn't leave gaps, and the 'focus' can be
// bigger than a cycle
_focus(b, e) {
return this._fast(Fraction(1).div(e.sub(b))).late(b);
return this._fast(Fraction(1).div(e.sub(b))).late(b.cyclePos());
}

_focusSpan(span) {
Expand Down
8 changes: 8 additions & 0 deletions packages/core/test/pattern.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
id,
ply,
rev,
time,
} from '../index.mjs';

import { steady } from '../signal.mjs';
Expand Down Expand Up @@ -791,6 +792,13 @@ describe('Pattern', () => {
).firstCycle(),
);
});
it('Squeezes to the correct cycle', () => {
expect(
pure(time.struct(true))._squeezeJoin().queryArc(3,4).map(x => x.value)
).toStrictEqual(
[Fraction(3.5)]
)
});
});
describe('ply', () => {
it('Can ply(3)', () => {
Expand Down

0 comments on commit 6279d94

Please sign in to comment.