2 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 "repeated-music.hh"
12 #include "rhythmic-head.hh"
13 #include "engraver-group-engraver.hh"
18 #include "chord-tremolo-iterator.hh"
19 #include "stem-tremolo.hh"
20 #include "math.h" // ceil
22 #include "translator.icc"
26 This acknowledges repeated music with "tremolo" style. It typesets
31 - perhaps use engraver this to steer other engravers? That would
32 create dependencies between engravers, which is bad.
34 - create dots if appropriate.
36 - create TremoloBeam iso Beam?
38 class Chord_tremolo_engraver : public Engraver
41 TRANSLATOR_DECLARATIONS (Chord_tremolo_engraver);
45 /// moment (global time) where beam started.
49 int total_duration_flags_;
51 /// location within measure where beam started.
52 Moment beam_start_location_;
54 bool body_is_sequential_;
56 Spanner *finished_beam_;
59 virtual void finalize ();
60 virtual bool try_music (Music *);
61 void stop_translation_timestep ();
62 void start_translation_timestep ();
63 void process_music ();
64 DECLARE_ACKNOWLEDGER(stem);
67 Chord_tremolo_engraver::Chord_tremolo_engraver ()
69 beam_ = finished_beam_ = 0;
73 body_is_sequential_ = false;
77 Chord_tremolo_engraver::try_music (Music *m)
79 if (m->is_mus_type ("repeated-music")
80 && m->get_property ("iterator-ctor") == Chord_tremolo_iterator::constructor_proc
83 Moment l = m->get_length ();
85 start_mom_ = now_mom ();
86 stop_mom_ = start_mom_ + l;
88 Music *body = Repeated_music::body (m);
89 body_is_sequential_ = body->is_mus_type ("sequential-music");
91 int elt_count = body_is_sequential_ ? scm_ilength (body->get_property ("elements")) : 1;
93 if (body_is_sequential_ && elt_count != 2)
95 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)
157 beam_->set_property ("gap-count", scm_from_int (flags_ - total_duration_flags_));
160 if (info.music_cause ()->is_mus_type ("rhythmic-event"))
162 Beam::add_stem (beam_, s);
166 String s = _ ("stem must have Rhythmic structure");
167 if (info.music_cause ())
168 info.music_cause ()->origin ()->warning (s);
175 && !body_is_sequential_)
177 stem_tremolo_ = make_item ("StemTremolo", repeat_->self_scm ());
178 stem_tremolo_->set_property ("flag-count",
179 scm_from_int (flags_));
180 stem_tremolo_->set_object ("stem",
181 info.grob ()->self_scm ());
182 stem_tremolo_->set_parent (info.grob (), X_AXIS);
187 Chord_tremolo_engraver::start_translation_timestep ()
189 if (beam_ && stop_mom_ == now_mom ())
191 finished_beam_ = beam_;
198 Chord_tremolo_engraver::stop_translation_timestep ()
204 programming_error ("beam and stem tremolo?");
212 ADD_ACKNOWLEDGER(Chord_tremolo_engraver,stem);
213 ADD_TRANSLATOR (Chord_tremolo_engraver,
214 /* descr */ "Generates beams for tremolo repeats.",
216 /* accepts */ "repeated-music",