# Yesterday You Said Tomorrow

0%

## Get Hands Dirty !

MIDI，Musical Instrument Digital Interface，乐器数字接口 ，是20 世纪80 年代初为解决电声乐器之间的通信问题而提出的。MIDI是编曲界最广泛的音乐标准格式，可称为「计算机能理解的乐谱」。它用音符的数字控制信号来记录音乐。

### MIDI File Format

MIDI 文件是由一系列的 chunk组成的，每个 chunk 的组成格式如下：

type length data
4 bytes 4 bytes length bytes

• Header Trunks，也就是 MThd类型
• Track Chunks，也就是 MTrk类型

• format
• tracks

指在这个 MIDI 文件中有多少个 Track chunks

• division

指定基本时间格式，根据最高位的不同，这两个字节有不同的含义。

• bit 15 = 0:

• bits 0-14
number of delta-time units in each a quarter-note.
• bit 15 = 1:

• bits 0-7
number of delta-time units per SMTPE frame

• bits 8-14
form a negative number, representing the number of SMTPE frames per second. Valid values correspond to those in the MTC Quarter Frame message.

#### Track Chunk

MTrk event的组成很简单，由delta timeevent组成。

<delta-time> is stored as a variable-length quantity. It represents the amount of time before the following event. If the first event in a track occurs at the very beginning of a track, or if two events occur simultaneously, a delta-time of zero is used. Delta-times are always present. (Not storing delta-times of 0 requires at least two bytes for any other value, and most delta-times aren’t zero.) Delta-time is in some fraction of a beat (or a second, for recording a track with SMPTE times), as specified in the header chunk.

• MIDI event：指 MIDI 通道信息，也是描述 MIDI 音乐的主要部分，参见下小节
• Sysex event：指系统控制信息，参见这里
• Meta event：主要记录一些元信息，包括版权信息、歌词、乐器名等，参见这里

### MIDI Messages

MIDI Messages可以分为两大类，专门用于某个特定 MIDI 通道的消息称为Channel Messages，而有些消息会影响到整个MIDI 系统（或者至少整个 MIDI 设备），称作 System Messages，系统消息不会和某个特定通道有关系。更加详细的可以分为以下几类：

• A Status Byte，一个状态字节
range: 0x80..FF
• Zero or more Data Bytes，0 或多个数据字节
range: 0x00..7F

• MIDI Note

Octave # C C# D D# E F F# G G# A A# B
-1 0 1 2 3 4 5 6 7 8 9 10 11
0 12 13 14 15 16 17 18 19 20 21 22 23
1 24 25 26 27 28 29 30 31 32 33 34 35
2 36 37 38 39 40 41 42 43 44 45 46 47
3 48 49 50 51 52 53 54 55 56 57 58 59
4 60 61 62 63 64 65 66 67 68 69 70 71
5 72 73 74 75 76 77 78 79 80 81 82 83
6 84 85 86 87 88 89 90 91 92 93 94 95
7 96 97 98 99 100 101 102 103 104 105 106 107
8 108 109 110 111 112 113 114 115 116 117 118 119
9 120 121 122 123 124 125 126 127

• Program Change

PC# Family PC# Family
1-8 Piano 65-72 Reed
9-16 Chromatic Percussion 73-80 Pipe
33-40 Bass 97-104 Synth Effects
41-48 Strings 105-112 Ethnic
49-56 Ensemble 113-120 Percussive
57-64 Brass 121-128 Sound Effects

## Brute Force

Now you might say what consititutes a melody ?

We were initially going to take the entire piano keyboard and to do the all at the entire piano keyboard. But let’s focus on the vocal range which is actually 2 octaves and we thought actually we’re thinking about pop music, which is the only thing that makes money that people sue over, doesn’t go to octaves. It goes a single octave so that’s what we landed on eight notes.

Now you might say how may notes consititutes a melody ?

So we looked at musicologists…and we landed at twelve notes.

Damien Riehl做了一个很巧妙的范围缩小，通过将研究目标锁定到人可歌唱的流行音乐，我们得出结论

• 一个旋律的每个音符通常只有 8 种选择，比如 C 大调，do re mi fa so la ti do
• 只需要 12 个音符即可组成几乎所有的旋律。
• 那么在这种情况下，有 $8^{12} = 68.7 million$ 种可能。

• 输入是一段 C:4,C:4,D:4,E:4,F:4,G:5序列，这里一共有 6 个 Note，说的是我们遍历的时候所有可以的选择
• 然后我们会传递一个 length 参数，比如这里传递的参数是 8
• 输出是一个有 8 个音符的旋律，每个音符可以有 6 种选择，这 6 种来自 C:4,C:4,D:4,E:4,F:4,G:5序列
• 那么，我们可以产生 $6^8$ 种遍历可能

Maybe melodies are just math which is just facts, which maybe are not copyrightable. If somebody is suing over a melody alone, not lyrics, not recordings, but just melody alone, maybe those cases go away.