2 // my-midi-parser.cc -- implement My_midi_parser
4 // copyright 1997 Jan Nieuwenhuizen <jan@digicash.com>
6 #include "string-convert.hh"
7 #include "duration-convert.hh"
8 #include "mi2mu-global.hh"
9 #include "my-midi-lexer.hh"
10 #include "my-midi-parser.hh"
11 #include "mudela-column.hh"
12 #include "mudela-item.hh"
13 #include "mudela-score.hh"
14 #include "mudela-staff.hh"
17 yyerror(char const* sz_l
)
19 midi_parser_l_g
->error (sz_l
);
23 My_midi_parser
* midi_parser_l_g
= 0;
25 My_midi_parser::My_midi_parser (String filename_str
, Sources
*sources_l
)
27 filename_str_
= filename_str
;
28 midi_lexer_p_
= new My_midi_lexer (filename_str_
,sources_l
);
29 midi_lexer_l_g
= midi_lexer_p_
; // ugh
37 mudela_score_p_
= new Mudela_score (1, 1, 1);
40 // ugh, belong to Mudela_{score,staff}
50 My_midi_parser::~My_midi_parser()
52 midi_lexer_l_g
= 0; // ugh
56 delete mudela_tempo_p_
;
57 delete mudela_meter_p_
;
58 delete mudela_score_p_
;
62 My_midi_parser::reset()
64 // open_mudela_note_l_list_.clear();
65 open_mudela_note_l_list_
.junk_links();
69 mudela_key_p_
= new Mudela_key (0, 0);
70 // useconds per 4: 250000 === 60 4 per minute
71 delete mudela_tempo_p_
;
72 mudela_tempo_p_
= new Mudela_tempo (1000000);
73 delete mudela_meter_p_
;
74 mudela_meter_p_
= new Mudela_meter (4, 2, 24, 8);
77 mudela_column_l_
= mudela_score_p_
->mudela_column_l (0);
86 My_midi_parser::add_score (Mudela_score
* mudela_score_p
)
88 assert (mudela_score_p_
);
90 #if 0 // ugh, already constructed
91 mudela_score_p_
= mudela_score_p
;
92 if (!mudela_column_l_
)
93 mudela_column_l_
= mudela_score_p_
->mudela_column_l (0);
96 mudela_score_p_
->mudela_key_l_
= mudela_key_p_
;
97 mudela_score_p_
->mudela_meter_l_
= mudela_meter_p_
;
98 mudela_score_p_
->mudela_tempo_l_
= mudela_tempo_p_
;
103 My_midi_parser::error (char const* sz_l
)
105 midi_lexer_l_g
->error (sz_l
);
108 exit (fatal_error_i_
);
112 My_midi_parser::forward (int i
)
118 dur
.durlog_i_
= -100;
120 Moment mom
= at_mom() + Duration_convert::dur2_mom (dur
);
122 mudela_column_l_
= mudela_score_p_
->mudela_column_l (mom
);
126 int bars_i
= (int) (mom
/ mudela_meter_p_
->bar_mom());
128 LOGOUT(NORMAL_ver
) << '[' << bar_i_
<< ']' << flush
;
134 My_midi_parser::at_mom()
136 assert (mudela_column_l_
);
137 // return mudela_column_l_ ? mudela_column_l_->at_mom() : 0;
138 return mudela_column_l_
->at_mom();
142 My_midi_parser::note_begin (int channel_i
, int pitch_i
, int dyn_i
)
147 Mudela_note
* p
= new Mudela_note (mudela_column_l_
, channel_i
, pitch_i
, dyn_i
);
148 // ugh, score doesn't know about last staff yet...
149 // mudela_score_p_->add_item (p);
150 mudela_staff_l_
->add_item (p
);
151 open_mudela_note_l_list_
.bottom().add (p
);
155 My_midi_parser::note_end (int channel_i
, int pitch_i
, int aftertouch_i
)
161 for (PCursor
<Mudela_note
*> i (open_mudela_note_l_list_
); i
.ok(); i
++)
163 if ( (i
->pitch_i_
== pitch_i
) && (i
->channel_i_
== channel_i
))
165 i
->end_column_l_
= mudela_column_l_
;
166 LOGOUT(DEBUG_ver
) << "Note: " << pitch_i
;
167 LOGOUT(DEBUG_ver
) << "; " << i
->mudela_column_l_
->at_mom_
;
168 LOGOUT(DEBUG_ver
) << ", " << i
->end_column_l_
->at_mom_
<< "\n";
173 warning (String ("junking note-end event: ")
174 + " channel = " + String_convert::i2dec_str (channel_i
, 0, ' ')
175 + ", pitch = " + String_convert::i2dec_str (pitch_i
, 0, ' '));
179 My_midi_parser::note_end_all()
182 for (PCursor
<Mudela_note
*> i (open_mudela_note_l_list_
); i
.ok(); i
++)
184 i
->end_column_l_
= mudela_column_l_
;
193 My_midi_parser::parse()
195 LOGOUT(NORMAL_ver
) << "\nParsing..." << flush
;
203 My_midi_parser::set_division_4 (int division_4_i
)
205 division_1_i_
= division_4_i
* 4;
207 Duration::division_1_i_s
= division_1_i_
;
208 if (division_4_i
< 0)
209 warning ("seconds iso metrical time");
213 My_midi_parser::set_key (int accidentals_i
, int minor_i
)
215 delete mudela_key_p_
;
216 mudela_key_p_
= new Mudela_key (accidentals_i
, minor_i
);
220 My_midi_parser::set_meter (int num_i
, int den_i
, int clocks_i
, int count_32_i
)
222 delete mudela_meter_p_
;
223 mudela_meter_p_
= new Mudela_meter (num_i
, den_i
, clocks_i
, count_32_i
);
227 My_midi_parser::set_tempo (int useconds_per_4_i
)
229 delete mudela_tempo_p_
;
230 mudela_tempo_p_
= new Mudela_tempo (useconds_per_4_i
);