UNPKG

shimi

Version:

A JS framework for building complex MIDI applications

43 lines (42 loc) 2.91 kB
import Scale from './Scale'; export declare function safeMod(value: number, divisor: number): number; export declare function sortComparison<T>(a: T, b: T, accessor: (x: T) => number): number; /** * This function accepts a string representation of a pitch, and returns the MIDI number representation of it. * * An important point to note is that the way shimi uses the term "pitch" isn't technically correct, but does serve to make things less ambiguous in areas where otherwise things could get confusing. In musical terminology, "pitch" is usually measured in hertz as the frequency at which some instrument is producing sound waves, meanwhile a "note" is a musical sound which has some frequency and duration. In MIDI terminology, "pitch" isn't really used, and "note" is a value from 0 - 127 which maps to a frequency (usually within the Western tuning system) that the receiving oscillator should resonate at. * * In order to avoid confusion, and since shimi is very much within the MIDI space and so barely touches upon frequencies, "note" keeps its definition from the musical world (see the [Note](https://jamescoyle1989.github.io/shimi/classes/Note.html) class). Meanwhile "pitch" refers to the MIDI note number ranging from 0 - 127 that the MIDI specification allows (https://www.inspiredacoustics.com/en/MIDI_note_numbers_and_center_frequencies). * * @param name The name parameter accepts 'A', 'B', ..., 'G' to return a value within the lowest octave that MIDI supports (range 0 - 11). * * Accidental symbols ♯, #, ♭, b, ♮, 𝄪 (double sharp), x (also double sharp), 𝄫 (double flat) are also supported, and can be stacked on top of each other, for example: 'C♯', 'Dx#', 'F♭♯'. * * A number can also be added to the end of the string to determine which octave the returned value should be in, for example: 'C5', 'D#7', 'Ab8' * @returns */ export declare function parsePitch(name: string): number; /** * Internal method called by parsePitch, this will interpret the start of the passed in string as a pitch name up until the first non-valid character is encountered. * @returns Returns an object containing the parsed MIDI pitch number, plus the index of the input at which it stopped parsing the pitch name. */ export declare function parsePitchFromStringStart(name: string): { pitch: number; parseEndIndex: number; }; export declare function parseRomanNumeralsFromStringStart(numerals: string, scale: Scale): { pitch: number; isMajor: boolean; parseEndIndex: number; }; export declare function parsePitchOrRomanNumeralsFromStringStart(input: string, scale: Scale): { pitch: number; isMajor: boolean; parseEndIndex: number; }; /** * Converts a MIDI pitch or note name into a hertz value. * @param pitch The MIDI pitch, or note name to be converted * @returns */ export declare function toHertz(pitch: number | string): number;