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_;
37 Score_element *stem_p_;
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 Item (get_property ("basicStemProperties"));
81 Stem::set_interface (stem_p_);
82 Staff_symbol_referencer::set_interface(stem_p_);
85 stem_p_->set_elt_property ("duration-log", gh_int2scm (duration_log));
90 Stem tremolo is never applied to a note by default,
91 is must me requested. But there is a default for the
96 the first and last (quarter) note bothe get one tremolo flag.
98 int requested_type = tremolo_req_l_->type_i_;
100 requested_type = default_tremolo_type_i_;
102 default_tremolo_type_i_ = requested_type;
106 tremolo_p_ = new Item (get_property ("basicStemTremoloProperties"));
107 Stem_tremolo::set_interface (tremolo_p_);
109 announce_element (Score_element_info (tremolo_p_, tremolo_req_l_));
111 The number of tremolo flags is the number of flags of
112 the tremolo-type minus the number of flags of the note
115 int tremolo_flags = intlog2 (requested_type) - 2
116 - (duration_log > 2 ? duration_log - 2 : 0);
117 if (tremolo_flags < 0)
119 tremolo_p_->set_elt_property ("tremolo-flags",
120 gh_int2scm (tremolo_flags));
123 announce_element (Score_element_info (stem_p_, r));
126 if (Stem::flag_i (stem_p_) != duration_log)
128 r->warning (_f ("Adding note head to incompatible stem (type = %d)", 1 << Stem::flag_i (stem_p_)));
131 Stem::add_head (stem_p_,h);
136 Stem_engraver::do_pre_move_processing()
140 Stem_tremolo::set_stem (tremolo_p_, stem_p_);
141 typeset_element (tremolo_p_);
147 SCM prop = get_property ("stemLeftBeamCount");
148 if (gh_number_p(prop))
150 Stem::set_beaming (stem_p_,gh_scm2int (prop),LEFT);
151 daddy_trans_l_->set_property ("stemLeftBeamCount", SCM_UNDEFINED);
153 prop = get_property ("stemRightBeamCount");
154 if (gh_number_p(prop))
156 Stem::set_beaming (stem_p_,gh_scm2int (prop), RIGHT);
157 daddy_trans_l_->set_property ("stemRightBeamCount", SCM_UNDEFINED);
161 // UGH. Should mark non-forced instead.
164 aargh: I don't get it. direction is being set (and then set
165 to forced), if we have a Chord_tremolo.
167 SCM dir = stem_p_->get_elt_property ("direction");
168 if (gh_number_p (dir) && to_dir(dir))
170 stem_p_->set_elt_property ("dir-forced", SCM_BOOL_T);
173 typeset_element(stem_p_);
182 Stem_engraver::do_try_music (Music* r)
184 if (Tremolo_req* a = dynamic_cast <Tremolo_req *> (r))