2 new-chord-tremolo-engraver.cc -- implement Chord_tremolo_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "engraver.hh"
12 #include "repeated-music.hh"
14 #include "rhythmic-head.hh"
15 #include "engraver-group-engraver.hh"
19 #include "note-head.hh"
22 #include "chord-tremolo-iterator.hh"
23 #include "stem-tremolo.hh"
24 #include "music-list.hh"
25 #include "math.h" // ceil
29 This acknowledges repeated music with "tremolo" style. It typesets
34 - perhaps use engraver this to steer other engravers? That would
35 create dependencies between engravers, which is bad.
37 - create dots if appropriate.
39 - create TremoloBeam iso Beam?
42 class Chord_tremolo_engraver : public Engraver
45 TRANSLATOR_DECLARATIONS(Chord_tremolo_engraver);
47 Repeated_music * repeat_;
49 /// moment (global time) where beam started.
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_mus_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;
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 if (total_dur < Rational (1,4))
110 This would require beams between flagged (8th) notes.
112 rp->origin ()->warning ("Chord tremolo is too short to denote properly.");
115 flags_ = intlog2 (note_dur.den ()) -2 ;
124 Chord_tremolo_engraver::process_music ()
128 if (sequential_body_b_ && !beam_)
130 beam_ = new Spanner (get_property ("Beam"));
131 beam_->set_grob_property ("chord-tremolo", SCM_BOOL_T);
133 SCM smp = get_property ("measurePosition");
135 = (unsmob_moment (smp)) ? *unsmob_moment (smp) : Moment (0);
136 beam_start_location_ = mp;
137 announce_grob(beam_, repeat_->self_scm());
139 else if (!sequential_body_b_ && !stem_tremolo_)
143 stem_tremolo_ = new Item (get_property ("StemTremolo"));
144 announce_grob(stem_tremolo_, repeat_->self_scm());
145 stem_tremolo_->set_grob_property ("flag-count",
146 scm_int2num (flags_));
152 Chord_tremolo_engraver::finalize ()
157 repeat_->origin ()->warning (_ ("unterminated chord tremolo"));
163 Chord_tremolo_engraver::typeset_beam ()
167 typeset_grob (finished_beam_);
173 Chord_tremolo_engraver::acknowledge_grob (Grob_info info)
175 if (beam_ && Stem::has_interface (info.grob_))
177 Grob * s = info.grob_;
179 if (start_mom_ == now_mom())
180 Stem::set_beaming (s, flags_, RIGHT);
182 Stem::set_beaming (s, flags_, LEFT);
184 SCM d = s->get_grob_property ("direction");
185 if (Stem::duration_log (s) != 1)
187 beam_->set_grob_property ("gap", gh_double2scm (0.8));
189 s->set_grob_property ("direction", d);
191 if (info.music_cause ()->is_mus_type ("rhythmic-event"))
193 Beam::add_stem (beam_, s);
197 String s = _ ("stem must have Rhythmic structure");
198 if (info.music_cause ())
199 info.music_cause ()->origin ()->warning (s);
204 else if (stem_tremolo_ && Stem::has_interface (info.grob_))
206 Stem_tremolo::set_stem (stem_tremolo_, info.grob_);
207 stem_tremolo_->set_parent (info.grob_,X_AXIS);
213 Chord_tremolo_engraver::start_translation_timestep ()
215 if (beam_ && stop_mom_ == now_mom ())
217 finished_beam_ = beam_;
225 Chord_tremolo_engraver::stop_translation_timestep ()
231 typeset_grob (stem_tremolo_);
238 ENTER_DESCRIPTION(Chord_tremolo_engraver,
239 /* descr */ "Generates beams for tremolo repeats.",
241 /* accepts */ "repeated-music",
242 /* acks */ "stem-interface note-head-interface",