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
44 VIRTUAL_COPY_CONS(Translator);
45 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_;
58 bool sequential_body_b_;
60 Spanner * finished_beam_p_;
63 virtual void finalize();
64 virtual bool try_music (Music*);
65 virtual void acknowledge_grob (Grob_info);
66 virtual void stop_translation_timestep();
67 virtual void start_translation_timestep();
68 virtual void process_music ();
71 Chord_tremolo_engraver::Chord_tremolo_engraver()
73 beam_p_ = finished_beam_p_ = 0;
77 sequential_body_b_ = false;
81 Chord_tremolo_engraver::try_music (Music * m)
83 Repeated_music * rp = dynamic_cast<Repeated_music*> (m);
85 && rp->get_mus_property ("iterator-ctor") == Chord_tremolo_iterator::constructor_cxx_function
88 Moment l = rp->length_mom ();
90 start_mom_ = now_mom ();
91 stop_mom_ = start_mom_ + l;
92 sequential_body_b_ = dynamic_cast<Sequential_music*> (rp->body ());
94 // ugh. should generate dots, triplet beams.
95 note_head_i_ = l.den () <? 4;
103 Chord_tremolo_engraver::process_music ()
107 if (sequential_body_b_ && !beam_p_)
109 beam_p_ = new Spanner (get_property ("Beam"));
110 beam_p_->set_grob_property ("chord-tremolo", SCM_BOOL_T);
113 SCM smp = get_property ("measurePosition");
115 = (unsmob_moment (smp)) ? *unsmob_moment (smp) : Moment (0);
116 beam_start_location_ = mp;
117 announce_grob (beam_p_, repeat_);
119 else if (!sequential_body_b_ && !stem_tremolo_)
121 int flags = intlog2(note_head_i_ * repeat_->repeat_count ()) -2;
124 stem_tremolo_ = new Item (get_property ("StemTremolo"));
125 Stem_tremolo::set_interface (stem_tremolo_);
127 announce_grob (stem_tremolo_, repeat_);
128 stem_tremolo_->set_grob_property ("tremolo-flags",
136 Chord_tremolo_engraver::finalize ()
141 repeat_->origin ()->warning (_ ("unterminated chord tremolo"));
147 Chord_tremolo_engraver::typeset_beam ()
149 if (finished_beam_p_)
151 typeset_grob (finished_beam_p_);
152 finished_beam_p_ = 0;
158 Chord_tremolo_engraver::acknowledge_grob (Grob_info info)
162 if (Stem::has_interface (info.elem_l_))
164 Grob * s = info.elem_l_;
165 int f = Stem::flag_i (s);
166 f = (f > 2) ? f - 2 : 1;
167 Stem::set_beaming (s, f, LEFT);
168 Stem::set_beaming (s, f, RIGHT);
171 URG: this sets the direction of the Stem s.
174 Stem:: type_i () ->first_head ()->get_direction () ->
175 Directional_element_interface::set (me, d);
178 don't understand this comment.
181 SCM d = s->get_grob_property ("direction");
182 if (Stem::type_i (s ) != 1)
184 int gap_i =Stem::flag_i (s ) - ((Stem::type_i (s ) >? 2) - 2);
185 beam_p_->set_grob_property ("beam-gap", gh_int2scm(gap_i));
187 s->set_grob_property ("direction", d);
189 if (dynamic_cast <Rhythmic_req *> (info.req_l_))
191 Beam::add_stem (beam_p_, s);
195 String s = _ ("stem must have Rhythmic structure");
197 info.req_l_->origin ()->warning (s);
203 else if (stem_tremolo_ && Stem::has_interface (info.elem_l_))
205 Stem_tremolo::set_stem (stem_tremolo_, info.elem_l_);
207 info.elem_l_->set_grob_property ("duration-log", gh_int2scm (intlog2 (note_head_i_)));
211 if (repeat_ && Note_head::has_interface (info.elem_l_))
213 info.elem_l_->set_grob_property ("duration-log", gh_int2scm (intlog2 (note_head_i_)));
219 Chord_tremolo_engraver::start_translation_timestep ()
221 if (beam_p_ && stop_mom_ == now_mom ())
223 finished_beam_p_ = beam_p_;
232 Chord_tremolo_engraver::stop_translation_timestep ()
238 typeset_grob (stem_tremolo_);
244 ADD_THIS_TRANSLATOR(Chord_tremolo_engraver);