]> git.donarmstrong.com Git - lilypond.git/blob - lily/stem-engraver.cc
release: 1.3.16
[lilypond.git] / lily / stem-engraver.cc
1 /*
2   stem-grav.cc -- implement Stem_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
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"
18
19 Stem_engraver::Stem_engraver()
20 {
21   abbrev_req_l_ = 0;
22   stem_p_ = 0;
23   abbrev_p_ = 0;
24   default_abbrev_i_ = 16;
25   rhythmic_req_l_ =0;
26 }
27
28 void
29 Stem_engraver::do_creation_processing ()
30 {
31   SCM prop = get_property ("abbrev", 0);
32   if (gh_number_p(prop)) 
33     {
34       default_abbrev_i_  = gh_scm2int (prop);
35     }
36 }
37
38 void
39 Stem_engraver::acknowledge_element(Score_element_info i)
40 {
41   if (Rhythmic_head * h = dynamic_cast<Rhythmic_head *> (i.elem_l_))
42     {
43       if (h->stem_l ())
44         return;
45       
46       Rhythmic_req * r = dynamic_cast <Rhythmic_req *> (i.req_l_);
47       int duration_log = r->duration_.durlog_i_;      
48       if (!stem_p_) 
49         {
50           stem_p_ = new Stem;
51           Staff_symbol_referencer_interface st(stem_p_);
52           st.set_interface ();
53           
54           stem_p_->set_elt_property ("duration-log", gh_int2scm (duration_log));
55
56           if (abbrev_req_l_)
57             {
58               /*
59                 suggests typing of:
60                 c8:16 c: c: c:
61                 hmm, which isn't so bad?
62               */
63               int t = abbrev_req_l_->type_i_;
64               if (!t)
65                 t = default_abbrev_i_;
66               else
67                 default_abbrev_i_ = t;
68
69               if (t)
70                 {
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)));
74                 }
75             }
76
77           // must give the request, to preserve the rhythmic info.
78           announce_element (Score_element_info (stem_p_, r));
79         }
80
81       if (stem_p_->flag_i () != duration_log)
82         {
83           r->warning (_f ("Adding note head to incompatible stem (type = %d)", 1 <<  stem_p_->flag_i ()));
84         }
85
86       stem_p_->add_head (h);
87     }
88 }
89
90 void
91 Stem_engraver::do_pre_move_processing()
92 {
93   if (abbrev_p_)
94     {
95       abbrev_p_->set_stem (stem_p_);
96       typeset_element (abbrev_p_);
97       abbrev_p_ = 0;
98     }
99
100   if (stem_p_)
101     {
102       Translator_group* which;
103       SCM prop = get_property ("stemLeftBeamCount", &which);
104       if (gh_number_p(prop))
105         {
106           stem_p_->set_beaming (gh_scm2int (prop),LEFT);
107           ((Translator_group*)which)->set_property ("stemLeftBeamCount", SCM_UNDEFINED);
108         }
109       prop = get_property ("stemRightBeamCount", &which);
110       if (gh_number_p(prop))
111         {
112           stem_p_->set_beaming (gh_scm2int (prop), RIGHT);
113           ((Translator_group*)which)->set_property ("stemRightBeamCount", SCM_UNDEFINED);
114         }
115
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))
119         {
120           stem_p_->set_elt_property ("dir-forced", SCM_BOOL_T);   
121         }
122
123
124       typeset_element(stem_p_);
125       stem_p_ = 0;
126     }
127   abbrev_req_l_ = 0;
128 }
129
130 bool
131 Stem_engraver::do_try_music (Music* r)
132 {
133   if (Tremolo_req* a = dynamic_cast <Tremolo_req *> (r))
134     {
135       abbrev_req_l_ = a;
136       return true;
137     }
138   return false;
139 }
140
141
142 ADD_THIS_TRANSLATOR(Stem_engraver);
143