2 new-chord-tremolo-engraver.cc -- implement Chord_tremolo_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 2000 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"
25 This acknowledges repeated music with "tremolo" style. It typesets
30 - perhaps use engraver this to steer other engravers? That would
31 create dependencies between engravers, which is bad.
33 - create dots if appropriate.
35 - create TremoloBeam iso Beam?
38 class Chord_tremolo_engraver : public Engraver
42 VIRTUAL_COPY_CONS(Translator);
43 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_;
57 Spanner * finished_beam_p_;
60 virtual void finalize();
61 virtual bool try_music (Music*);
62 virtual void acknowledge_grob (Grob_info);
63 virtual void stop_translation_timestep();
64 virtual void start_translation_timestep();
65 virtual void create_grobs ();
68 Chord_tremolo_engraver::Chord_tremolo_engraver()
70 beam_p_ = finished_beam_p_ = 0;
76 Chord_tremolo_engraver::try_music (Music * m)
78 Repeated_music * rp = dynamic_cast<Repeated_music*> (m);
80 && rp->get_mus_property ("iterator-ctor") == Chord_tremolo_iterator::constructor_cxx_function
83 Moment l = rp->body_length_mom ();
85 start_mom_ = now_mom ();
86 stop_mom_ = start_mom_ + l;
88 // ugh. should generate dots, triplet beams.
89 note_head_i_ = l.den () <? 4;
96 Chord_tremolo_engraver::create_grobs ()
98 if (repeat_ && !beam_p_)
100 beam_p_ = new Spanner (get_property ("Beam"));
101 Beam::set_interface (beam_p_);
102 beam_p_->set_grob_property ("chord-tremolo", SCM_BOOL_T);
105 SCM smp = get_property ("measurePosition");
106 Moment mp = (unsmob_moment (smp)) ? *unsmob_moment (smp) : Moment (0);
107 beam_start_location_ = mp;
108 announce_grob (beam_p_, repeat_);
114 Chord_tremolo_engraver::finalize ()
119 repeat_->origin ()->warning (_ ("unterminated chord tremolo"));
121 finished_beam_p_ = beam_p_;
130 Chord_tremolo_engraver::typeset_beam ()
132 if (finished_beam_p_)
134 typeset_grob (finished_beam_p_);
135 finished_beam_p_ = 0;
141 Chord_tremolo_engraver::acknowledge_grob (Grob_info info)
145 if (Stem::has_interface (info.elem_l_))
147 Grob * s = info.elem_l_;
148 int f = Stem::flag_i (s);
149 f = (f > 2) ? f - 2 : 1;
150 Stem::set_beaming (s, f, LEFT);
151 Stem::set_beaming (s, f, RIGHT);
154 URG: this sets the direction of the Stem s.
157 Stem:: type_i () ->first_head ()->get_direction () ->
158 Directional_element_interface::set (me, d);
161 don't understand this comment.
164 SCM d = s->get_grob_property ("direction");
165 if (Stem::type_i (s ) != 1)
167 int gap_i =Stem::flag_i (s ) - ((Stem::type_i (s ) >? 2) - 2);
168 beam_p_->set_grob_property ("beam-gap", gh_int2scm(gap_i));
170 s->set_grob_property ("direction", d);
172 if (dynamic_cast <Rhythmic_req *> (info.req_l_))
174 Beam::add_stem (beam_p_, s);
178 String s = _ ("stem must have Rhythmic structure");
180 info.req_l_->origin ()->warning (s);
185 if (Note_head::has_interface (info.elem_l_))
187 info.elem_l_->set_grob_property ("duration-log", gh_int2scm (intlog2 (note_head_i_)));
194 Chord_tremolo_engraver::start_translation_timestep ()
196 if (beam_p_ && stop_mom_ == now_mom ())
198 finished_beam_p_ = beam_p_;
207 Chord_tremolo_engraver::stop_translation_timestep ()
212 ADD_THIS_TRANSLATOR(Chord_tremolo_engraver);