Types
Primitive Types
Section titled “Primitive Types”The most fundamental types in Meantonal are Pitch
and Interval
, both of which represent 2d vectors.
A Pitch
is a struct with two members, w
and h
.
typedef struct { int w; // whole steps int h; // half steps} Pitch;
w
holds the number of whole steps from .h
holds the number of half steps from .
Interval
Section titled “Interval”An Interval
is a struct with two members, w
and h
.
typedef struct { int w; // whole steps int h; // half steps} Interval;
w
holds the number of whole steps from the unison.h
holds the number of half steps from the unison.
The Pitch
and Interval
type are effectively identical, and one can even be cast to the other. They are distinct because they generally represent different things. An Interval
describes the distance between two Pitch
vectors.
Tonal types
Section titled “Tonal types”These types encode the information needed to represent a governing “key” or “mode”, and perform diatonic operations and queries within that context.
enum Mode
Section titled “enum Mode”Used when defining a TonalContext
. Numbered in descending fifths, starting with Lydian as 0.
enum Mode { LYDIAN, IONIAN, MIXOLYDIAN, DORIAN, AEOLIAN, PHRYGIAN, LOCRIAN,
MAJOR = IONIAN, MINOR = AEOLIAN};
TonalContext
Section titled “TonalContext”A TonalContext
is a struct holding data about the governing “key” or “mode”.
typedef struct { struct { int letter; int accidental; } tonic; enum Mode mode; int chroma_offset; // offset used by internal functions to reconcile notes.} TonalContext;
enum Degree
Section titled “enum Degree”This enum allows scale degrees (0-indexed so TONIC is 0) to be specified by their functional names. Used by degree_number
and degree_chroma
.
enum Degree { TONIC, SUPERTONIC, MEDIANT, SUBDOMINANT, DOMINANT, SUBMEDIANT, SUBTONIC};
enum Alteration
Section titled “enum Alteration”This enum communicates the alteration of scale degrees within a key, used with degree_alteration
.
enum Alteration { FOREIGN_DEG_FLAT = -2, LOWERED_DEG, DIATONIC_DEG, RAISED_DEG, FOREIGN_DEG_SHARP};
FOREIGN_DEG_FLAT
and FOREIGN_DEG_SHARP
indicate notes that do not lie within the window of 17 perfect fifths Meantonal uses to define a TonalContext
(that is, the note could not resolve by diatonic semitone to a natural degree within the key or mode).
Map Types
Section titled “Map Types”These types include mapping matrices for linear mapping operations and a special vector type to store the result of applying 2-dimensional maps.
The Map1d
type represents a matrix. Its members are labelled m0
and m1
to reinforce this.
typedef struct { int m0, m1;} Map1d;
Multiplying a Map1d
matrix with a MapVec
via map_to_1d
produces a single integer as the result.
Multiplying a matrix with a 2d vector is equivalent to taking the dot product between two 2d vectors, so they can also be thought of as 2d vectors if you prefer.
The Map2d
type represents a matrix. Its members are labelled row-first, then column.
typedef struct { int m00, m01; int m10, m11;} Map2d;
Multiplying a Map2d
matrix with a MapVec
via map_to_2d
produces another MapVec
.
MapVec
Section titled “MapVec”The MapVec
type exists to store the vectors used with a Map1d
by map_to_1d and Map2d
by map_to_2d.
typedef struct { int x; int y;} MapVec;
MirrorAxis
Section titled “MirrorAxis”The MirrorAxis
type is to do with a different kind of mapping operation: pitch inversion about a fixed axis.
typedef struct { int w; int h;} MirrorAxis;
Slightly misleadingly, it looks like a regular Pitch
or Interval
, but this is strictly a result of how the inversion is applied.
Created by axis_create
or axis_from_spn
. Used with pitch_invert
.
Alternative Representations
Section titled “Alternative Representations”The following types store alternative representations of pitch data. They correspond more closely with natural language, and can therefore potentially be useful as:
- An intermediate type on the way to pretty printing information about a group of musical objects to the end user.
- An intermediate type on the way to rendering standard notation.
- An intermediate parsing target from plaintext before converting into
Pitch
orInterval
vectors.
StandardPitch
Section titled “StandardPitch”The StandardPitch
type stores pitches in effectively the same fashion as Scientific Pitch Notation: as a triple of letter
, accidental
, and octave
.
typedef struct { int letter; int accidental; int octave;} StandardPitch;
Created with pitch_to_standard
from a regular Pitch
. More rarely parsed into a Pitch
using pitch_from_standard
.