2 stem-engraver.cc -- implement Stem_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2006 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"
27 Make stems upon receiving noteheads.
29 class Stem_engraver : public Engraver
33 Stream_event *rhythmic_ev_;
34 Stream_event *tremolo_ev_;
36 TRANSLATOR_DECLARATIONS (Stem_engraver);
39 void make_stem (Grob_info);
41 DECLARE_TRANSLATOR_LISTENER (tremolo);
42 DECLARE_ACKNOWLEDGER (rhythmic_head);
43 void stop_translation_timestep ();
46 Stem_engraver::Stem_engraver ()
55 Stem_engraver::make_stem (Grob_info gi)
57 /* Announce the cause of the head as cause of the stem. The
58 stem needs a rhythmic structure to fit it into a beam. */
59 stem_ = make_item ("Stem", gi.grob ()->self_scm ());
63 /* Stem tremolo is never applied to a note by default,
64 is must me requested. But there is a default for the
69 the first and last (quarter) note bothe get one tremolo flag. */
71 = scm_to_int (tremolo_ev_->get_property ("tremolo-type"));
72 SCM f = get_property ("tremoloFlags");
75 if (scm_is_number (f))
76 requested_type = scm_to_int (f);
81 context ()->set_property ("tremoloFlags", scm_from_int (requested_type));
85 we take the duration log from the Event, since the duration-log
86 for a note head is always <= 2.
88 Stream_event *ev = gi.event_cause ();
89 Duration *dur = unsmob_duration (ev->get_property ("duration"));
91 int tremolo_flags = intlog2 (requested_type) - 2
92 - (dur->duration_log () > 2 ? dur->duration_log () - 2 : 0);
93 if (tremolo_flags <= 0)
95 tremolo_ev_->origin ()->warning (_ ("tremolo duration is too long"));
101 tremolo_ = make_item ("StemTremolo", tremolo_ev_->self_scm ());
103 /* The number of tremolo flags is the number of flags of the
104 tremolo-type minus the number of flags of the note itself. */
105 tremolo_->set_property ("flag-count", scm_from_int (tremolo_flags));
106 tremolo_->set_parent (stem_, X_AXIS);
107 stem_->set_object ("tremolo-flag", tremolo_->self_scm ());
108 tremolo_->set_object ("stem", stem_->self_scm ());
114 Stem_engraver::acknowledge_rhythmic_head (Grob_info gi)
116 if (Rhythmic_head::get_stem (gi.grob ()))
119 Stream_event *cause = gi.event_cause ();
122 Duration *d = unsmob_duration (cause->get_property ("duration"));
129 if (Stem::duration_log (stem_) != d->duration_log ())
132 gi.event_cause ()->origin ()->warning (_f ("adding note head to incompatible stem (type = %d)",
133 1 << Stem::duration_log (stem_)));
134 gi.event_cause ()->origin ()->warning (_f ("maybe input should specify polyphonic voices"));
137 Stem::add_head (stem_, gi.grob ());
141 Stem_engraver::stop_translation_timestep ()
146 /* FIXME: junk these properties. */
147 SCM prop = get_property ("stemLeftBeamCount");
148 if (scm_is_number (prop))
150 Stem::set_beaming (stem_, scm_to_int (prop), LEFT);
151 context ()->unset_property (ly_symbol2scm ("stemLeftBeamCount"));
153 prop = get_property ("stemRightBeamCount");
154 if (scm_is_number (prop))
156 Stem::set_beaming (stem_, scm_to_int (prop), RIGHT);
157 context ()->unset_property (ly_symbol2scm ("stemRightBeamCount"));
164 IMPLEMENT_TRANSLATOR_LISTENER (Stem_engraver, tremolo);
166 Stem_engraver::listen_tremolo (Stream_event *ev)
168 ASSIGN_EVENT_ONCE (tremolo_ev_, ev);
171 ADD_ACKNOWLEDGER (Stem_engraver, rhythmic_head);
173 ADD_TRANSLATOR (Stem_engraver,
175 /* doc */ "Create stems and single-stem tremolos. It also works together with "
176 "the beam engraver for overriding beaming.",
185 "stemRightBeamCount ",