2 new-chord-tremolo-engraver.cc -- implement Chord_tremolo_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2003 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"
19 #include "bar-line.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 TRANSLATOR_DECLARATIONS(Percent_repeat_engraver);
41 Repeated_music * repeat_;
43 /// moment (global time) where beam started.
47 /// location within measure where beam started.
48 Moment beam_start_location_;
60 Item * double_percent_;
62 Spanner * finished_perc_;
65 virtual void finalize ();
66 virtual bool try_music (Music*);
67 virtual void stop_translation_timestep ();
68 virtual void start_translation_timestep ();
69 virtual void process_music ();
72 Percent_repeat_engraver::Percent_repeat_engraver ()
74 perc_ = finished_perc_ = 0;
83 Percent_repeat_engraver::try_music (Music * m)
85 Repeated_music * rp = dynamic_cast<Repeated_music*> (m);
87 && rp->get_mus_property ("iterator-ctor")
88 == Percent_repeat_iterator::constructor_proc
91 body_length_ = rp->body_get_length ();
92 int count = rp->repeat_count ();
94 Moment now = now_mom ();
96 stop_mom_ = start_mom_ + Moment (count) * body_length_;
97 next_moment_ = start_mom_ + body_length_;
99 SCM m = get_property ("measureLength");
101 if (unsmob_moment (m))
102 meas_len = *unsmob_moment (m);
104 if (body_length_ < meas_len &&
105 meas_len.main_part_.mod_rat (body_length_.main_part_) == Moment (Rational (0,0)))
106 repeat_sign_type_ = BEAT;
107 else if (meas_len == body_length_)
108 repeat_sign_type_ = MEASURE;
109 else if (Moment (2)* meas_len == body_length_)
111 repeat_sign_type_ = DOUBLE_MEASURE;
112 next_moment_ += meas_len ;
116 warning (_ ("Don't know how to handle a percent repeat of this length."));
123 Global_translator *global =top_engraver();
124 for (int i = 0; i < count; i++)
125 global->add_moment_to_process (next_moment_ + Moment (i) * body_length_);
134 Percent_repeat_engraver::process_music ()
136 if (repeat_ && now_mom () == next_moment_)
138 if (repeat_sign_type_ == BEAT)
140 beat_slash_ = new Item (get_property ("RepeatSlash"));
141 announce_grob(beat_slash_, repeat_->self_scm());
143 else if (repeat_sign_type_ == MEASURE)
145 finished_perc_ = perc_;
147 perc_ = new Spanner (get_property ("PercentRepeat"));
148 SCM col =get_property ("currentCommandColumn");
149 perc_->set_bound (LEFT, unsmob_grob (col));
150 announce_grob(perc_, repeat_->self_scm());
152 else if (repeat_sign_type_ == DOUBLE_MEASURE)
154 double_percent_ = new Item (get_property ("DoublePercentRepeat"));
155 announce_grob(double_percent_, repeat_->self_scm());
158 forbid breaks on a % line. Should forbid all breaks, really.
161 top_engraver()->forbid_breaks (); // guh. Use properties!
163 next_moment_ = next_moment_ + body_length_;
165 top_engraver()->add_moment_to_process (next_moment_);
170 Percent_repeat_engraver::finalize ()
175 repeat_->origin ()->warning (_ ("unterminated chord tremolo"));
181 Percent_repeat_engraver::typeset_perc ()
185 SCM col =get_property ("currentCommandColumn");
186 finished_perc_->set_bound (RIGHT, unsmob_grob (col));
187 typeset_grob (finished_perc_);
193 typeset_grob (beat_slash_);
199 typeset_grob (double_percent_);
208 Percent_repeat_engraver::start_translation_timestep ()
210 if (stop_mom_ == now_mom ())
214 finished_perc_ = perc_;
219 repeat_sign_type_ = UNKNOWN;
225 Percent_repeat_engraver::stop_translation_timestep ()
233 ENTER_DESCRIPTION(Percent_repeat_engraver,
234 /* descr */ "Make beat, whole bar and double bar repeats.",
235 /* creats*/ "PercentRepeat RepeatSlash DoublePercentRepeat",
236 /* accepts */ "repeated-music",
238 /* reads */ "measureLength currentCommandColumn",