]> git.donarmstrong.com Git - lilypond.git/blob - lily/rhythmic-column-engraver.cc
release: 1.3.109
[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<Grob> rhead_l_arr_;
22   Link_array<Grob> grace_slur_endings_;
23   Grob * stem_l_;
24   Grob *ncol_p_;
25   Grob *dotcol_l_;
26
27 protected:
28   VIRTUAL_COPY_CONS(Translator);
29   virtual void acknowledge_grob (Grob_info);
30   virtual void create_grobs ();
31   virtual void stop_translation_timestep();
32   virtual void start_translation_timestep();
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::create_grobs ()
50 {
51   if (rhead_l_arr_.size ())
52     {
53       if (!ncol_p_)
54         {
55           ncol_p_ = new Item (get_property("NoteColumn"));
56           Note_column::set_interface (ncol_p_);
57           announce_grob (ncol_p_, 0);
58         }
59
60       for (int i=0; i < rhead_l_arr_.size (); i++)
61         {
62           if (!rhead_l_arr_[i]->parent_l(X_AXIS))
63             Note_column::add_head (ncol_p_, rhead_l_arr_[i]);
64         }
65       rhead_l_arr_.set_size (0);
66     }
67
68   
69   if (ncol_p_)
70     {
71       if (dotcol_l_
72           && !dotcol_l_->parent_l (X_AXIS))
73         {
74           Note_column::set_dotcol (ncol_p_, dotcol_l_);
75         }
76
77       if (stem_l_
78           && !stem_l_->parent_l(X_AXIS))
79         {
80           Note_column::set_stem (ncol_p_, stem_l_);
81           stem_l_ = 0;
82         }
83
84       SCM wg = get_property ("weAreGraceContext");
85       bool wegrace = to_boolean (wg);
86
87       if (!wegrace)
88         for (int i=0; i < grace_slur_endings_.size(); i++)
89           Slur::add_column (grace_slur_endings_[i], ncol_p_);
90       grace_slur_endings_.clear ();
91     }
92 }
93
94 void
95 Rhythmic_column_engraver::acknowledge_grob (Grob_info i)
96 {
97   SCM wg = get_property ("weAreGraceContext");
98   bool wegrace = to_boolean (wg);
99   if (wegrace != to_boolean (i.elem_l_->get_grob_property ("grace"))
100     && !Slur::has_interface (i.elem_l_))
101     return ;
102   
103   Item * item =  dynamic_cast <Item *> (i.elem_l_);
104   if (item && Stem::has_interface (item))
105     {
106       stem_l_ = item;
107     }
108   else if (item && Rhythmic_head::has_interface (item))
109     {
110       rhead_l_arr_.push (item);
111     }
112   else if (item && Dot_column::has_interface (item))
113     {
114       dotcol_l_ = item;
115     }
116   else if (Slur::has_interface (i.elem_l_))
117     {
118       /*
119         end slurs starting on grace notes
120        */
121       
122       if (to_boolean (i.elem_l_->get_grob_property ("grace")))
123         grace_slur_endings_.push (i.elem_l_);
124    }
125 }
126
127 void
128 Rhythmic_column_engraver::stop_translation_timestep()
129 {
130   if (ncol_p_) 
131     {
132       typeset_grob (ncol_p_);
133       ncol_p_ =0;
134     }
135 }
136
137 void
138 Rhythmic_column_engraver::start_translation_timestep()
139 {
140   grace_slur_endings_.clear ();
141   dotcol_l_ =0;
142   stem_l_ =0;
143 }
144
145 ADD_THIS_TRANSLATOR(Rhythmic_column_engraver);
146