From 8052e10f0c1d0ebf7c3b64adeb6f2f8a339a28ca Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Sun, 21 Jan 2024 00:39:26 +0100 Subject: [PATCH] implement fit with pat state --- packages/core/pattern.mjs | 16 +++++++++------- packages/core/repl.mjs | 11 ----------- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/packages/core/pattern.mjs b/packages/core/pattern.mjs index 408b5398..e98c4f2b 100644 --- a/packages/core/pattern.mjs +++ b/packages/core/pattern.mjs @@ -427,7 +427,7 @@ export class Pattern { * @noAutocomplete */ 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() */ export const fit = register('fit', (pat) => - pat.withHap((hap) => - hap.withValue((v) => ({ - ...v, - speed: 1 / hap.whole.duration, - unit: 'c', - })), + pat.withHaps((haps, state) => + haps.map((hap) => + hap.withValue((v) => ({ + ...v, + speed: (state.controls._cps || 1) / hap.whole.duration, + unit: 'c', + })), + ), ), ); diff --git a/packages/core/repl.mjs b/packages/core/repl.mjs index 9fb6b4b9..65a9ba01 100644 --- a/packages/core/repl.mjs +++ b/packages/core/repl.mjs @@ -142,19 +142,8 @@ export function repl({ // 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({ loopAt, - fit, all, hush, setCps,