@libraz/libcantus - v1.1.0
    Preparing search index...

    Function transposeNote

    • Transpose a note by a signed number of semitones, keeping its spelling.

      The letter moves by the diatonic distance of the conventional interval for that many semitones and the accidental is recomputed for the new letter, so enharmonic identity survives: Ab4 up a major second is Bb4, not A#4, and the operation is an exact inverse of itself. An octave-less note stays octave-less.

      A bare semitone count cannot distinguish an augmented fourth from a diminished fifth; pass spelling to override the letter distance when the enharmonic choice matters.

      Parameters

      • note: NoteData

        The note to transpose.

      • semitones: number

        The signed semitone offset.

      • Optionalopts: { spelling?: "flat" | "sharp" }

        spelling forces the result onto the sharp or flat side instead of following the source note's letter.

      Returns NoteData

      The transposed note.

      import { transposeNote, formatNote, parseNote } from '@libraz/libcantus';
      formatNote(transposeNote(parseNote('Ab4'), 2)); // 'Bb4'
      formatNote(transposeNote(parseNote('Ab4'), 2, { spelling: 'sharp' })); // 'A#4'