UNPKG

temperament

Version:

A library for working with musical temperaments.

209 lines (208 loc) 7.44 kB
export namespace schema { let title: string; let description: string; let type: string; let required: string[]; namespace properties { export namespace name { let description_1: string; export { description_1 as description }; let type_1: string; export { type_1 as type }; } export namespace description_2 { let description_3: string; export { description_3 as description }; let type_2: string; export { type_2 as type }; } export { description_2 as description }; export namespace source { let description_4: string; export { description_4 as description }; let type_3: string; export { type_3 as type }; } export namespace octaveBaseName { let description_5: string; export { description_5 as description }; let type_4: string; export { type_4 as type }; } export namespace referencePitch { let description_6: string; export { description_6 as description }; let type_5: string; export { type_5 as type }; export let exclusiveMinimum: number; } export namespace referenceName { let description_7: string; export { description_7 as description }; let type_6: string; export { type_6 as type }; } export namespace referenceOctave { let description_8: string; export { description_8 as description }; let type_7: string; export { type_7 as type }; } export namespace notes { let description_9: string; export { description_9 as description }; let type_8: string; export { type_8 as type }; export let minProperties: number; export namespace additionalProperties { let description_10: string; export { description_10 as description }; let type_9: string; export { type_9 as type }; export let minItems: number; export let maxItems: number; export let items: { description: string; type: string; }[]; } } } } /** The size of an octave in cents. */ export const OCTAVE_SIZE: 1200; /** * Contains a complete description of a musical temperament. * * Most interaction with a `Temperament` should be through its public methods, * documented below. However, "metadata" properties (such as the name of the * temperament) are available for direct access, since changing them has no * effect on the internal structure of the temperament. These metadata * properties correspond directly to properties in the input data, and are * documented below. Please note that a metadata property may be `undefined` if * it was not defined in the input data. */ export class Temperament { /** * Creates a new temperament. * * @param data {TemperamentData} the temperament data, in the format defined * by the schema */ constructor(data: TemperamentData); /** The name of the temperament. * * @readonly @type {string} */ readonly name: string; /** A short description of the temperament. * * @readonly @type {string | undefined} */ readonly description: string | undefined; /** The source of the temperament data (e.g. a URL). * * @readonly @type {string | undefined} */ readonly source: string | undefined; /** @private @readonly @type {string} */ private readonly _octaveBaseName; /** @private @readonly @type {string} */ private readonly _referenceName; /** @private @readonly @type {number} */ private readonly _referenceOctave; /** @private @type {number} */ private _referencePitch; /** @private @readonly @type {string[]} */ private readonly _noteNames; /** @private @readonly @type {Map<string, number>} */ private readonly _offsets; /** * Returns an array of the note names defined in the temperament. * * @returns {string[]} the note names, sorted in increasing order of pitch * starting with the octave base */ get noteNames(): string[]; /** * Returns the name of the octave base note. * * @returns {string} the name of the octave base note */ get octaveBaseName(): string; /** * Returns the name of the reference note. * * @returns {string} the name of the reference note */ get referenceName(): string; /** * Returns the octave number of the reference note. * * @returns {number} the octave number of the reference note */ get referenceOctave(): number; /** * Sets the reference pitch. * * @param pitch {number} the reference pitch (in Hz) * @throws {Error} if `pitch` is not positive */ set referencePitch(arg: number); /** * Returns the reference pitch. * * @returns {number} the reference pitch, in Hz */ get referencePitch(): number; /** * Returns the closest note to the given pitch (in Hz), along with the pitch * difference (in cents). * * @param pitch {number} the pitch of the note to identify (in Hz) * @returns {[string, number]} a tuple containing the note name as its first * element and the offset (in cents) from that note as its second element * @throws {Error} if `pitch` is not positive */ getNoteNameFromPitch(pitch: number): [string, number]; /** * Return an array with octave numbers in order, forming a range with the * given radius around the reference octave. * * @param radius {number} the number of octaves on either end of the reference * octave to include. Must be non-negative. * @returns {number[]} a range of octave numbers * @throws {Error} if `radius` is negative */ getOctaveRange(radius: number): number[]; /** * Returns the offset of the given note. * * @param note {string} the name of the note * @param octave {number} the octave number of the note * @returns {number} the offset (in cents), relative to the reference pitch * @throws {Error} if `note` is not defined */ getOffset(note: string, octave: number): number; /** * Returns the pitch of the given note. * * @param note {string} the name of the note * @param octave {number} the octave number of the note * @returns {number} the pitch (in Hz) * @throws {Error} if `note` is not defined */ getPitch(note: string, octave: number): number; /** * Returns temperament data in the format defined by the schema. * * The returned data is not necessarily equal to the data object passed in the * constructor, but it is equivalent as a temperament. For example, the way * the note offsets are expressed may be different. * * @returns {TemperamentData} temperament data describing this temperament, * suitable for conversion to JSON */ toJSON(): TemperamentData; } export type TemperamentData = import("./schema").Temperament;