2 stem-grav.cc -- implement Stem_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2001 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 int duration_log = unsmob_duration (i.req_l_->get_mus_property ("duration"))-> duration_log ();
61 stem_p_ = new Item (get_property ("Stem"));
62 Stem::set_interface (stem_p_);
63 Staff_symbol_referencer::set_interface (stem_p_);
66 stem_p_->set_grob_property ("duration-log", gh_int2scm (duration_log));
71 Stem tremolo is never applied to a note by default,
72 is must me requested. But there is a default for the
77 the first and last (quarter) note bothe get one tremolo flag.
79 int requested_type = gh_scm2int (tremolo_req_l_->get_mus_property ("tremolo-type"));
81 SCM f = get_property ("tremoloFlags");
82 if (!requested_type && gh_number_p (f))
83 requested_type = gh_scm2int (f);
85 daddy_trans_l_->set_property ("tremoloFlags", gh_int2scm (requested_type));
89 tremolo_p_ = new Item (get_property ("StemTremolo"));
90 Stem_tremolo::set_interface (tremolo_p_);
92 announce_grob (tremolo_p_, tremolo_req_l_);
94 The number of tremolo flags is the number of flags of
95 the tremolo-type minus the number of flags of the note
98 int tremolo_flags = intlog2 (requested_type) - 2
99 - (duration_log > 2 ? duration_log - 2 : 0);
100 if (tremolo_flags < 0)
102 tremolo_p_->set_grob_property ("tremolo-flags",
103 gh_int2scm (tremolo_flags));
106 announce_grob (stem_p_, i.req_l_);
109 if (Stem::flag_i (stem_p_) != duration_log)
111 i.req_l_->origin ()->warning (_f ("Adding note head to incompatible stem (type = %d)", 1 << Stem::flag_i (stem_p_)));
114 Stem::add_head (stem_p_,h);
119 Stem_engraver::stop_translation_timestep ()
123 Stem_tremolo::set_stem (tremolo_p_, stem_p_);
124 typeset_grob (tremolo_p_);
130 SCM prop = get_property ("stemLeftBeamCount");
131 if (gh_number_p (prop))
133 Stem::set_beaming (stem_p_,gh_scm2int (prop),LEFT);
134 daddy_trans_l_->set_property ("stemLeftBeamCount", SCM_UNDEFINED);
136 prop = get_property ("stemRightBeamCount");
137 if (gh_number_p (prop))
139 Stem::set_beaming (stem_p_,gh_scm2int (prop), RIGHT);
140 daddy_trans_l_->set_property ("stemRightBeamCount", SCM_UNDEFINED);
144 // UGH. Should mark non-forced instead.
146 aargh: I don't get it. direction is being set (and then set
147 to forced), if we have a Chord_tremolo.
149 SCM dir = stem_p_->get_grob_property ("direction");
150 if (gh_number_p (dir) && to_dir (dir))
152 stem_p_->set_grob_property ("dir-forced", SCM_BOOL_T);
155 typeset_grob (stem_p_);
164 Stem_engraver::try_music (Music* r)
166 if (Tremolo_req* a = dynamic_cast <Tremolo_req *> (r))
174 ENTER_DESCRIPTION(Stem_engraver,
175 /* descr */ "Create stems and single-stem tremolos. It also works together with
176 the beam engraver for overriding beaming.",
177 /* creats*/ "Stem StemTremolo",
178 /* acks */ "rhythmic-head-interface",
179 /* reads */ "tremoloFlags stemLeftBeamCount stemRightBeamCount",