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 acknowledge_element (Score_element_info);
31 virtual void do_pre_move_processing ();
32 virtual bool do_try_music (Music*);
35 Score_element *stem_p_;
36 Score_element *tremolo_p_;
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_element(Score_element_info i)
55 Score_element* h = i.elem_l_;
56 if (Rhythmic_head::has_interface (h))
58 if (Rhythmic_head::stem_l (h))
61 Rhythmic_req * r = dynamic_cast <Rhythmic_req *> (i.req_l_);
62 int duration_log = r->duration_.durlog_i_;
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_elt_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 = tremolo_req_l_->type_i_;
84 SCM f = get_property ("tremoloFlags");
85 if (!requested_type && gh_number_p (f))
86 requested_type = gh_scm2int (f);
88 daddy_trans_l_->set_property ("tremoloFlags", gh_int2scm (requested_type));
92 tremolo_p_ = new Item (get_property ("StemTremolo"));
93 Stem_tremolo::set_interface (tremolo_p_);
95 announce_element (tremolo_p_, tremolo_req_l_);
97 The number of tremolo flags is the number of flags of
98 the tremolo-type minus the number of flags of the note
101 int tremolo_flags = intlog2 (requested_type) - 2
102 - (duration_log > 2 ? duration_log - 2 : 0);
103 if (tremolo_flags < 0)
105 tremolo_p_->set_elt_property ("tremolo-flags",
106 gh_int2scm (tremolo_flags));
109 announce_element (stem_p_, r);
112 if (Stem::flag_i (stem_p_) != duration_log)
114 r->origin ()->warning (_f ("Adding note head to incompatible stem (type = %d)", 1 << Stem::flag_i (stem_p_)));
117 Stem::add_head (stem_p_,h);
122 Stem_engraver::do_pre_move_processing()
126 Stem_tremolo::set_stem (tremolo_p_, stem_p_);
127 typeset_element (tremolo_p_);
133 SCM prop = get_property ("stemLeftBeamCount");
134 if (gh_number_p(prop))
136 Stem::set_beaming (stem_p_,gh_scm2int (prop),LEFT);
137 daddy_trans_l_->set_property ("stemLeftBeamCount", SCM_UNDEFINED);
139 prop = get_property ("stemRightBeamCount");
140 if (gh_number_p(prop))
142 Stem::set_beaming (stem_p_,gh_scm2int (prop), RIGHT);
143 daddy_trans_l_->set_property ("stemRightBeamCount", SCM_UNDEFINED);
147 // 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_elt_property ("direction");
154 if (gh_number_p (dir) && to_dir(dir))
156 stem_p_->set_elt_property ("dir-forced", SCM_BOOL_T);
159 typeset_element(stem_p_);
168 Stem_engraver::do_try_music (Music* r)
170 if (Tremolo_req* a = dynamic_cast <Tremolo_req *> (r))