8 #include "midi-main.hh"
9 #include "my-midi-lexer.hh"
10 #include "midi-parser.hh"
19 %option yyclass="My_midi_lexer"
33 INT7_8UNSET [\x00-\x7f]
35 VARINT {INT7_8SET}{0,3}{INT7_8UNSET}
40 XRUNNING_STATUS [\x30-\x4f]
41 RUNNING_STATUS [\x00-\x5f]
42 DATA_ENTRY [\x60-\x79]
43 ALL_NOTES_OFF [\x7a-\x7f]
46 POLYPHONIC_AFTERTOUCH [\xa0-\xaf]
47 CONTROLMODE_CHANGE [\xb0-\xbf]
48 PROGRAM_CHANGE [\xc0-\xcf]
49 CHANNEL_AFTERTOUCH [\xd0-\xdf]
50 PITCHWHEEL_RANGE [\xe0-\xef]
61 INSTRUMENT_NAME [\x04]
66 END_OF_TRACK [\x2f][\x00]
68 SMPTE_OFFSET [\x54][\x05]
75 {HEADER}/{INT32} { // using /{INT32}; longer match than {INT32}
76 dtor << "lex: header" << endl;
77 yy_push_state( int16 );
78 yy_push_state( int16 );
79 yy_push_state( int16 );
80 yy_push_state( int32 );
84 {TRACK}/{INT32} { // using /{INT32}; longer match than {INT32}
85 dtor << "lex: track" << endl;
86 yy_push_state( track );
87 yy_push_state( int32 );
91 error( String( "top level: illegal byte: " )
92 + String_convert::bin2hex_str( String( *YYText() ) ) );
96 dtor << "lex: int32" << endl;
97 assert( YYLeng() == 4 );
98 String str( (Byte const*)YYText(), YYLeng() );
99 yylval.i = String_convert::bin2_i( str );
104 dtor << "lex: int16" << endl;
105 assert( YYLeng() == 2 );
106 String str( (Byte const*)YYText(), YYLeng() );
107 yylval.i = String_convert::bin2_i( str );
112 dtor << "lex: int8" << endl;
113 assert( YYLeng() == 1 );
114 // yylval.byte = *(Byte*)YYText();
115 yylval.i = *(Byte*)YYText();
121 String str( (Byte const*)YYText(), YYLeng() );
122 yylval.i = My_midi_lexer::varint2_i( str );
123 dtor << String( "lex: track: varint(" )
124 + String( yylval.i ) + "): "
125 + String_convert::bin2hex_str( str ) << endl;
126 yy_push_state( event );
130 error( String( "track: illegal byte: " )
131 + String_convert::bin2hex_str( String( *YYText() ) ) );
134 <event>{RUNNING_STATUS} {
135 // yylval.byte = *(Byte*)YYText();
136 yylval.i = *(Byte*)YYText();
137 dtor << String ( "lex: running status: " ) + String( yylval.i ) << endl;
139 // yy_push_state( int8 );
140 yy_push_state( int8 );
141 return RUNNING_STATUS;
143 <event>{DATA_ENTRY} {
144 // yylval.byte = *(Byte*)YYText();
145 yylval.i = *(Byte*)YYText();
146 dtor << String ( "lex: undefined data entry: " ) + String( yylval.i ) << endl;
148 yy_push_state( int8 );
151 <event>{ALL_NOTES_OFF} {
152 dtor << "lex: all note off" << endl;
153 // yylval.byte = *(Byte*)YYText();
154 yylval.i = *(Byte*)YYText();
155 dtor << String ( "lex: all notes off: " ) + String( yylval.i ) << endl;
157 yy_push_state( int8 );
158 yy_push_state( int8 );
159 return ALL_NOTES_OFF;
162 dtor << "lex: note off" << endl;
163 // yylval.byte = *(Byte*)YYText();
164 yylval.i = *(Byte*)YYText();
166 yy_push_state( int8 );
167 yy_push_state( int8 );
171 dtor << "lex: note on" << endl;
172 // yylval.byte = *(Byte*)YYText();
173 yylval.i = *(Byte*)YYText();
175 yy_push_state( int8 );
176 yy_push_state( int8 );
179 <event>{POLYPHONIC_AFTERTOUCH} {
180 dtor << "lex: polyphonic aftertouch" << endl;
181 // yylval.byte = *(Byte*)YYText();
182 yylval.i = *(Byte*)YYText();
184 yy_push_state( int8 );
185 yy_push_state( int8 );
186 return POLYPHONIC_AFTERTOUCH;
188 <event>{CONTROLMODE_CHANGE} {
189 dtor << "lex: controlmode change" << endl;
190 // yylval.byte = *(Byte*)YYText();
191 yylval.i = *(Byte*)YYText();
193 yy_push_state( int8 );
194 yy_push_state( int8 );
195 return CONTROLMODE_CHANGE;
197 <event>{PROGRAM_CHANGE} {
198 dtor << "lex: program change" << endl;
199 // yylval.byte = *(Byte*)YYText();
200 yylval.i = *(Byte*)YYText();
202 yy_push_state( int8 );
203 return PROGRAM_CHANGE;
205 <event>{CHANNEL_AFTERTOUCH} {
206 dtor << "lex: channel aftertouch" << endl;
207 // yylval.byte = *(Byte*)YYText();
208 yylval.i = *(Byte*)YYText();
210 yy_push_state( int8 );
211 yy_push_state( int8 );
212 return CHANNEL_AFTERTOUCH;
214 <event>{PITCHWHEEL_RANGE} {
215 dtor << "lex: pitchwheel range" << endl;
216 // yylval.byte = *(Byte*)YYText();
217 yylval.i = *(Byte*)YYText();
219 yy_push_state( int8 );
220 yy_push_state( int8 );
221 return PITCHWHEEL_RANGE;
223 <event>{SYSEX_EVENT1} { // len data
224 dtor << "lex: sysex1" << endl;
226 yy_push_state( data );
229 <event>{SYSEX_EVENT2} { // len data
230 dtor << "lex: sysex2" << endl;
232 // yy_push_state( int8 ); //?
233 yy_push_state( data );
236 <event>{META_EVENT} {
237 dtor << "lex: meta" << endl;
238 yy_push_state( meta_event );
242 error( String( "event: illegal byte: " )
243 + String_convert::bin2hex_str( String( *YYText() ) ) );
246 <meta_event>{SEQUENCE} { // ssss sequence number
247 dtor << "lex: sequence" << endl;
250 yy_push_state( int16 );
253 <meta_event>{TEXT} { // len data
254 dtor << "lex: text" << endl;
257 yy_push_state( data );
260 <meta_event>{COPYRIGHT} {
261 dtor << "lex: copyright" << endl;
264 yy_push_state( data );
267 <meta_event>{TRACK_NAME} {
268 dtor << "lex: track name" << endl;
271 yy_push_state( data );
274 <meta_event>{INSTRUMENT_NAME} {
275 dtor << "lex: instrument name" << endl;
278 yy_push_state( data );
279 return INSTRUMENT_NAME;
281 <meta_event>{LYRIC} {
282 dtor << "lex: lyric" << endl;
285 yy_push_state( data );
288 <meta_event>{MARKER} {
289 dtor << "lex: marker" << endl;
292 yy_push_state( data );
295 <meta_event>{CUE_POINT} {
296 dtor << "lex: cue point" << endl;
299 yy_push_state( data );
302 <meta_event>{TEMPO} { // tttttt usec
303 dtor << "lex: tempo" << endl;
306 yy_push_state( int8 );
307 yy_push_state( int8 );
308 yy_push_state( int8 );
311 <meta_event>{SMPTE_OFFSET} { // hr mn se fr ff
312 dtor << "lex: smpte offset" << endl;
315 yy_push_state( int8 );
316 yy_push_state( int8 );
317 yy_push_state( int8 );
318 yy_push_state( int8 );
319 yy_push_state( int8 );
322 <meta_event>{TIME} { // nn dd cc bb
323 dtor << "lex: time" << endl;
326 yy_push_state( int8 );
327 yy_push_state( int8 );
328 yy_push_state( int8 );
329 yy_push_state( int8 );
332 <meta_event>{KEY} { // sf mi
333 dtor << "lex: key" << endl;
336 yy_push_state( int8 );
337 yy_push_state( int8 );
340 <meta_event>{SSME} { // len data
341 dtor << "lex: smme" << endl;
344 yy_push_state( data );
347 <meta_event>{END_OF_TRACK} {
348 dtor << "lex: end of track" << endl;
355 warning( String( "meta_event: unimplemented event: " )
356 + String_convert::bin2hex_str( String( *YYText() ) ),
357 *this->here_ch_c_l() );
360 yy_push_state( int8 );
361 yy_push_state( int8 );
366 dtor << "lex: data" << endl;
367 String str( (Byte const*)YYText(), YYLeng() );
368 int i = My_midi_lexer::varint2_i( str );
369 String* str_p = new String;
371 *str_p += (char)yyinput();
372 yylval.str_p = str_p;
377 error( String( "data: illegal byte: " )
378 + String_convert::bin2hex_str( String( *YYText() ) ) );
383 // mtor << "<<EOF>>";
386 yyterminate(); // can't move this, since it actually rets a YY_NULL