]> git.donarmstrong.com Git - lilypond.git/blob - lily/rhythmic-column-engraver.cc
release: 1.3.69
[lilypond.git] / lily / rhythmic-column-engraver.cc
1 /*
2   rhythmic-column-grav.cc -- implement Rhythmic_column_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9
10 #include "slur.hh"
11 #include "engraver.hh"
12 #include "rhythmic-head.hh"
13 #include "stem.hh"
14 #include "note-column.hh"
15 #include "dot-column.hh"
16 #include "musical-request.hh"
17 #include "item.hh"
18
19 class Rhythmic_column_engraver :public Engraver
20 {
21   Link_array<Score_element> rhead_l_arr_;
22   Link_array<Slur> grace_slur_endings_;
23   Score_element * stem_l_;
24   Note_column *ncol_p_;
25   Score_element *dotcol_l_;
26
27 protected:
28   VIRTUAL_COPY_CONS(Translator);
29   virtual void acknowledge_element (Score_element_info);
30   virtual void process_acknowledged ();
31   virtual void do_pre_move_processing();
32   virtual void do_post_move_processing();
33 public:
34   Rhythmic_column_engraver();
35   
36 };
37
38
39
40 Rhythmic_column_engraver::Rhythmic_column_engraver()
41 {
42   stem_l_ =0;
43   ncol_p_=0;
44   dotcol_l_ =0;
45 }
46
47
48 void
49 Rhythmic_column_engraver::process_acknowledged ()
50 {
51   if (rhead_l_arr_.size ())
52     {
53       if (!ncol_p_)
54         {
55           ncol_p_ = new Note_column (get_property("basicNoteColumnProperties"));
56           announce_element (Score_element_info (ncol_p_, 0));
57         }
58
59       for (int i=0; i < rhead_l_arr_.size (); i++)
60         {
61           if (!rhead_l_arr_[i]->parent_l(X_AXIS))
62             ncol_p_->add_head (rhead_l_arr_[i]);
63         }
64       rhead_l_arr_.set_size (0);
65     }
66
67   
68   if (ncol_p_)
69     {
70       if (dotcol_l_
71           && !dotcol_l_->parent_l (X_AXIS))
72         {
73           ncol_p_->set_dotcol (dotcol_l_);
74         }
75
76       if (stem_l_
77           && !stem_l_->parent_l(X_AXIS))
78         {
79           ncol_p_->set_stem (stem_l_);
80           stem_l_ = 0;
81         }
82
83       SCM wg = get_property ("weAreGraceContext");
84       bool wegrace = to_boolean (wg);
85
86       if (!wegrace)
87         for (int i=0; i < grace_slur_endings_.size(); i++)
88           grace_slur_endings_[i]->add_column (ncol_p_);
89       grace_slur_endings_.clear ();
90     }
91 }
92
93 void
94 Rhythmic_column_engraver::acknowledge_element (Score_element_info i)
95 {
96   SCM wg = get_property ("weAreGraceContext");
97   bool wegrace = to_boolean (wg);
98   if (wegrace != to_boolean (i.elem_l_->get_elt_property ("grace"))
99     && !dynamic_cast<Slur*> (i.elem_l_))
100     return ;
101   
102   Item * item =  dynamic_cast <Item *> (i.elem_l_);
103   if (item && Stem::has_interface (item))
104     {
105       stem_l_ = item;
106     }
107   else if (item && Rhythmic_head::has_interface (item))
108     {
109       rhead_l_arr_.push (item);
110     }
111   else if (item && Dot_column::has_interface (item))
112     {
113       dotcol_l_ = item;
114     }
115   else if (Slur *s = dynamic_cast<Slur*> (i.elem_l_))
116     {
117       /*
118         end slurs starting on grace notes
119        */
120       
121       if (to_boolean (s->get_elt_property ("grace")))
122         grace_slur_endings_.push (s);
123    }
124 }
125
126 void
127 Rhythmic_column_engraver::do_pre_move_processing()
128 {
129   if (ncol_p_) 
130     {
131       typeset_element (ncol_p_);
132       ncol_p_ =0;
133     }
134 }
135
136 void
137 Rhythmic_column_engraver::do_post_move_processing()
138 {
139   grace_slur_endings_.clear ();
140   dotcol_l_ =0;
141   stem_l_ =0;
142 }
143
144 ADD_THIS_TRANSLATOR(Rhythmic_column_engraver);
145