lilypond-0.1.57
[lilypond.git] / lily / abbreviation-beam-engraver.cc
blobe8e8ef0614e92e639a46df0e71692845ed0820d1
1 /*
2 abbreviation-beam-engraver.cc -- implement Abbreviation_beam_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997 Han-Wen Nienhuys <hanwen@stack.nl>
7 Jan Nieuwenhuizen <jan@digicash.com>
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"
18 IMPLEMENT_IS_TYPE_B1(Abbreviation_beam_engraver, Engraver);
19 ADD_THIS_TRANSLATOR(Abbreviation_beam_engraver);
21 Abbreviation_beam_engraver::Abbreviation_beam_engraver ()
23 span_reqs_drul_[LEFT] = span_reqs_drul_[RIGHT] = 0;
24 abeam_p_ = 0;
27 bool
28 Abbreviation_beam_engraver::do_try_request (Request*r)
30 Musical_req* mus_l = r->musical ();
31 if (!mus_l)
32 return false;
34 Abbreviation_beam_req * b = mus_l->abbrev_beam ();
36 if (!b)
37 return false;
39 if (bool (abeam_p_) == bool (b->spantype == Span_req::START))
40 return false;
42 Direction d = (!abeam_p_) ? LEFT : RIGHT;
43 if (span_reqs_drul_[d] && !span_reqs_drul_[d]->equal_b (mus_l))
44 return false;
46 span_reqs_drul_[d] = b;
47 return true;
50 void
51 Abbreviation_beam_engraver::do_process_requests ()
53 if (!abeam_p_ && span_reqs_drul_[LEFT]) {
54 abeam_p_ = new Abbreviation_beam;
55 announce_element (Score_elem_info (abeam_p_, span_reqs_drul_[LEFT]));
59 void
60 Abbreviation_beam_engraver::do_pre_move_processing ()
62 if (abeam_p_ && span_reqs_drul_[RIGHT]) {
63 typeset_element (abeam_p_);
64 abeam_p_ = 0;
66 span_reqs_drul_[RIGHT] =
67 span_reqs_drul_[LEFT] = 0;
71 void
72 Abbreviation_beam_engraver::do_removal_processing ()
74 if (abeam_p_)
76 span_reqs_drul_[LEFT]->warning (_("unterminated beam"));
77 typeset_element (abeam_p_);
78 abeam_p_ = 0;
82 void
83 Abbreviation_beam_engraver::acknowledge_element (Score_elem_info i)
85 if (!abeam_p_ || !i.elem_l_->is_type_b (Stem::static_name ()))
86 return;
88 Stem* s = (Stem*)i.elem_l_->item ();
90 int type_i = span_reqs_drul_[LEFT]->type_i_;
91 s->flag_i_ = intlog2 (type_i) - 2;
92 if (span_reqs_drul_[RIGHT])
93 s->beams_left_i_ = s->flag_i_;
94 else
95 s->beams_right_i_ = s->flag_i_;
97 if (s->type_i () != 1) // no abbrev gaps on half note
98 s->beam_gap_i_ = s->flag_i_ - ((s->type_i () >? 2) - 2);
100 abeam_p_->add (s);