2 stem-engraver.cc -- implement Stem_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2008 Han-Wen Nienhuys <hanwen@xs4all.nl>
12 #include "directional-element-interface.hh"
13 #include "duration.hh"
14 #include "international.hh"
17 #include "rhythmic-head.hh"
18 #include "script-interface.hh"
19 #include "staff-symbol-referencer.hh"
20 #include "stem-tremolo.hh"
22 #include "stream-event.hh"
24 #include "translator.icc"
26 class Stem_engraver : public Engraver
30 Stream_event *rhythmic_ev_;
31 Stream_event *tremolo_ev_;
33 TRANSLATOR_DECLARATIONS (Stem_engraver);
36 void make_stem (Grob_info);
38 DECLARE_TRANSLATOR_LISTENER (tremolo);
39 DECLARE_ACKNOWLEDGER (rhythmic_head);
40 void stop_translation_timestep ();
43 Stem_engraver::Stem_engraver ()
52 Stem_engraver::make_stem (Grob_info gi)
54 /* Announce the cause of the head as cause of the stem. The
55 stem needs a rhythmic structure to fit it into a beam. */
56 stem_ = make_item ("Stem", gi.grob ()->self_scm ());
60 /* Stem tremolo is never applied to a note by default,
61 is must me requested. But there is a default for the
66 the first and last (quarter) note bothe get one tremolo flag. */
68 = scm_to_int (tremolo_ev_->get_property ("tremolo-type"));
69 SCM f = get_property ("tremoloFlags");
72 if (scm_is_number (f))
73 requested_type = scm_to_int (f);
78 context ()->set_property ("tremoloFlags", scm_from_int (requested_type));
82 we take the duration log from the Event, since the duration-log
83 for a note head is always <= 2.
85 Stream_event *ev = gi.event_cause ();
86 Duration *dur = unsmob_duration (ev->get_property ("duration"));
88 int tremolo_flags = intlog2 (requested_type) - 2
89 - (dur->duration_log () > 2 ? dur->duration_log () - 2 : 0);
90 if (tremolo_flags <= 0)
92 tremolo_ev_->origin ()->warning (_ ("tremolo duration is too long"));
98 tremolo_ = make_item ("StemTremolo", tremolo_ev_->self_scm ());
100 /* The number of tremolo flags is the number of flags of the
101 tremolo-type minus the number of flags of the note itself. */
102 tremolo_->set_property ("flag-count", scm_from_int (tremolo_flags));
103 tremolo_->set_parent (stem_, X_AXIS);
104 stem_->set_object ("tremolo-flag", tremolo_->self_scm ());
105 tremolo_->set_object ("stem", stem_->self_scm ());
111 Stem_engraver::acknowledge_rhythmic_head (Grob_info gi)
113 if (Rhythmic_head::get_stem (gi.grob ()))
116 Stream_event *cause = gi.event_cause ();
119 Duration *d = unsmob_duration (cause->get_property ("duration"));
126 if (Stem::duration_log (stem_) != d->duration_log ())
129 gi.event_cause ()->origin ()->warning (_f ("adding note head to incompatible stem (type = %d)",
130 1 << Stem::duration_log (stem_)));
131 gi.event_cause ()->origin ()->warning (_ ("maybe input should specify polyphonic voices"));
134 Stem::add_head (stem_, gi.grob ());
138 Stem_engraver::stop_translation_timestep ()
143 /* FIXME: junk these properties. */
144 SCM prop = get_property ("stemLeftBeamCount");
145 if (scm_is_number (prop))
147 Stem::set_beaming (stem_, scm_to_int (prop), LEFT);
148 context ()->unset_property (ly_symbol2scm ("stemLeftBeamCount"));
150 prop = get_property ("stemRightBeamCount");
151 if (scm_is_number (prop))
153 Stem::set_beaming (stem_, scm_to_int (prop), RIGHT);
154 context ()->unset_property (ly_symbol2scm ("stemRightBeamCount"));
161 IMPLEMENT_TRANSLATOR_LISTENER (Stem_engraver, tremolo);
163 Stem_engraver::listen_tremolo (Stream_event *ev)
165 ASSIGN_EVENT_ONCE (tremolo_ev_, ev);
168 ADD_ACKNOWLEDGER (Stem_engraver, rhythmic_head);
170 ADD_TRANSLATOR (Stem_engraver,
172 "Create stems and single-stem tremolos. It also works"
173 " together with the beam engraver for overriding beaming.",
182 "stemRightBeamCount ",