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"
16 #include "note-head.hh"
19 #include "chord-tremolo-iterator.hh"
20 #include "stem-tremolo.hh"
21 #include "math.h" // ceil
25 This acknowledges repeated music with "tremolo" style. It typesets
30 - perhaps use engraver this to steer other engravers? That would
31 create dependencies between engravers, which is bad.
33 - create dots if appropriate.
35 - create TremoloBeam iso Beam?
37 class Chord_tremolo_engraver : public Engraver
40 TRANSLATOR_DECLARATIONS (Chord_tremolo_engraver);
44 /// moment (global time) where beam started.
48 int total_duration_flags_;
50 /// location within measure where beam started.
51 Moment beam_start_location_;
53 bool body_is_sequential_;
55 Spanner *finished_beam_;
58 virtual void finalize ();
59 virtual bool try_music (Music *);
60 virtual void acknowledge_grob (Grob_info);
61 virtual void stop_translation_timestep ();
62 virtual void start_translation_timestep ();
63 virtual void process_music ();
66 Chord_tremolo_engraver::Chord_tremolo_engraver ()
68 beam_ = finished_beam_ = 0;
72 body_is_sequential_ = false;
76 Chord_tremolo_engraver::try_music (Music *m)
78 if (m->is_mus_type ("repeated-music")
79 && m->get_property ("iterator-ctor") == Chord_tremolo_iterator::constructor_proc
82 Moment l = m->get_length ();
84 start_mom_ = now_mom ();
85 stop_mom_ = start_mom_ + l;
87 Music *body = Repeated_music::body (m);
88 body_is_sequential_ = body->is_mus_type ("sequential-music");
90 int elt_count = body_is_sequential_ ? scm_ilength (body->get_property ("elements")) : 1;
92 if (body_is_sequential_ && elt_count != 2)
94 m->origin ()->warning (_f ("expect 2 elements for chord tremolo, found %d", elt_count));
100 Rational total_dur = l.main_part_;
101 Rational note_dur = total_dur / Rational (elt_count * Repeated_music::repeat_count (repeat_));
103 total_duration_flags_ = max (0, (intlog2 (total_dur.den ()) - 2));
105 flags_ = intlog2 (note_dur.den ()) -2;
114 Chord_tremolo_engraver::process_music ()
116 if (repeat_ && body_is_sequential_ && !beam_)
118 beam_ = make_spanner ("Beam", repeat_->self_scm ());
119 beam_->set_property ("chord-tremolo", SCM_BOOL_T);
121 beam_start_location_ = robust_scm2moment (get_property ("measurePosition"), Moment (0));
126 Chord_tremolo_engraver::finalize ()
131 repeat_->origin ()->warning (_ ("unterminated chord tremolo"));
137 Chord_tremolo_engraver::typeset_beam ()
143 Chord_tremolo_engraver::acknowledge_grob (Grob_info info)
145 if (beam_ && Stem::has_interface (info.grob ()))
147 Grob *s = info.grob ();
149 if (start_mom_ == now_mom ())
150 Stem::set_beaming (s, flags_, RIGHT);
152 Stem::set_beaming (s, flags_, LEFT);
154 if (Stem::duration_log (s) != 1)
156 beam_->set_property ("gap-count", scm_int2num (flags_ - total_duration_flags_));
159 if (info.music_cause ()->is_mus_type ("rhythmic-event"))
161 Beam::add_stem (beam_, s);
165 String s = _ ("stem must have Rhythmic structure");
166 if (info.music_cause ())
167 info.music_cause ()->origin ()->warning (s);
173 && flags_ && !body_is_sequential_ && Stem::has_interface (info.grob ()))
175 stem_tremolo_ = make_item ("StemTremolo", repeat_->self_scm ());
176 stem_tremolo_->set_property ("flag-count",
177 scm_int2num (flags_));
178 stem_tremolo_->set_property ("stem",
179 info.grob ()->self_scm ());
180 stem_tremolo_->set_parent (info.grob (), X_AXIS);
185 Chord_tremolo_engraver::start_translation_timestep ()
187 if (beam_ && stop_mom_ == now_mom ())
189 finished_beam_ = beam_;
196 Chord_tremolo_engraver::stop_translation_timestep ()
202 programming_error ("beam and stem tremolo?");
209 ADD_TRANSLATOR (Chord_tremolo_engraver,
210 /* descr */ "Generates beams for tremolo repeats.",
212 /* accepts */ "repeated-music",
213 /* acks */ "stem-interface note-head-interface",