A collection of functions to manipulate musical notes
Given a note name, returns its parts: [letter, accidentals, octave, rest]:
tokenize("c##4"); // => ["C", "##", "4", ""]
tokenize("c##4 mixolidian"); // => ["C", "##", "4", " mixolidian"]
tokenize("not a note"); // => ["", "", "", ""]
Given a note name, return the same note with less accidentals (or "" if not a valid note):
simplify("C#"); // => "C#"
simplify("C##"); // => "D"
simplify("C###"); // => "D#"
Given a note name, returns it enharmonic not (or "" if not valid note):
enharmonic("C#"); // => "Db"
enharmonic("C##"); // => "D"
enharmonic("C###"); // => "Eb"
Given an interval, returns a function that transposes a note by that interval:
["C", "D", "E"].map(transposeBy("5P"));
// => ["G", "A", "B"]
Given an interval, returns a function that transposes a note by that interval:
["1P", "3M", "5P"].map(transposeFrom("C"));
// => ["C", "E", "G"]
Transpose a note a given number of fifths:
transposeFifths("G4", 3); // => "E6"
transposeFifths("G", 3); // => "E"
[0, 1, 2, 3, 4, 5, 6].map(n => transposeFifths("F#", n));
// => ["F#", "C#", "G#", "D#", "A#", "E#", "B#"]
[0, -1, -2, -3, -4, -5, -6].map(n => transposeFifths("Bb", n));
// => ["Bb", "Eb", "Ab", "Db", "Gb", "Cb", "Fb"]