2 my-lily-parser.cc -- implement My_lily_parser
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
10 #include "my-lily-parser.hh"
11 #include "my-lily-lexer.hh"
14 #include "music-list.hh"
15 #include "musical-request.hh"
16 #include "command-request.hh"
19 #include "file-results.hh"
20 #include "midi-def.hh"
21 #include "paper-def.hh"
22 #include "identifier.hh"
24 My_lily_parser::My_lily_parser (Sources * source_l)
29 abbrev_beam_type_i_ = 0;
30 default_duration_.durlog_i_ = 2;
31 default_abbrev_i_ = 0;
38 My_lily_parser::~My_lily_parser()
41 delete default_header_p_;
47 My_lily_parser::set_version_check (bool ig)
49 ignore_version_b_ = ig;
53 My_lily_parser::parse_file (String init, String s)
55 lexer_p_ = new My_lily_lexer;
57 lexer_p_->main_input_str_ = s;
59 *mlog << _ ("Parsing...");
61 init_parse_b_ = false;
62 set_yydebug (!monitor->silent_b ("Parser") && check_debug);
63 lexer_p_->new_input (init, source_l_);
66 if (!define_spot_array_.empty())
68 warning (_ ("braces don't match"));
72 inclusion_global_array = lexer_p_->filename_str_arr_;
76 My_lily_parser::remember_spot()
78 define_spot_array_.push (here_input());
82 My_lily_parser::here_ch_C() const
84 return lexer_p_->here_ch_C();
88 My_lily_parser::parser_error (String s)
90 here_input().error (s);
92 exit (fatal_error_i_);
98 My_lily_parser::set_abbrev_beam (int type_i)
100 abbrev_beam_type_i_ = type_i;
105 My_lily_parser::set_last_duration (Duration const *d)
107 default_duration_ = *d;
112 My_lily_parser::get_word_element (String s, Duration * duration_p)
114 Simultaneous_music* velt_p = new Request_chord;
116 Lyric_req* lreq_p = new Lyric_req;
117 lreq_p ->text_str_ = s;
118 lreq_p->duration_ = *duration_p;
119 lreq_p->set_spot (here_input());
121 velt_p->add_music (lreq_p);
129 My_lily_parser::get_rest_element (String s, Duration * duration_p)
131 Simultaneous_music* velt_p = new Request_chord;
132 velt_p->set_spot (here_input());
136 Skip_req * skip_p = new Skip_req;
137 skip_p->duration_ = *duration_p;
139 skip_p->set_spot (here_input());
140 velt_p->add_music (skip_p);
144 Rest_req * rest_req_p = new Rest_req;
145 rest_req_p->duration_ = *duration_p;
146 rest_req_p->set_spot (here_input());
148 velt_p->add_music (rest_req_p);
156 My_lily_parser::get_chord (Musical_pitch tonic, Array<Musical_pitch>* add_arr_p, Array<Musical_pitch>* sub_arr_p, Duration d)
158 Simultaneous_music*v = new Request_chord;
159 v->set_spot (here_input ());
161 Note_req* n = new Note_req;
166 for (int i = 0; i < add_arr_p->size (); i++)
168 Musical_pitch p = tonic;
169 Musical_pitch q = (*add_arr_p)[i];
170 // duh, c7 should mean <c bes>
171 if (q.notename_i_ == 6)
176 add_arr_p->sort (Musical_pitch::compare);
177 for (int i = 0; i < sub_arr_p->size (); i++)
179 Musical_pitch p = tonic;
180 Musical_pitch q = (*add_arr_p)[i];
181 // duh, c7 should mean <c bes>
182 if (q.notename_i_ == 6)
187 sub_arr_p->sort (Musical_pitch::compare);
189 Musical_pitch third (2);
190 Musical_pitch mthird (2, -1);
191 Musical_pitch missing;
193 missing.transpose (third);
198 p.transpose (mthird);
201 must have minimum at 5 (3 is added automatically as missing)
203 if (!add_arr_p->size ())
205 else if ((add_arr_p->top () < p) && (add_arr_p->top ().notename_i_ != p.notename_i_))
207 add_arr_p->sort (Musical_pitch::compare);
209 Array<Musical_pitch> triads;
210 triads.push (third); // c e
211 triads.push (mthird); // d f
212 triads.push (mthird); // e g
213 triads.push (third); // f a
214 // 7 always seems means 7-...
215 triads.push (third); // g b
216 // triads.push (mthird); // g bes
217 triads.push (mthird); // a c
218 triads.push (mthird); // b d
221 if first addition is 4, assume sus4 and don't add third implicitely
223 Musical_pitch sus (3);
224 sus.transpose (tonic);
225 if (add_arr_p->size ())
226 if ((*add_arr_p)[0] == sus)
227 missing.transpose (mthird);
232 for (int i = 0; i < add_arr_p->size (); i++)
234 Musical_pitch p = (*add_arr_p)[i];
238 if (p.notename_i_ != missing.notename_i_)
240 if ((missing.notename_i_ - tonic.notename_i_ + 7) % 7 == 6)
242 Musical_pitch special_seven = missing;
243 Musical_pitch lower (0, -1);
244 special_seven.transpose (lower);
245 add_arr_p->insert (special_seven, i++);
248 add_arr_p->insert (missing, i++);
250 missing.transpose (triads[(missing.notename_i_ - tonic.notename_i_ + 7) % 7]);
257 add all that aren't subtracted
259 for (int i = 0; i < add_arr_p->size (); i++)
261 Musical_pitch p = (*add_arr_p)[i];
262 Note_req* n = new Note_req;
265 for (int j = 0; j < sub_arr_p->size (); j++)
267 if (p == (*sub_arr_p)[j])
278 v->set_spot (here_input ());
283 My_lily_parser::get_note_element (Note_req *rq, Duration * duration_p)
285 Simultaneous_music*v = new Request_chord;
286 v->set_spot (here_input ());
290 rq->duration_ = *duration_p;
291 rq->set_spot (here_input ());
301 My_lily_parser::get_parens_request (int t)
303 Array<Request*>& reqs = *new Array<Request*>;
307 reqs.push (new Tie_req);
314 if (!abbrev_beam_type_i_)
316 reqs.push (new Beam_req);
320 Abbreviation_beam_req* a = new Abbreviation_beam_req;
321 a->type_i_ = abbrev_beam_type_i_;
323 abbrev_beam_type_i_ = 0;
332 reqs.push (new Span_dynamic_req);
338 reqs.push (new Slur_req);
352 dynamic_cast<Span_req*> (reqs[0])->spantype = Span_req::START;
358 dynamic_cast<Span_req*> (reqs[0])->spantype = Span_req::STOP;
365 for (int i = 0; i < reqs.size (); i++)
366 if (dynamic_cast<Span_dynamic_req*> (reqs[i]))
368 Span_dynamic_req* s_l= dynamic_cast<Span_dynamic_req*> (reqs[i]);
369 s_l->dynamic_dir_ = (t == '<') ? UP:DOWN;
372 // ugh? don't we do this in the parser too?
373 reqs[0]->set_spot (here_input());
378 My_lily_parser::add_requests (Simultaneous_music*v)
380 for (int i = 0; i < pre_reqs.size(); i++)
382 v->add_music (pre_reqs[i]);
385 for (int i = 0; i <post_reqs.size(); i++)
387 v->add_music (post_reqs[i]);
394 My_lily_parser::pop_spot()
396 return define_spot_array_.pop();
400 My_lily_parser::here_input() const
402 Source_file * f_l= lexer_p_->source_file_l();
403 return Input (f_l, here_ch_C());
407 My_lily_parser::default_paper_p ()
409 Identifier *id = lexer_p_->lookup_identifier ("$defaultpaper");
410 return id ? id->access_content_Paper_def (true) : new Paper_def ;
414 My_lily_parser::default_midi_p ()
416 Identifier *id = lexer_p_->lookup_identifier ("$defaultmidi");
417 return id ? id->access_content_Midi_def (true) : new Midi_def ;