2 new-chord-tremolo-engraver.cc -- implement Chord_tremolo_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "score-engraver.hh"
12 #include "repeated-music.hh"
13 #include "global-context.hh"
18 #include "percent-repeat-iterator.hh"
19 #include "bar-line.hh"
20 #include "side-position-interface.hh"
22 #include "translator.icc"
24 class Percent_repeat_engraver : public Engraver
28 TRANSLATOR_DECLARATIONS (Percent_repeat_engraver);
33 /// moment (global time) where beam started.
37 /// location within measure where beam started.
38 Moment beam_start_location_;
48 Repeat_sign_type repeat_sign_type_;
50 Item *double_percent_;
51 Item *double_percent_counter_;
54 Spanner *percent_counter_;
55 Spanner *finished_percent_;
56 Spanner *finished_percent_counter_;
61 virtual void finalize ();
62 virtual bool try_music (Music *);
64 void stop_translation_timestep ();
65 void start_translation_timestep ();
66 void process_music ();
69 Percent_repeat_engraver::Percent_repeat_engraver ()
74 finished_percent_ = 0;
75 finished_percent_counter_ = 0;
78 double_percent_counter_ = 0;
86 Percent_repeat_engraver::try_music (Music *m)
88 if (m->is_mus_type ("repeated-music")
89 && m->get_property ("iterator-ctor")
90 == Percent_repeat_iterator::constructor_proc
93 body_length_ = Repeated_music::body_get_length (m);
94 total_count_ = Repeated_music::repeat_count (m);
96 Moment now = now_mom ();
98 stop_mom_ = start_mom_ + Moment (total_count_) * body_length_;
99 next_moment_ = start_mom_;
100 next_moment_ += body_length_;
102 Moment meas_len (robust_scm2moment (get_property ("measureLength"),
105 if (meas_len == body_length_)
106 repeat_sign_type_ = MEASURE;
107 else if (Moment (2) * meas_len == body_length_)
108 repeat_sign_type_ = DOUBLE_MEASURE;
111 warning (_f ("can't handle a percent repeat of length: %s",
112 body_length_.to_string ()));
118 Global_context *global = get_global_context ();
119 for (int i = 1; i < total_count_; i++)
121 Moment m = next_moment_ + Moment (i) * body_length_;
122 global->add_moment_to_process (m);
124 /* bars between % too. */
125 if (repeat_sign_type_ == DOUBLE_MEASURE)
126 global->add_moment_to_process (m - meas_len);
129 if (repeat_sign_type_ == DOUBLE_MEASURE)
130 next_moment_ += meas_len;
140 Percent_repeat_engraver::process_music ()
142 if (repeat_ && now_mom () == next_moment_)
145 if (repeat_sign_type_ == MEASURE)
147 finished_percent_ = percent_;
148 finished_percent_counter_ = percent_counter_;
151 percent_ = make_spanner ("PercentRepeat", repeat_->self_scm ());
153 Grob *col = unsmob_grob (get_property ("currentCommandColumn"));
154 percent_->set_bound (LEFT, col);
156 if (total_count_ > 2)
159 = make_spanner ("PercentRepeatCounter", repeat_->self_scm ());
162 SCM text = scm_number_to_string (scm_from_int (count_),
164 percent_counter_->set_property ("text", text);
165 percent_counter_->set_bound (LEFT, col);
166 Side_position_interface::add_support (percent_counter_,
168 percent_counter_->set_parent (percent_, Y_AXIS);
171 else if (repeat_sign_type_ == DOUBLE_MEASURE)
173 double_percent_ = make_item ("DoublePercentRepeat", repeat_->self_scm ());
175 if (total_count_ > 2)
177 double_percent_counter_
178 = make_item ("DoublePercentRepeatCounter",
179 repeat_->self_scm());
181 SCM text = scm_number_to_string (scm_from_int (count_),
183 double_percent_counter_->set_property ("text", text);
185 Side_position_interface::add_support (double_percent_counter_,
187 double_percent_counter_->set_parent (double_percent_, Y_AXIS);
188 double_percent_counter_->set_parent (double_percent_, X_AXIS);
192 forbid breaks on a % line. Should forbid all breaks, really.
194 Ugh. Why can't this be regular communication between
197 get_score_engraver ()->forbid_breaks ();
199 next_moment_ = next_moment_ + body_length_;
204 Percent_repeat_engraver::finalize ()
209 repeat_->origin ()->warning (_ ("unterminated percent repeat"));
210 percent_->suicide ();
211 percent_counter_->suicide();
216 Percent_repeat_engraver::typeset_perc ()
218 if (finished_percent_)
220 Grob *col = unsmob_grob (get_property ("currentCommandColumn"));
222 finished_percent_->set_bound (RIGHT, col);
223 finished_percent_ = 0;
225 if (finished_percent_counter_)
226 finished_percent_counter_->set_bound (RIGHT, col);
228 finished_percent_counter_ = 0;
232 double_percent_counter_ = 0;
236 Percent_repeat_engraver::start_translation_timestep ()
238 if (stop_mom_ == now_mom ())
242 finished_percent_ = percent_;
243 finished_percent_counter_ = percent_counter_;
250 percent_counter_ = 0;
251 repeat_sign_type_ = UNKNOWN;
256 Percent_repeat_engraver::stop_translation_timestep ()
261 ADD_TRANSLATOR (Percent_repeat_engraver,
262 /* doc */ "Make whole bar and double bar repeats.",
264 "PercentRepeat DoublePercentRepeat "
265 "PercentRepeatCounter DoublePercentRepeatCounter",
266 /* accept */ "repeated-music",
267 /* read */ "measureLength currentCommandColumn",