UNPKG

moment-of-symmetry

Version:

Moment of Symmetry (MOS) musical scale generation and analysis for Javascript

175 lines (174 loc) 9.48 kB
import { EdoMapEntry, ModeInfo, MosInfo, MosScaleInfo, RangeInfo } from './info.js'; export * from './hardness.js'; export * from './names.js'; export * from './generator-ratio.js'; export * from './info.js'; export * from './notation.js'; /** * Shared parameters for functions that select a MOS mode by brightness. */ export type BaseOptions = { /** How many bright generators to go downwards. Also the number of small/minor intervals in the resulting scale. Default = 0. */ down?: number; /** How many bright generators to go upwards. Also the number of large/major intervals in the resulting scale. Defaults to the maximum possible. */ up?: number; }; /** * Parameters for the {@link modeInfo} function. */ export interface ModeInfoOptions extends BaseOptions { /** If true adds extra mode names in parenthesis such as Ionian (Major). */ extraNames?: boolean; } /** * Parameters for the {@link mos} function. */ export interface MosOptions extends BaseOptions { /** Size of the large step. Default = 2.*/ sizeOfLargeStep?: number; /** Size of small step. Default = 1. */ sizeOfSmallStep?: number; } /** * Parameters for the {@link mosWithParent} function. */ export interface MosWithParentOptions extends MosOptions { /** How the main scale relates to the parent. Defaults to 'sharp'. */ accidentals?: 'flat' | 'sharp'; } /** * Parameters for the {@link mosWithDaughter} function. */ export interface MosWithDaughterOptions extends MosOptions { /** How daughter notes that are outside the parent scale are labeled. Defaults to 'sharp'. */ accidentals?: 'flat' | 'sharp' | 'both'; } /** * Produce an array of booleans that is mixed as evenly as possible. * @param numberOfTrue Number of true elements * @param numberOfFalse Number of false elements * @returns The array of evenly mixed booleans */ export declare function euclid(numberOfTrue: number, numberOfFalse: number): boolean[]; /** * Obtain the bright generator of the MOS scale expressed as multipliers of the size of the large and small steps. * @param numberOfLargeSteps Number of large steps in the MOS pattern. * @param numberOfSmallSteps Number of small steps in the MOS pattern. * @returns An array of [number of large steps in the bright generator, number of small steps in the bright generator]. */ export declare function brightGeneratorMonzo(numberOfLargeSteps: number, numberOfSmallSteps: number): [number, number]; /** * Obtain an abstract string like 'LLsLLLs' corresponding to the mode specified. * @param numberOfLargeSteps Number of large steps in the MOS pattern. * @param numberOfSmallSteps Number of small steps in the MOS pattern. * @param options Options for brightness of the scale. * @returns String with the given number of 'L' and 's' characters in the specified mode. */ export declare function stepString(numberOfLargeSteps: number, numberOfSmallSteps: number, options?: BaseOptions): string; /** * Generate MOS pattern as a subset of an EDO. * @param numberOfLargeSteps Number of large steps in the MOS pattern. * @param numberOfSmallSteps Number of small steps in the MOS pattern. * @param options Options for sizes of the steps and brightness of the scale. * @returns An array of integers representing the EDO subset. The 0 degree is not included, but the final degree representing the size of the EDO is. */ export declare function mos(numberOfLargeSteps: number, numberOfSmallSteps: number, options?: MosOptions): number[]; /** * Generate MOS pattern as a subset of an EDO with parent MOS relationship indicated. * @param numberOfLargeSteps Number of large steps in the MOS pattern. * @param numberOfSmallSteps Number of small steps in the MOS pattern. * @param options Options for sizes of the steps, brightness of the scale and flat/sharp relationship. * @returns A map of integers representing the EDO subset to booleans indicating if the scale degree belongs to the parent MOS or not. * The 0 degree is not included, but the final degree representing the size of the EDO is. */ export declare function mosWithParent(numberOfLargeSteps: number, numberOfSmallSteps: number, options?: MosWithParentOptions): Map<number, boolean>; /** * Generate a daughter MOS as a subset of an EDO while labeling each degree by its relationship to the parent MOS. * @param numberOfLargeSteps Number of large steps in the parent MOS. * @param numberOfSmallSteps Number of small steps in the parent MOS. * @param options Options for sizes of the steps, brightness of the scale, and daughter accidental labeling. * @returns A map of EDO degrees to labels indicating whether a degree is in the parent MOS (`'parent'`) or belongs to the daughter as `'flat'`, `'sharp'`, or `'both'`. * The 0 degree is not included, but the final degree representing the size of the EDO is. */ export declare function mosWithDaughter(numberOfLargeSteps: number, numberOfSmallSteps: number, options?: MosWithDaughterOptions): Map<number, "parent" | "flat" | "sharp" | "both">; /** * Information about the modes of a MOS scale. * @param numberOfLargeSteps Number of large steps in the MOS pattern. * @param numberOfSmallSteps Number of small steps in the MOS pattern. * @param extraNames If true adds extra mode names in parenthesis such as Ionian (Major). * @returns An array of mode information, ordered from darkest to brightest. */ export declare function mosModes(numberOfLargeSteps: number, numberOfSmallSteps: number, extraNames?: boolean): ModeInfo[]; /** * Information about a mode of a MOS scale. * @param numberOfLargeSteps Number of large steps in the MOS pattern. * @param numberOfSmallSteps Number of small steps in the MOS pattern. * @param options Options for brightness of the scale and for adding extra names like Ionian (Major). * @returns Information about the selected mode. */ export declare function modeInfo(numberOfLargeSteps: number, numberOfSmallSteps: number, options?: ModeInfoOptions): ModeInfo; /** * Split a string like "5L 2s" into [5, 2]. * @param mosPattern MOS pattern such as "5L 2s". * @returns A pair of integers representing the number of large and small steps. */ export declare function splitMosPattern(mosPattern: string): [number, number]; /** * Calculate the parent MOS of a given MOS pattern. * @param mosPattern MOS pattern such as "5L 2s". * @returns Information about the parent MOS. */ export declare function parentMos(mosPattern: string): MosInfo; /** * Calculate the parent MOS of a given MOS pattern. * @param numberOfLargeSteps Number of large steps in the MOS pattern. * @param numberOfSmallSteps Number of small steps in the MOS pattern. * @returns Information about the parent MOS. */ export declare function parentMos(numberOfLargeSteps: number, numberOfSmallSteps: number): MosInfo; /** * Obtain detailed information about a MOS scale embedded in an EDO. * @param numberOfLargeSteps Number of large steps in the MOS pattern. * @param numberOfSmallSteps Number of small steps in the MOS pattern. * @param sizeOfLargeStep Size of the large step in EDO steps. * @param sizeOfSmallStep Size of the small step in EDO steps. * @returns Information about the MOS scale, including generators, period data, and hardness. */ export declare function mosScaleInfo(numberOfLargeSteps: number, numberOfSmallSteps: number, sizeOfLargeStep?: number, sizeOfSmallStep?: number): MosScaleInfo; /** * Calculate the daughter MOS implied by a parent MOS and its step sizes. * @param numberOfLargeSteps Number of large steps in the parent MOS. * @param numberOfSmallSteps Number of small steps in the parent MOS. * @param sizeOfLargeStep Size of the parent MOS large step in EDO steps. * @param sizeOfSmallStep Size of the parent MOS small step in EDO steps. * @returns Information about the daughter MOS scale. */ export declare function daughterMos(numberOfLargeSteps: number, numberOfSmallSteps: number, sizeOfLargeStep: number, sizeOfSmallStep: number): MosScaleInfo; /** * Construct a mapping from EDO size to supported MOS scales. * @param maxSize Maximum size of the MOS patterns to include. * @returns A mapping from EDO size to an array of information about the supported MOS scales. */ export declare function makeEdoMap(maxSize?: number): Map<number, EdoMapEntry[]>; /** * Find a MOS scale supported by the given EDO. * @param edo Size of the EDO. * @returns Information about the supported MOS scale. */ export declare function anyForEdo(edo: number): MosScaleInfo; /** * Find all MOS scales supported by the given EDO within the given constraints. * @param edo Size of the EDO. * @param minSize Minimum size of a MOS scale in the result. * @param maxSize Maximum size of a MOS scale in the result. * @param maxHardness Maximum hardness of the step ratio L/s. * @returns Array of information about the supported MOS scales. */ export declare function allForEdo(edo: number, minSize?: number, maxSize?: number, maxHardness?: number): MosScaleInfo[]; /** * Find the ranges of all (equally tempered) fractions of the equave that span MOS scales. * @param size Size of the scales to consider. * @param includeMultiPeriods Include scales that split the equave into multiple periods. * @returns Information about the ranges of generator that span MOS. Ranges are grouped by period and otherwise sorted in ascending order. */ export declare function generatorRanges(size: number, includeMultiPeriods?: boolean): RangeInfo[];