Installation
Currently there are three implementations of Meantonal: one in JavaScript, one in Python and one in C.
JavaScript
Section titled “JavaScript”Just run the following command in your project directory to get started:
npm install meantonalYou’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); // M3let 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#4Python
Section titled “Python”Install the meantonal package from PyPI:
pip install meantonalYou’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) # M3n = 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#4Since 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 # E4q - p # M3Adding 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.hYou must #define MEANTONAL in exactly one file before the first inclusion of meantonal.h:
#include <stdlib.h>
#define MEANTONAL#include "meantonal.h"
Pitch c4, e4; // declares but does not assign values to two Pitch vectorsPitch g4 = { 28, 11 }; // directly initialises a Pitch// assigning valuesif (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 vectorInterval P5 = interval_between(c4, g5); // creates a perfect 5th interval vector
// etc.After that, just include meantonal.h in any other files as needed.
#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.