-
Notifications
You must be signed in to change notification settings - Fork 0
/
meta.v
198 lines (195 loc) · 2.94 KB
/
meta.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
module vmidi
struct SequenceNumber {
delta_time u64
msb byte
lsb byte
}
struct TextEvent {
delta_time u64
text string
}
struct CopyrightNotice {
delta_time u64
text string
}
struct TrackName {
delta_time u64
text string
}
struct InstrumentName {
delta_time u64
text string
}
struct Lyrics {
delta_time u64
text string
}
struct Marker {
delta_time u64
text string
}
struct CuePoint {
delta_time u64
text string
}
struct DeviceName {
delta_time u64
text string
}
struct MidiChannelPrefix {
delta_time u64
channel byte
}
struct EndOfTrack {
delta_time u64
}
struct SetTempo {
delta_time u64
microseconds int
}
struct SMPTEOffset {
delta_time u64
hour byte
min byte
sec byte
fr byte
subfr byte
}
struct TimeSignature {
delta_time u64
numer byte
denom byte
metro byte
nds byte
}
struct KeySignature {
delta_time u64
key byte
scale byte
}
struct SequencerSpecific {
delta_time u64
data []byte
}
fn read_meta(file []byte, mut index_track &int, delta_time u64) ?TrkData {
mut index := (*index_track) + 1
meta_type := file[index]
index++
length := get_variable_length_value(file, mut &index)
data := subarray(file, index, index + int(length))
index += int(length)
mut meta := TrkData{}
match meta_type {
0x00 {
meta = SequenceNumber {
delta_time: delta_time
msb: data[0]
lsb: data[1]
}
}
0x01 {
meta = TextEvent {
delta_time: delta_time
text: data.bytestr()
}
}
0x02 {
meta = CopyrightNotice {
delta_time: delta_time
text: data.bytestr()
}
}
0x03 {
meta = TrackName {
delta_time: delta_time
text: data.bytestr()
}
}
0x04 {
meta = InstrumentName {
delta_time: delta_time
text: data.bytestr()
}
}
0x05 {
meta = Lyrics {
delta_time: delta_time
text: data.bytestr()
}
}
0x06 {
meta = Marker {
delta_time: delta_time
text: data.bytestr()
}
}
0x07 {
meta = CuePoint {
delta_time: delta_time
text: data.bytestr()
}
}
0x09 {
meta = DeviceName {
delta_time: delta_time
text: data.bytestr()
}
}
0x20 {
meta = MidiChannelPrefix {
delta_time: delta_time
channel: data[0]
}
}
0x21 { // Obsolete MIDI Port
}
0x2f {
meta = EndOfTrack {}
delta_time: delta_time
}
0x51 {
meta = SetTempo {
delta_time: delta_time
microseconds: byte_to_int(data)
}
}
0x54 {
meta = SMPTEOffset {
delta_time: delta_time
hour: data[0]
min: data[1]
sec: data[2]
fr: data[3]
subfr: data[4]
}
}
0x58 {
meta = TimeSignature {
delta_time: delta_time
numer: data[0]
denom: data[1]
metro: data[2]
nds : data[3]
}
}
0x59 {
meta = KeySignature {
delta_time: delta_time
key: data[0]
scale: data[1]
}
}
0x7f {
meta = SequencerSpecific {
delta_time: delta_time
data: data
}
}
else {
println('UNKNOWN META ${meta_type.hex()}')
// return none
}
}
(*index_track) = index
return meta
}