2 new-chord-tremolo-engraver.cc -- implement Chord_tremolo_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2002 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"
16 #include "musical-request.hh"
19 #include "note-head.hh"
22 #include "chord-tremolo-iterator.hh"
23 #include "stem-tremolo.hh"
24 #include "music-list.hh"
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 /// location within measure where beam started.
52 Moment beam_start_location_;
56 bool sequential_body_b_;
58 Spanner * finished_beam_p_;
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_p_ = finished_beam_p_ = 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_cxx_function
86 Moment l = rp->length_mom ();
88 start_mom_ = now_mom ();
89 stop_mom_ = start_mom_ + l;
90 sequential_body_b_ = dynamic_cast<Sequential_music*> (rp->body ());
92 // ugh. should generate dots, triplet beams.
93 note_head_i_ = l.den () <? 4;
101 Chord_tremolo_engraver::process_music ()
105 if (sequential_body_b_ && !beam_p_)
107 beam_p_ = new Spanner (get_property ("Beam"));
108 beam_p_->set_grob_property ("chord-tremolo", SCM_BOOL_T);
111 SCM smp = get_property ("measurePosition");
113 = (unsmob_moment (smp)) ? *unsmob_moment (smp) : Moment (0);
114 beam_start_location_ = mp;
115 announce_grob(beam_p_, repeat_->self_scm());
117 else if (!sequential_body_b_ && !stem_tremolo_)
119 int flags = intlog2 (note_head_i_ * repeat_->repeat_count ()) -2;
122 stem_tremolo_ = new Item (get_property ("StemTremolo"));
123 announce_grob(stem_tremolo_, repeat_->self_scm());
124 stem_tremolo_->set_grob_property ("flag-count",
132 Chord_tremolo_engraver::finalize ()
137 repeat_->origin ()->warning (_ ("unterminated chord tremolo"));
143 Chord_tremolo_engraver::typeset_beam ()
145 if (finished_beam_p_)
147 typeset_grob (finished_beam_p_);
148 finished_beam_p_ = 0;
154 Chord_tremolo_engraver::acknowledge_grob (Grob_info info)
158 if (Stem::has_interface (info.grob_l_))
160 Grob * s = info.grob_l_;
161 int f = Stem::flag_i (s);
162 f = (f > 2) ? f - 2 : 1;
163 Stem::set_beaming (s, f, LEFT);
164 Stem::set_beaming (s, f, RIGHT);
167 URG: this sets the direction of the Stem s.
170 Stem:: type_i () ->first_head ()->get_direction () ->
171 Directional_element_interface::set (me, d);
174 don't understand this comment.
177 SCM d = s->get_grob_property ("direction");
178 if (Stem::type_i (s) != 1)
180 int gap_i =Stem::flag_i (s) - ((Stem::type_i (s) >? 2) - 2);
181 beam_p_->set_grob_property ("gap", gh_int2scm (gap_i));
183 s->set_grob_property ("direction", d);
185 if (dynamic_cast <Rhythmic_req *> (info.music_cause ()))
187 Beam::add_stem (beam_p_, s);
191 String s = _ ("stem must have Rhythmic structure");
192 if (info.music_cause ())
193 info.music_cause ()->origin ()->warning (s);
199 else if (stem_tremolo_ && Stem::has_interface (info.grob_l_))
201 Stem_tremolo::set_stem (stem_tremolo_, info.grob_l_);
203 info.grob_l_->set_grob_property ("duration-log", gh_int2scm (intlog2 (note_head_i_)));
207 if (repeat_ && Note_head::has_interface (info.grob_l_))
209 info.grob_l_->set_grob_property ("duration-log", gh_int2scm (intlog2 (note_head_i_)));
215 Chord_tremolo_engraver::start_translation_timestep ()
217 if (beam_p_ && stop_mom_ == now_mom ())
219 finished_beam_p_ = beam_p_;
228 Chord_tremolo_engraver::stop_translation_timestep ()
234 typeset_grob (stem_tremolo_);
242 ENTER_DESCRIPTION(Chord_tremolo_engraver,
243 /* descr */ "Generates beams for tremolo repeats.",
245 /* acks */ "stem-interface note-head-interface",