diff options
| -rw-r--r-- | key-picker.mjs | 18 | ||||
| -rw-r--r-- | scale.mjs | 8 |
2 files changed, 19 insertions, 7 deletions
diff --git a/key-picker.mjs b/key-picker.mjs index fe344ae..6d2efbe 100644 --- a/key-picker.mjs +++ b/key-picker.mjs @@ -1,4 +1,4 @@ -import { MajorScale, MinorScale, Note, chromaticScale } from "./scale.mjs"; +import { AugmentedScale, DiminishedScale, MajorScale, MinorScale, Note, allDiatonicScales } from "./scale.mjs"; function scaleFrom(tonic, scale) { switch (scale) { @@ -70,14 +70,18 @@ function formChanged(form) { Array.from(form.getElementsByClassName(c)).forEach(elt => elt.innerText = scale[i]); }); - // todo: memoize this or put it in the scales module. - const allScales = chromaticScale.flatMap(tonic => { - return [MajorScale(tonic), MinorScale(tonic)]; - }) + function suffixFromIndex(i) { + switch (i % 2) { + case 0: + return ''; + case 1: + return 'm'; + } + } const availableScales = - allScales.reduce((acc, s, i) => { - const suffix = i % 2 == 0 ? '' : 'm'; + allDiatonicScales.reduce((acc, s, i) => { + const suffix = suffixFromIndex(i); if (scale.includes(s.tonic) && scale.includes(s.third) && scale.includes(s.fifth)) { return acc.concat(`${s.tonic}${suffix}`); } @@ -182,3 +182,11 @@ export function MinorScale(tonic) { const intervals = [2, 1, 2, 2, 1, 2]; return new Scale(tonic, intervals); } + +// well, a lot of them. +export const allDiatonicScales = chromaticScale.flatMap(tonic => { + return [ + MajorScale(tonic), + MinorScale(tonic) + ]; +}) |
