Skip to content

Installation

Currently there are three implementations of Meantonal: one in JavaScript, one in Python and one in C.

Just run the following command in your project directory to get started:

npm install meantonal

You’re now ready to import and use Meantonal’s classes.

import { SPN, Helmholtz, Interval, TonalContext, MirrorAxis } from "meantonal";
let p = SPN.toPitch("C4");
let q = Helmholtz.toPitch("e'");
let m = p.intervalTo(q); // M3
let n = Interval.fromName("M3");
m.isEqual(n); // true
let context = TonalContext.fromStrings("Eb", "major");
q = q.snapDiatonic(context); // q has now snapped to Eb4
let axis = MirrorAxis.fromSPN("D4", "A4"));
q = q.invert(axis); // q is now G#4

Install the meantonal package from PyPI:

pip install meantonal

You’re now ready to import and use Meantonal’s classes.

from meantonal import SPN, Helmholtz, Interval, TonalContext, MirrorAxis
p = SPN.to_pitch("C4")
q = Helmholtz.to_pitch("e'")
m = p.interval_to(q) # M3
n = Interval.from_name("M3")
m.is_equal(n) # True
context = TonalContext.from_strings("Eb", "major")
q = q.snap_to(context) # q has now snapped to Eb4
axis = MirrorAxis.from_spn("D4", "A4")
q = q.invert(axis) # q is now G#4

Since pitches and intervals are just vectors, the Python implementation also supports natural arithmetic on them directly, in the style of datetime/timedelta:

p = SPN.to_pitch("C4")
m = Interval.from_name("M3")
q = p + m # E4
q - p # M3

Adding Meantonal to a C project is as simple as copying the meantonal.h header file somewhere into your project’s directory, which can be done via the following bash script:

curl https://meantonal.org/meantonal.h > meantonal.h

You must #define MEANTONAL in exactly one file before the first inclusion of meantonal.h:

foo.c
#include <stdlib.h>
#define MEANTONAL
#include "meantonal.h"
Pitch c4, e4; // declares but does not assign values to two Pitch vectors
Pitch g4 = { 28, 11 }; // directly initialises a Pitch
// assigning values
if (pitch_from_spn("C4", &c4)) {
fprintf(stderr, "error parsing pitch from SPN");
exit(EXIT_FAILURE);
}
if (pitch_from_spn("E4", &e4)) {
fprintf(stderr, "error parsing pitch from SPN");
exit(EXIT_FAILURE);
}
Interval M3 = interval_between(c4, e4); // creates a major 3rd Interval vector
Interval P5 = interval_between(c4, g5); // creates a perfect 5th interval vector
// etc.

After that, just include meantonal.h in any other files as needed.

bar.c
#include <stdlib.h>
#include "meantonal.h"
Pitch p;
if (pitch_from_spn("E4", &p)) {
fprintf(stderr, "error parsing pitch from SPN");
exit(EXIT_FAILURE);
}
MirrorAxis a;
if (axis_from_spn("C4", "G4")) {
fprintf(stderr, "error parsing pitch(es) from SPN when creating MirrorAxis");
exit(EXIT_FAILURE);
}
pitch_invert(p, a); // p has been inverted about the axis to Eb4
// etc.