2 new-chord-tremolo-engraver.cc -- implement Chord_tremolo_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include "repeated-music.hh"
13 #include "rhythmic-head.hh"
14 #include "engraver-group-engraver.hh"
17 #include "note-head.hh"
20 #include "chord-tremolo-iterator.hh"
21 #include "stem-tremolo.hh"
22 #include "music-list.hh"
23 #include "math.h" // ceil
27 This acknowledges repeated music with "tremolo" style. It typesets
32 - perhaps use engraver this to steer other engravers? That would
33 create dependencies between engravers, which is bad.
35 - create dots if appropriate.
37 - create TremoloBeam iso Beam?
40 class Chord_tremolo_engraver : public Engraver
43 TRANSLATOR_DECLARATIONS (Chord_tremolo_engraver);
45 Repeated_music * repeat_;
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 sequential_body_b_;
58 Spanner * finished_beam_;
61 virtual void finalize ();
62 virtual bool try_music (Music*);
63 virtual void acknowledge_grob (Grob_info);
64 virtual void stop_translation_timestep ();
65 virtual void start_translation_timestep ();
66 virtual void process_music ();
69 Chord_tremolo_engraver::Chord_tremolo_engraver ()
71 beam_ = finished_beam_ = 0;
75 sequential_body_b_ = false;
79 Chord_tremolo_engraver::try_music (Music * m)
81 Repeated_music * rp = dynamic_cast<Repeated_music*> (m);
83 && rp->get_property ("iterator-ctor") == Chord_tremolo_iterator::constructor_proc
86 Moment l = rp->get_length ();
88 start_mom_ = now_mom ();
89 stop_mom_ = start_mom_ + l;
91 Sequential_music * seq = dynamic_cast<Sequential_music*> (rp->body ());
92 sequential_body_b_ = seq;
94 int elt_count = seq ? scm_ilength (seq-> music_list ()) : 1;
96 if (seq && elt_count != 2)
98 rp->origin ()->warning (_f ("Chord tremolo with %d elements. Must have two elements.", elt_count));
104 Rational total_dur = l.main_part_;
105 Rational note_dur = total_dur / Rational (elt_count * repeat_->repeat_count ());
107 total_duration_flags_ = 0 >? (intlog2 (total_dur.den ()) - 2);
109 flags_ = intlog2 (note_dur.den ()) -2 ;
118 Chord_tremolo_engraver::process_music ()
120 if (repeat_ && sequential_body_b_ && !beam_)
122 beam_ = make_spanner ("Beam", repeat_->self_scm ());
123 beam_->set_property ("chord-tremolo", SCM_BOOL_T);
125 beam_start_location_ = robust_scm2moment (get_property ("measurePosition"), Moment (0));
130 Chord_tremolo_engraver::finalize ()
135 repeat_->origin ()->warning (_ ("unterminated chord tremolo"));
141 Chord_tremolo_engraver::typeset_beam ()
147 Chord_tremolo_engraver::acknowledge_grob (Grob_info info)
149 if (beam_ && Stem::has_interface (info.grob_))
151 Grob * s = info.grob_;
153 if (start_mom_ == now_mom ())
154 Stem::set_beaming (s, flags_, RIGHT);
156 Stem::set_beaming (s, flags_, LEFT);
158 if (Stem::duration_log (s) != 1)
160 beam_->set_property ("gap-count", scm_int2num (flags_ - total_duration_flags_));
163 if (info.music_cause ()->is_mus_type ("rhythmic-event"))
165 Beam::add_stem (beam_, s);
169 String s = _ ("stem must have Rhythmic structure");
170 if (info.music_cause ())
171 info.music_cause ()->origin ()->warning (s);
177 flags_ && !sequential_body_b_ && Stem::has_interface (info.grob_))
179 stem_tremolo_ = make_item ("StemTremolo", repeat_->self_scm ());
180 stem_tremolo_->set_property ("flag-count",
181 scm_int2num (flags_));
182 stem_tremolo_->set_property ("stem",
183 info.grob_->self_scm ());
184 stem_tremolo_->set_parent (info.grob_, X_AXIS);
190 Chord_tremolo_engraver::start_translation_timestep ()
192 if (beam_ && stop_mom_ == now_mom ())
194 finished_beam_ = beam_;
202 Chord_tremolo_engraver::stop_translation_timestep ()
208 programming_error ("Huh, beam and stem tremolo?");
217 ADD_TRANSLATOR (Chord_tremolo_engraver,
218 /* descr */ "Generates beams for tremolo repeats.",
220 /* accepts */ "repeated-music",
221 /* acks */ "stem-interface note-head-interface",