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; // 10
toInterval
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; // 2
A 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 31EDO
compose
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);
Creates a TuningMap
instance.
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 cents
toHz(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); // 880
toCents
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); // 400
toRatio
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.7489046221194973