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"
12 #include "musical-request.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*);
35 Rhythmic_req *rhythmic_req_l_;
36 Tremolo_req* tremolo_req_l_;
39 Stem_engraver::Stem_engraver ()
49 Stem_engraver::acknowledge_grob (Grob_info i)
52 if (Rhythmic_head::has_interface (h))
54 if (Rhythmic_head::stem_l (h))
57 /* Reverted to the old method so chord tremolos work again. /MB
60 Rhythmic_req *rhythmic_req = dynamic_cast <Rhythmic_req *> (i.music_cause ());
62 duration_log = unsmob_duration (rhythmic_req->get_mus_property ("duration"))-> duration_log ();
66 stem_p_ = new Item (get_property ("Stem"));
68 stem_p_->set_grob_property ("duration-log", gh_int2scm (duration_log));
73 Stem tremolo is never applied to a note by default,
74 is must me requested. But there is a default for the
79 the first and last (quarter) note bothe get one tremolo flag.
81 int requested_type = gh_scm2int (tremolo_req_l_->get_mus_property ("tremolo-type"));
83 SCM f = get_property ("tremoloFlags");
84 if (!requested_type && gh_number_p (f))
85 requested_type = gh_scm2int (f);
87 daddy_trans_l_->set_property ("tremoloFlags", gh_int2scm (requested_type));
91 tremolo_p_ = new Item (get_property ("StemTremolo"));
92 announce_grob(tremolo_p_, tremolo_req_l_->self_scm());
95 The number of tremolo flags is the number of flags of
96 the tremolo-type minus the number of flags of the note
99 int tremolo_flags = intlog2 (requested_type) - 2
100 - (duration_log > 2 ? duration_log - 2 : 0);
101 if (tremolo_flags < 0)
103 tremolo_p_->set_grob_property ("flag-count",
104 gh_int2scm (tremolo_flags));
105 tremolo_p_->set_parent (stem_p_, X_AXIS);
110 We announce the cause of the head as cause of the stem.
111 The stem needs a rhythmic structure to fit it into a beam. */
112 announce_grob(stem_p_, i.music_cause ()->self_scm());
115 if (Stem::duration_log (stem_p_) != duration_log)
117 i.music_cause ()->origin ()->warning (_f ("Adding note head to incompatible stem (type = %d)", 1 << Stem::duration_log (stem_p_)));
120 Stem::add_head (stem_p_,h);
125 Stem_engraver::stop_translation_timestep ()
129 Stem_tremolo::set_stem (tremolo_p_, stem_p_);
130 typeset_grob (tremolo_p_);
136 SCM prop = get_property ("stemLeftBeamCount");
137 if (gh_number_p (prop))
139 Stem::set_beaming (stem_p_,gh_scm2int (prop),LEFT);
140 daddy_trans_l_->unset_property (ly_symbol2scm ("stemLeftBeamCount"));
142 prop = get_property ("stemRightBeamCount");
143 if (gh_number_p (prop))
145 Stem::set_beaming (stem_p_,gh_scm2int (prop), RIGHT);
146 daddy_trans_l_->unset_property (ly_symbol2scm ("stemRightBeamCount"));
150 // UGH. Should mark non-forced instead.
152 aargh: I don't get it. direction is being set (and then set
153 to forced), if we have a Chord_tremolo.
157 Why the separate check for forced directions? --hwn.
161 SCM dir = stem_p_->get_grob_property ("direction");
162 if (gh_number_p (dir) && to_dir (dir))
164 stem_p_->set_grob_property ("dir-forced", SCM_BOOL_T);
167 typeset_grob (stem_p_);
176 Stem_engraver::try_music (Music* r)
178 if (Tremolo_req* a = dynamic_cast <Tremolo_req *> (r))
186 ENTER_DESCRIPTION(Stem_engraver,
187 /* descr */ "Create stems and single-stem tremolos. It also works together with
188 the beam engraver for overriding beaming.",
189 /* creats*/ "Stem StemTremolo",
190 /* acks */ "rhythmic-head-interface",
191 /* reads */ "tremoloFlags stemLeftBeamCount stemRightBeamCount",