lilypond-1.3.28
[lilypond.git] / lily / stem-engraver.cc
blob91a679eca6e10dedb2e07f167458cefe6c3907a3
1 /*
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>
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 "misc.hh"
15 #include "stem-tremolo.hh"
16 #include "staff-info.hh"
17 #include "translator-group.hh"
19 Stem_engraver::Stem_engraver()
21 abbrev_req_l_ = 0;
22 stem_p_ = 0;
23 abbrev_p_ = 0;
24 default_abbrev_i_ = 16;
25 rhythmic_req_l_ =0;
28 void
29 Stem_engraver::do_creation_processing ()
31 SCM prop = get_property ("abbrev", 0);
32 if (gh_number_p(prop))
34 default_abbrev_i_ = gh_scm2int (prop);
38 void
39 Stem_engraver::acknowledge_element(Score_element_info i)
41 if (Rhythmic_head * h = dynamic_cast<Rhythmic_head *> (i.elem_l_))
43 if (h->stem_l ())
44 return;
46 Rhythmic_req * r = dynamic_cast <Rhythmic_req *> (i.req_l_);
47 int duration_log = r->duration_.durlog_i_;
48 if (!stem_p_)
50 stem_p_ = new Stem;
51 Staff_symbol_referencer_interface st(stem_p_);
52 st.set_interface ();
54 stem_p_->set_elt_property ("duration-log", gh_int2scm (duration_log));
56 if (abbrev_req_l_)
59 suggests typing of:
60 c8:16 c: c: c:
61 hmm, which isn't so bad?
63 int t = abbrev_req_l_->type_i_;
64 if (!t)
65 t = default_abbrev_i_;
66 else
67 default_abbrev_i_ = t;
69 if (t)
71 abbrev_p_ = new Stem_tremolo;
72 announce_element (Score_element_info (abbrev_p_, abbrev_req_l_));
73 abbrev_p_->set_elt_property ("tremolo-flags", gh_int2scm (intlog2 (t) - (duration_log>? 2)));
77 // must give the request, to preserve the rhythmic info.
78 announce_element (Score_element_info (stem_p_, r));
81 if (stem_p_->flag_i () != duration_log)
83 r->warning (_f ("Adding note head to incompatible stem (type = %d)", 1 << stem_p_->flag_i ()));
86 stem_p_->add_head (h);
90 void
91 Stem_engraver::do_pre_move_processing()
93 if (abbrev_p_)
95 abbrev_p_->set_stem (stem_p_);
96 typeset_element (abbrev_p_);
97 abbrev_p_ = 0;
100 if (stem_p_)
102 Translator_group* which;
103 SCM prop = get_property ("stemLeftBeamCount", &which);
104 if (gh_number_p(prop))
106 stem_p_->set_beaming (gh_scm2int (prop),LEFT);
107 ((Translator_group*)which)->set_property ("stemLeftBeamCount", SCM_UNDEFINED);
109 prop = get_property ("stemRightBeamCount", &which);
110 if (gh_number_p(prop))
112 stem_p_->set_beaming (gh_scm2int (prop), RIGHT);
113 ((Translator_group*)which)->set_property ("stemRightBeamCount", SCM_UNDEFINED);
116 // UGH. Should mark non-forced instead.
117 SCM dir = stem_p_->get_elt_property ("direction");
118 if (gh_number_p (dir) && to_dir(dir))
120 stem_p_->set_elt_property ("dir-forced", SCM_BOOL_T);
124 typeset_element(stem_p_);
125 stem_p_ = 0;
127 abbrev_req_l_ = 0;
130 bool
131 Stem_engraver::do_try_music (Music* r)
133 if (Tremolo_req* a = dynamic_cast <Tremolo_req *> (r))
135 abbrev_req_l_ = a;
136 return true;
138 return false;
142 ADD_THIS_TRANSLATOR(Stem_engraver);