]> git.donarmstrong.com Git - lilypond.git/blob - lily/stem-engraver.cc
patch::: 1.1.49.uu1
[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       Rhythmic_req * r = dynamic_cast <Rhythmic_req *> (i.req_l_);
44       int duration_log = r->duration_.durlog_i_;      
45       if (!stem_p_) 
46         {
47           stem_p_ = new Stem;
48           stem_p_->flag_i_ = duration_log;
49
50           if (abbrev_req_l_)
51             {
52               /*
53                 suggests typing of:
54                 c8:16 c: c: c:
55                 hmm, which isn't so bad?
56               */
57               int t = abbrev_req_l_->type_i_;
58               if (!t)
59                 t = default_abbrev_i_;
60               else
61                 default_abbrev_i_ = t;
62
63               if (t)
64                 {
65                   abbrev_p_ = new Stem_tremolo;
66                   announce_element (Score_element_info (abbrev_p_, abbrev_req_l_));
67                   abbrev_p_->abbrev_flags_i_ =intlog2 (t) - (duration_log>? 2);
68                 }
69             }
70
71           // must give the request, to preserve the rhythmic info.
72           announce_element (Score_element_info (stem_p_, r));
73         }
74
75       if (stem_p_->flag_i_ != duration_log)
76         {
77           r->warning (_f("Adding note head to incompatible stem (type = %d)", 1 <<  stem_p_->flag_i_));
78         }
79
80       stem_p_->add_head (h);
81     }
82 }
83
84 void
85 Stem_engraver::do_pre_move_processing()
86 {
87   if (abbrev_p_)
88     {
89       abbrev_p_->set_stem (stem_p_);
90       typeset_element (abbrev_p_);
91       abbrev_p_ = 0;
92     }
93
94   if (stem_p_)
95     {
96       Scalar prop = get_property ("verticalDirection", 0);
97       Direction dir = prop.isnum_b () ? (Direction)int(prop) : CENTER;
98       if (dir)
99         {
100           stem_p_->dir_ = dir;
101           stem_p_->set_elt_property (dir_forced_scm_sym, SCM_BOOL_T);
102         }
103
104       Translator_group const *which;
105       prop = get_property ("stemLeftBeamCount", &which);
106       if (prop.isnum_b ())
107         {
108           stem_p_->beams_i_drul_[LEFT] = prop;
109           ((Translator_group*)which)->set_property ("stemLeftBeamCount", "");
110         }
111       prop = get_property ("stemRightBeamCount", &which);
112       if (prop.isnum_b ())
113         {
114           stem_p_->beams_i_drul_[RIGHT] = prop;
115           ((Translator_group*)which)->set_property ("stemRightBeamCount", "");
116         }
117
118       typeset_element(stem_p_);
119       stem_p_ = 0;
120     }
121   abbrev_req_l_ = 0;
122 }
123
124 bool
125 Stem_engraver::do_try_music (Music* r)
126 {
127   if (Tremolo_req* a = dynamic_cast <Tremolo_req *> (r))
128     {
129       abbrev_req_l_ = a;
130       return true;
131     }
132   return false;
133 }
134
135
136 ADD_THIS_TRANSLATOR(Stem_engraver);