A macro package for simplifying composition on Mathematica
git clone [email protected]:Genius-Society/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: 我们使用向量和数字来代替复杂的 SoundNote[] 系列函数。 经简化后的一首完整歌曲格式如下:
track1 = {
{params of section 1}, (*{片段1参数}*)
{notes of section 1}, (*{片段1乐谱}*)
{params of section 2}, (*{片段2参数}*)
{notes of section 2}, (*{片段2乐谱}*)
...
{params of section m}, (*{片段m参数}*)
{notes of section m} (*{片段m乐谱}*)
};
track2 = {
{params of section 1}, (*{片段1参数}*)
{notes of section 1}, (*{片段1乐谱}*)
{params of section 2}, (*{片段2参数}*)
{notes of section 2}, (*{片段2乐谱}*)
...
{params of section n}, (*{片段n参数}*)
{notes of section n} (*{片段n乐谱}*)
};
...
player[track1, soundfont1, track2, soundfont2, ...]
(*player[track1, 音色1, track2, 音色2, ...]*)
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: 一个片段由参数域和乐谱域组成,参数域包含4个必要参数(音调、中心音、移调、速度)和一个可选参数(音量 或 音量变化);其中参数域遵循以下规则:
Format 格式 |
Remark 符号 |
---|---|
{m, c, s, t} | m is 0(major) or 1(minor) 为大小调(0大调,1小调); c is central note integer 为中心音 ([0, 11]); s is transposing(The whole piece moves up s semitones) 为移调(片段整体移动s个半音); 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 (音量从 vs 渐变到 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: 对于乐谱域的音符,12音模式使用起来并不方便,一旦调性固定,可将其转为7音模式:
Please refer to the demo code Demo_BWV-1079.nb or visit our song library https://mathmusic.netlify.app for more details; Before compiling songs, please run the macro package first. 可参考示例代码 Demo_BWV-1079.nb 或浏览 我的Mathematica音乐库 来弄清具体用法; 生成乐谱之前请先运行 mathematica_music_pack.nb
Besides, the e-piano.nb
is a piano keyboard UI, you can play it as a virtual piano on Mathematica.
另外,e-piano.nb
是一个编写于 Mathematica 上的钢琴键盘,可作为虚拟钢琴来弹奏。