2 stem-grav.cc -- implement Stem_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 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 do_creation_processing ();
31 virtual void acknowledge_element (Score_element_info);
32 virtual void do_pre_move_processing ();
33 virtual bool do_try_music (Music*);
36 int default_tremolo_type_i_;
38 Score_element *tremolo_p_;
39 Rhythmic_req *rhythmic_req_l_;
40 Tremolo_req* tremolo_req_l_;
43 ADD_THIS_TRANSLATOR (Stem_engraver);
45 Stem_engraver::Stem_engraver ()
50 default_tremolo_type_i_ = 16;
55 Stem_engraver::do_creation_processing ()
58 huh, why only at creation time?
60 SCM prop = get_property ("tremoloFlags");
61 if (gh_number_p(prop))
63 default_tremolo_type_i_ = gh_scm2int (prop);
68 Stem_engraver::acknowledge_element(Score_element_info i)
70 Score_element* h = i.elem_l_;
71 if (Rhythmic_head::has_interface (h))
73 if (Rhythmic_head::stem_l (h))
76 Rhythmic_req * r = dynamic_cast <Rhythmic_req *> (i.req_l_);
77 int duration_log = r->duration_.durlog_i_;
80 stem_p_ = new Stem (get_property ("basicStemProperties"));
81 Staff_symbol_referencer::set_interface(stem_p_);
84 stem_p_->set_elt_property ("duration-log", gh_int2scm (duration_log));
89 Stem tremolo is never applied to a note by default,
90 is must me requested. But there is a default for the
95 the first and last (quarter) note bothe get one tremolo flag.
97 int requested_type = tremolo_req_l_->type_i_;
99 requested_type = default_tremolo_type_i_;
101 default_tremolo_type_i_ = requested_type;
105 tremolo_p_ = new Item (get_property ("basicStemTremoloProperties"));
106 Stem_tremolo::set_interface (tremolo_p_);
108 announce_element (Score_element_info (tremolo_p_, tremolo_req_l_));
110 The number of tremolo flags is the number of flags of
111 the tremolo-type minus the number of flags of the note
114 int tremolo_flags = intlog2 (requested_type) - 2
115 - (duration_log > 2 ? duration_log - 2 : 0);
116 if (tremolo_flags < 0)
118 tremolo_p_->set_elt_property ("tremolo-flags",
119 gh_int2scm (tremolo_flags));
122 announce_element (Score_element_info (stem_p_, r));
125 if (Stem::flag_i (stem_p_) != duration_log)
127 r->warning (_f ("Adding note head to incompatible stem (type = %d)", 1 << Stem::flag_i (stem_p_)));
130 Stem::add_head (stem_p_,h);
135 Stem_engraver::do_pre_move_processing()
139 Stem_tremolo::set_stem (tremolo_p_, stem_p_);
140 typeset_element (tremolo_p_);
146 SCM prop = get_property ("stemLeftBeamCount");
147 if (gh_number_p(prop))
149 Stem::set_beaming (stem_p_,gh_scm2int (prop),LEFT);
150 daddy_trans_l_->set_property ("stemLeftBeamCount", SCM_UNDEFINED);
152 prop = get_property ("stemRightBeamCount");
153 if (gh_number_p(prop))
155 Stem::set_beaming (stem_p_,gh_scm2int (prop), RIGHT);
156 daddy_trans_l_->set_property ("stemRightBeamCount", SCM_UNDEFINED);
160 // UGH. Should mark non-forced instead.
163 aargh: I don't get it. direction is being set (and then set
164 to forced), if we have a Chord_tremolo.
166 SCM dir = stem_p_->get_elt_property ("direction");
167 if (gh_number_p (dir) && to_dir(dir))
169 stem_p_->set_elt_property ("dir-forced", SCM_BOOL_T);
172 typeset_element(stem_p_);
181 Stem_engraver::do_try_music (Music* r)
183 if (Tremolo_req* a = dynamic_cast <Tremolo_req *> (r))