A macro package for simplifying composition on Mathematica
git clone git@github.com:MuGeminorum/Mathematica-Music-Pack.git
cd Mathematica-Music-Pack
We use vectors and numbers to replace complicated SoundNote[] functions. A complete song has many sections, its format is as follow:
track1 = {
{params of section 1},
{notes of section 1},
{params of section 2},
{notes of section 2},
...
{params of section m},
{notes of section m}
};
track2 = {
{params of section 1},
{notes of section 1},
{params of section 2},
{notes of section 2},
...
{params of section n},
{notes of section n}
};
...
player[track1, soundfont1, track2, soundfont2, ...]
One section consists of an info part and a note part, the info part includes 4 required params(tonality, central note, transposition, tempo) and one optional param(volume number or volume change vector); While the note part contains melodies and chords. The info part follows below format rules:
Format |
Remark |
---|---|
{m, c, s, t} | m is 0(major) or 1(minor); c is central note integer([0, 11]); s is transferring(The whole piece moves up s semitones); t is tempo(the number = a quarter note); |
{m, c, s, t, v} | v is volume([0, 1]); |
{m, c, s, t, {vs, vt}} | Volume fades from vs to vt |
The central note list is as follow:
C | C#/Db | D | Eb/D# | E | F | F#/Gb | G | Ab/G# | A | Bb/A# | B |
---|---|---|---|---|---|---|---|---|---|---|---|
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
The note part has melodies and chords, which consists of different kinds of notes:
Effect | Format | Remark |
---|---|---|
Rest | {l} | l is duration; |
Tone | {n, l} | n is note value; |
Chord | {{n1, n2, ...}, l} | nk are chord note values; |
Staccato | {n, {l1, l2}} | l1 is real duration, l2 is duration ratio; |
Vibrato | {{n1, n2}, l1, tn} | tn is trill number; |
Arpeggio | {{n1, n2, ...}, l1, l2} | l2 is duration ratio; |
Tenuto | {bottom note, top notes} | Bottom note can be a tone or a chord, top notes consist of any above type. |
With these rules, we can get a concise format of notes.
For notes in the note part, 12-note scheme is unfriendly to us, it can be transferred into 7-note scheme once the tonality is fixed:
Please refer to the demo code Demo_BWV-1079.nb or visit our song library https://mugeminorum.github.io/Mathematica-Music-Pack for more details; Before compiling songs, please run the macro package first.
Besides, the e-piano.nb
is a piano keyboard UI, you can play it as a virtual piano on Mathematica.