lilypond-1.3.12
[lilypond.git] / lily / chord-tremolo-engraver.cc
blob6c9f9e2bc890c88a137c26d72b1a3ead8be4f69e
1 /*
2 chord-tremolo-engraver.cc -- implement Chord_tremolo_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 "timing-translator.hh"
12 #include "chord-tremolo-engraver.hh"
13 #include "stem.hh"
14 #include "beam.hh"
15 #include "musical-request.hh"
16 #include "misc.hh"
17 #include "warn.hh"
18 #include "score-engraver.hh"
20 ADD_THIS_TRANSLATOR (Chord_tremolo_engraver);
22 Chord_tremolo_engraver::Chord_tremolo_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 Chord_tremolo_engraver::do_try_music (Music* m)
33 if (Chord_tremolo_req* b = dynamic_cast <Chord_tremolo_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 tremolo beam to end"));
42 return false;
45 reqs_drul_[d] = b;
46 return true;
49 return false;
52 void
53 Chord_tremolo_engraver::do_process_requests ()
55 if (reqs_drul_[STOP])
57 if (!abeam_p_)
58 reqs_drul_[STOP]->warning (_ ("no tremolo 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 a tremolo beam"));
84 return;
87 prev_start_req_ = reqs_drul_[START];
89 abeam_p_ = new Beam;
90 abeam_p_->set_elt_property ("chord-tremolo", SCM_BOOL_T);
92 announce_element (Score_element_info (abeam_p_, reqs_drul_[LEFT]));
96 void
97 Chord_tremolo_engraver::do_post_move_processing ()
99 reqs_drul_ [START] = 0;
102 void
103 Chord_tremolo_engraver::do_pre_move_processing ()
105 typeset_beam ();
108 void
109 Chord_tremolo_engraver::typeset_beam ()
111 if (finished_abeam_p_)
113 typeset_element (finished_abeam_p_);
114 finished_abeam_p_ = 0;
116 reqs_drul_[STOP] = 0;
120 void
121 Chord_tremolo_engraver::do_removal_processing ()
123 typeset_beam ();
124 if (abeam_p_)
126 prev_start_req_->warning (_ ("unfinished tremolo beam"));
127 finished_abeam_p_ = abeam_p_;
128 typeset_beam ();
132 void
133 Chord_tremolo_engraver::acknowledge_element (Score_element_info i)
135 if (abeam_p_)
137 if (Stem* s = dynamic_cast<Stem *> (i.elem_l_))
139 int type_i = prev_start_req_->type_i_;
140 s->set_elt_property ("duration-log", gh_int2scm (intlog2 (type_i) - 2));
142 s->set_beaming (s->flag_i (), LEFT);
143 s->set_beaming ( s->flag_i (), RIGHT);
146 #if 0
147 if (s->type_i () != 1)
149 int gap_i =s->flag_i () - ((s->type_i () >? 2) - 2);
150 s->set_elt_property ("beam-gap", gh_int2scm(gap_i));
152 #else
153 if (s->type_i () != 1)
155 int gap_i =s->flag_i () - ((s->type_i () >? 2) - 2);
156 abeam_p_->set_elt_property ("beam-gap", gh_int2scm(gap_i));
158 #endif
160 abeam_p_->add_stem (s);