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
+2 -2
View File
@@ -796,7 +796,7 @@ describe('Pattern', () => {
});
});
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());
}),
it('Can apply a pattern of functions', () => {
@@ -804,7 +804,7 @@ describe('Pattern', () => {
expect(sequence('a', 'b').apply(fast(2), fast(3)).firstCycle()).toStrictEqual(
sequence('a', 'b').fast(2, 3).firstCycle(),
);
});
}));
});
describe('layer', () => {
it('Can layer up multiple functions', () => {
+12 -9
View File
@@ -266,9 +266,14 @@ export const scale = register(
pat
.fmap((value) => {
const isObject = typeof value === 'object';
// The case where the note has been defined via `n` or `pure`
if (!isObject || (isObject && ('n' in value || 'value' in value))) {
const step = isObject ? (value.n ?? value.value) : value;
// If value is a pure value, place it on `n` so that we interpret it as a scale
// degree
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
if (isNote(step)) {
// legacy..
@@ -277,7 +282,7 @@ export const scale = register(
try {
const [number, offset] = _convertStepToNumberAndOffset(step);
let note;
if (isObject && value.anchor) {
if (value.anchor) {
note = stepInNamedScale(number, scale, value.anchor);
} else {
note = scaleStep(number, scale);
@@ -290,11 +295,9 @@ export const scale = register(
}
return value;
}
// The case where the note has been defined via `note`
else {
const note = _getNearestScaleNote(scale, value.note);
return pure(isObject ? { ...value, note } : note);
}
throw new Error(
`Invalid value format for 'scale'. Value must contain 'n' or 'note' but received ${Object.keys(value)}`,
);
})
.outerJoin()
// legacy:
+2 -2
View File
@@ -18,8 +18,8 @@
--docsearch-modal-background: var(--background);
--docsearch-muted-color: color-mix(in srgb, var(--foreground), #fff 30%);
--docsearch-key-gradient: var(--foreground);
--docsearch-key-shadow: inset 0 -2px 0 0 var(--gutterForeground), inset 0 0 1px 1px var(--foreground),
0 1px 2px 1px var(--gutterBackground);
--docsearch-key-shadow:
inset 0 -2px 0 0 var(--gutterForeground), inset 0 0 1px 1px var(--foreground), 0 1px 2px 1px var(--gutterBackground);
}
.dark {
--docsearch-muted-color: color-mix(in srgb, var(--foreground), #000 30%);
+1 -1
View File
@@ -381,7 +381,7 @@ Sampler effects are functions that can be used to change the behaviour of sample
### scrub
<JsDoc client:idle name="Pattern.scrub" h={0} />{' '}
<JsDoc client:idle name="Pattern.scrub" h={0} />
### speed