Skip to content

Commit

Permalink
Add type documentation for diamond-mos.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
frostburn committed May 12, 2024
1 parent f15eb22 commit 9d8eba9
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/diamond-mos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,21 @@ import {
} from './pythagorean';
import {ZERO} from './utils';

/**
* Base degree for a mosstep in a 0-indexed array.
*/
export type MosDegree = {
/**
* The perfect or neutral central interval.
*/
center: TimeMonzo;
/**
* Flag to indicate if the degree has minor and major variants.
*/
imperfect: boolean;
/**
* The lopsided neutral variant of a bright or dark generator.
*/
mid?: TimeMonzo;
};

Expand Down Expand Up @@ -48,20 +60,39 @@ export type MosConfig = {
degrees: MosDegree[];
};

/**
* Generic 0-indexed mosstep.
*/
export type MosStep = {
type: 'MosStep';
quality: IntervalQuality;
augmentations?: AugmentedQuality[];
degree: 0;
};

/**
* Accidental in Diamond-mos notation.
*
* & = Raises a note by a moschroma +(L-s)
* e = Raises a note by half a moschroma +(L-s)/2
* a = Lowers a note by half a moschroma -(L-s)/2
* @ = Lowers a note by a moschroma -(L-s)
*/
export type MosAccidental = '&' | 'e' | 'a' | '@';

/**
* Potentially fractional Diamond-mos accidental.
*/
export type SplitMosAccidental = {
fraction: VulgarFraction;
accidental: Accidental | MosAccidental;
};

/**
* Diamond-mos nominals from J to Z.
*
* The number of valid nominals corresponds to the size of the MOS scale and repeats every equave.
*/
export type MosNominal =
| 'J'
| 'K'
Expand Down Expand Up @@ -91,6 +122,11 @@ export type AbsoluteMosPitch = {
octave: number;
};

/**
* Obtain relative values for one equave-run of the given config of a MOS declaration with implicit unison.
* @param config Result of a MOS declaration.
* @returns An array of relative time monzos.
*/
export function scaleMonzos(config: MosConfig) {
const entries = Array.from(config.scale);
entries.sort((a, b) => a[0].localeCompare(b[0]));
Expand All @@ -99,6 +135,12 @@ export function scaleMonzos(config: MosConfig) {
return monzos;
}

/**
* Convert a generic 0-indexed TAMNAMS mosstep to a relative time monzo.
* @param node MosStep like P0ms.
* @param config Result of a MOS declaration.
* @returns A relative time monzo.
*/
export function mosMonzo(node: MosStep, config: MosConfig): TimeMonzo {
const baseDegree = mmod(Math.abs(node.degree), config.degrees.length);
const periods = (node.degree - baseDegree) / config.degrees.length;
Expand Down Expand Up @@ -189,6 +231,12 @@ function mosInflection(
return new TimeMonzo(ZERO, vector);
}

/**
* Convert a Diamond-mos note to a time monzo relative to J4 = C4.
* @param node Absolute note like J@5.
* @param config Result of a MOS declaration.
* @returns A time monzo relative to J4.
*/
export function absoluteMosMonzo(
node: AbsoluteMosPitch,
config: MosConfig
Expand Down

0 comments on commit 9d8eba9

Please sign in to comment.