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

    Function toNoteData

    • Resolve any note-shaped value to plain Note data.

      The counterpart of toSpelledInterval for notes: an entry point takes whatever form the caller has — the name a text field holds, the MIDI number a device sends, the data the pitch module returns, or a Note instance — and gets one shape back. An instance is accepted through its toJSON method rather than by its type, because the core layer cannot import the model layer that defines the class.

      A number is read as MIDI and spelled with sharps, the same reading midiToNote takes by default. Where a key is known the caller spells it there instead — spellPitch reads the key — because no single default suits both a G# in E major and an Ab in Eb major.

      Parameters

      • value: NoteLike

        A note name, a MIDI number, plain note data, or a value whose toJSON returns note data.

      Returns NoteData

      The validated note data, carrying octave only when the value has one.

      If the value is not note-shaped, or its letter, alteration, or octave fall outside the range a spelled note holds.

      import { toNoteData } from '@libraz/libcantus';
      toNoteData('Eb4'); // { letter: 2, alter: -1, octave: 4 }
      toNoteData(60); // { letter: 0, alter: 0, octave: 4 }