2 // my-midi-parser.cc -- implement My_midi_parser
4 // copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
9 yyerror(char const* sz_l
)
11 midi_parser_l_g
->error( sz_l
);
15 My_midi_parser
* midi_parser_l_g
= 0;
17 My_midi_parser::My_midi_parser( String filename_str
)
19 midi_parser_l_g
= this;
20 filename_str_
= filename_str
;
21 midi_lexer_p_
= new My_midi_lexer( filename_str_
);
32 My_midi_parser::~My_midi_parser()
43 My_midi_parser::reset()
46 midi_key_p_
= new Midi_key( 0, 0 );
47 // useconds per 4: 250000 === 60 4 per minute
49 midi_tempo_p_
= new Midi_tempo( 250000 );
51 midi_time_p_
= new Midi_time( 4, 4, 384, 8 );
58 for ( int i
= 0; i
< CHANNELS_i
; i
++ )
59 for ( int j
= 0; j
< PITCHES_i
; j
++ )
60 // running_i64_i64_a_[ i ][ j ] = -1;
61 running_i64_i64_a_
[ i
][ j
] = 0;
65 My_midi_parser::add_score( Midi_score
* midi_score_p
)
67 assert( !midi_score_p_
);
68 midi_score_p_
= midi_score_p
;
73 My_midi_parser::error( char const* sz_l
)
75 midi_lexer_l_g
->error( sz_l
);
78 exit( fatal_error_i_
);
82 My_midi_parser::forward( int i
)
90 return Duration_convert::i2_mom( now_i64_
, division_1_i_
);
94 My_midi_parser::note_begin( int channel_i
, int pitch_i
, int dyn_i
)
96 // one pitch a channel at time!
97 // heu, what about { < c2 > < c4 d4 > }
98 // assert( running_i64_i64_a_[ channel_i ][ pitch_i ] == -1 );
99 running_i64_i64_a_
[ channel_i
][ pitch_i
] = now_i64_
;
103 My_midi_parser::note_end_midi_event_p( int channel_i
, int pitch_i
, int dyn_i
)
105 Int64 start_i64
= running_i64_i64_a_
[ channel_i
][ pitch_i
];
107 // running_i64_i64_a_[ channel_i ][ pitch_i ] = -1;
108 // assert( start_i64 != -1 ); // did we start?
110 return new Midi_note( midi_key_p_
->notename_str( pitch_i
), midi_time_p_
->i2_dur( now_i64_
- start_i64
, division_1_i_
) );
114 My_midi_parser::output_mudela( String filename_str
)
116 assert( midi_score_p_
);
117 midi_score_p_
->process();
118 return midi_score_p_
->output_mudela( filename_str
);
122 My_midi_parser::parse()
128 My_midi_parser::set_division_4( int division_4_i
)
130 division_1_i_
= division_4_i
* 4;
131 if ( division_4_i
< 0 )
132 warning( "seconds iso metrical time" , 0 );
136 My_midi_parser::set_key( int accidentals_i
, int minor_i
)
139 midi_key_p_
= new Midi_key( accidentals_i
, minor_i
);
143 My_midi_parser::set_tempo( int useconds_i
)
145 delete midi_tempo_p_
;
146 midi_tempo_p_
= new Midi_tempo( useconds_i
);
150 My_midi_parser::set_time( int num_i
, int den_i
, int clocks_i
, int count_32_i
)
153 midi_time_p_
= new Midi_time( num_i
, den_i
, clocks_i
, count_32_i
);