2 stem-grav.cc -- implement Stem_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "staff-symbol-referencer.hh"
10 #include "rhythmic-head.hh"
14 #include "stem-tremolo.hh"
16 #include "translator-group.hh"
17 #include "engraver.hh"
22 Make stems upon receiving noteheads.
24 class Stem_engraver : public Engraver
26 TRANSLATOR_DECLARATIONS(Stem_engraver);
28 virtual void acknowledge_grob (Grob_info);
29 virtual void stop_translation_timestep ();
30 virtual bool try_music (Music*);
39 Stem_engraver::Stem_engraver ()
49 Stem_engraver::acknowledge_grob (Grob_info i)
52 if (Rhythmic_head::has_interface (h))
54 if (Rhythmic_head::get_stem (h))
57 /* Reverted to the old method so chord tremolos work again. /MB
61 Music * m = i.music_cause ();
62 if (m->is_mus_type ("rhythmic-event"))
63 duration_log = unsmob_duration (m->get_mus_property ("duration"))-> duration_log ();
67 stem_ = new Item (get_property ("Stem"));
69 stem_->set_grob_property ("duration-log", gh_int2scm (duration_log));
74 Stem tremolo is never applied to a note by default,
75 is must me evented. But there is a default for the
80 the first and last (quarter) note bothe get one tremolo flag.
82 int evented_type = gh_scm2int (tremolo_req_->get_mus_property ("tremolo-type"));
83 SCM f = get_property ("tremoloFlags");
84 if (!evented_type && gh_number_p (f))
85 evented_type = gh_scm2int (f);
87 daddy_trans_->set_property ("tremoloFlags", gh_int2scm (evented_type));
89 int tremolo_flags = intlog2 (evented_type) - 2
90 - (duration_log > 2 ? duration_log - 2 : 0);
91 if (tremolo_flags <= 0)
93 tremolo_req_->origin()->warning (_("tremolo duration is too long"));
99 tremolo_ = new Item (get_property ("StemTremolo"));
100 announce_grob(tremolo_, tremolo_req_->self_scm());
103 The number of tremolo flags is the number of flags of
104 the tremolo-type minus the number of flags of the note
107 tremolo_->set_grob_property ("flag-count",
108 gh_int2scm (tremolo_flags));
109 tremolo_->set_parent (stem_, X_AXIS);
114 We announce the cause of the head as cause of the stem.
115 The stem needs a rhythmic structure to fit it into a beam. */
116 announce_grob(stem_, i.music_cause ()->self_scm());
119 if (Stem::duration_log (stem_) != duration_log)
121 i.music_cause ()->origin ()->warning (_f ("Adding note head to incompatible stem (type = %d)", 1 << Stem::duration_log (stem_)));
124 Stem::add_head (stem_,h);
129 Stem_engraver::stop_translation_timestep ()
133 Stem_tremolo::set_stem (tremolo_, stem_);
134 typeset_grob (tremolo_);
140 SCM prop = get_property ("stemLeftBeamCount");
141 if (gh_number_p (prop))
143 Stem::set_beaming (stem_,gh_scm2int (prop),LEFT);
144 daddy_trans_->unset_property (ly_symbol2scm ("stemLeftBeamCount"));
146 prop = get_property ("stemRightBeamCount");
147 if (gh_number_p (prop))
149 Stem::set_beaming (stem_,gh_scm2int (prop), RIGHT);
150 daddy_trans_->unset_property (ly_symbol2scm ("stemRightBeamCount"));
153 typeset_grob (stem_);
162 Stem_engraver::try_music (Music* r)
164 if (r->is_mus_type ("tremolo-event"))
172 ENTER_DESCRIPTION(Stem_engraver,
173 /* descr */ "Create stems and single-stem tremolos. It also works together with
174 the beam engraver for overriding beaming.",
175 /* creats*/ "Stem StemTremolo",
176 /* accepts */ "tremolo-event",
177 /* acks */ "rhythmic-head-interface",
178 /* reads */ "tremoloFlags stemLeftBeamCount stemRightBeamCount",