UNPKG

@tonaljs/note

Version:

Parse and manipulate music notes in scientific notation

196 lines (193 loc) 6.62 kB
import { Pitch } from '@tonaljs/pitch'; import { distance as distance$1, transpose as transpose$1 } from '@tonaljs/pitch-distance'; import { IntervalName } from '@tonaljs/pitch-interval'; import { note, NoteLiteral, Note, NoteName } from '@tonaljs/pitch-note'; export { NoteType } from '@tonaljs/pitch-note'; /** * Return the natural note names without octave * @function * @example * Note.names(); // => ["C", "D", "E", "F", "G", "A", "B"] */ declare function names(array?: any[]): string[]; /** * Get a note from a note name * * @function * @example * Note.get('Bb4') // => { name: "Bb4", midi: 70, chroma: 10, ... } */ declare const get: typeof note; /** * Get the note name * @function */ declare const name: (note: NoteLiteral) => string; /** * Get the note pitch class name * @function */ declare const pitchClass: (note: NoteLiteral) => string; /** * Get the note accidentals * @function */ declare const accidentals: (note: NoteLiteral) => string; /** * Get the note octave * @function */ declare const octave: (note: NoteLiteral) => number | undefined; /** * Get the note midi * @function */ declare const midi: (note: NoteLiteral) => number | null; /** * Get the note midi * @function */ declare const freq: (note: NoteLiteral) => number | null; /** * Get the note chroma * @function */ declare const chroma: (note: NoteLiteral) => number; /** * Given a midi number, returns a note name. Uses flats for altered notes. * * @function * @param {number} midi - the midi note number * @return {string} the note name * @example * Note.fromMidi(61) // => "Db4" * Note.fromMidi(61.7) // => "D4" */ declare function fromMidi(midi: number): string; /** * Given a midi number, returns a note name. Uses flats for altered notes. */ declare function fromFreq(freq: number): string; /** * Given a midi number, returns a note name. Uses flats for altered notes. */ declare function fromFreqSharps(freq: number): string; /** * Given a midi number, returns a note name. Uses flats for altered notes. * * @function * @param {number} midi - the midi note number * @return {string} the note name * @example * Note.fromMidiSharps(61) // => "C#4" */ declare function fromMidiSharps(midi: number): string; declare const distance: typeof distance$1; /** * Transpose a note by an interval */ declare const transpose: typeof transpose$1; declare const tr: typeof transpose$1; /** * Transpose by an interval. * @function * @param {string} interval * @return {function} a function that transposes by the given interval * @example * ["C", "D", "E"].map(Note.transposeBy("5P")); * // => ["G", "A", "B"] */ declare const transposeBy: (interval: IntervalName) => (note: NoteName) => string; declare const trBy: (interval: IntervalName) => (note: NoteName) => string; /** * Transpose from a note * @function * @param {string} note * @return {function} a function that transposes the the note by an interval * ["1P", "3M", "5P"].map(Note.transposeFrom("C")); * // => ["C", "E", "G"] */ declare const transposeFrom: (note: NoteName) => (interval: IntervalName) => string; declare const trFrom: (note: NoteName) => (interval: IntervalName) => string; /** * Transpose a note by a number of perfect fifths. * * @function * @param {string} note - the note name * @param {number} fifths - the number of fifths * @return {string} the transposed note name * * @example * import { transposeFifths } from "@tonaljs/note" * transposeFifths("G4", 1) // => "D" * [0, 1, 2, 3, 4].map(fifths => transposeFifths("C", fifths)) // => ["C", "G", "D", "A", "E"] */ declare function transposeFifths(noteName: NoteName, fifths: number): NoteName; declare const trFifths: typeof transposeFifths; declare function transposeOctaves(noteName: NoteName, octaves: number): NoteName; type NoteComparator = (a: Note, b: Note) => number; declare const ascending: NoteComparator; declare const descending: NoteComparator; declare function sortedNames(notes: any[], comparator?: NoteComparator): string[]; declare function sortedUniqNames(notes: any[]): string[]; /** * Simplify a note * * @function * @param {string} note - the note to be simplified * - sameAccType: default true. Use same kind of accidentals that source * @return {string} the simplified note or '' if not valid note * @example * simplify("C##") // => "D" * simplify("C###") // => "D#" * simplify("C###") * simplify("B#4") // => "C5" */ declare const simplify: (noteName: NoteName | Pitch) => string; /** * Get enharmonic of a note * * @function * @param {string} note * @param [string] - [optional] Destination pitch class * @return {string} the enharmonic note name or '' if not valid note * @example * Note.enharmonic("Db") // => "C#" * Note.enharmonic("C") // => "C" * Note.enharmonic("F2","E#") // => "E#2" * Note.enharmonic("C##b"); // => "" */ declare function enharmonic(noteName: string, destName?: string): string; /** @deprecated */ declare const _default: { names: typeof names; get: typeof note; name: (note: NoteLiteral) => string; pitchClass: (note: NoteLiteral) => string; accidentals: (note: NoteLiteral) => string; octave: (note: NoteLiteral) => number | undefined; midi: (note: NoteLiteral) => number | null; ascending: NoteComparator; descending: NoteComparator; distance: typeof distance$1; sortedNames: typeof sortedNames; sortedUniqNames: typeof sortedUniqNames; fromMidi: typeof fromMidi; fromMidiSharps: typeof fromMidiSharps; freq: (note: NoteLiteral) => number | null; fromFreq: typeof fromFreq; fromFreqSharps: typeof fromFreqSharps; chroma: (note: NoteLiteral) => number; transpose: typeof transpose$1; tr: typeof transpose$1; transposeBy: (interval: IntervalName) => (note: NoteName) => string; trBy: (interval: IntervalName) => (note: NoteName) => string; transposeFrom: (note: NoteName) => (interval: IntervalName) => string; trFrom: (note: NoteName) => (interval: IntervalName) => string; transposeFifths: typeof transposeFifths; transposeOctaves: typeof transposeOctaves; trFifths: typeof transposeFifths; simplify: (noteName: NoteName | Pitch) => string; enharmonic: typeof enharmonic; }; export { type NoteComparator, accidentals, ascending, chroma, _default as default, descending, distance, enharmonic, freq, fromFreq, fromFreqSharps, fromMidi, fromMidiSharps, get, midi, name, names, octave, pitchClass, simplify, sortedNames, sortedUniqNames, tr, trBy, trFifths, trFrom, transpose, transposeBy, transposeFifths, transposeFrom, transposeOctaves };