The note rendered as scientific pitch notation in English, e.g. 'G4' or
'Bb'. Use Note.format to write it in another notation system.
The pitch class (0..11), ignoring octave.
The diatonic letter number: 0..6 for C..B.
The chromatic alteration in semitones: -1 flat, 0 natural, +1 sharp, ...
The octave (scientific pitch notation), or undefined for a bare pitch class.
A copy of the underlying plain note object.
StaticofBuild a note from its parts, without reading any text.
The parts are the fields a note holds, so nothing here is interpreted:
Note.parse is what reads 'Bb' or 'C#4', and a letter name given
here may carry neither an accidental nor an octave.
The diatonic letter, as a number 0..6 (C..B) or a bare
natural letter name 'C'..'B'.
The chromatic alteration in semitones; defaults to natural.
Optionaloctave: number
The octave (scientific pitch notation); omit it for a bare pitch class.
The note.
StaticparseParse a note name (e.g. 'C#4', 'Bb', 'F##3'), in any of the
supported note-name systems.
The system is detected from the name itself unless one is given, exactly as
Key.parse reads a key name: 'gis' is a G sharp, while a bare
'B' is the English B natural until 'german' says otherwise.
The note text.
Optionalopts: NoteNameOptions
system reads the name in that notation system instead of
detecting it.
The parsed note.
If the text is not a valid note. Use Note.tryParse where failure is ordinary, such as a note field read on every keystroke.
StatictryParse a note name, reporting failure instead of throwing it.
The same reading as Note.parse, for the callers where text that does not name a note yet is the normal state of the input rather than a fault.
The note text.
Optionalopts: NoteNameOptions
system reads the name in that notation system instead of
detecting it.
The note, or the error explaining why the text is not one.
StaticfromName a MIDI number (middle C = C4 = 60) as a note.
The MIDI number.
Whether to prefer sharps or flats for black keys.
The spelled note, with octave.
StaticfromThe note name written in a notation system.
The counterpart of Note.parse: a getter cannot take an argument, so the system is named here instead of on Function.name.
Optionalopts: NoteNameOptions
system writes the name in that notation system instead of
English.
The note name, including the octave when the note has one.
The note's frequency in Hz.
The note's MIDI number is read as a step index, which is how the tuning module numbers steps: under twelve divisions the two coincide, and under any other the step index keeps counting from the same reference. A Tuning carries the three fields this takes, so an instance of it can be passed here directly.
Optionaltuning: TuningTable
The temperament to read the note under; twelve-tone equal temperament with A4 = 440 Hz by default.
The frequency in Hz.
Transpose by a signed number of semitones, keeping the spelling.
The letter moves by the diatonic distance of the conventional interval for
that many semitones, so Ab4 up a major second is Bb4 rather than A#4
and a flat key stays on the flat side. An octave-less note stays
octave-less: only its pitch class is moved. Transposing by zero is the
identity: the original spelling is preserved (no enharmonic respelling).
The signed semitone offset.
Optionalopts: { spelling?: "flat" | "sharp" }
spelling forces the result onto the sharp or flat side
instead of following this note's letter.
The transposed note.
The spelled interval from this note to another.
The second note.
The interval, which Interval.toJSON unwraps to plain data.
Transpose by a spelled interval, keeping the spelling the interval names.
Unlike Note.transpose, which picks a letter from the semitone count, the interval's diatonic number decides the letter: C up an augmented second is D#, not Eb.
An interval name (e.g. 'A2', '-m3'), plain interval
data, or an Interval; a descending interval moves down.
The transposed note.
The same spelled note in another octave.
The letter and the alteration are untouched, so this places a note in a
register rather than moving it by an interval: Cb4 given octave 3 is
Cb3, not the B3 it sounds as.
The octave (scientific pitch notation), where middle C is C4.
The note in that octave.
The note a transposing instrument must read to sound this one.
The direction is written-side, as Key.forInstrument is for a key: the part is transposed away from what the instrument sounds, so a B flat instrument — which sounds a major second lower than it reads — has a concert C4 written as D4. The interval decides the letter, so a concert E flat 3 reads as C4 on an alto saxophone rather than as B sharp 3.
The opposite reading, a written note back to the pitch it sounds, is Note.transposeBy applied to instrumentTransposition — the instrument's own written-to-sounding interval.
A built-in instrument name, or an interval naming a transposition the table does not carry.
The note the player reads.
import { instrumentTransposition, Note } from '@libraz/libcantus';
Note.parse('C4').forInstrument('clarinetBb').name; // 'D4'
Note.parse('Eb3').forInstrument('altoSax').name; // 'C4'
// And back: what a written C4 on a clarinet in A sounds as.
Note.parse('C4').transposeBy(instrumentTransposition('clarinetA')).name; // 'A3'
The other ways this note can be spelled: the same sounding pitch written on the letter above and on the letter below.
A list rather than a single answer, because a note has no one enharmonic
partner the way a key has: C#4 is both Db4 and B##3. Only spellings
within a double accidental are offered — the letters two steps away would
need a triple one — so a note whose neighbours are unwritable gets a
shorter list, and an octave-less note stays octave-less.
The alternative spellings, the letter above first.
The scale degree this note occupies in a key, counted from 1 at the tonic.
The degree is read from the sounding pitch, so an enharmonic spelling
answers for the pitch it sounds: in C major both F# and Gb are outside
the scale, and both B# and C are the tonic.
The 1-based degree, or null when the note is not in the scale.
StaticfromRebuild a note from its Note.toJSON output.
The serialized note.
The wrapped note.
Order two notes by the pitch they sound, for Array.prototype.sort.
Sounding pitch, not spelling: an enharmonic pair compares equal, so C#4
and Db4 keep the order they were given in while every note that sounds
lower comes before them. Note.equals is the spelling comparison,
and the two deliberately disagree about enharmonics.
A note carrying an octave is ordered by its MIDI number and an octave-less one by its pitch class, so the octave-less notes of a mixed list gather at the bottom rather than being placed in a register they do not name.
The note to compare with.
Negative when this note sounds lower, zero when the two sound the same pitch, positive when it sounds higher.
Whether another note has the same letter, alteration, and octave.
The note to compare.
True if the spellings are identical.
The plain note data, for JSON serialization.
Private class fields do not serialize, so an explicit toJSON keeps
JSON.stringify(note) from collapsing to {}.
A copy of the underlying plain note object.
The note's name, so a template literal or a log line reads as the note.
Optionalopts: NoteNameOptions
system writes the name in that notation system instead of
English, as Key.toString does for a key.
The spelled name, e.g. 'Bb3'.
An immutable spelled note: a diatonic letter plus a chromatic alteration and an optional octave. Wraps the plain note object and delegates to the pitch module; every transformation returns a new instance.
Example