Map
The classes in this section allow arbitrary or matrices to be multiplied by vectors.
MapVec
Section titled “MapVec”The MapVec provides a generic vector type that 2-dimensional mapping operations can return, and provides methods to be converted into a Pitch or Interval vector as required.
MapVec follows the shape of Pitch and Interval, exposing two fields:
x: number;y: number;Class Constructor
Section titled “Class Constructor”constructor(x: number, y: number);Simple pass in coordinates to instantiate a vector:
let v = new MapVec(12, 5);toPitch
Section titled “toPitch”toPitch(): Pitch;Converts a MapVec into a Pitch vector.
let v = new MapVec(25, 10);let p = v.toPitch();
p.w; // 25p.h; // 10toInterval
Section titled “toInterval”toInterval(): Interval;Converts a MapVec into an Interval vector.
let v = new MapVec(5, 2);let m = v.toInterval();
p.w; // 5p.h; // 2A Map1D is a matrix, used to map a 2-dimensional vector to a 1-dimensional number. Conceptually, many of Meantonal’s Pitch and Interval queries utilise this principle under the hood (see the Learn page for a detailed explanation).
Class Constructor
Section titled “Class Constructor”constructor(m0: number, m1: number);Creates a matrix :
let A = new Map1D(5, 3);map(v: MapVec | Pitch | Interval): number;Carries out the mapping operation on the passed in vector. Result will be a number.
let A = new Map(5, 3); // 31EDO mapping matrixlet p = SPN.toPitch("G4");
A.map(p); // sends p to 18, essentially a MIDI style mapping for 31EDOcompose
Section titled “compose”compose(map: Map2D): Map1D;Composes the Map1D instance with a passed in Map2D; essentially carries out matrix multiplication:
Returns a new Map1D. Creating new maps from the composition of existing maps can save on unnecessary computation.
A Map1D is a matrix, used to map a 2-dimensional vector to another 2-dimensional vector. Essentially effects a change of coordinate system: (see the Learn page for a detailed explanation).
Class Constructor
Section titled “Class Constructor”constructor(m00: number, m01: number, m10: number, m11: number);Creates a matrix:
let A = new Map2D(1, 2, 3, 4);map(v: MapVec | Pitch | Interval): MapVec;Carries out the mapping operation on the passed in vector. Result will be a generic MapVec.
let A = new Map2D(2, -5, -1, 3); // basis change: (w, h) => (P5, P8)let p = SPN.toPitch("E5");
A.map(p) // (4, 3)compose
Section titled “compose”compose(map: Map2D): Map2D;Composes the Map2D instance with a passed in Map2D; essentially carries out matrix multiplication:
Returns a new Map2D. Creating new maps from the composition of existing maps can save on unnecessary computation.
TuningMap
Section titled “TuningMap”A TuningMap represents a map onto a given tuning system, and is used to produce frequency values for Pitch vectors in that tuning. It is specified in terms of:
- The width of its fifth in cents:
- The name of a reference pitch in Scientific Pitch Notation.
- The frequency of that reference pitch in Hz.
If no reference pitch is given, the default C4 = 261.6255653Hz. This is equivalent to A4 = 440Hz in 12TET, but is centered about C4.
Class Constructor
Section titled “Class Constructor”constructor( fifth: number, referencePitch?: string, referenceFreq?: number midiMap?: Map1D;);Creates a TuningMap instance manually.
fromEDO
Section titled “fromEDO”static fromEDO( edo: number, referencePitch?: string, referenceFreq?: number): TuningMap;If you’re working with EDO tuning system, it can be more convenient to initialise a TuningMap by specifying the number of parts the octave is divided into rather than the specific width of a perfect fifth in cents within that system. This static method allows just that.
As with the class constructor, if the reference Pitch and its frequency are not specified, defaults to C4 = 261.6255653Hz.
const T = TuningMap.fromEDO(31);
let p = Pitch("C4");T.toHz(p); // ~261.63Hz
let m = Interval("M3");T.toCents(m); // ~387.10 centstoHz(p: Pitch): number;Returns the frequency of the passed-in Pitch in Hertz.
const T = TuningMap.fromEDO(12, "A4", 440);
let p = SPN.toPitch("A4");T.toHz(p); // 440
p = SPN.toPitch("A5");T.toHz(p); // 880toCents
Section titled “toCents”toCents(m: Interval): number;Returns the width of the passed in Interval in cents.
const T = TuningMap.fromEDO(12);
let m = Interval.fromName("M3");T.toCents(m); // 400toRatio
Section titled “toRatio”toRatio(m: Interval): number;Returns the ratio of the passed Interval as a decimal number.
const T = TuningMap.fromEDO(31);
let m = Interval.fromName("A6");T.toRatio(m); // 1.7489046221194973EDOMap
Section titled “EDOMap”This handy class creates a map to a well-ordered integer numbering for a given EDO tuning. For 12TET this is equivalent to standard MIDI, and for other EDO tunings a similar numbering is generated.
Class Constructor
Section titled “Class Constructor”constructor(edo: number);Create an EDOMap instance by simply specifying the number of parts the octave will be divided into.
toNumber
Section titled “toNumber”toNumber(p: Pitch): number;Returns an ordered pitch numbering for the passed Pitch as an integer. For 12TET, this will be the ordinary MIDI value for a given Pitch, but for other EDO tunings it provides an ordered MIDI-equvalent mapping.
const T1 = new EDOMap(12);const T2 = new EDOMap(31);
let p = SPN.toPitch("C4");
T1.toNumber(p); // 60T2.toNumber(p); // 155compare
Section titled “compare”compare(p: Pitch, q: Pitch): number;In the specified EDO:
- Returns a positive number if p is above q.
- Returns a negative value if p is below q.
- Returns 0 if p and q are enharmonic.
let p = SPN.toPitch("C#4");let q = SPN.toPitch("Db4");
let T = new EDOMap(53);T.compare(p, q); // 1
T = new EDOMap(31);T.compare(p, q); // -1
T = new EDOMap(12);T.compare(p, q); // 0