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 ());
62 we take the duration log from the Event, since the duration-log
63 for a note head is always <= 2.
65 Stream_event *ev = gi.event_cause ();
66 Duration *dur = unsmob_duration (ev->get_property ("duration"));
68 stem_->set_property ("duration-log", dur ? scm_from_int (dur->duration_log ()) : 0);
72 /* Stem tremolo is never applied to a note by default,
73 is must me requested. But there is a default for the
78 the first and last (quarter) note bothe get one tremolo flag. */
80 = scm_to_int (tremolo_ev_->get_property ("tremolo-type"));
81 SCM f = get_property ("tremoloFlags");
84 if (scm_is_number (f))
85 requested_type = scm_to_int (f);
90 context ()->set_property ("tremoloFlags", scm_from_int (requested_type));
92 int tremolo_flags = intlog2 (requested_type) - 2
93 - (dur->duration_log () > 2 ? dur->duration_log () - 2 : 0);
94 if (tremolo_flags <= 0)
96 tremolo_ev_->origin ()->warning (_ ("tremolo duration is too long"));
102 tremolo_ = make_item ("StemTremolo", tremolo_ev_->self_scm ());
104 /* The number of tremolo flags is the number of flags of the
105 tremolo-type minus the number of flags of the note itself. */
106 tremolo_->set_property ("flag-count", scm_from_int (tremolo_flags));
107 tremolo_->set_parent (stem_, X_AXIS);
108 stem_->set_object ("tremolo-flag", tremolo_->self_scm ());
109 tremolo_->set_object ("stem", stem_->self_scm ());
115 Stem_engraver::acknowledge_rhythmic_head (Grob_info gi)
117 if (Rhythmic_head::get_stem (gi.grob ()))
120 Stream_event *cause = gi.event_cause ();
123 Duration *d = unsmob_duration (cause->get_property ("duration"));
130 if (Stem::duration_log (stem_) != d->duration_log ())
133 gi.event_cause ()->origin ()->warning (_f ("adding note head to incompatible stem (type = %d)",
134 1 << Stem::duration_log (stem_)));
135 gi.event_cause ()->origin ()->warning (_f ("maybe input should specify polyphonic voices"));
138 Stem::add_head (stem_, gi.grob ());
142 Stem_engraver::stop_translation_timestep ()
147 /* FIXME: junk these properties. */
148 SCM prop = get_property ("stemLeftBeamCount");
149 if (scm_is_number (prop))
151 Stem::set_beaming (stem_, scm_to_int (prop), LEFT);
152 context ()->unset_property (ly_symbol2scm ("stemLeftBeamCount"));
154 prop = get_property ("stemRightBeamCount");
155 if (scm_is_number (prop))
157 Stem::set_beaming (stem_, scm_to_int (prop), RIGHT);
158 context ()->unset_property (ly_symbol2scm ("stemRightBeamCount"));
165 IMPLEMENT_TRANSLATOR_LISTENER (Stem_engraver, tremolo);
167 Stem_engraver::listen_tremolo (Stream_event *ev)
172 ADD_ACKNOWLEDGER (Stem_engraver, rhythmic_head);
174 ADD_TRANSLATOR (Stem_engraver,
175 /* doc */ "Create stems and single-stem tremolos. It also works together with "
176 "the beam engraver for overriding beaming.",
180 /* accept */ "tremolo-event",
184 "stemRightBeamCount ",