2 new-chord-tremolo-engraver.cc -- implement Chord_tremolo_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "engraver.hh"
11 #include "repeated-music.hh"
12 #include "engraver-group-engraver.hh"
13 #include "global-translator.hh"
18 #include "percent-repeat-iterator.hh"
21 #include "score-engraver.hh"
22 #include "translator-group.hh"
25 This acknowledges repeated music with "percent" style. It typesets
30 - BEAT case: Create items for single beat repeats, i.e. c4 / / /
32 - DOUBLE_MEASURE case: attach a % to an appropriate barline.
35 class Percent_repeat_engraver : public Engraver
39 VIRTUAL_COPY_CONS (Translator);
40 Percent_repeat_engraver ();
42 Repeated_music * repeat_;
44 /// moment (global time) where beam started.
48 /// location within measure where beam started.
49 Moment beam_start_location_;
61 Item * double_percent_;
63 Spanner * finished_perc_p_;
66 virtual void finalize ();
67 virtual bool try_music (Music*);
68 virtual void stop_translation_timestep ();
69 virtual void start_translation_timestep ();
70 virtual void process_music ();
73 Percent_repeat_engraver::Percent_repeat_engraver ()
75 perc_p_ = finished_perc_p_ = 0;
84 Percent_repeat_engraver::try_music (Music * m)
86 Repeated_music * rp = dynamic_cast<Repeated_music*> (m);
88 && rp->get_mus_property ("iterator-ctor")
89 == Percent_repeat_iterator::constructor_cxx_function
92 body_length_ = rp->body_length_mom ();
93 int count = rp->repeat_count ();
95 Moment now = now_mom ();
97 stop_mom_ = start_mom_ + Moment (count) * body_length_;
98 next_moment_ = start_mom_ + body_length_;
100 SCM m = get_property ("measureLength");
102 if (unsmob_moment (m))
103 meas_len = *unsmob_moment (m);
105 if (body_length_ < meas_len &&
106 meas_len.main_part_.mod_rat (body_length_.main_part_) == Moment (0,0))
107 repeat_sign_type_ = BEAT;
108 else if (meas_len == body_length_)
109 repeat_sign_type_ = MEASURE;
110 else if (Moment (2)* meas_len == body_length_)
112 repeat_sign_type_ = DOUBLE_MEASURE;
113 next_moment_ += meas_len ;
117 warning (_ ("Don't know how to handle a percent repeat of this length."));
124 Global_translator *global_l =0;
125 Translator *t = this;
128 t = t->daddy_trans_l_ ;
129 global_l = dynamic_cast<Global_translator*> (t);
133 for (int i = 0; i < count; i++)
134 global_l->add_moment_to_process (now + Moment (1+i) * body_length_);
143 Percent_repeat_engraver::process_music ()
145 if (repeat_ && now_mom () == next_moment_)
147 if (repeat_sign_type_ == BEAT)
149 beat_slash_ = new Item (get_property ("RepeatSlash"));
150 announce_grob (beat_slash_, repeat_);
152 else if (repeat_sign_type_ == MEASURE)
154 finished_perc_p_ = perc_p_;
156 perc_p_ = new Spanner (get_property ("PercentRepeat"));
157 SCM col =get_property ("currentCommandColumn");
158 perc_p_->set_bound (LEFT, unsmob_grob (col));
159 announce_grob (perc_p_, repeat_);
161 else if (repeat_sign_type_ == DOUBLE_MEASURE)
164 double_percent_ = new Item (get_property ("DoublePercentRepeat"));
165 announce_grob (double_percent_, repeat_);
168 forbid breaks on a % line. Should forbid all breaks, really.
170 Score_engraver * e = 0;
171 Translator * t = daddy_grav_l ();
172 for (; !e && t; t = t->daddy_trans_l_)
174 e = dynamic_cast<Score_engraver*> (t);
178 programming_error ("No score engraver!");
180 e->forbid_breaks (); // guh. Use properties!
182 next_moment_ = next_moment_ + body_length_;
187 Percent_repeat_engraver::finalize ()
192 repeat_->origin ()->warning (_ ("unterminated chord tremolo"));
198 Percent_repeat_engraver::typeset_perc ()
200 if (finished_perc_p_)
202 SCM col =get_property ("currentCommandColumn");
203 finished_perc_p_->set_bound (RIGHT, unsmob_grob (col));
204 typeset_grob (finished_perc_p_);
205 finished_perc_p_ = 0;
210 typeset_grob (beat_slash_);
216 typeset_grob (double_percent_);
225 Percent_repeat_engraver::start_translation_timestep ()
227 if (stop_mom_ == now_mom ())
231 finished_perc_p_ = perc_p_;
236 repeat_sign_type_ = UNKNOWN;
242 Percent_repeat_engraver::stop_translation_timestep ()
247 ADD_THIS_TRANSLATOR (Percent_repeat_engraver);