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