first take at reset

This commit is contained in:
Felix Roos 2022-04-22 22:21:43 +02:00
parent c38e4f7206
commit 0fae8b2b10

View File

@ -721,6 +721,31 @@ export class Pattern {
_velocity(velocity) {
return this._withContext((context) => ({ ...context, velocity: (context.velocity || 1) * velocity }));
}
reset(pat) {
pat = reify(pat);
return new Pattern((state) => {
const hps = pat
.query(state)
.map((event) => {
const haps = this.query(new State(new TimeSpan(event.part.begin.sub(event.whole.begin), event.duration))).map(
(hap) =>
hap
.withSpan((s) => {
s = s.withTime((t) => t.add(event.whole.begin));
// s = s.intersection(state.span) || s;
return s;
})
.setContext(hap.combineContext(event)),
);
//console.log('haps',haps.map(h=>h.show()))
return haps;
})
.flat();
//console.log('hps',hps.map(h=>h.show()))
return hps;
});
}
}
// pattern composers