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
24 This acknowledges repeated music with "tremolo" style. It typesets
29 - perhaps use engraver this to steer other engravers? That would
30 create dependencies between engravers, which is bad.
32 - create dots if appropriate.
34 - create TremoloBeam iso Beam?
36 class Chord_tremolo_engraver : public Engraver
39 TRANSLATOR_DECLARATIONS (Chord_tremolo_engraver);
43 /// moment (global time) where beam started.
47 int total_duration_flags_;
49 /// location within measure where beam started.
50 Moment beam_start_location_;
52 bool body_is_sequential_;
54 Spanner *finished_beam_;
57 virtual void finalize ();
58 virtual bool try_music (Music *);
59 virtual void acknowledge_grob (Grob_info);
60 virtual void stop_translation_timestep ();
61 virtual void start_translation_timestep ();
62 virtual void process_music ();
65 Chord_tremolo_engraver::Chord_tremolo_engraver ()
67 beam_ = finished_beam_ = 0;
71 body_is_sequential_ = false;
75 Chord_tremolo_engraver::try_music (Music *m)
77 if (m->is_mus_type ("repeated-music")
78 && m->get_property ("iterator-ctor") == Chord_tremolo_iterator::constructor_proc
81 Moment l = m->get_length ();
83 start_mom_ = now_mom ();
84 stop_mom_ = start_mom_ + l;
86 Music *body = Repeated_music::body (m);
87 body_is_sequential_ = body->is_mus_type ("sequential-music");
89 int elt_count = body_is_sequential_ ? scm_ilength (body->get_property ("elements")) : 1;
91 if (body_is_sequential_ && elt_count != 2)
93 m->origin ()->warning (_f ("expect 2 elements for chord tremolo, found %d", elt_count));
99 Rational total_dur = l.main_part_;
100 Rational note_dur = total_dur / Rational (elt_count * Repeated_music::repeat_count (repeat_));
102 total_duration_flags_ = max (0, (intlog2 (total_dur.den ()) - 2));
104 flags_ = intlog2 (note_dur.den ()) -2;
113 Chord_tremolo_engraver::process_music ()
115 if (repeat_ && body_is_sequential_ && !beam_)
117 beam_ = make_spanner ("Beam", repeat_->self_scm ());
118 beam_->set_property ("chord-tremolo", SCM_BOOL_T);
120 beam_start_location_ = robust_scm2moment (get_property ("measurePosition"), Moment (0));
125 Chord_tremolo_engraver::finalize ()
130 repeat_->origin ()->warning (_ ("unterminated chord tremolo"));
136 Chord_tremolo_engraver::typeset_beam ()
142 Chord_tremolo_engraver::acknowledge_grob (Grob_info info)
144 if (beam_ && Stem::has_interface (info.grob ()))
146 Grob *s = info.grob ();
148 if (start_mom_ == now_mom ())
149 Stem::set_beaming (s, flags_, RIGHT);
151 Stem::set_beaming (s, flags_, LEFT);
153 if (Stem::duration_log (s) != 1)
155 beam_->set_property ("gap-count", scm_int2num (flags_ - total_duration_flags_));
158 if (info.music_cause ()->is_mus_type ("rhythmic-event"))
160 Beam::add_stem (beam_, s);
164 String s = _ ("stem must have Rhythmic structure");
165 if (info.music_cause ())
166 info.music_cause ()->origin ()->warning (s);
173 && !body_is_sequential_
174 && Stem::has_interface (info.grob ()))
176 stem_tremolo_ = make_item ("StemTremolo", repeat_->self_scm ());
177 stem_tremolo_->set_property ("flag-count",
178 scm_int2num (flags_));
179 stem_tremolo_->set_property ("stem",
180 info.grob ()->self_scm ());
181 stem_tremolo_->set_parent (info.grob (), X_AXIS);
186 Chord_tremolo_engraver::start_translation_timestep ()
188 if (beam_ && stop_mom_ == now_mom ())
190 finished_beam_ = beam_;
197 Chord_tremolo_engraver::stop_translation_timestep ()
203 programming_error ("beam and stem tremolo?");
210 ADD_TRANSLATOR (Chord_tremolo_engraver,
211 /* descr */ "Generates beams for tremolo repeats.",
213 /* accepts */ "repeated-music",
214 /* acks */ "stem-interface",