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"
20 Make stems upon receiving noteheads.
22 class Stem_engraver : public Engraver
26 VIRTUAL_COPY_CONS (Translator);
30 virtual void acknowledge_grob (Grob_info);
31 virtual void stop_translation_timestep ();
32 virtual bool try_music (Music*);
37 Rhythmic_req *rhythmic_req_l_;
38 Tremolo_req* tremolo_req_l_;
41 ADD_THIS_TRANSLATOR (Stem_engraver);
43 Stem_engraver::Stem_engraver ()
53 Stem_engraver::acknowledge_grob (Grob_info i)
56 if (Rhythmic_head::has_interface (h))
58 if (Rhythmic_head::stem_l (h))
61 int duration_log = unsmob_duration (i.req_l_->get_mus_property ("duration"))-> duration_log ();
65 stem_p_ = new Item (get_property ("Stem"));
66 Stem::set_interface (stem_p_);
67 Staff_symbol_referencer::set_interface (stem_p_);
70 stem_p_->set_grob_property ("duration-log", gh_int2scm (duration_log));
75 Stem tremolo is never applied to a note by default,
76 is must me requested. 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_req_l_->get_mus_property ("tremolo-type"));
85 SCM f = get_property ("tremoloFlags");
86 if (!requested_type && gh_number_p (f))
87 requested_type = gh_scm2int (f);
89 daddy_trans_l_->set_property ("tremoloFlags", gh_int2scm (requested_type));
93 tremolo_p_ = new Item (get_property ("StemTremolo"));
94 Stem_tremolo::set_interface (tremolo_p_);
96 announce_grob (tremolo_p_, tremolo_req_l_);
98 The number of tremolo flags is the number of flags of
99 the tremolo-type minus the number of flags of the note
102 int tremolo_flags = intlog2 (requested_type) - 2
103 - (duration_log > 2 ? duration_log - 2 : 0);
104 if (tremolo_flags < 0)
106 tremolo_p_->set_grob_property ("tremolo-flags",
107 gh_int2scm (tremolo_flags));
110 announce_grob (stem_p_, i.req_l_);
113 if (Stem::flag_i (stem_p_) != duration_log)
115 i.req_l_->origin ()->warning (_f ("Adding note head to incompatible stem (type = %d)", 1 << Stem::flag_i (stem_p_)));
118 Stem::add_head (stem_p_,h);
123 Stem_engraver::stop_translation_timestep ()
127 Stem_tremolo::set_stem (tremolo_p_, stem_p_);
128 typeset_grob (tremolo_p_);
134 SCM prop = get_property ("stemLeftBeamCount");
135 if (gh_number_p (prop))
137 Stem::set_beaming (stem_p_,gh_scm2int (prop),LEFT);
138 daddy_trans_l_->set_property ("stemLeftBeamCount", SCM_UNDEFINED);
140 prop = get_property ("stemRightBeamCount");
141 if (gh_number_p (prop))
143 Stem::set_beaming (stem_p_,gh_scm2int (prop), RIGHT);
144 daddy_trans_l_->set_property ("stemRightBeamCount", SCM_UNDEFINED);
148 // UGH. Should mark non-forced instead.
150 aargh: I don't get it. direction is being set (and then set
151 to forced), if we have a Chord_tremolo.
153 SCM dir = stem_p_->get_grob_property ("direction");
154 if (gh_number_p (dir) && to_dir (dir))
156 stem_p_->set_grob_property ("dir-forced", SCM_BOOL_T);
159 typeset_grob (stem_p_);
168 Stem_engraver::try_music (Music* r)
170 if (Tremolo_req* a = dynamic_cast <Tremolo_req *> (r))