lilypond-0.1.14
[lilypond.git] / src / midi-parser.y
blob466b5c58d53abb7fe68d521031dffc759b162c1a
1 %{
3 #include <iostream.h>
5 #include "proto.hh" // ugh, these all for midi-main.hh
6 #include "plist.hh"
7 #include "string.hh"
8 #include "sourcefile.hh"
9 #include "source.hh"
10 #include "midi-main.hh" // *tors
12 #include "my-midi-lexer.hh"
13 #include "my-midi-parser.hh"
14 #include "moment.hh"
15 #include "duration.hh"
16 #include "midi-event.hh"
17 #include "midi-track.hh"
18 #include "midi-score.hh"
20 #ifndef NDEBUG
21 #define YYDEBUG 1
22 #endif
24 //ugh
25 static track_i = 0;
29 %union {
30 Byte byte;
31 char c;
32 int i;
33 String* str_p;
34 Request* request_p;
35 Midi_event* midi_event_p; // Voice_element* ?
36 Midi_score* midi_score_p; // Input_score* ?
37 Midi_track* midi_track_p; // Input_music* ?
40 %token HEADER TRACK
41 %token SYSEX_EVENT1 SYSEX_EVENT2
42 %token META_EVENT
43 %token SEQUENCE TEXT COPYRIGHT TRACK_NAME INSTRUMENT_NAME LYRIC MARKER CUE_POINT
44 %token END_OF_TRACK TEMPO SMPTE_OFFSET TIME KEY SSME
46 %token<i> INT8 INT16 INT32 INT7_8UNSET INT7_8SET VARINT
47 %token<i> RUNNING_STATUS DATA_ENTRY ALL_NOTES_OFF
48 %token<i> NOTE_OFF NOTE_ON
49 %token<i> POLYPHONIC_AFTERTOUCH CONTROLMODE_CHANGE PROGRAM_CHANGE
50 %token<i> CHANNEL_AFTERTOUCH PITCHWHEEL_RANGE
51 %token<str_p> DATA
53 %type <i> varint
54 %type <midi_score_p> header midi_score
55 %type <midi_track_p> track
56 %type <midi_event_p> event
57 %type <midi_event_p> the_event meta_event the_meta_event text_event midi_event sysex_event
58 %type <midi_event_p> running_status data_entry all_notes_off
59 %type <midi_event_p> note_off note_on
60 %type <midi_event_p> polyphonic_aftertouch controlmode_change program_change
61 %type <midi_event_p> channel_aftertouch pitchwheel_range
65 midi: /* empty */
66 | midi midi_score {
67 midi_parser_l_g->add_score( $2 );
68 track_i = 0;
72 midi_score:
73 header {
75 | midi_score track {
76 $$->add_track( $2 );
77 midi_parser_l_g->reset();
81 header:
82 HEADER INT32 INT16 INT16 INT16 {
83 $$ = new Midi_score( $3, $4, $5 );
84 midi_parser_l_g->set_division_4( $5 );
88 track:
89 TRACK INT32 {
90 $$ = new Midi_track( track_i++ );
92 | track event {
93 $$->add_event( midi_parser_l_g->mom(), $2 );
97 event:
98 varint the_event {
99 $$ = $2;
100 if ( $2 && $2->mudela_str().length_i() )
101 dtor << $2->mudela_str() << " " << flush;
105 varint:
106 VARINT {
107 midi_parser_l_g->forward( $1 );
111 the_event:
112 meta_event {
114 | midi_event {
116 | sysex_event {
120 meta_event:
121 META_EVENT the_meta_event {
122 $$ = $2;
125 META_EVENT INT8 INT8 INT8 {
126 $$ = 0;
130 the_meta_event:
131 SEQUENCE INT16 {
133 | text_event DATA {
134 $$ = 0;
135 dtor << *$2 << endl;
136 delete $2;
138 | END_OF_TRACK {
139 $$ = 0;
141 | TEMPO INT8 INT8 INT8 {
142 $$ = new Midi_tempo( ( $2 << 16 ) + ( $3 << 8 ) + $4 );
143 dtor << $$->mudela_str() << endl; // ?? waai not at event:
144 midi_parser_l_g->set_tempo( ( $2 << 16 ) + ( $3 << 8 ) + $4 );
146 | SMPTE_OFFSET INT8 INT8 INT8 INT8 INT8 {
147 $$ = 0;
149 | TIME INT8 INT8 INT8 INT8 {
150 $$ = new Midi_time( $2, $3, $4, $5 );
151 dtor << $$->mudela_str() << endl; // ?? waai not at event:
152 midi_parser_l_g->set_time( $2, $3, $4, $5 );
154 | KEY INT8 INT8 {
155 $$ = new Midi_key( $2, $3 );
156 midi_parser_l_g->set_key( $2, $3 );
158 | SSME DATA {
159 $$ = 0;
160 delete $2;
164 text_event:
165 TEXT {
166 dtor << "\n% Text: ";
168 | COPYRIGHT {
169 dtor << "\n% Copyright: ";
171 | TRACK_NAME {
172 dtor << "\n% Track name: ";
174 | INSTRUMENT_NAME {
175 dtor << "\n% Instrument name: ";
177 | LYRIC {
178 dtor << "\n% Lyric: ";
180 | MARKER {
181 dtor << "\n% Marker: ";
183 | CUE_POINT {
184 dtor << "\n% Cue point: ";
188 midi_event:
189 running_status {
191 | data_entry {
193 | all_notes_off {
195 | note_off {
197 | note_on {
199 | polyphonic_aftertouch {
201 | controlmode_change {
203 | program_change {
205 | channel_aftertouch {
207 | pitchwheel_range {
211 running_status:
212 RUNNING_STATUS INT8 { //INT8 {
213 $$ = 0;
217 data_entry:
218 DATA_ENTRY INT8 {
219 $$ = 0;
223 all_notes_off:
224 ALL_NOTES_OFF INT8 INT8 {
225 $$ = 0;
229 note_off:
230 NOTE_OFF INT8 INT8 {
231 int i = $1;
232 i = i & ~0x80;
233 $$ = midi_parser_l_g->note_end_midi_event_p( $1 & ~0x80, $2, $3 );
237 note_on:
238 NOTE_ON INT8 INT8 {
239 int i = $1;
240 i = i & ~0x90;
241 $$ = 0;
242 midi_parser_l_g->note_begin( $1 & ~0x90, $2, $3 );
246 polyphonic_aftertouch:
247 POLYPHONIC_AFTERTOUCH INT8 INT8 {
248 $$ = 0;
252 controlmode_change:
253 CONTROLMODE_CHANGE INT8 INT8 {
254 $$ = 0;
258 program_change:
259 PROGRAM_CHANGE INT8 {
260 $$ = 0;
264 channel_aftertouch:
265 CHANNEL_AFTERTOUCH INT8 INT8 {
266 $$ = 0;
270 pitchwheel_range:
271 PITCHWHEEL_RANGE INT8 INT8 {
272 $$ = 0;
276 sysex_event:
277 SYSEX_EVENT1 DATA {
278 $$ = 0;
280 | SYSEX_EVENT2 DATA { // INT8 ?
281 $$ = 0;