lilypond-0.1.37
[lilypond.git] / src / my-midi-parser.cc
blob31555f79af542aa7b39dc25bda168e02e5e98c9a
1 //
2 // my-midi-parser.cc -- implement My_midi_parser
3 //
4 // copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
6 #include "proto.hh"
8 #include "plist.hh" // ugh
9 #include "string.hh"
10 #include "source-file.hh"
11 #include "source.hh"
12 #include "midi-main.hh" // *tors
14 #include "my-midi-lexer.hh"
15 #include "my-midi-parser.hh"
16 #include "duration.hh"
17 #include "midi-event.hh"
18 #include "lily-stream.hh"
19 #include "track-column.hh"
20 #include "midi-track.hh"
21 #include "midi-score.hh"
22 #include "my-midi-lexer.hh"
23 #include "my-midi-parser.hh"
25 void
26 yyerror(char const* sz_l )
28 midi_parser_l_g->error( sz_l );
32 My_midi_parser* midi_parser_l_g;
34 My_midi_parser::My_midi_parser( String filename_str )
36 midi_lexer_p_ = new My_midi_lexer( filename_str );
37 midi_parser_l_g = this;
38 defined_ch_c_l_ = 0;
39 fatal_error_i_ = 0;
40 midi_key_p_ = 0;
41 midi_score_p_ = 0;
42 midi_tempo_p_ = 0;
43 midi_time_p_ = 0;
44 reset();
47 void
48 My_midi_parser::reset()
50 delete midi_key_p_;
51 midi_key_p_ = new Midi_key( 0, 0 );
52 // useconds per 4: 250000 === 60 4 per minute
53 delete midi_tempo_p_;
54 midi_tempo_p_ = new Midi_tempo( 250000 );
55 delete midi_time_p_;
56 midi_time_p_ = new Midi_time( 4, 4, 384, 8 );
58 now_i64_ = 0;
60 for ( int i = 0; i < CHANNELS_i; i++ )
61 for ( int j = 0; j < PITCHES_i; j++ )
62 // running_i64_i64_a_[ i ][ j ] = -1;
63 running_i64_i64_a_[ i ][ j ] = 0;
66 My_midi_parser::~My_midi_parser()
68 delete midi_lexer_p_;
69 midi_parser_l_g = 0;
70 delete midi_key_p_;
71 delete midi_tempo_p_;
72 delete midi_time_p_;
73 delete midi_score_p_;
76 void
77 My_midi_parser::add_score( Midi_score* midi_score_p )
79 assert( !midi_score_p_ );
80 midi_score_p_ = midi_score_p;
83 void
84 My_midi_parser::error( char const* sz_l )
86 midi_lexer_l_g->error( sz_l );
88 if ( fatal_error_i_ )
89 exit( fatal_error_i_ );
92 void
93 My_midi_parser::forward( int i )
95 now_i64_ += i;
98 Moment
99 My_midi_parser::mom()
101 return Duration_convert::i2_mom( now_i64_, division_1_i_ );
104 void
105 My_midi_parser::note_begin( int channel_i, int pitch_i, int dyn_i )
107 // one pitch a channel at time!
108 // heu, what about { < c2 > < c4 d4 > }
109 // assert( running_i64_i64_a_[ channel_i ][ pitch_i ] == -1 );
110 running_i64_i64_a_[ channel_i ][ pitch_i ] = now_i64_;
113 Midi_event*
114 My_midi_parser::note_end_midi_event_p( int channel_i, int pitch_i, int dyn_i )
116 Int64 start_i64 = running_i64_i64_a_[ channel_i ][ pitch_i ];
117 // running_i64_i64_a_[ channel_i ][ pitch_i ] = -1;
118 // did we start?
119 // assert( start_i64 != -1 );
120 return new Midi_note( midi_key_p_, midi_time_p_, division_1_i_, pitch_i, now_i64_ - start_i64 );
124 My_midi_parser::output_mudela( String filename_str )
126 assert( midi_score_p_ );
127 return midi_score_p_->output_mudela( filename_str );
131 My_midi_parser::parse()
133 return ::yyparse();
136 void
137 My_midi_parser::set_division_4( int division_4_i )
139 division_1_i_ = division_4_i * 4;
140 if ( division_4_i < 0 )
141 warning( "seconds iso metrical time" , 0 );
144 void
145 My_midi_parser::set_key( int accidentals_i, int minor_i )
147 delete midi_key_p_;
148 midi_key_p_ = new Midi_key( accidentals_i, minor_i );
151 void
152 My_midi_parser::set_tempo( int useconds_i )
154 delete midi_tempo_p_;
155 midi_tempo_p_ = new Midi_tempo( useconds_i );
158 void
159 My_midi_parser::set_time( int num_i, int den_i, int clocks_i, int count_32_i )
161 delete midi_time_p_;
162 midi_time_p_ = new Midi_time( num_i, den_i, clocks_i, count_32_i );