mirror of
https://github.com/eliasstepanik/strudel-docker.git
synced 2026-01-25 12:38:35 +00:00
Fixes squeezeJoin, and in the process struct/keepif. fixes #216 Co-authored-by: Felix Roos <flix91@gmail.com>
This commit is contained in:
parent
852f01fddd
commit
513e0d748d
@ -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
|
// pattern of values. In this case it takes whole cycles of the inner pattern to fit each event
|
||||||
// in the outer pattern.
|
// in the outer pattern.
|
||||||
_squeezeJoin() {
|
_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;
|
const pat_of_pats = this;
|
||||||
function query(state) {
|
function query(state) {
|
||||||
|
// Get the events with the inner patterns. Ignore continuous events (without 'wholes')
|
||||||
const haps = pat_of_pats.discreteOnly().query(state);
|
const haps = pat_of_pats.discreteOnly().query(state);
|
||||||
|
// A function to map over the events from the outer pattern.
|
||||||
function flatHap(outerHap) {
|
function flatHap(outerHap) {
|
||||||
const pat = outerHap.value._focusSpan(outerHap.wholeOrPart());
|
// Get the inner pattern, slowed and shifted so that the 'whole'
|
||||||
const innerHaps = pat.query(state.setSpan(outerHap.part));
|
// 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) {
|
function munge(outer, inner) {
|
||||||
let whole = undefined;
|
let whole = undefined;
|
||||||
if (inner.whole && outer.whole) {
|
if (inner.whole && outer.whole) {
|
||||||
@ -753,7 +763,7 @@ export class Pattern {
|
|||||||
// Similar to compress, but doesn't leave gaps, and the 'focus' can be
|
// Similar to compress, but doesn't leave gaps, and the 'focus' can be
|
||||||
// bigger than a cycle
|
// bigger than a cycle
|
||||||
_focus(b, e) {
|
_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) {
|
_focusSpan(span) {
|
||||||
@ -1347,11 +1357,16 @@ function _composeOp(a, b, func) {
|
|||||||
pat = preprocess(pat);
|
pat = preprocess(pat);
|
||||||
other = preprocess(other);
|
other = preprocess(other);
|
||||||
}
|
}
|
||||||
var result = pat['_op' + how](other, (a) => (b) => _composeOp(a, b, op));
|
var result;
|
||||||
// hack to remove undefs when doing 'keepif'
|
// hack to remove undefs when doing 'keepif'
|
||||||
if (what === 'keepif') {
|
if (what === 'keepif') {
|
||||||
|
// avoid union, as we want to throw away the value of 'b' completely
|
||||||
|
result = pat['_op' + how](other, (a) => (b) => op(a, b));
|
||||||
result = result._removeUndefineds();
|
result = result._removeUndefineds();
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
result = pat['_op' + how](other, (a) => (b) => _composeOp(a, b, op));
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
if (how === 'Squeeze') {
|
if (how === 'Squeeze') {
|
||||||
|
|||||||
@ -42,6 +42,7 @@ import {
|
|||||||
id,
|
id,
|
||||||
ply,
|
ply,
|
||||||
rev,
|
rev,
|
||||||
|
time,
|
||||||
} from '../index.mjs';
|
} from '../index.mjs';
|
||||||
|
|
||||||
import { steady } from '../signal.mjs';
|
import { steady } from '../signal.mjs';
|
||||||
@ -791,6 +792,13 @@ describe('Pattern', () => {
|
|||||||
).firstCycle(),
|
).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', () => {
|
describe('ply', () => {
|
||||||
it('Can ply(3)', () => {
|
it('Can ply(3)', () => {
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user