UNPKG

shimi

Version:

A JS framework for building complex MIDI applications

131 lines (130 loc) 6.84 kB
import { IPitchContainer, FitPitchOptions } from './IPitchContainer'; import ScaleTemplate from './ScaleTemplate'; /** This class is used by the Scale class to hold information about the proper naming of pitches, relative to some specific scale */ export declare class PitchName { pitch: number; letter: string; accidental: number; constructor(pitch: number, letter: string, accidental?: number); toString(): string; } /** * The Scale class defines the collection of pitches that make up a specific scale. * * @category Chords & Scales */ export default class Scale implements IPitchContainer { /** Returns the name of this type. This can be used rather than instanceof which is sometimes unreliable. */ get typeName(): string; /** The name of the scale */ get name(): string; set name(value: string); private _name; /** * The pitches which make up the scale, ordered ascending by scale degree from the scale's root, with each pitch within the range 0 - 11. * * For example, the pitches collection for F major would be: `[5, 7, 9, 10, 0, 2, 4]` */ get pitches(): number[]; private _pitches; /** The template which the scale is built from. */ get template(): ScaleTemplate; private _template; /** How many pitches are in the scale. */ get length(): number; /** The root pitch of the scale. */ get root(): number; private _pitchNames; /** * @param template The ScaleTemplate object which defines the scale type that this scale uses. * @param root The root of the scale. Can also take pitch names, see the [pitch](../functions/pitch.html) method for more information. */ constructor(template: ScaleTemplate, root: number | string); /** * Returns true if the passed in pitch belongs to the scale. Can also take pitch names, see the [pitch](../functions/pitch.html) method for more information. * * For example: * ``` * cMajor.contains(7) //returns true * cMajor.contains('Db7') //returns false * cMajor.contains('A8') //returns true * ``` */ contains(pitch: number | string): boolean; /** Returns the scale degree of the passed in pitch, or -1 if it's not contained. Can also take pitch names, see the [pitch](../functions/pitch.html) function for more information. */ degreeOf(pitch: number | string): number; /** * Takes a numerical pitch value and returns a string representation of that pitch, that makes sense relative to the scale. * * For example: * ``` * cMajor.getPitchName(7) //returns 'G' * cMajor.getPitchName('E') //returns 'E' * cMinor.getPitchName('E') //returns 'E♮' * ``` * @param pitch The pitch to get the string representation of. Can also take pitch names, see the [pitch](../functions/pitch.html) method for more information. * @param showOctave Whether to show a number after the name showing which octave we're in. * @returns */ getPitchName(pitch: number | string, showOctave?: boolean): string; /** * The degree method accepts a numerical scale degree, and returns the numerical pitch value which it corresponds to. * @param degree The degree of the scale to fetch. This starts counting from root = 1. * * If degree is greater than scale.length, then how much higher it is will determine how many octaves it shifts up in its search. For example: * ``` * cMajor.degree(3, 2) //returns 40 * cMajor.degree(10, 2) //returns 52 * cMajor.degree(17, 2) //returns 64 * ``` * * Similarly, if degree is less than 1, then how much lower it is will determine how many octaves it shifts down in its search. * @param rootOctave The octave of the scale root, which the returned pitch is calculated in relation to. * @returns */ getPitchByDegree(degree: number, rootOctave?: number): number; /** * The pitchesInRange method takes 2 numerical values, and returns all scale pitches which exist within that range. The search is inclusive of the passed in pitch parameters. Can also take pitch names, see the [pitch](../functions/pitch.html) method for more information. * * Note, if lowPitch > highPitch, then rather than throw an error, lowPitch & highPitch are swapped in their roles. * @param lowPitch The low pitch to compare against. * @param highPitch The high pitch to compare against. * @returns */ pitchesInRange(lowPitch: number | string, highPitch: number | string): Array<number>; /** * Returns a pitch near to the passed in pitch, but which should fit better with the notes within the scale. * @param pitch The pitch which we want to fit to the scale. Can also take pitch names, see the [pitch](../functions/pitch.html) method for more information. * @param options The options allow us to configure how we want the pitch to be fitted to the scale. * @returns Returns a new pitch number. */ fitPitch(pitch: number | string, options?: Partial<FitPitchOptions>, fallbackOptions?: Partial<FitPitchOptions>): number; /** * Generates an array which specifies how each note (both in & out of the scale should be named */ private _generatePitchNames; private _notInUsedNames; private _matchesPreference; /** Returns a new Scale object whose root is 7 semi-tones above (or 5 semi-tones below) the root of the current scale. */ getDominantScale(): Scale; /** Returns a new Scale object whose root is 5 semi-tones above (or 7 semi-tones below) the root of the calling scale. */ getSubdominantScale(): Scale; /** Returns a new Scale object whose root is x semi-tones above or below the root of the calling scale. */ getTransposedScale(transposition: number): Scale; /** * Returns a new Scale object that is relative to the current scale, according to how the template.relativityToMajor properties have been set up. * * For example, `eMinor.getRelativeScale(shimi.ScaleTemplate.dorian)` would return an A dorian scale. * @param template The template which we want the relative scale to be of. If the calling scale already has that template, then the method just returns the calling scale object. * @returns */ getRelativeScale(template: ScaleTemplate): Scale; /** * Returns a new Scale object that is parallel to the current scale. * * For example, `eMinor.getRelativeScale(shimi.ScaleTemplate.dorian)` would return an E dorian scale. * @param template The template which we want the parallel scale to be of. If the calling scale already has that template, then the method just returns the calling scale object. * @returns */ getParallelScale(template: ScaleTemplate): Scale; }