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 acknowledge_grob (Grob_info);
69 virtual void stop_translation_timestep ();
70 virtual void start_translation_timestep ();
71 virtual void process_music ();
74 Percent_repeat_engraver::Percent_repeat_engraver ()
76 perc_p_ = finished_perc_p_ = 0;
85 Percent_repeat_engraver::try_music (Music * m)
87 Repeated_music * rp = dynamic_cast<Repeated_music*> (m);
89 && rp->get_mus_property ("iterator-ctor")
90 == Percent_repeat_iterator::constructor_cxx_function
93 body_length_ = rp->body_length_mom ();
94 int count = rp->repeat_count ();
96 Moment now = now_mom ();
98 stop_mom_ = start_mom_ + Moment (count) * body_length_;
99 next_moment_ = start_mom_ + body_length_;
101 SCM m = get_property ("measureLength");
103 if (unsmob_moment (m))
104 meas_len = *unsmob_moment (m);
106 if (body_length_ < meas_len &&
107 meas_len.mod_rat (body_length_) == Moment (0,0))
108 repeat_sign_type_ = BEAT;
109 else if (meas_len == body_length_)
110 repeat_sign_type_ = MEASURE;
111 else if (Moment (2)* meas_len == body_length_)
113 repeat_sign_type_ = DOUBLE_MEASURE;
114 next_moment_ += meas_len ;
118 warning (_ ("Don't know how to handle a percent repeat of this length."));
125 Global_translator *global_l =0;
126 Translator *t = this;
129 t = t->daddy_trans_l_ ;
130 global_l = dynamic_cast<Global_translator*> (t);
134 for (int i = 0; i < count; i++)
135 global_l->add_moment_to_process (now + Moment (1+i) * body_length_);
144 Percent_repeat_engraver::process_music ()
146 if (repeat_ && now_mom () == next_moment_)
148 if (repeat_sign_type_ == BEAT)
150 beat_slash_ = new Item (get_property ("RepeatSlash"));
151 announce_grob (beat_slash_, repeat_);
153 else if (repeat_sign_type_ == MEASURE)
155 finished_perc_p_ = perc_p_;
157 perc_p_ = new Spanner (get_property ("PercentRepeat"));
158 SCM col =get_property ("currentCommandColumn");
159 perc_p_->set_bound (LEFT, unsmob_grob (col));
160 announce_grob (perc_p_, repeat_);
162 else if (repeat_sign_type_ == DOUBLE_MEASURE)
165 double_percent_ = new Item (get_property ("DoublePercentRepeat"));
166 announce_grob (double_percent_, repeat_);
169 forbid breaks on a % line. Should forbid all breaks, really.
171 Score_engraver * e = 0;
172 Translator * t = daddy_grav_l ();
173 for (; !e && t; t = t->daddy_trans_l_)
175 e = dynamic_cast<Score_engraver*> (t);
179 programming_error ("No score engraver!");
181 e->forbid_breaks (); // guh. Use properties!
183 next_moment_ = next_moment_ + body_length_;
188 Percent_repeat_engraver::finalize ()
193 repeat_->origin ()->warning (_ ("unterminated chord tremolo"));
199 Percent_repeat_engraver::typeset_perc ()
201 if (finished_perc_p_)
203 SCM col =get_property ("currentCommandColumn");
204 finished_perc_p_->set_bound (RIGHT, unsmob_grob (col));
205 typeset_grob (finished_perc_p_);
206 finished_perc_p_ = 0;
211 typeset_grob (beat_slash_);
217 typeset_grob (double_percent_);
224 Percent_repeat_engraver::acknowledge_grob (Grob_info info)
231 Percent_repeat_engraver::start_translation_timestep ()
233 if (stop_mom_ == now_mom ())
237 finished_perc_p_ = perc_p_;
242 repeat_sign_type_ = UNKNOWN;
248 Percent_repeat_engraver::stop_translation_timestep ()
253 ADD_THIS_TRANSLATOR (Percent_repeat_engraver);