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"
24 Make stems upon receiving noteheads.
26 class Stem_engraver : public Engraver
33 TRANSLATOR_DECLARATIONS (Stem_engraver);
36 void make_stem (Grob_info);
38 DECLARE_ACKNOWLEDGER (rhythmic_head);
39 void stop_translation_timestep ();
40 virtual bool try_music (Music *);
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 ());
59 we take the duration log from the Event, since the duration-log
60 for a note head is always <= 2.
62 Music *music = gi.music_cause ();
63 Duration *dur = unsmob_duration (music->get_property ("duration"));
65 stem_->set_property ("duration-log", dur ? scm_from_int (dur->duration_log ()) : 0);
69 /* Stem tremolo is never applied to a note by default,
70 is must me requested. But there is a default for the
75 the first and last (quarter) note bothe get one tremolo flag. */
77 = scm_to_int (tremolo_ev_->get_property ("tremolo-type"));
78 SCM f = get_property ("tremoloFlags");
81 if (scm_is_number (f))
82 requested_type = scm_to_int (f);
87 context ()->set_property ("tremoloFlags", scm_from_int (requested_type));
89 int tremolo_flags = intlog2 (requested_type) - 2
90 - (dur->duration_log () > 2 ? dur->duration_log () - 2 : 0);
91 if (tremolo_flags <= 0)
93 tremolo_ev_->origin ()->warning (_ ("tremolo duration is too long"));
99 tremolo_ = make_item ("StemTremolo", tremolo_ev_->self_scm ());
101 /* The number of tremolo flags is the number of flags of the
102 tremolo-type minus the number of flags of the note itself. */
103 tremolo_->set_property ("flag-count", scm_from_int (tremolo_flags));
104 tremolo_->set_parent (stem_, X_AXIS);
105 stem_->set_object ("tremolo-flag", tremolo_->self_scm ());
106 tremolo_->set_object ("stem", stem_->self_scm ());
112 Stem_engraver::acknowledge_rhythmic_head (Grob_info gi)
114 if (Rhythmic_head::get_stem (gi.grob ()))
117 Music *cause = gi.music_cause ();
120 Duration *d = unsmob_duration (cause->get_property ("duration"));
127 if (Stem::duration_log (stem_) != d->duration_log ())
130 gi.music_cause ()->origin ()->warning (_f ("adding note head to incompatible stem (type = %d)",
131 1 << Stem::duration_log (stem_)));
132 gi.music_cause ()->origin ()->warning (_f ("maybe input should specify polyphonic voices"));
135 Stem::add_head (stem_, gi.grob ());
139 Stem_engraver::stop_translation_timestep ()
144 /* FIXME: junk these properties. */
145 SCM prop = get_property ("stemLeftBeamCount");
146 if (scm_is_number (prop))
148 Stem::set_beaming (stem_, scm_to_int (prop), LEFT);
149 context ()->unset_property (ly_symbol2scm ("stemLeftBeamCount"));
151 prop = get_property ("stemRightBeamCount");
152 if (scm_is_number (prop))
154 Stem::set_beaming (stem_, scm_to_int (prop), RIGHT);
155 context ()->unset_property (ly_symbol2scm ("stemRightBeamCount"));
163 Stem_engraver::try_music (Music *m)
165 if (m->is_mus_type ("tremolo-event"))
173 #include "translator.icc"
175 ADD_ACKNOWLEDGER (Stem_engraver, rhythmic_head);
177 ADD_TRANSLATOR (Stem_engraver,
178 /* doc */ "Create stems and single-stem tremolos. It also works together with "
179 "the beam engraver for overriding beaming.",
180 /* create */ "Stem StemTremolo",
181 /* accept */ "tremolo-event",
182 /* read */ "tremoloFlags stemLeftBeamCount stemRightBeamCount",