]> git.donarmstrong.com Git - lilypond.git/blob - lily/stem-engraver.cc
release: 1.1.48
[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 }
26
27 void
28 Stem_engraver::do_creation_processing ()
29 {
30   Scalar prop = get_property ("abbrev", 0);
31   if (prop.isnum_b ()) 
32     {
33       default_abbrev_i_  = prop;
34     }
35 }
36
37 void
38 Stem_engraver::acknowledge_element(Score_element_info i)
39 {
40   if (Rhythmic_head * h = dynamic_cast<Rhythmic_head *> (i.elem_l_))
41     {
42       Rhythmic_req * r = dynamic_cast <Rhythmic_req *> (i.req_l_);
43       int duration_log = r->duration_.durlog_i_;      
44       if (!stem_p_) 
45         {
46           stem_p_ = new Stem;
47           stem_p_->flag_i_ = duration_log;
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 Stem_tremolo;
65                   announce_element (Score_element_info (abbrev_p_, abbrev_req_l_));
66                   abbrev_p_->abbrev_flags_i_ =intlog2 (t) - (duration_log>? 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
74       if (stem_p_->flag_i_ != duration_log)
75         {
76           r->warning (_f("Adding note head to incompatible stem (type = %d)", 1 <<  stem_p_->flag_i_));
77         }
78
79       stem_p_->add_head (h);
80     }
81 }
82
83 void
84 Stem_engraver::do_pre_move_processing()
85 {
86   if (abbrev_p_)
87     {
88       abbrev_p_->set_stem (stem_p_);
89       typeset_element (abbrev_p_);
90       abbrev_p_ = 0;
91     }
92
93   if (stem_p_)
94     {
95       Scalar prop = get_property ("verticalDirection", 0);
96       Direction dir = prop.isnum_b () ? (Direction)int(prop) : CENTER;
97       if (dir)
98         {
99           stem_p_->dir_ = dir;
100           stem_p_->set_elt_property (dir_forced_scm_sym, SCM_BOOL_T);
101         }
102
103       Translator_group const *which;
104       prop = get_property ("stemLeftBeamCount", &which);
105       if (prop.isnum_b ())
106         {
107           stem_p_->beams_i_drul_[LEFT] = prop;
108           ((Translator_group*)which)->set_property ("stemLeftBeamCount", "");
109         }
110       prop = get_property ("stemRightBeamCount", &which);
111       if (prop.isnum_b ())
112         {
113           stem_p_->beams_i_drul_[RIGHT] = prop;
114           ((Translator_group*)which)->set_property ("stemRightBeamCount", "");
115         }
116
117       typeset_element(stem_p_);
118       stem_p_ = 0;
119     }
120   abbrev_req_l_ = 0;
121 }
122
123 bool
124 Stem_engraver::do_try_music (Music* r)
125 {
126   if (Tremolo_req* a = dynamic_cast <Tremolo_req *> (r))
127     {
128       abbrev_req_l_ = a;
129       return true;
130     }
131   return false;
132 }
133
134
135 ADD_THIS_TRANSLATOR(Stem_engraver);