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_;
53 Spanner *percent_counter_;
54 Spanner *finished_percent_;
55 Spanner *finished_percent_counter_;
60 virtual void finalize ();
61 virtual bool try_music (Music *);
63 void stop_translation_timestep ();
64 void start_translation_timestep ();
65 void process_music ();
68 Percent_repeat_engraver::Percent_repeat_engraver ()
73 finished_percent_ = 0;
74 finished_percent_counter_ = 0;
77 double_percent_counter_ = 0;
85 Percent_repeat_engraver::try_music (Music *m)
87 if (m->is_mus_type ("repeated-music")
88 && m->get_property ("iterator-ctor")
89 == Percent_repeat_iterator::constructor_proc
92 body_length_ = Repeated_music::body_get_length (m);
93 total_count_ = Repeated_music::repeat_count (m);
95 Moment now = now_mom ();
97 stop_mom_ = start_mom_ + Moment (total_count_) * body_length_;
98 next_moment_ = start_mom_ + body_length_;
100 Moment meas_len (robust_scm2moment (get_property ("measureLength"), Moment (1)));
101 if (meas_len == body_length_)
102 repeat_sign_type_ = MEASURE;
103 else if (Moment (2) * meas_len == body_length_)
104 repeat_sign_type_ = DOUBLE_MEASURE;
107 warning (_f ("can't handle a percent repeat of length: %s",
108 body_length_.to_string ()));
114 Global_context *global = get_global_context ();
115 for (int i = 1; i < total_count_; i++)
117 Moment m = next_moment_ + Moment (i) * body_length_;
118 global->add_moment_to_process (m);
120 /* bars between % too. */
121 if (repeat_sign_type_ == DOUBLE_MEASURE)
122 global->add_moment_to_process (m - meas_len);
125 if (repeat_sign_type_ == DOUBLE_MEASURE)
126 next_moment_ += meas_len;
136 Percent_repeat_engraver::process_music ()
138 if (repeat_ && now_mom () == next_moment_)
141 if (repeat_sign_type_ == MEASURE)
143 finished_percent_ = percent_;
144 finished_percent_counter_ = percent_counter_;
147 percent_ = make_spanner ("PercentRepeat", repeat_->self_scm ());
149 Grob *col = unsmob_grob (get_property ("currentCommandColumn"));
150 percent_->set_bound (LEFT, col);
152 if (total_count_ > 2)
155 = make_spanner ("PercentRepeatCounter", repeat_->self_scm ());
158 SCM text = scm_number_to_string (scm_from_int (count_),
160 percent_counter_->set_property ("text", text);
161 percent_counter_->set_bound (LEFT, col);
162 Side_position_interface::add_support (percent_counter_,
164 percent_counter_->set_parent (percent_, Y_AXIS);
167 else if (repeat_sign_type_ == DOUBLE_MEASURE)
169 double_percent_ = make_item ("DoublePercentRepeat", repeat_->self_scm ());
171 if (total_count_ > 2)
173 double_percent_counter_
174 = make_item ("DoublePercentRepeatCounter",
175 repeat_->self_scm());
177 SCM text = scm_number_to_string (scm_from_int (count_),
179 double_percent_counter_->set_property ("text", text);
181 Side_position_interface::add_support (double_percent_counter_,
183 double_percent_counter_->set_parent (double_percent_, Y_AXIS);
184 double_percent_counter_->set_parent (double_percent_, X_AXIS);
188 forbid breaks on a % line. Should forbid all breaks, really.
190 Ugh. Why can't this be regular communication between
193 get_score_engraver ()->forbid_breaks ();
195 next_moment_ = next_moment_ + body_length_;
200 Percent_repeat_engraver::finalize ()
205 repeat_->origin ()->warning (_ ("unterminated percent repeat"));
206 percent_->suicide ();
207 percent_counter_->suicide();
212 Percent_repeat_engraver::typeset_perc ()
214 if (finished_percent_)
216 Grob *col = unsmob_grob (get_property ("currentCommandColumn"));
218 finished_percent_->set_bound (RIGHT, col);
219 finished_percent_ = 0;
221 if (finished_percent_counter_)
222 finished_percent_counter_->set_bound (RIGHT, col);
224 finished_percent_counter_ = 0;
228 double_percent_counter_ = 0;
232 Percent_repeat_engraver::start_translation_timestep ()
234 if (stop_mom_ == now_mom ())
238 finished_percent_ = percent_;
239 finished_percent_counter_ = percent_counter_;
246 percent_counter_ = 0;
247 repeat_sign_type_ = UNKNOWN;
252 Percent_repeat_engraver::stop_translation_timestep ()
257 ADD_TRANSLATOR (Percent_repeat_engraver,
258 /* doc */ "Make whole bar and double bar repeats.",
260 "PercentRepeat DoublePercentRepeat "
261 "PercentRepeatCounter DoublePercentRepeatCounter",
262 /* accept */ "repeated-music",
263 /* read */ "measureLength currentCommandColumn",