From 7fc8f1c5c94713f3da4eded782ff16c0936cb109 Mon Sep 17 00:00:00 2001 From: tyow Date: Fri, 30 Jan 2026 14:12:31 -0500 Subject: [PATCH] xen/scale parity improvements --- packages/xen/xen.mjs | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/packages/xen/xen.mjs b/packages/xen/xen.mjs index cc96f4110..6ede42616 100644 --- a/packages/xen/xen.mjs +++ b/packages/xen/xen.mjs @@ -4,7 +4,7 @@ Copyright (C) 2022 Strudel contributors - see . */ -import { register, _mod, parseNumeral } from '@strudel/core'; +import { register, _mod, parseNumeral, removeUndefineds } from '@strudel/core'; export function edo(name) { if (!/^[1-9]+[0-9]*edo$/.test(name)) { @@ -49,11 +49,20 @@ function xenOffset(xenScale, offset, index = 0) { // scaleNameOrRatios: string || number[], steps?: number export const xen = register('xen', function (scaleNameOrRatios, pat) { - return pat.withHap((hap) => { - const scale = getXenScale(scaleNameOrRatios); - const frequency = xenOffset(scale, parseNumeral(hap.value)); - return hap.withValue(() => frequency); - }); + return pat.withHaps((haps) => { + haps = haps.map(hap=>{ + let hVal = hap.value + const isObject = typeof hVal === 'object'; + // If hVal is a pure value, place it on `n` so that we interpret it as a scale degree + hVal = isObject ? hVal : { n: hVal }; + const { n, value, ...otherValues } = hVal; + const scale = getXenScale(scaleNameOrRatios); + const frequency = xenOffset(scale, parseNumeral(hVal.n)); + hap.value = isObject ? {...otherValues, freq: frequency } : frequency + return hap; + }); + return removeUndefineds(haps) + }) }); export const tuning = register('tuning', function (ratios, pat) {