]> git.donarmstrong.com Git - lilypond.git/blob - lily/stem-engraver.cc
1679e52441275bdab90ca4e37760835274188471
[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 "stem-engraver.hh"
10 #include "note-head.hh"
11 #include "stem.hh"
12 #include "musical-request.hh"
13 #include "duration-convert.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   Scalar prop = get_property ("abbrev", 0);
32   if (prop.isnum_b ()) 
33     {
34       default_abbrev_i_  = 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           stem_p_->flag_i_ = duration_log;
52
53           if (abbrev_req_l_)
54             {
55               /*
56                 suggests typing of:
57                 c8:16 c: c: c:
58                 hmm, which isn't so bad?
59               */
60               int t = abbrev_req_l_->type_i_;
61               if (!t)
62                 t = default_abbrev_i_;
63               else
64                 default_abbrev_i_ = t;
65
66               if (t)
67                 {
68                   abbrev_p_ = new Stem_tremolo;
69                   announce_element (Score_element_info (abbrev_p_, abbrev_req_l_));
70                   abbrev_p_->abbrev_flags_i_ =intlog2 (t) - (duration_log>? 2);
71                 }
72             }
73
74           // must give the request, to preserve the rhythmic info.
75           announce_element (Score_element_info (stem_p_, r));
76         }
77
78       if (stem_p_->flag_i_ != duration_log)
79         {
80           r->warning (_f ("Adding note head to incompatible stem (type = %d)", 1 <<  stem_p_->flag_i_));
81         }
82
83       stem_p_->add_head (h);
84     }
85 }
86
87 void
88 Stem_engraver::do_pre_move_processing()
89 {
90   if (abbrev_p_)
91     {
92       abbrev_p_->set_stem (stem_p_);
93       typeset_element (abbrev_p_);
94       abbrev_p_ = 0;
95     }
96
97   if (stem_p_)
98     {
99       Scalar prop = get_property ("verticalDirection", 0);
100       Direction dir = prop.isnum_b () ? (Direction)int(prop) : CENTER;
101       if (dir)
102         {
103           stem_p_->dir_ = dir;
104           stem_p_->set_elt_property (dir_forced_scm_sym, SCM_BOOL_T);
105         }
106
107       Translator_group* which;
108       prop = get_property ("stemLeftBeamCount", &which);
109       if (prop.isnum_b ())
110         {
111           stem_p_->beams_i_drul_[LEFT] = prop;
112           ((Translator_group*)which)->set_property ("stemLeftBeamCount", "");
113         }
114       prop = get_property ("stemRightBeamCount", &which);
115       if (prop.isnum_b ())
116         {
117           stem_p_->beams_i_drul_[RIGHT] = prop;
118           ((Translator_group*)which)->set_property ("stemRightBeamCount", "");
119         }
120
121       prop = get_property ("stemLength", 0);
122       if (prop.isnum_b ())
123         {
124           stem_p_->set_elt_property (length_scm_sym, gh_double2scm (prop.to_f ()));
125         }
126
127       prop = get_property ("stemStyle", 0);
128       if (prop.to_bool ())
129         {
130           stem_p_->set_elt_property (style_scm_sym, ly_ch_C_to_scm (prop.ch_C()));
131         }
132       
133       typeset_element(stem_p_);
134       stem_p_ = 0;
135     }
136   abbrev_req_l_ = 0;
137 }
138
139 bool
140 Stem_engraver::do_try_music (Music* r)
141 {
142   if (Tremolo_req* a = dynamic_cast <Tremolo_req *> (r))
143     {
144       abbrev_req_l_ = a;
145       return true;
146     }
147   return false;
148 }
149
150
151 ADD_THIS_TRANSLATOR(Stem_engraver);