2 stem-grav.cc -- implement Stem_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "staff-symbol-referencer.hh"
10 #include "rhythmic-head.hh"
14 #include "stem-tremolo.hh"
18 #include "engraver.hh"
23 Make stems upon receiving noteheads.
25 class Stem_engraver : public Engraver
27 TRANSLATOR_DECLARATIONS(Stem_engraver);
29 virtual void acknowledge_grob (Grob_info);
30 virtual void stop_translation_timestep ();
31 virtual bool try_music (Music*);
40 Stem_engraver::Stem_engraver ()
50 Stem_engraver::acknowledge_grob (Grob_info i)
53 if (Rhythmic_head::has_interface (h))
55 if (Rhythmic_head::get_stem (h))
58 /* Reverted to the old method so chord tremolos work again. /MB
62 Music * m = i.music_cause ();
63 if (m->is_mus_type ("rhythmic-event"))
64 duration_log = unsmob_duration (m->get_property ("duration"))-> duration_log ();
68 stem_ = make_item ("Stem");
70 stem_->set_property ("duration-log", gh_int2scm (duration_log));
75 Stem tremolo is never applied to a note by default,
76 is must me evuested. But there is a default for the
81 the first and last (quarter) note bothe get one tremolo flag.
83 int requested_type = gh_scm2int (tremolo_ev_->get_property ("tremolo-type"));
84 SCM f = get_property ("tremoloFlags");
87 requested_type = gh_scm2int (f);
91 daddy_context_->set_property ("tremoloFlags", gh_int2scm (requested_type));
93 int tremolo_flags = intlog2 (requested_type) - 2
94 - (duration_log > 2 ? duration_log - 2 : 0);
95 if (tremolo_flags <= 0)
97 tremolo_ev_->origin()->warning (_("tremolo duration is too long"));
103 tremolo_ = make_item ("StemTremolo");
104 announce_grob(tremolo_, tremolo_ev_->self_scm());
107 The number of tremolo flags is the number of flags of
108 the tremolo-type minus the number of flags of the note
111 tremolo_->set_property ("flag-count",
112 gh_int2scm (tremolo_flags));
113 tremolo_->set_parent (stem_, X_AXIS);
114 stem_->set_property ("tremolo-flag", tremolo_->self_scm ());
119 We announce the cause of the head as cause of the stem.
120 The stem needs a rhythmic structure to fit it into a beam. */
121 announce_grob(stem_, i.music_cause ()->self_scm());
124 if (Stem::duration_log (stem_) != duration_log)
126 i.music_cause ()->origin ()->warning (_f ("Adding note head to incompatible stem (type = %d)", 1 << Stem::duration_log (stem_))
127 + _f ("Don't you want polyphonic voices instead?")
131 Stem::add_head (stem_,h);
136 Stem_engraver::stop_translation_timestep ()
140 Stem_tremolo::set_stem (tremolo_, stem_);
141 typeset_grob (tremolo_);
147 SCM prop = get_property ("stemLeftBeamCount");
148 if (gh_number_p (prop))
150 Stem::set_beaming (stem_,gh_scm2int (prop),LEFT);
151 daddy_context_->unset_property (ly_symbol2scm ("stemLeftBeamCount"));
153 prop = get_property ("stemRightBeamCount");
154 if (gh_number_p (prop))
156 Stem::set_beaming (stem_,gh_scm2int (prop), RIGHT);
157 daddy_context_->unset_property (ly_symbol2scm ("stemRightBeamCount"));
160 typeset_grob (stem_);
169 Stem_engraver::try_music (Music* r)
171 if (r->is_mus_type ("tremolo-event"))
179 ENTER_DESCRIPTION(Stem_engraver,
180 /* descr */ "Create stems and single-stem tremolos. It also works together with "
181 "the beam engraver for overriding beaming.",
182 /* creats*/ "Stem StemTremolo",
183 /* accepts */ "tremolo-event",
184 /* acks */ "rhythmic-head-interface",
185 /* reads */ "tremoloFlags stemLeftBeamCount stemRightBeamCount",