From luserdroog@21:1/5 to All on Sun Dec 12 19:47:08 2021
This is the same code from my previous thread, but with the sweet-
as-pie two liner *scan* function and copious pretentious comments.
Also, better variable names and more `const` everywhere.
I added a helper function `up()` to write the figured bass representation
of chord shapes with having to count up so high. OTOH seeing the
numbers up to 15 gives you a reasonable intuition about fancy chords
like 9-, 11-, 13- chords. It still looks prettier to me using `up()`.
//midi note number[s] for a note(name,octave) or chord(name,octave)
//a la luser droog la la la
//a note name is a case-insensitive note letter 'a'..'g', 'A'..'G'
// optionally followed by '#' for sharp or 'b' for flat
//a chord name is a case-insensitive note letter
// optionally followed by an accidental '#'|'b'
// optionally followed by 'm' for minor
// optionally followed by '7' for a 7th chord
const major_tetrachord = [ 2, 2, 1 ];
const minor_tetrachord = [ 2, 1, 2 ];
//there are 2 other ancient, weird tetrachords with odd intervals
//(enharmonic and chromatic) that don't fit with our schema here
//and cannot reasonably be accommodated in a system of linear half-steps IMO
//mode names according to Boethius
const ionian_mode = [ ...major_tetrachord, //defined by Nicomachus as two disjunct
2, //tetrachords separated by a tone
//these are intervals between adjacent notes of the mode, ie.
//ionian_mode is the interval between the root and the major second (2 half steps)
//ionian_mode " " " " the second and the major third (2 more half steps)
//ionian_mode " " " " the third and the fourth (1 half step) //...
//use repeat() to make longer sequences of intervals
//use running_sum() to convert to a sequence of note numbers
// which can be indexed by scale degree, ie.
//running_sum(ionian_mode) = 0 the root
//running_sum(ionian_mode) = 2 the major second //running_sum(ionian_mode) = 4 the major third //running_sum(ionian_mode) = 5 the perfect fourth (note these are also fret numbers)
const mixolydian_mode = [ ...major_tetrachord, //need this for 7th chords and stuff
...major_tetrachord, //like A/E and C/G chords
2 ]; //defined by Nicomachus as two conjoint tetrachords
const aeolian_mode = [ ...minor_tetrachord, //need this for decoding note names ['A'..'G']
...minor_tetrachord ]; //add another 2 to fill the octave if needed