scales can now be anchored

This commit is contained in:
Felix Roos 2024-01-05 13:03:40 +01:00
parent f37652edb3
commit b27f177138
3 changed files with 86 additions and 2 deletions

View file

@ -6,6 +6,7 @@ This program is free software: you can redistribute it and/or modify it under th
import { Note, Interval, Scale } from '@tonaljs/tonal';
import { register, _mod, silence, logger, pure, isNote } from '@strudel.cycles/core';
import { stepInNamedScale } from './tonleiter.mjs';
const octavesInterval = (octaves) => (octaves <= 0 ? -1 : 1) + octaves * 7 + 'P';
@ -184,7 +185,12 @@ export const scale = register('scale', function (scale, pat) {
return silence;
}
try {
const note = scaleStep(asNumber, scale);
let note;
if (value.anchor) {
note = stepInNamedScale(asNumber, scale, value.anchor);
} else {
note = scaleStep(asNumber, scale);
}
value = pure(isObject ? { ...value, note } : note);
} catch (err) {
logger(`[tonal] ${err.message}`, 'error');