lilypond-1.3.12
[lilypond.git] / lily / stem-engraver.cc
blob09e490bdff28f2bbd24217a5f3026d6300a94d78
1 /*
2 stem-grav.cc -- implement Stem_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
9 #include "staff-symbol-referencer.hh"
10 #include "stem-engraver.hh"
11 #include "note-head.hh"
12 #include "stem.hh"
13 #include "musical-request.hh"
14 #include "duration-convert.hh"
15 #include "misc.hh"
16 #include "stem-tremolo.hh"
17 #include "staff-info.hh"
18 #include "translator-group.hh"
20 Stem_engraver::Stem_engraver()
22 abbrev_req_l_ = 0;
23 stem_p_ = 0;
24 abbrev_p_ = 0;
25 default_abbrev_i_ = 16;
26 rhythmic_req_l_ =0;
29 void
30 Stem_engraver::do_creation_processing ()
32 SCM prop = get_property ("abbrev", 0);
33 if (gh_number_p(prop))
35 default_abbrev_i_ = gh_scm2int (prop);
39 void
40 Stem_engraver::acknowledge_element(Score_element_info i)
42 if (Rhythmic_head * h = dynamic_cast<Rhythmic_head *> (i.elem_l_))
44 if (h->stem_l ())
45 return;
47 Rhythmic_req * r = dynamic_cast <Rhythmic_req *> (i.req_l_);
48 int duration_log = r->duration_.durlog_i_;
49 if (!stem_p_)
51 stem_p_ = new Stem;
52 Staff_symbol_referencer_interface st(stem_p_);
53 st.set_interface ();
55 stem_p_->set_elt_property ("duration-log", gh_int2scm (duration_log));
57 if (abbrev_req_l_)
60 suggests typing of:
61 c8:16 c: c: c:
62 hmm, which isn't so bad?
64 int t = abbrev_req_l_->type_i_;
65 if (!t)
66 t = default_abbrev_i_;
67 else
68 default_abbrev_i_ = t;
70 if (t)
72 abbrev_p_ = new Stem_tremolo;
73 announce_element (Score_element_info (abbrev_p_, abbrev_req_l_));
74 abbrev_p_->abbrev_flags_i_ =intlog2 (t) - (duration_log>? 2);
78 // must give the request, to preserve the rhythmic info.
79 announce_element (Score_element_info (stem_p_, r));
82 if (stem_p_->flag_i () != duration_log)
84 r->warning (_f ("Adding note head to incompatible stem (type = %d)", 1 << stem_p_->flag_i ()));
87 stem_p_->add_head (h);
91 void
92 Stem_engraver::do_pre_move_processing()
94 if (abbrev_p_)
96 abbrev_p_->set_stem (stem_p_);
97 typeset_element (abbrev_p_);
98 abbrev_p_ = 0;
101 if (stem_p_)
103 Translator_group* which;
104 SCM prop = get_property ("stemLeftBeamCount", &which);
105 if (gh_number_p(prop))
107 stem_p_->set_beaming (gh_scm2int (prop),LEFT);
108 ((Translator_group*)which)->set_property ("stemLeftBeamCount", SCM_UNDEFINED);
110 prop = get_property ("stemRightBeamCount", &which);
111 if (gh_number_p(prop))
113 stem_p_->set_beaming (gh_scm2int (prop), RIGHT);
114 ((Translator_group*)which)->set_property ("stemRightBeamCount", SCM_UNDEFINED);
117 // UGH. Should mark non-forced instead.
118 SCM dir = stem_p_->get_elt_property ("direction");
119 if (gh_number_p (dir) && to_dir(dir))
121 stem_p_->set_elt_property ("dir-forced", SCM_BOOL_T);
125 typeset_element(stem_p_);
126 stem_p_ = 0;
128 abbrev_req_l_ = 0;
131 bool
132 Stem_engraver::do_try_music (Music* r)
134 if (Tremolo_req* a = dynamic_cast <Tremolo_req *> (r))
136 abbrev_req_l_ = a;
137 return true;
139 return false;
143 ADD_THIS_TRANSLATOR(Stem_engraver);