6 #include "midi-parser.hh"
15 %option yyclass="My_midi_lexer"
29 INT7_8UNSET [\x00-\x7f]
31 VARINT {INT7_8SET}{0,3}{INT7_8UNSET}
36 XRUNNING_STATUS [\x30-\x4f]
37 RUNNING_STATUS [\x00-\x5f]
38 DATA_ENTRY [\x60-\x79]
39 ALL_NOTES_OFF [\x7a-\x7f]
42 POLYPHONIC_AFTERTOUCH [\xa0-\xaf]
43 CONTROLMODE_CHANGE [\xb0-\xbf]
44 PROGRAM_CHANGE [\xc0-\xcf]
45 CHANNEL_AFTERTOUCH [\xd0-\xdf]
46 PITCHWHEEL_RANGE [\xe0-\xef]
57 YYINSTRUMENT_NAME [\x04]
62 END_OF_TRACK [\x2f][\x00]
64 SMPTE_OFFSET [\x54][\x05]
71 {HEADER}/{INT32} { // using /{INT32}; longer match than {INT32}
72 dtor << "lex: header" << endl;
73 yy_push_state( int16 );
74 yy_push_state( int16 );
75 yy_push_state( int16 );
76 yy_push_state( int32 );
80 {TRACK}/{INT32} { // using /{INT32}; longer match than {INT32}
81 dtor << "lex: track" << endl;
82 yy_push_state( track );
83 yy_push_state( int32 );
87 error( String( "top level: illegal byte: " )
88 + String_convert::bin2hex_str( String( *YYText() ) ) );
92 dtor << "lex: int32" << endl;
93 assert( YYLeng() == 4 );
94 String str( (Byte const*)YYText(), YYLeng() );
95 yylval.i = String_convert::bin2_i( str );
100 dtor << "lex: int16" << endl;
101 assert( YYLeng() == 2 );
102 String str( (Byte const*)YYText(), YYLeng() );
103 yylval.i = String_convert::bin2_i( str );
108 dtor << "lex: int8" << endl;
109 assert( YYLeng() == 1 );
110 // yylval.byte = *(Byte*)YYText();
111 yylval.i = *(Byte*)YYText();
117 String str( (Byte const*)YYText(), YYLeng() );
118 yylval.i = My_midi_lexer::varint2_i( str );
119 dtor << String( "lex: track: varint(" )
120 + String( yylval.i ) + "): "
121 + String_convert::bin2hex_str( str ) << endl;
122 yy_push_state( event );
126 error( String( "track: illegal byte: " )
127 + String_convert::bin2hex_str( String( *YYText() ) ) );
130 <event>{RUNNING_STATUS} {
131 // yylval.byte = *(Byte*)YYText();
132 yylval.i = *(Byte*)YYText();
133 dtor << String ( "lex: running status: " ) + String( yylval.i ) << endl;
135 // yy_push_state( int8 );
136 yy_push_state( int8 );
137 return RUNNING_STATUS;
139 <event>{DATA_ENTRY} {
140 // yylval.byte = *(Byte*)YYText();
141 yylval.i = *(Byte*)YYText();
142 dtor << String ( "lex: undefined data entry: " ) + String( yylval.i ) << endl;
144 yy_push_state( int8 );
147 <event>{ALL_NOTES_OFF} {
148 dtor << "lex: all note off" << endl;
149 // yylval.byte = *(Byte*)YYText();
150 yylval.i = *(Byte*)YYText();
151 dtor << String ( "lex: all notes off: " ) + String( yylval.i ) << endl;
153 yy_push_state( int8 );
154 yy_push_state( int8 );
155 return ALL_NOTES_OFF;
158 dtor << "lex: note off" << endl;
159 // yylval.byte = *(Byte*)YYText();
160 yylval.i = *(Byte*)YYText();
162 yy_push_state( int8 );
163 yy_push_state( int8 );
167 dtor << "lex: note on" << endl;
168 // yylval.byte = *(Byte*)YYText();
169 yylval.i = *(Byte*)YYText();
171 yy_push_state( int8 );
172 yy_push_state( int8 );
175 <event>{POLYPHONIC_AFTERTOUCH} {
176 dtor << "lex: polyphonic aftertouch" << endl;
177 // yylval.byte = *(Byte*)YYText();
178 yylval.i = *(Byte*)YYText();
180 yy_push_state( int8 );
181 yy_push_state( int8 );
182 return POLYPHONIC_AFTERTOUCH;
184 <event>{CONTROLMODE_CHANGE} {
185 dtor << "lex: controlmode change" << endl;
186 // yylval.byte = *(Byte*)YYText();
187 yylval.i = *(Byte*)YYText();
189 yy_push_state( int8 );
190 yy_push_state( int8 );
191 return CONTROLMODE_CHANGE;
193 <event>{PROGRAM_CHANGE} {
194 dtor << "lex: program change" << endl;
195 // yylval.byte = *(Byte*)YYText();
196 yylval.i = *(Byte*)YYText();
198 yy_push_state( int8 );
199 return PROGRAM_CHANGE;
201 <event>{CHANNEL_AFTERTOUCH} {
202 dtor << "lex: channel aftertouch" << endl;
203 // yylval.byte = *(Byte*)YYText();
204 yylval.i = *(Byte*)YYText();
206 yy_push_state( int8 );
207 yy_push_state( int8 );
208 return CHANNEL_AFTERTOUCH;
210 <event>{PITCHWHEEL_RANGE} {
211 dtor << "lex: pitchwheel range" << endl;
212 // yylval.byte = *(Byte*)YYText();
213 yylval.i = *(Byte*)YYText();
215 yy_push_state( int8 );
216 yy_push_state( int8 );
217 return PITCHWHEEL_RANGE;
219 <event>{SYSEX_EVENT1} { // len data
220 dtor << "lex: sysex1" << endl;
222 yy_push_state( data );
225 <event>{SYSEX_EVENT2} { // len data
226 dtor << "lex: sysex2" << endl;
228 // yy_push_state( int8 ); //?
229 yy_push_state( data );
232 <event>{META_EVENT} {
233 dtor << "lex: meta" << endl;
234 yy_push_state( meta_event );
238 error( String( "event: illegal byte: " )
239 + String_convert::bin2hex_str( String( *YYText() ) ) );
242 <meta_event>{SEQUENCE} { // ssss sequence number
243 dtor << "lex: sequence" << endl;
246 yy_push_state( int16 );
249 <meta_event>{YYTEXT} { // len data
250 dtor << "lex: text" << endl;
251 // yylval.byte = *(Byte*)YYText();
252 yylval.i = *(Byte*)YYText();
255 yy_push_state( data );
258 <meta_event>{YYCOPYRIGHT} {
259 dtor << "lex: copyright" << endl;
260 // yylval.byte = *(Byte*)YYText();
261 yylval.i = *(Byte*)YYText();
264 yy_push_state( data );
267 <meta_event>{YYTRACK_NAME} {
268 dtor << "lex: track name" << endl;
269 // yylval.byte = *(Byte*)YYText();
270 yylval.i = *(Byte*)YYText();
273 yy_push_state( data );
276 <meta_event>{YYINSTRUMENT_NAME} {
277 dtor << "lex: instrument name" << endl;
278 // yylval.byte = *(Byte*)YYText();
279 yylval.i = *(Byte*)YYText();
282 yy_push_state( data );
283 return YYINSTRUMENT_NAME;
285 <meta_event>{YYLYRIC} {
286 dtor << "lex: lyric" << endl;
287 // yylval.byte = *(Byte*)YYText();
288 yylval.i = *(Byte*)YYText();
291 yy_push_state( data );
294 <meta_event>{YYMARKER} {
295 dtor << "lex: marker" << endl;
296 // yylval.byte = *(Byte*)YYText();
297 yylval.i = *(Byte*)YYText();
300 yy_push_state( data );
303 <meta_event>{YYCUE_POINT} {
304 dtor << "lex: cue point" << endl;
305 // yylval.byte = *(Byte*)YYText();
306 yylval.i = *(Byte*)YYText();
309 yy_push_state( data );
312 <meta_event>{TEMPO} { // tttttt usec
313 dtor << "lex: tempo" << endl;
316 yy_push_state( int8 );
317 yy_push_state( int8 );
318 yy_push_state( int8 );
321 <meta_event>{SMPTE_OFFSET} { // hr mn se fr ff
322 dtor << "lex: smpte offset" << endl;
325 yy_push_state( int8 );
326 yy_push_state( int8 );
327 yy_push_state( int8 );
328 yy_push_state( int8 );
329 yy_push_state( int8 );
332 <meta_event>{TIME} { // nn dd cc bb
333 dtor << "lex: time" << endl;
336 yy_push_state( int8 );
337 yy_push_state( int8 );
338 yy_push_state( int8 );
339 yy_push_state( int8 );
342 <meta_event>{KEY} { // sf mi
343 dtor << "lex: key" << endl;
346 yy_push_state( int8 );
347 yy_push_state( int8 );
350 <meta_event>{SSME} { // len data
351 dtor << "lex: smme" << endl;
354 yy_push_state( data );
357 <meta_event>{END_OF_TRACK} {
358 dtor << "lex: end of track" << endl;
365 warning( String( "meta_event: unimplemented event: " )
366 + String_convert::bin2hex_str( String( *YYText() ) ),
367 this->here_ch_c_l() );
370 yy_push_state( int8 );
371 yy_push_state( int8 );
376 dtor << "lex: data" << endl;
377 String str( (Byte const*)YYText(), YYLeng() );
378 int i = My_midi_lexer::varint2_i( str );
379 String* str_p = new String;
381 *str_p += (char)yyinput();
382 yylval.str_p = str_p;
387 error( String( "data: illegal byte: " )
388 + String_convert::bin2hex_str( String( *YYText() ) ) );
393 // mtor << "<<EOF>>";
396 yyterminate(); // can't move this, since it actually rets a YY_NULL