Handle scale-for-notes when n also supplied

This commit is contained in:
Aria 2025-10-04 02:07:35 -05:00
parent 0ecacae71e
commit 3ef6c7c921
4 changed files with 17 additions and 14 deletions

View file

@ -796,7 +796,7 @@ describe('Pattern', () => {
}); });
}); });
describe('apply', () => { describe('apply', () => {
it('Can apply a function', () => { (it('Can apply a function', () => {
expect(sequence('a', 'b').apply(fast(2)).firstCycle()).toStrictEqual(sequence('a', 'b').fast(2).firstCycle()); expect(sequence('a', 'b').apply(fast(2)).firstCycle()).toStrictEqual(sequence('a', 'b').fast(2).firstCycle());
}), }),
it('Can apply a pattern of functions', () => { it('Can apply a pattern of functions', () => {
@ -804,7 +804,7 @@ describe('Pattern', () => {
expect(sequence('a', 'b').apply(fast(2), fast(3)).firstCycle()).toStrictEqual( expect(sequence('a', 'b').apply(fast(2), fast(3)).firstCycle()).toStrictEqual(
sequence('a', 'b').fast(2, 3).firstCycle(), sequence('a', 'b').fast(2, 3).firstCycle(),
); );
}); }));
}); });
describe('layer', () => { describe('layer', () => {
it('Can layer up multiple functions', () => { it('Can layer up multiple functions', () => {

View file

@ -266,9 +266,14 @@ export const scale = register(
pat pat
.fmap((value) => { .fmap((value) => {
const isObject = typeof value === 'object'; const isObject = typeof value === 'object';
// The case where the note has been defined via `n` or `pure` // If value is a pure value, place it on `n` so that we interpret it as a scale
if (!isObject || (isObject && ('n' in value || 'value' in value))) { // degree
const step = isObject ? (value.n ?? value.value) : value; value = typeof value !== 'object' ? { n: value } : value;
if ('note' in value) {
const note = _getNearestScaleNote(scale, value.note);
return pure({ ...value, note });
} else if ('n' in value || 'value' in value) {
const step = value.n ?? value.value;
delete value.n; // remove n so it won't cause trouble delete value.n; // remove n so it won't cause trouble
if (isNote(step)) { if (isNote(step)) {
// legacy.. // legacy..
@ -277,7 +282,7 @@ export const scale = register(
try { try {
const [number, offset] = _convertStepToNumberAndOffset(step); const [number, offset] = _convertStepToNumberAndOffset(step);
let note; let note;
if (isObject && value.anchor) { if (value.anchor) {
note = stepInNamedScale(number, scale, value.anchor); note = stepInNamedScale(number, scale, value.anchor);
} else { } else {
note = scaleStep(number, scale); note = scaleStep(number, scale);
@ -290,11 +295,9 @@ export const scale = register(
} }
return value; return value;
} }
// The case where the note has been defined via `note` throw new Error(
else { `Invalid value format for 'scale'. Value must contain 'n' or 'note' but received ${Object.keys(value)}`,
const note = _getNearestScaleNote(scale, value.note); );
return pure(isObject ? { ...value, note } : note);
}
}) })
.outerJoin() .outerJoin()
// legacy: // legacy:

View file

@ -18,8 +18,8 @@
--docsearch-modal-background: var(--background); --docsearch-modal-background: var(--background);
--docsearch-muted-color: color-mix(in srgb, var(--foreground), #fff 30%); --docsearch-muted-color: color-mix(in srgb, var(--foreground), #fff 30%);
--docsearch-key-gradient: var(--foreground); --docsearch-key-gradient: var(--foreground);
--docsearch-key-shadow: inset 0 -2px 0 0 var(--gutterForeground), inset 0 0 1px 1px var(--foreground), --docsearch-key-shadow:
0 1px 2px 1px var(--gutterBackground); inset 0 -2px 0 0 var(--gutterForeground), inset 0 0 1px 1px var(--foreground), 0 1px 2px 1px var(--gutterBackground);
} }
.dark { .dark {
--docsearch-muted-color: color-mix(in srgb, var(--foreground), #000 30%); --docsearch-muted-color: color-mix(in srgb, var(--foreground), #000 30%);

View file

@ -381,7 +381,7 @@ Sampler effects are functions that can be used to change the behaviour of sample
### scrub ### scrub
<JsDoc client:idle name="Pattern.scrub" h={0} />{' '} <JsDoc client:idle name="Pattern.scrub" h={0} />
### speed ### speed