lilypond-0.1.9
[lilypond.git] / m2m / midi-parser.y
blob297b9facd8204fa8a678c588b03006ef9a90a0f2
1 %{
3 #include "m2m.hh"
5 #ifndef NDEBUG
6 #define YYDEBUG 1
7 #endif
9 %}
11 %union {
12 Byte byte;
13 char c;
14 int i;
15 String* str_p;
16 Request* request_p;
17 Midi_event* midi_event_p; // Voice_element* ?
18 Midi_score* midi_score_p; // Input_score* ?
19 Midi_track* midi_track_p; // Input_music* ?
22 %token HEADER TRACK
23 %token SYSEX_EVENT1 SYSEX_EVENT2
24 %token META_EVENT
25 %token SEQUENCE
26 %token END_OF_TRACK TEMPO SMPTE_OFFSET TIME KEY SSME
28 %token<i> INT8 INT16 INT32 INT7_8UNSET INT7_8SET VARINT
29 %token<i> RUNNING_STATUS DATA_ENTRY ALL_NOTES_OFF
30 %token<i> NOTE_OFF NOTE_ON
31 %token<i> POLYPHONIC_AFTERTOUCH CONTROLMODE_CHANGE PROGRAM_CHANGE
32 %token<i> CHANNEL_AFTERTOUCH PITCHWHEEL_RANGE
33 %token<i> YYTEXT YYCOPYRIGHT YYTRACK_NAME YYINSTRUMENT_NAME YYLYRIC YYMARKER YYCUE_POINT
34 %token<str_p> DATA
36 %type <i> varint
37 %type <midi_score_p> header midi_score
38 %type <midi_track_p> track
39 %type <midi_event_p> event
40 %type <midi_event_p> the_event meta_event the_meta_event text_event midi_event sysex_event
41 %type <midi_event_p> running_status data_entry all_notes_off
42 %type <midi_event_p> note_off note_on
43 %type <midi_event_p> polyphonic_aftertouch controlmode_change program_change
44 %type <midi_event_p> channel_aftertouch pitchwheel_range
48 midi: /* empty */
49 | midi midi_score {
50 midi_parser_l_g->add_score( $2 );
54 midi_score:
55 header {
57 | midi_score track {
58 $$->add_track( $2 );
59 if ( midi_parser_l_g->copyright_str_.length_i() )
60 $2->copyright_str_ = midi_parser_l_g->copyright_str_;
61 if ( midi_parser_l_g->track_name_str_.length_i() )
62 $2->name_str_ = midi_parser_l_g->track_name_str_;
63 if ( midi_parser_l_g->instrument_str_.length_i() )
64 $2->instrument_str_ = midi_parser_l_g->instrument_str_;
65 midi_parser_l_g->reset();
69 header:
70 HEADER INT32 INT16 INT16 INT16 {
71 $$ = new Midi_score( $3, $4, $5 );
72 midi_parser_l_g->set_division_4( $5 );
76 track:
77 TRACK INT32 {
78 $$ = new Midi_track( midi_parser_l_g->track_i_++,
79 // silly, cause not set yet!
80 midi_parser_l_g->copyright_str_,
81 midi_parser_l_g->track_name_str_,
82 midi_parser_l_g->instrument_str_ );
84 | track event {
85 $$->add_event( midi_parser_l_g->mom(), $2 );
89 event:
90 varint the_event {
91 $$ = $2;
92 if ( $2 ) {
93 String str = $2->mudela_str( false );
94 if ( str.length_i() )
95 dtor << str << " " << flush;
100 varint:
101 VARINT {
102 midi_parser_l_g->forward( $1 );
106 the_event:
107 meta_event {
109 | midi_event {
111 | sysex_event {
115 meta_event:
116 META_EVENT the_meta_event {
117 $$ = $2;
120 META_EVENT INT8 INT8 INT8 {
121 $$ = 0;
125 the_meta_event:
126 SEQUENCE INT16 {
128 | text_event DATA {
129 Midi_text::Type type = (Midi_text::Type)$1;
130 $$ = 0;
131 switch ( type )
133 case Midi_text::COPYRIGHT:
134 midi_parser_l_g->copyright_str_ = *$2;
135 break;
136 case Midi_text::TRACK_NAME:
137 midi_parser_l_g->track_name_str_ = *$2;
138 while ( midi_parser_l_g->track_name_str_.index_i( ' ' ) != -1 )
139 *(midi_parser_l_g->track_name_str_.ch_l() + midi_parser_l_g->track_name_str_.index_i( ' ' ) ) = '_';
140 break;
141 case Midi_text::INSTRUMENT_NAME:
142 midi_parser_l_g->instrument_str_ = *$2;
143 break;
144 default:
145 $$ = new Midi_text( type, *$2 );
146 break;
148 dtor << *$2 << endl;
149 delete $2;
151 | END_OF_TRACK {
152 $$ = 0;
154 | TEMPO INT8 INT8 INT8 {
155 $$ = new Midi_tempo( ( $2 << 16 ) + ( $3 << 8 ) + $4 );
156 dtor << $$->mudela_str( false ) << endl;
157 midi_parser_l_g->set_tempo( ( $2 << 16 ) + ( $3 << 8 ) + $4 );
159 | SMPTE_OFFSET INT8 INT8 INT8 INT8 INT8 {
160 $$ = 0;
162 | TIME INT8 INT8 INT8 INT8 {
163 $$ = new Midi_time( $2, $3, $4, $5 );
164 dtor << $$->mudela_str( true ) << endl;
165 midi_parser_l_g->set_time( $2, $3, $4, $5 );
167 | KEY INT8 INT8 {
168 $$ = new Midi_key( $2, $3 );
169 midi_parser_l_g->set_key( $2, $3 );
171 | SSME DATA {
172 $$ = new Midi_text( (Midi_text::Type)0, *$2 );
173 delete $2;
177 text_event:
178 YYTEXT {
179 dtor << "\n% Text: ";
181 | YYCOPYRIGHT {
182 dtor << "\n% Copyright: ";
184 | YYTRACK_NAME {
185 dtor << "\n% Track name: ";
187 | YYINSTRUMENT_NAME {
188 dtor << "\n% Instrument name: ";
190 | YYLYRIC {
191 dtor << "\n% Lyric: ";
193 | YYMARKER {
194 dtor << "\n% Marker: ";
196 | YYCUE_POINT {
197 dtor << "\n% Cue point: ";
201 midi_event:
202 running_status {
204 | data_entry {
206 | all_notes_off {
208 | note_off {
210 | note_on {
212 | polyphonic_aftertouch {
214 | controlmode_change {
216 | program_change {
218 | channel_aftertouch {
220 | pitchwheel_range {
224 running_status:
225 RUNNING_STATUS INT8 { //INT8 {
226 $$ = 0;
230 data_entry:
231 DATA_ENTRY INT8 {
232 $$ = 0;
236 all_notes_off:
237 ALL_NOTES_OFF INT8 INT8 {
238 $$ = 0;
242 note_off:
243 NOTE_OFF INT8 INT8 {
244 int i = $1;
245 i = i & ~0x80;
246 $$ = midi_parser_l_g->note_end_midi_event_p( $1 & ~0x80, $2, $3 );
250 note_on:
251 NOTE_ON INT8 INT8 {
252 int i = $1;
253 i = i & ~0x90;
254 $$ = 0;
255 midi_parser_l_g->note_begin( $1 & ~0x90, $2, $3 );
259 polyphonic_aftertouch:
260 POLYPHONIC_AFTERTOUCH INT8 INT8 {
261 $$ = 0;
265 controlmode_change:
266 CONTROLMODE_CHANGE INT8 INT8 {
267 $$ = 0;
271 program_change:
272 PROGRAM_CHANGE INT8 {
273 $$ = 0;
277 channel_aftertouch:
278 CHANNEL_AFTERTOUCH INT8 INT8 {
279 $$ = 0;
283 pitchwheel_range:
284 PITCHWHEEL_RANGE INT8 INT8 {
285 $$ = 0;
289 sysex_event:
290 SYSEX_EVENT1 DATA {
291 $$ = 0;
293 | SYSEX_EVENT2 DATA { // INT8 ?
294 $$ = 0;