lilypond-0.0.62
[lilypond.git] / m2m / my-midi-parser.cc
blobff0f44935ef3af90d2e269239e25ede4e0f07176
1 //
2 // my-midi-parser.cc -- implement My_midi_parser
3 //
4 // copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
6 #include "m2m.hh"
8 void
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_ );
22 defined_ch_c_l_ = 0;
23 fatal_error_i_ = 0;
24 midi_key_p_ = 0;
25 midi_score_p_ = 0;
26 midi_tempo_p_ = 0;
27 midi_time_p_ = 0;
28 track_i_ = 0;
29 reset();
32 My_midi_parser::~My_midi_parser()
34 delete midi_lexer_p_;
35 midi_parser_l_g = 0;
36 delete midi_key_p_;
37 delete midi_tempo_p_;
38 delete midi_time_p_;
39 delete midi_score_p_;
42 void
43 My_midi_parser::reset()
45 delete midi_key_p_;
46 midi_key_p_ = new Midi_key( 0, 0 );
47 // useconds per 4: 250000 === 60 4 per minute
48 delete midi_tempo_p_;
49 midi_tempo_p_ = new Midi_tempo( 250000 );
50 delete midi_time_p_;
51 midi_time_p_ = new Midi_time( 4, 4, 384, 8 );
52 now_i64_ = 0;
54 copyright_str_ = "";
55 track_name_str_ = "";
56 instrument_str_ = "";
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;
64 void
65 My_midi_parser::add_score( Midi_score* midi_score_p )
67 assert( !midi_score_p_ );
68 midi_score_p_ = midi_score_p;
69 track_i_ = 0;
72 void
73 My_midi_parser::error( char const* sz_l )
75 midi_lexer_l_g->error( sz_l );
77 if ( fatal_error_i_ )
78 exit( fatal_error_i_ );
81 void
82 My_midi_parser::forward( int i )
84 now_i64_ += i;
87 Moment
88 My_midi_parser::mom()
90 return Duration_convert::i2_mom( now_i64_, division_1_i_ );
93 void
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_;
102 Midi_event*
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()
124 return ::yyparse();
127 void
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 );
135 void
136 My_midi_parser::set_key( int accidentals_i, int minor_i )
138 delete midi_key_p_;
139 midi_key_p_ = new Midi_key( accidentals_i, minor_i );
142 void
143 My_midi_parser::set_tempo( int useconds_i )
145 delete midi_tempo_p_;
146 midi_tempo_p_ = new Midi_tempo( useconds_i );
149 void
150 My_midi_parser::set_time( int num_i, int den_i, int clocks_i, int count_32_i )
152 delete midi_time_p_;
153 midi_time_p_ = new Midi_time( num_i, den_i, clocks_i, count_32_i );