2 new-chord-tremolo-engraver.cc -- implement Chord_tremolo_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2000--2001 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_);
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 Stem_tremolo::set_interface (stem_tremolo_);
125 announce_grob (stem_tremolo_, repeat_);
126 stem_tremolo_->set_grob_property ("tremolo-flags",
134 Chord_tremolo_engraver::finalize ()
139 repeat_->origin ()->warning (_ ("unterminated chord tremolo"));
145 Chord_tremolo_engraver::typeset_beam ()
147 if (finished_beam_p_)
149 typeset_grob (finished_beam_p_);
150 finished_beam_p_ = 0;
156 Chord_tremolo_engraver::acknowledge_grob (Grob_info info)
160 if (Stem::has_interface (info.grob_l_))
162 Grob * s = info.grob_l_;
163 int f = Stem::flag_i (s);
164 f = (f > 2) ? f - 2 : 1;
165 Stem::set_beaming (s, f, LEFT);
166 Stem::set_beaming (s, f, RIGHT);
169 URG: this sets the direction of the Stem s.
172 Stem:: type_i () ->first_head ()->get_direction () ->
173 Directional_element_interface::set (me, d);
176 don't understand this comment.
179 SCM d = s->get_grob_property ("direction");
180 if (Stem::type_i (s) != 1)
182 int gap_i =Stem::flag_i (s) - ((Stem::type_i (s) >? 2) - 2);
183 beam_p_->set_grob_property ("gap", gh_int2scm (gap_i));
185 s->set_grob_property ("direction", d);
187 if (dynamic_cast <Rhythmic_req *> (info.music_cause ()))
189 Beam::add_stem (beam_p_, s);
193 String s = _ ("stem must have Rhythmic structure");
194 if (info.music_cause ())
195 info.music_cause ()->origin ()->warning (s);
201 else if (stem_tremolo_ && Stem::has_interface (info.grob_l_))
203 Stem_tremolo::set_stem (stem_tremolo_, info.grob_l_);
205 info.grob_l_->set_grob_property ("duration-log", gh_int2scm (intlog2 (note_head_i_)));
209 if (repeat_ && Note_head::has_interface (info.grob_l_))
211 info.grob_l_->set_grob_property ("duration-log", gh_int2scm (intlog2 (note_head_i_)));
217 Chord_tremolo_engraver::start_translation_timestep ()
219 if (beam_p_ && stop_mom_ == now_mom ())
221 finished_beam_p_ = beam_p_;
230 Chord_tremolo_engraver::stop_translation_timestep ()
236 typeset_grob (stem_tremolo_);
244 ENTER_DESCRIPTION(Chord_tremolo_engraver,
245 /* descr */ "Generates beams for tremolo repeats.",
247 /* acks */ "stem-interface note-head-interface",