Installation
Currently there are two implementations of Meantonal: one in JavaScript and one in C.
JavaScript
Section titled “JavaScript”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); // 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#4
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
:
#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.