2 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>
9 #include "math.h" // ceil
12 #include "chord-tremolo-iterator.hh"
13 #include "engraver-group.hh"
14 #include "international.hh"
17 #include "repeated-music.hh"
18 #include "rhythmic-head.hh"
20 #include "stem-tremolo.hh"
24 #include "translator.icc"
28 This acknowledges repeated music with "tremolo" style. It typesets
33 - perhaps use engraver this to steer other engravers? That would
34 create dependencies between engravers, which is bad.
36 - create dots if appropriate.
38 - create TremoloBeam iso Beam?
40 class Chord_tremolo_engraver : public Engraver
43 TRANSLATOR_DECLARATIONS (Chord_tremolo_engraver);
47 /// moment (global time) where beam started.
51 int total_duration_flags_;
53 /// location within measure where beam started.
54 Moment beam_start_location_;
56 bool body_is_sequential_;
58 Spanner *finished_beam_;
61 virtual void finalize ();
62 virtual bool try_music (Music *);
63 void stop_translation_timestep ();
64 void start_translation_timestep ();
65 void process_music ();
66 DECLARE_ACKNOWLEDGER (stem);
69 Chord_tremolo_engraver::Chord_tremolo_engraver ()
71 beam_ = finished_beam_ = 0;
75 body_is_sequential_ = false;
79 Chord_tremolo_engraver::try_music (Music *m)
81 if (m->is_mus_type ("repeated-music")
82 && m->get_property ("iterator-ctor") == Chord_tremolo_iterator::constructor_proc
85 Moment l = m->get_length ();
87 start_mom_ = now_mom ();
88 stop_mom_ = start_mom_ + l;
90 Music *body = Repeated_music::body (m);
91 body_is_sequential_ = body->is_mus_type ("sequential-music");
93 int elt_count = body_is_sequential_ ? scm_ilength (body->get_property ("elements")) : 1;
95 if (body_is_sequential_ && elt_count != 2)
96 m->origin ()->warning (_f ("expect 2 elements for chord tremolo, found %d", elt_count));
101 Rational total_dur = l.main_part_;
102 Rational note_dur = total_dur / Rational (elt_count * Repeated_music::repeat_count (repeat_));
104 total_duration_flags_ = max (0, (intlog2 (total_dur.den ()) - 2));
106 flags_ = intlog2 (note_dur.den ()) -2;
115 Chord_tremolo_engraver::process_music ()
117 if (repeat_ && body_is_sequential_ && !beam_)
119 beam_ = make_spanner ("Beam", repeat_->self_scm ());
120 beam_->set_property ("chord-tremolo", SCM_BOOL_T);
122 beam_start_location_ = robust_scm2moment (get_property ("measurePosition"), Moment (0));
127 Chord_tremolo_engraver::finalize ()
132 repeat_->origin ()->warning (_ ("unterminated chord tremolo"));
138 Chord_tremolo_engraver::typeset_beam ()
144 Chord_tremolo_engraver::acknowledge_stem (Grob_info info)
148 Grob *s = info.grob ();
150 if (start_mom_ == now_mom ())
151 Stem::set_beaming (s, flags_, RIGHT);
153 Stem::set_beaming (s, flags_, LEFT);
155 if (Stem::duration_log (s) != 1)
156 beam_->set_property ("gap-count", scm_from_int (flags_ - total_duration_flags_));
158 if (info.ultimate_music_cause ()->is_mus_type ("rhythmic-event"))
159 Beam::add_stem (beam_, s);
162 string s = _ ("stem must have Rhythmic structure");
163 if (info.music_cause ())
164 info.music_cause ()->origin ()->warning (s);
171 && !body_is_sequential_)
173 stem_tremolo_ = make_item ("StemTremolo", repeat_->self_scm ());
174 stem_tremolo_->set_property ("flag-count",
175 scm_from_int (flags_));
176 stem_tremolo_->set_object ("stem",
177 info.grob ()->self_scm ());
178 stem_tremolo_->set_parent (info.grob (), X_AXIS);
183 Chord_tremolo_engraver::start_translation_timestep ()
185 if (beam_ && stop_mom_ == now_mom ())
187 finished_beam_ = beam_;
194 Chord_tremolo_engraver::stop_translation_timestep ()
200 programming_error ("beam and stem tremolo?");
207 ADD_ACKNOWLEDGER (Chord_tremolo_engraver, stem);
208 ADD_TRANSLATOR (Chord_tremolo_engraver,
209 /* doc */ "Generates beams for tremolo repeats.",
211 /* accept */ "repeated-music",