UNPKG

@tonaljs/scale

Version:

Musical scales and its relations

139 lines (136 loc) 4.2 kB
import { NoteName } from '@tonaljs/pitch-note'; import { ScaleType, names as names$1 } from '@tonaljs/scale-type'; type ScaleName = string; type ScaleNameTokens = [string, string]; interface Scale extends ScaleType { tonic: string | null; type: string; notes: NoteName[]; } /** * Given a string with a scale name and (optionally) a tonic, split * that components. * * It returns an array with the form [ name, tonic ] where tonic can be a * note name or null and name can be any arbitrary string * (this function doesn't check if that scale name exists) * * @function * @param {string} name - the scale name * @return {Array} an array [tonic, name] * @example * tokenize("C mixolydian") // => ["C", "mixolydian"] * tokenize("anything is valid") // => ["", "anything is valid"] * tokenize() // => ["", ""] */ declare function tokenize(name: ScaleName): ScaleNameTokens; /** * Get all scale names * @function */ declare const names: typeof names$1; /** * Get a Scale from a scale name. */ declare function get(src: ScaleName | ScaleNameTokens): Scale; /** * @deprecated * @use Scale.get */ declare const scale: typeof get; declare function detect(notes: string[], options?: { tonic?: string; match?: "exact" | "fit"; }): string[]; /** * Get all chords that fits a given scale * * @function * @param {string} name - the scale name * @return {Array<string>} - the chord names * * @example * scaleChords("pentatonic") // => ["5", "64", "M", "M6", "Madd9", "Msus2"] */ declare function scaleChords(name: string): string[]; /** * Get all scales names that are a superset of the given one * (has the same notes and at least one more) * * @function * @param {string} name * @return {Array} a list of scale names * @example * extended("major") // => ["bebop", "bebop dominant", "bebop major", "chromatic", "ichikosucho"] */ declare function extended(name: string): string[]; /** * Find all scales names that are a subset of the given one * (has less notes but all from the given scale) * * @function * @param {string} name * @return {Array} a list of scale names * * @example * reduced("major") // => ["ionian pentatonic", "major pentatonic", "ritusen"] */ declare function reduced(name: string): string[]; /** * Given an array of notes, return the scale: a pitch class set starting from * the first note of the array * * @function * @param {string[]} notes * @return {string[]} pitch classes with same tonic * @example * scaleNotes(['C4', 'c3', 'C5', 'C4', 'c4']) // => ["C"] * scaleNotes(['D4', 'c#5', 'A5', 'F#6']) // => ["D", "F#", "A", "C#"] */ declare function scaleNotes(notes: NoteName[]): string[]; type ScaleMode = [string, string]; /** * Find mode names of a scale * * @function * @param {string} name - scale name * @example * modeNames("C pentatonic") // => [ * ["C", "major pentatonic"], * ["D", "egyptian"], * ["E", "malkos raga"], * ["G", "ritusen"], * ["A", "minor pentatonic"] * ] */ declare function modeNames(name: string): ScaleMode[]; declare function rangeOf(scale: string | string[]): (fromNote: string, toNote: string) => (string | undefined)[]; /** * Returns a function to get a note name from the scale degree. * * @example * [1, 2, 3].map(Scale.degrees("C major")) => ["C", "D", "E"] * [1, 2, 3].map(Scale.degrees("C4 major")) => ["C4", "D4", "E4"] */ declare function degrees(scaleName: string | ScaleNameTokens): (degree: number) => string; /** * Sames as `degree` but with 0-based index */ declare function steps(scaleName: string | ScaleNameTokens): (normalized: number) => string; /** @deprecated */ declare const _default: { degrees: typeof degrees; detect: typeof detect; extended: typeof extended; get: typeof get; modeNames: typeof modeNames; names: typeof names$1; rangeOf: typeof rangeOf; reduced: typeof reduced; scaleChords: typeof scaleChords; scaleNotes: typeof scaleNotes; steps: typeof steps; tokenize: typeof tokenize; scale: typeof get; }; export { type Scale, _default as default, degrees, detect, extended, get, modeNames, names, rangeOf, reduced, scale, scaleChords, scaleNotes, steps, tokenize };