implement fit with pat state

This commit is contained in:
Felix Roos 2024-01-21 00:39:26 +01:00
parent 738cea0025
commit 8052e10f0c
2 changed files with 9 additions and 18 deletions

View File

@ -427,7 +427,7 @@ export class Pattern {
* @noAutocomplete * @noAutocomplete
*/ */
withHaps(func) { withHaps(func) {
return new Pattern((state) => func(this.query(state))); return new Pattern((state) => func(this.query(state), state));
} }
/** /**
@ -2377,12 +2377,14 @@ export const { loopAt, loopat } = register(['loopAt', 'loopat'], function (facto
* s("rhodes/4").fit() * s("rhodes/4").fit()
*/ */
export const fit = register('fit', (pat) => export const fit = register('fit', (pat) =>
pat.withHap((hap) => pat.withHaps((haps, state) =>
hap.withValue((v) => ({ haps.map((hap) =>
...v, hap.withValue((v) => ({
speed: 1 / hap.whole.duration, ...v,
unit: 'c', speed: (state.controls._cps || 1) / hap.whole.duration,
})), unit: 'c',
})),
),
), ),
); );

View File

@ -142,19 +142,8 @@ export function repl({
// already defined.. // already defined..
} }
const fit = register('fit', (pat) =>
pat.withHap((hap) =>
hap.withValue((v) => ({
...v,
speed: scheduler.cps / hap.whole.duration, // overwrite speed completely?
unit: 'c',
})),
),
);
evalScope({ evalScope({
loopAt, loopAt,
fit,
all, all,
hush, hush,
setCps, setCps,