lilypond-1.4.4
[lilypond.git] / lily / stem-engraver.cc
blob9375bd9a7f18ff554ed46a0d111c035fe33db985
1 /*
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>
7 */
9 #include "staff-symbol-referencer.hh"
10 #include "rhythmic-head.hh"
11 #include "stem.hh"
12 #include "musical-request.hh"
13 #include "misc.hh"
14 #include "stem-tremolo.hh"
15 #include "item.hh"
16 #include "translator-group.hh"
17 #include "engraver.hh"
19 /**
20 Make stems upon receiving noteheads.
22 class Stem_engraver : public Engraver
25 public:
26 VIRTUAL_COPY_CONS (Translator);
27 Stem_engraver ();
29 protected:
30 virtual void acknowledge_grob (Grob_info);
31 virtual void stop_translation_timestep ();
32 virtual bool try_music (Music*);
34 private:
35 Grob *stem_p_;
36 Grob *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 ()
45 tremolo_req_l_ = 0;
46 stem_p_ = 0;
47 tremolo_p_ = 0;
48 rhythmic_req_l_ =0;
52 void
53 Stem_engraver::acknowledge_grob (Grob_info i)
55 Grob* h = i.elem_l_;
56 if (Rhythmic_head::has_interface (h))
58 if (Rhythmic_head::stem_l (h))
59 return;
61 int duration_log = unsmob_duration (i.req_l_->get_mus_property ("duration"))-> duration_log ();
63 if (!stem_p_)
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));
72 if (tremolo_req_l_)
75 Stem tremolo is never applied to a note by default,
76 is must me requested. But there is a default for the
77 tremolo value:
79 c4:8 c c:
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);
88 else
89 daddy_trans_l_->set_property ("tremoloFlags", gh_int2scm (requested_type));
91 if (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
100 itself.
102 int tremolo_flags = intlog2 (requested_type) - 2
103 - (duration_log > 2 ? duration_log - 2 : 0);
104 if (tremolo_flags < 0)
105 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);
122 void
123 Stem_engraver::stop_translation_timestep ()
125 if (tremolo_p_)
127 Stem_tremolo::set_stem (tremolo_p_, stem_p_);
128 typeset_grob (tremolo_p_);
129 tremolo_p_ = 0;
132 if (stem_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_);
160 stem_p_ = 0;
164 tremolo_req_l_ = 0;
167 bool
168 Stem_engraver::try_music (Music* r)
170 if (Tremolo_req* a = dynamic_cast <Tremolo_req *> (r))
172 tremolo_req_l_ = a;
173 return true;
175 return false;