Notes
Parse and manipulate notes
Note properties
Note.get
get(noteName: string) => Note
Given a note name, it returns an object with the following properties:
- name: the note name
- pc: the pitch class name
- letter: the note letter
- step: the letter number (0..6)
- acc: the note accidentals
- alt: the accidental number (..., -1 = 'b', 0 = '', 1 = '#', ...)
- oct: the octave (or null if not present)
- chroma: the note chroma (0..11)
- midi: the note midi or null if octave is not present
- freq: the note frequency in Hertzes, or null if the octave is not present
It has several shorthands to retrieve properties easily:
Note.fromMidi
fromMidi(midi: number) => string
Given a midi number, returns the note name. This function is the same as midiToNoteName
from @tonaljs/midi
There's also a Note.fromMidiSharps
version:
Note.fromFreq
Note.fromFreq(freq: number) => string
Given a frequency in Hz, returns the note name.
It rounds to the nearest name:
There's also a Note.fromFreqSharps
version:
Transposition and distances
Note.transpose
transpose(note: string, interval: string) => string
Transpose a note by an interval. It returns the note name or "" if not valid parameters.
Examples:
transposeBy
and transposeFrom
are currified versions of this function to make easy work with arrays:
Note.transposeFifths
transposeFifths(noteName: string, fifths: number) => string
Transpose a note a given number of fifths:
Note.distance
distance(from: string, to: string) => string
Find the interval between two notes:
Named collections
Note.names
names(array?: any[]) => string[]
Get note names of an array of anything. Notice that names are normalized:
Without parameters, it returns a list of natural pitch classes:
Note.sortedNames
sortedNames(array?: any[], comparator?: NoteComparator) => string[]
Sort an array of note names in ascending order. Pitch classes are listed before notes. Anything that is not a note is removed:
An optional comparator can be passed as a second argument:
Note.sortedUniqNames
sortedUniqNames(array?: any[]) => string[]
Sort notes ascending and remove duplicates.
Enharmonics
Note.simplify
simplify(noteName: string) => string
Given a note name, return the same note with less accidentals (or "" if not a valid note):
Note.enharmonic
enharmonic(noteName: string, pitchClass?: string) => string
Given a note name, returns its enharmonic (or "" if not valid note):
The destination pitch class can be enforced to calculate the octave:
Enforced pitch class must have the same chroma as the note, otherwise "" is returned: