]> git.donarmstrong.com Git - lilypond.git/blob - lily/stem-engraver.cc
release: 1.1.18
[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--1998 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 "abbrev.hh"
16
17 Stem_engraver::Stem_engraver()
18 {
19   abbrev_req_l_ = 0;
20   stem_p_ = 0;
21   abbrev_p_ = 0;
22   default_abbrev_i_ = 16;
23 }
24
25 void
26 Stem_engraver::do_creation_processing ()
27 {
28   Scalar prop = get_property ("abbrev", 0);
29   if (prop.isnum_b ()) 
30     {
31       default_abbrev_i_  = prop;
32     }
33 }
34
35 void
36 Stem_engraver::acknowledge_element(Score_element_info i)
37 {
38   if (dynamic_cast<Rhythmic_head *> (i.elem_l_))
39     {
40       Rhythmic_head *h  = dynamic_cast<Rhythmic_head *> (i.elem_l_);
41       if (!stem_p_) 
42         {
43           Rhythmic_req * r = dynamic_cast <Rhythmic_req *> (i.req_l_);
44           stem_p_ = new Stem;
45           int durlog_i = r->duration_.durlog_i_;
46           stem_p_->flag_i_ = durlog_i;
47
48           
49           if (abbrev_req_l_)
50             {
51               /*
52                 suggests typing of:
53                    c8:16 c: c: c:
54                 hmm, which isn't so bad?
55               */
56               int t = abbrev_req_l_->type_i_;
57               if (!t)
58                 t = default_abbrev_i_;
59               else
60                 default_abbrev_i_ = t;
61
62               if (t)
63                 {
64                   abbrev_p_ = new Abbreviation;
65                   announce_element (Score_element_info (abbrev_p_, abbrev_req_l_));
66                   abbrev_p_->abbrev_flags_i_ =intlog2 (t) - (durlog_i>? 2);
67                 }
68             }
69
70           // must give the request, to preserve the rhythmic info.
71           announce_element (Score_element_info (stem_p_, r));
72         }
73       stem_p_->add_head (h);
74     }
75 }
76
77 void
78 Stem_engraver::do_pre_move_processing()
79 {
80   if (abbrev_p_)
81     {
82       abbrev_p_->set_stem (stem_p_);
83       typeset_element (abbrev_p_);
84       abbrev_p_ = 0;
85     }
86
87   if (stem_p_)
88     {
89       Scalar prop = get_property ("ydirection", 0);
90       Direction dir = prop.isnum_b () ? (Direction)int(prop) : CENTER;
91       if (dir)
92         {
93           stem_p_->dir_ = dir;
94           stem_p_->dir_forced_b_ = true;
95         }
96
97       Translator const *which;
98       prop = get_property ("stemLeftBeamCount", &which);
99       if (prop.isnum_b ())
100         {
101           stem_p_->beams_i_drul_[LEFT] = prop;
102           ((Translator*)which)->set_property ("stemLeftBeamCount", "");
103         }
104       prop = get_property ("stemRightBeamCount", &which);
105       if (prop.isnum_b ())
106         {
107           stem_p_->beams_i_drul_[RIGHT] = prop;
108           ((Translator*)which)->set_property ("stemRightBeamCount", "");
109         }
110
111
112       typeset_element(stem_p_);
113       stem_p_ = 0;
114     }
115   abbrev_req_l_ = 0;
116 }
117
118 bool
119 Stem_engraver::do_try_music (Music* r)
120 {
121   if (Abbreviation_req* a = dynamic_cast <Abbreviation_req *> (r))
122     {
123       abbrev_req_l_ = a;
124       return true;
125     }
126   return false;
127 }
128
129
130 ADD_THIS_TRANSLATOR(Stem_engraver);