lilypond-1.3.122
[lilypond.git] / lily / abbreviation-beam-engraver.cc
blobd264169f9f0aae2d7ef6c1a4f517ea116fd2b195
1 /*
2 abbreviation-beam-engraver.cc -- implement Abbreviation_beam_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 Jan Nieuwenhuizen <janneke@gnu.org>
8 */
10 #include "duration-convert.hh"
11 #include "time-description.hh"
12 #include "abbreviation-beam-engraver.hh"
13 #include "stem.hh"
14 #include "abbreviation-beam.hh"
15 #include "musical-request.hh"
16 #include "misc.hh"
17 #include "warn.hh"
18 #include "score-engraver.hh"
20 ADD_THIS_TRANSLATOR (Abbreviation_beam_engraver);
22 Abbreviation_beam_engraver::Abbreviation_beam_engraver ()
24 reqs_drul_[LEFT] = reqs_drul_[RIGHT] = 0;
25 abeam_p_ = 0;
26 finished_abeam_p_ = 0;
27 prev_start_req_ = 0;
30 bool
31 Abbreviation_beam_engraver::do_try_music (Music* m)
33 if (Abbreviation_beam_req* b = dynamic_cast <Abbreviation_beam_req *> (m))
35 Direction d = b->span_dir_;
36 if (reqs_drul_[d] && !reqs_drul_[d]->equal_b (b))
37 return false;
39 if ((d == STOP) && !abeam_p_)
41 m->warning (_ ("No abbreviation beam to end"));
42 return false;
45 reqs_drul_[d] = b;
46 return true;
49 return false;
52 void
53 Abbreviation_beam_engraver::do_process_requests ()
55 if (reqs_drul_[STOP])
57 if (!abeam_p_)
58 reqs_drul_[STOP]->warning (_("No abbreviation beam to end"));
59 prev_start_req_ = 0;
60 finished_abeam_p_ = abeam_p_;
61 abeam_p_ = 0;
64 if (abeam_p_)
66 Score_engraver * e = 0;
67 Translator * t = daddy_grav_l ();
68 for (; !e && t; t = t->daddy_trans_l_)
70 e = dynamic_cast<Score_engraver*> (t);
73 if (!e)
74 programming_error ("No score engraver!");
75 else
76 e->forbid_breaks ();
79 if (reqs_drul_[START])
81 if (abeam_p_)
83 reqs_drul_[START]->warning (_ ("Already have an abbreviation beam"));
84 return;
87 prev_start_req_ = reqs_drul_[START];
89 abeam_p_ = new Abbreviation_beam;
90 announce_element (Score_element_info (abeam_p_, reqs_drul_[LEFT]));
94 void
95 Abbreviation_beam_engraver::do_post_move_processing ()
97 reqs_drul_ [START] = 0;
100 void
101 Abbreviation_beam_engraver::do_pre_move_processing ()
103 typeset_beam ();
106 void
107 Abbreviation_beam_engraver::typeset_beam ()
109 if (finished_abeam_p_)
111 typeset_element (finished_abeam_p_);
112 finished_abeam_p_ = 0;
114 reqs_drul_[STOP] = 0;
118 void
119 Abbreviation_beam_engraver::do_removal_processing ()
121 typeset_beam ();
122 if (abeam_p_)
124 prev_start_req_->warning (_ ("Unfinished abbreviation beam"));
125 finished_abeam_p_ = abeam_p_;
126 typeset_beam ();
130 void
131 Abbreviation_beam_engraver::acknowledge_element (Score_element_info i)
133 if (abeam_p_)
135 if (Stem* s = dynamic_cast<Stem *> (i.elem_l_))
137 int type_i = prev_start_req_->type_i_;
138 s->flag_i_ = intlog2 (type_i) - 2;
140 s->beams_i_drul_[LEFT] = s->flag_i_;
141 s->beams_i_drul_[RIGHT] = s->flag_i_;
143 abeam_p_->multiple_i_ = s->flag_i_;
145 abbrev gaps on all but half note
147 #if 0
148 if (s->type_i () != 1)
150 int gap_i =s->flag_i_ - ((s->type_i () >? 2) - 2);
151 s->set_elt_property (beam_gap_scm_sym, gh_int2scm(gap_i));
153 #else
154 if (s->type_i () != 1)
156 int gap_i =s->flag_i_ - ((s->type_i () >? 2) - 2);
157 abeam_p_->set_elt_property (beam_gap_scm_sym, gh_int2scm(gap_i));
159 #endif
161 abeam_p_->add_stem (s);