2 new-chord-tremolo-engraver.cc -- implement Chord_tremolo_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>, Erik Sandberg <mandolaerik@gmail.com>
10 #include "score-engraver.hh"
12 #include "bar-line.hh"
13 #include "global-context.hh"
14 #include "international.hh"
17 #include "repeated-music.hh"
18 #include "side-position-interface.hh"
20 #include "stream-event.hh"
23 #include "translator.icc"
26 * TODO: Create separate Double_percent_repeat_engraver?
27 * Or, at least move double percent handling to Slash_repeat_engraver
30 class Percent_repeat_engraver : public Engraver
34 TRANSLATOR_DECLARATIONS (Percent_repeat_engraver);
37 Stream_event *percent_event_;
39 /// moment (global time) where percent started.
49 Repeat_sign_type repeat_sign_type_;
52 Spanner *percent_counter_;
55 Grob *first_command_column_;
56 Moment command_moment_;
59 virtual void finalize ();
60 DECLARE_TRANSLATOR_LISTENER (percent);
62 void stop_translation_timestep ();
63 void start_translation_timestep ();
64 void process_music ();
67 Percent_repeat_engraver::Percent_repeat_engraver ()
73 first_command_column_ = 0;
74 command_moment_ = Moment (-1);
78 Percent_repeat_engraver::start_translation_timestep ()
80 if (now_mom ().main_part_ != command_moment_.main_part_)
82 first_command_column_ = unsmob_grob (get_property ("currentCommandColumn"));
83 command_moment_ = now_mom ();
86 if (stop_mom_.main_part_ == now_mom ().main_part_)
91 repeat_sign_type_ = UNKNOWN;
95 IMPLEMENT_TRANSLATOR_LISTENER (Percent_repeat_engraver, percent);
97 Percent_repeat_engraver::listen_percent (Stream_event *ev)
101 Moment body_length = get_event_length (ev);
102 Moment meas_len (robust_scm2moment (get_property ("measureLength"),
104 if (meas_len == body_length)
106 repeat_sign_type_ = MEASURE;
107 start_mom_ = now_mom ();
108 stop_mom_ = now_mom () + body_length;
109 get_global_context ()->add_moment_to_process (stop_mom_);
111 else if (Moment (2) * meas_len == body_length)
113 repeat_sign_type_ = DOUBLE_MEASURE;
114 start_mom_ = now_mom () + meas_len;
115 stop_mom_ = now_mom () + body_length; /* never used */
116 get_global_context ()->add_moment_to_process (start_mom_);
121 don't warn about percent repeats: slash repeats are not
122 exactly 1 or 2 measures long.
129 /* print a warning: no assignment happens because
130 percent_event_ != 0 */
131 ASSIGN_EVENT_ONCE (percent_event_, ev);
135 Percent_repeat_engraver::process_music ()
137 if (percent_event_ && now_mom ().main_part_ == start_mom_.main_part_)
139 if (repeat_sign_type_ == MEASURE)
144 percent_ = make_spanner ("PercentRepeat", percent_event_->self_scm ());
146 Grob *col = first_command_column_;
147 percent_->set_bound (LEFT, col);
149 SCM count = percent_event_->get_property ("repeat-count");
150 if (count != SCM_EOL && to_boolean (get_property ("countPercentRepeats")))
153 = make_spanner ("PercentRepeatCounter", percent_event_->self_scm ());
155 SCM text = scm_number_to_string (count, scm_from_int (10));
156 percent_counter_->set_property ("text", text);
157 percent_counter_->set_bound (LEFT, col);
158 Side_position_interface::add_support (percent_counter_,
160 percent_counter_->set_parent (percent_, Y_AXIS);
163 percent_counter_ = 0;
165 else if (repeat_sign_type_ == DOUBLE_MEASURE)
167 Item *double_percent = make_item ("DoublePercentRepeat", percent_event_->self_scm ());
169 SCM count = percent_event_->get_property ("repeat-count");
171 && to_boolean (get_property ("countPercentRepeats")))
173 Item *double_percent_counter = make_item ("DoublePercentRepeatCounter",
174 percent_event_->self_scm());
176 SCM text = scm_number_to_string (count,
178 double_percent_counter->set_property ("text", text);
180 Side_position_interface::add_support (double_percent_counter,
182 double_percent_counter->set_parent (double_percent, Y_AXIS);
183 double_percent_counter->set_parent (double_percent, X_AXIS);
186 /* forbid breaks on a % line. Should forbid all breaks, really. */
187 context ()->get_score_context ()->set_property ("forbidBreak", SCM_BOOL_T);
189 /* No more processing needed. */
190 repeat_sign_type_ = UNKNOWN;
196 Percent_repeat_engraver::finalize ()
200 percent_event_->origin ()->warning (_ ("unterminated percent repeat"));
201 percent_->suicide ();
202 percent_counter_->suicide();
207 Percent_repeat_engraver::typeset_perc ()
211 Grob *col = first_command_column_;
213 percent_->set_bound (RIGHT, col);
216 if (percent_counter_)
217 percent_counter_->set_bound (RIGHT, col);
218 percent_counter_ = 0;
225 Percent_repeat_engraver::stop_translation_timestep ()
229 ADD_TRANSLATOR (Percent_repeat_engraver,
231 "Make whole bar and double bar repeats.",
234 "DoublePercentRepeat "
235 "DoublePercentRepeatCounter "
237 "PercentRepeatCounter ",
240 "countPercentRepeats "
241 "currentCommandColumn "