Make splice cps-aware (#932)

* make splice cps-aware

* format

* copypaste fix
This commit is contained in:
Alex McLean 2024-01-20 22:47:31 +00:00 committed by GitHub
parent a7f5d0e0c1
commit 738cea0025
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 11 deletions

View File

@ -41,7 +41,7 @@ export class Cyclist {
this.lastEnd = end; this.lastEnd = end;
// query the pattern for events // query the pattern for events
const haps = this.pattern.queryArc(begin, end); const haps = this.pattern.queryArc(begin, end, { _cps: this.cps });
const tickdeadline = phase - time; // time left until the phase is a whole number const tickdeadline = phase - time; // time left until the phase is a whole number
this.lastTick = time + tickdeadline; this.lastTick = time + tickdeadline;

View File

@ -340,9 +340,9 @@ export class Pattern {
* silence * silence
* @noAutocomplete * @noAutocomplete
*/ */
queryArc(begin, end) { queryArc(begin, end, controls = {}) {
try { try {
return this.query(new State(new TimeSpan(begin, end))); return this.query(new State(new TimeSpan(begin, end), controls));
} catch (err) { } catch (err) {
logger(`[query]: ${err.message}`, 'error'); logger(`[query]: ${err.message}`, 'error');
return []; return [];
@ -2341,14 +2341,19 @@ export const splice = register(
'splice', 'splice',
function (npat, ipat, opat) { function (npat, ipat, opat) {
const sliced = slice(npat, ipat, opat); const sliced = slice(npat, ipat, opat);
return sliced.withHap(function (hap) { return new Pattern((state) => {
return hap.withValue((v) => ({ // TODO - default cps to 0.5
...{ const cps = state.controls._cps || 1;
speed: (1 / v._slices / hap.whole.duration) * (v.speed || 1), const haps = sliced.query(state);
unit: 'c', return haps.map((hap) =>
}, hap.withValue((v) => ({
...v, ...{
})); speed: (cps / v._slices / hap.whole.duration) * (v.speed || 1),
unit: 'c',
},
...v,
})),
);
}); });
}, },
false, // turns off auto-patternification false, // turns off auto-patternification