@tonaljs/interval
Version:
Parse and manipulate music intervals
145 lines (142 loc) • 4.54 kB
TypeScript
import { distance as distance$1 } from '@tonaljs/pitch-distance';
import { IntervalName, interval } from '@tonaljs/pitch-interval';
/**
* Get the natural list of names
*/
declare function names(): IntervalName[];
/**
* Get properties of an interval
*
* @function
* @example
* Interval.get('P4') // => {"alt": 0, "dir": 1, "name": "4P", "num": 4, "oct": 0, "q": "P", "semitones": 5, "simple": 4, "step": 3, "type": "perfectable"}
*/
declare const get: typeof interval;
/**
* Get name of an interval
*
* @function
* @example
* Interval.name('4P') // => "4P"
* Interval.name('P4') // => "4P"
* Interval.name('C4') // => ""
*/
declare const name: (name: string) => string;
/**
* Get semitones of an interval
* @function
* @example
* Interval.semitones('P4') // => 5
*/
declare const semitones: (name: string) => number;
/**
* Get quality of an interval
* @function
* @example
* Interval.quality('P4') // => "P"
*/
declare const quality: (name: string) => "dddd" | "ddd" | "dd" | "d" | "m" | "M" | "P" | "A" | "AA" | "AAA" | "AAAA";
/**
* Get number of an interval
* @function
* @example
* Interval.num('P4') // => 4
*/
declare const num: (name: string) => number;
/**
* Get the simplified version of an interval.
*
* @function
* @param {string} interval - the interval to simplify
* @return {string} the simplified interval
*
* @example
* Interval.simplify("9M") // => "2M"
* Interval.simplify("2M") // => "2M"
* Interval.simplify("-2M") // => "7m"
* ["8P", "9M", "10M", "11P", "12P", "13M", "14M", "15P"].map(Interval.simplify)
* // => [ "8P", "2M", "3M", "4P", "5P", "6M", "7M", "8P" ]
*/
declare function simplify(name: IntervalName): IntervalName;
/**
* Get the inversion (https://en.wikipedia.org/wiki/Inversion_(music)#Intervals)
* of an interval.
*
* @function
* @param {string} interval - the interval to invert in interval shorthand
* notation or interval array notation
* @return {string} the inverted interval
*
* @example
* Interval.invert("3m") // => "6M"
* Interval.invert("2M") // => "7m"
*/
declare function invert(name: IntervalName): IntervalName;
/**
* Get interval name from semitones number. Since there are several interval
* names for the same number, the name it's arbitrary, but deterministic.
*
* @param {Integer} num - the number of semitones (can be negative)
* @return {string} the interval name
* @example
* Interval.fromSemitones(7) // => "5P"
* Interval.fromSemitones(-7) // => "-5P"
*/
declare function fromSemitones(semitones: number): IntervalName;
/**
* Find interval between two notes
*
* @example
* Interval.distance("C4", "G4"); // => "5P"
*/
declare const distance: typeof distance$1;
/**
* Adds two intervals
*
* @function
* @param {string} interval1
* @param {string} interval2
* @return {string} the added interval name
* @example
* Interval.add("3m", "5P") // => "7m"
*/
declare const add: (a: IntervalName, b: IntervalName) => IntervalName | undefined;
/**
* Returns a function that adds an interval
*
* @function
* @example
* ['1P', '2M', '3M'].map(Interval.addTo('5P')) // => ["5P", "6M", "7M"]
*/
declare const addTo: (interval: string) => (other: string) => string | undefined;
/**
* Subtracts two intervals
*
* @function
* @param {string} minuendInterval
* @param {string} subtrahendInterval
* @return {string} the subtracted interval name
* @example
* Interval.subtract('5P', '3M') // => '3m'
* Interval.subtract('3M', '5P') // => '-3m'
*/
declare const subtract: (a: IntervalName, b: IntervalName) => IntervalName | undefined;
declare function transposeFifths(interval: IntervalName, fifths: number): IntervalName;
/** @deprecated */
declare const _default: {
names: typeof names;
get: typeof interval;
name: (name: string) => string;
num: (name: string) => number;
semitones: (name: string) => number;
quality: (name: string) => "dddd" | "ddd" | "dd" | "d" | "m" | "M" | "P" | "A" | "AA" | "AAA" | "AAAA";
fromSemitones: typeof fromSemitones;
distance: typeof distance$1;
invert: typeof invert;
simplify: typeof simplify;
add: (a: IntervalName, b: IntervalName) => IntervalName | undefined;
addTo: (interval: string) => (other: string) => string | undefined;
subtract: (a: IntervalName, b: IntervalName) => IntervalName | undefined;
transposeFifths: typeof transposeFifths;
};
export { add, addTo, _default as default, distance, fromSemitones, get, invert, name, names, num, quality, semitones, simplify, subtract, transposeFifths };