-
Notifications
You must be signed in to change notification settings - Fork 14
/
midi.grammar
299 lines (293 loc) · 16.3 KB
/
midi.grammar
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
<?xml version="1.0" encoding="UTF-8"?>
<ufwb version="1.17">
<grammar name="MIDI" start="id:7" author="Nicolas Kniebihler" fileextension="mid, kipr" uti="public.midi-audio" complete="yes">
<description>Grammar for MIDI and .kipr files, inspired by Andreas Pehnack's work.</description>
<structure name="MIDI file" id="7" length="0" encoding="ISO_8859-1:1987" endian="big" signed="no">
<structref name="Header Chunk" id="9" structure="id:8"/>
<structref name="Track Chunk" id="11" repeatmax="numberOfTracks" structure="id:10"/>
</structure>
<structure name="Chunk" id="13" length="chunkSize+8" encoding="ISO_8859-1:1987" endian="big" signed="no">
<string name="chunkID" mustmatch="yes" id="14" type="fixed-length" length="4">
<fixedvalues>
<fixedvalue name="MThd" value="MThd"/>
</fixedvalues>
</string>
<number name="chunkSize" id="15" type="integer" length="4"/>
</structure>
<structure name="Header Chunk" id="8" extends="id:13">
<number name="formatType" id="19" type="integer" length="2"/>
<number name="numberOfTracks" id="20" type="integer" length="2"/>
<number name="timeDivision" id="21" type="integer" length="2"/>
</structure>
<structure name="Track Chunk" id="10" extends="id:13">
<string name="chunkID" id="23" type="fixed-length" length="4">
<fixedvalues>
<fixedvalue name="MTrk" value="MTrk"/>
</fixedvalues>
</string>
<structure name="trackData" id="24" length="0" repeatmax="-1" order="variable">
<structref name="MetaData" id="27" repeatmin="0" repeatmax="-1" structure="id:26"/>
<structref name="NoteOffEvent" id="29" repeatmin="0" repeatmax="-1" structure="id:28"/>
<structref name="NoteOnEvent" id="31" repeatmin="0" repeatmax="-1" structure="id:30"/>
<structref name="Aftertouch" id="33" repeatmin="0" repeatmax="-1" structure="id:32"/>
<structref name="Control Change" id="35" repeatmin="0" repeatmax="-1" structure="id:34"/>
<structref name="Program Change" id="37" repeatmin="0" repeatmax="-1" structure="id:36"/>
<structref name="Canal Pressure" id="39" repeatmin="0" repeatmax="-1" structure="id:38"/>
<structref name="Pitch Wheel Change" id="41" repeatmin="0" repeatmax="-1" structure="id:40"/>
<structref name="Message" id="43" repeatmin="0" repeatmax="-1" structure="id:42"/>
</structure>
</structure>
<structure name="MetaData" id="26" encoding="ISO_8859-1:1987" endian="big" signed="no">
<structref name="deltaTime" id="47" structure="id:46"/>
<binary name="header" mustmatch="yes" id="48" length="1">
<fixedvalues>
<fixedvalue name="<unnamed>" value="FF"/>
</fixedvalues>
</binary>
<binary name="type" mustmatch="yes" id="49" length="1">
<fixedvalues>
<fixedvalue name="Sequence Number" value="00"/>
<fixedvalue name="Text Event" value="01"/>
<fixedvalue name="Copyright Notice" value="02"/>
<fixedvalue name="Sequence Name" value="03"/>
<fixedvalue name="Instrument Name" value="04"/>
<fixedvalue name="Lyric/Display" value="05"/>
<fixedvalue name="Marker text" value="06"/>
<fixedvalue name="Cue Point" value="07"/>
<fixedvalue name="Program Name" value="08"/>
<fixedvalue name="Peripheric Name" value="09"/>
<fixedvalue name="MIDI Channel Prefix" value="20"/>
<fixedvalue name="MIDI Port" value="21"/>
<fixedvalue name="End of Track" value="2F"/>
<fixedvalue name="Tempo Setting" value="51"/>
<fixedvalue name="SMPTE Offset" value="54"/>
<fixedvalue name="Time Signature" value="58"/>
<fixedvalue name="Key Signature" value="59"/>
<fixedvalue name="Sequencer Specific Event" value="7F"/>
</fixedvalues>
</binary>
<number name="length" id="50" type="integer" length="1"/>
<binary name="data" id="51" length="length"/>
</structure>
<structure name="Event" id="53" encoding="ISO_8859-1:1987" endian="big" signed="no">
<structref name="deltaTime" id="54" structure="id:46"/>
<binary name="type" mustmatch="yes" id="55" length="4" lengthunit="bit">
<fixedvalues>
<fixedvalue name="<unnamed>" value="08"/>
<fixedvalue name="<unnamed>" value="09"/>
<fixedvalue name="<unnamed>" value="0A"/>
<fixedvalue name="<unnamed>" value="0B"/>
<fixedvalue name="<unnamed>" value="0C"/>
<fixedvalue name="<unnamed>" value="0D"/>
<fixedvalue name="<unnamed>" value="0E"/>
</fixedvalues>
</binary>
<number name="canal" id="56" type="integer" length="4" lengthunit="bit"/>
<structure name="data" id="57"/>
</structure>
<structure name="NoteOffEvent" id="28" extends="id:53">
<binary name="type" id="61">
<fixedvalues>
<fixedvalue value="08"/>
</fixedvalues>
</binary>
<structure name="data" id="62">
<number name="note" id="64" type="integer" length="1"/>
<number name="velocity" id="65" type="integer" length="1"/>
<structure name="repeat" id="66" length="0" alignment="0" repeatmin="0" repeatmax="-1">
<structref name="deltaTime" id="67" structure="id:46"/>
<binary name="repeatBit" mustmatch="yes" id="68" length="1" lengthunit="bit">
<fixedvalues>
<fixedvalue name="<unnamed>" value="00"/>
</fixedvalues>
</binary>
<number name="note" id="69" type="integer" length="7" lengthunit="bit"/>
<number name="velocity" id="70" type="integer" length="1"/>
</structure>
</structure>
</structure>
<structure name="NoteOnEvent" id="30" extends="id:53">
<binary name="type" id="75">
<fixedvalues>
<fixedvalue value="09"/>
</fixedvalues>
</binary>
<structure name="data" id="76">
<number name="note" id="78" type="integer" length="1"/>
<number name="velocity" id="79" type="integer" length="1"/>
<structure name="repeat" id="80" repeatmin="0" repeatmax="-1">
<structref name="deltaTime" id="81" structure="id:46"/>
<binary name="repeatBit" mustmatch="yes" id="82" length="1" lengthunit="bit">
<fixedvalues>
<fixedvalue name="<unnamed>" value="00"/>
</fixedvalues>
</binary>
<number name="note" id="83" type="integer" length="7" lengthunit="bit"/>
<number name="velocity" id="84" type="integer" length="1"/>
</structure>
</structure>
</structure>
<structure name="Aftertouch" id="32" extends="id:53">
<binary name="type" id="89">
<fixedvalues>
<fixedvalue value="0A"/>
</fixedvalues>
</binary>
<structure name="data" id="90">
<number name="note" id="92" type="integer" length="1"/>
<number name="vibrato" id="93" type="integer" length="1"/>
</structure>
</structure>
<structure name="Control Change" id="34" extends="id:53">
<binary name="type" id="97">
<fixedvalues>
<fixedvalue name="<unnamed>" value="0B"/>
</fixedvalues>
</binary>
<structure name="data" id="98">
<binary name="type" id="100" length="1">
<fixedvalues>
<fixedvalue name="Bank Select" value="00"/>
<fixedvalue name="Modulation Wheel" value="01"/>
<fixedvalue name="Breath Controller" value="02"/>
<fixedvalue name="Foot Controller" value="04"/>
<fixedvalue name="Portamento Time" value="05"/>
<fixedvalue name="Data Entry MSB" value="06"/>
<fixedvalue name="Channel Volume" value="07"/>
<fixedvalue name="Balance" value="08"/>
<fixedvalue name="Pan" value="0A"/>
<fixedvalue name="Expression Controller" value="0B"/>
<fixedvalue name="Effect Control 1" value="0C"/>
<fixedvalue name="Effect Control 2" value="0D"/>
<fixedvalue name="General Purpose 1" value="10"/>
<fixedvalue name="General Purpose 2" value="11"/>
<fixedvalue name="General Purpose 3" value="12"/>
<fixedvalue name="General Purpose 4" value="13"/>
<fixedvalue name="Damper Pedal" value="40"/>
<fixedvalue name="Portamento On/Off" value="41"/>
<fixedvalue name="Sostenuto On/Off" value="42"/>
<fixedvalue name="Soft Pedal On/Off" value="43"/>
<fixedvalue name="Legato Footswitch" value="44"/>
<fixedvalue name="Hold 2" value="45"/>
<fixedvalue name="Sound Variation" value="46"/>
<fixedvalue name="Timber/Harmonic Intens" value="47"/>
<fixedvalue name="Release Time" value="48"/>
<fixedvalue name="Attack Time" value="49"/>
<fixedvalue name="Brightness" value="4A"/>
<fixedvalue name="Decay Time" value="4B"/>
<fixedvalue name="Vibrato Rate" value="4C"/>
<fixedvalue name="Vibrato Depth" value="4D"/>
<fixedvalue name="Vibrato Delay" value="4E"/>
<fixedvalue name="Portamento Control" value="54"/>
<fixedvalue name="High Resolution Velocity Prefix" value="58"/>
<fixedvalue name="Reverb Send Level" value="5B"/>
<fixedvalue name="Tremolo Depth" value="5C"/>
<fixedvalue name="Chorus Send Level" value="5D"/>
<fixedvalue name="Detune Depth" value="5E"/>
<fixedvalue name="Phaser Depth" value="5F"/>
<fixedvalue name="Data Increment +1" value="60"/>
<fixedvalue name="Data Increment -1" value="61"/>
<fixedvalue name="NRPN - LSB" value="62"/>
<fixedvalue name="NRPN - MSB" value="63"/>
<fixedvalue name="RPN - LSB" value="64"/>
<fixedvalue name="RPN - MSB" value="65"/>
<fixedvalue name="All Sound Off" value="78"/>
<fixedvalue name="Reset All Controllers" value="79"/>
<fixedvalue name="Local Control On/Off" value="7A"/>
<fixedvalue name="All Notes Off" value="7B"/>
<fixedvalue name="Omni Mode Off" value="7C"/>
<fixedvalue name="Omni Mode On" value="7D"/>
<fixedvalue name="Mono Mode On" value="7E"/>
<fixedvalue name="Poly Mode On" value="7F"/>
</fixedvalues>
</binary>
<number name="value" id="101" type="integer" length="1"/>
</structure>
</structure>
<structure name="Program Change" id="36" extends="id:53">
<binary name="type" id="105">
<fixedvalues>
<fixedvalue name="<unnamed>" value="0C"/>
</fixedvalues>
</binary>
<structure name="data" id="106">
<number name="instrument" id="108" type="integer" length="1"/>
</structure>
</structure>
<structure name="Canal Pressure" id="38" extends="id:53">
<binary name="type" id="112">
<fixedvalues>
<fixedvalue value="0D"/>
</fixedvalues>
</binary>
<structure name="data" id="113">
<number name="vibrato" id="115" type="integer" length="1"/>
</structure>
</structure>
<structure name="Pitch Wheel Change" id="40" extends="id:53">
<binary name="type" id="119">
<fixedvalues>
<fixedvalue value="0E"/>
</fixedvalues>
</binary>
</structure>
<structure name="deltaTime" id="46" length="0" encoding="ISO_8859-1:1987" endian="big" signed="no">
<structref name="deltaTimeHigh" id="125" repeatmin="0" repeatmax="3" structure="id:124"/>
<structref name="deltaTimeLow" id="127" structure="id:126"/>
</structure>
<structure name="deltaTimeLow" id="126" length="1" encoding="ISO_8859-1:1987" endian="big" signed="no">
<binary name="bit" mustmatch="yes" id="129" length="1" lengthunit="bit">
<fixedvalues>
<fixedvalue name="<unnamed>" value="00"/>
</fixedvalues>
</binary>
<number name="time" id="130" type="integer" length="7" lengthunit="bit"/>
</structure>
<structure name="deltaTimeHigh" id="124" length="1" alignment="0" encoding="ISO_8859-1:1987" endian="big" signed="no">
<binary name="bit" mustmatch="yes" id="132" length="1" lengthunit="bit">
<fixedvalues>
<fixedvalue name="<unnamed>" value="01"/>
</fixedvalues>
</binary>
<number name="time" id="133" type="integer" length="7" lengthunit="bit"/>
</structure>
<structure name="Message" id="42" repeatmax="-1" encoding="ISO_8859-1:1987" endian="big" signed="no">
<structref name="deltaTime" id="135" structure="id:46"/>
<binary name="header" mustmatch="yes" id="136" length="1">
<fixedvalues>
<fixedvalue value="F0"/>
</fixedvalues>
</binary>
<structref name="length" id="137" structure="id:46"/>
<scriptelement name="data" id="138">
<script name="unnamed" type="Generic">
<source language="Python">results = currentMapper.getCurrentResults()
lastResult = results.getLastResult()
time = lastResult.getValue().getUnsignedNumber()
lastResult = results.getPrevResult(lastResult) # bit
lastResult = results.getPrevResult(lastResult) # deltaTimeLow
multiplicator = 128
lastResult = results.getPrevResult(lastResult)
previousResultName = lastResult.getName()
while previousResultName == "time":
highTime = lastResult.getValue().getUnsignedNumber()
time += highTime * multiplicator
multiplicator *= 128
lastResult = results.getPrevResult(lastResult) # bit
lastResult = results.getPrevResult(lastResult) # deltaTimeHigh
lastResult = results.getPrevResult(lastResult)
previousResultName = lastResult.getName()
debugLog("!!!!!!! time=" + str(time))
grammar = currentMapper.getCurrentGrammar()
structure = grammar.getStructureByName("Elements")
element = structure.getElementByName("MessageData")
currentMapper.mapElementWithSize(element, time)
</source>
</script>
</scriptelement>
</structure>
<structure name="Elements" id="140" encoding="ISO_8859-1:1987" endian="big" signed="no">
<binary name="MessageData" id="141" length="remaining"/>
</structure>
</grammar>
</ufwb>