]> git.donarmstrong.com Git - lilypond.git/blob - lily/rhythmic-column-engraver.cc
release: 1.5.1
[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--2001 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   Grob * stem_l_;
23   Grob *ncol_p_;
24   Grob *dotcol_l_;
25
26 protected:
27   VIRTUAL_COPY_CONS (Translator);
28   virtual void acknowledge_grob (Grob_info);
29   virtual void create_grobs ();
30   virtual void stop_translation_timestep ();
31   virtual void start_translation_timestep ();
32 public:
33   Rhythmic_column_engraver ();
34   
35 };
36
37
38
39 Rhythmic_column_engraver::Rhythmic_column_engraver ()
40 {
41   stem_l_ =0;
42   ncol_p_=0;
43   dotcol_l_ =0;
44 }
45
46
47 void
48 Rhythmic_column_engraver::create_grobs ()
49 {
50   if (rhead_l_arr_.size ())
51     {
52       if (!ncol_p_)
53         {
54           ncol_p_ = new Item (get_property ("NoteColumn"));
55           Note_column::set_interface (ncol_p_);
56           announce_grob (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             Note_column::add_head (ncol_p_, 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           Note_column::set_dotcol (ncol_p_, dotcol_l_);
74         }
75
76       if (stem_l_
77           && !stem_l_->parent_l (X_AXIS))
78         {
79           Note_column::set_stem (ncol_p_, stem_l_);
80           stem_l_ = 0;
81         }
82
83     }
84 }
85
86 void
87 Rhythmic_column_engraver::acknowledge_grob (Grob_info i)
88 {
89   Item * item =  dynamic_cast <Item *> (i.elem_l_);
90   if (item && Stem::has_interface (item))
91     {
92       stem_l_ = item;
93     }
94   else if (item && Rhythmic_head::has_interface (item))
95     {
96       rhead_l_arr_.push (item);
97     }
98   else if (item && Dot_column::has_interface (item))
99     {
100       dotcol_l_ = item;
101     }
102 }
103
104 void
105 Rhythmic_column_engraver::stop_translation_timestep ()
106 {
107   if (ncol_p_) 
108     {
109       typeset_grob (ncol_p_);
110       ncol_p_ =0;
111     }
112 }
113
114 void
115 Rhythmic_column_engraver::start_translation_timestep ()
116 {
117   dotcol_l_ =0;
118   stem_l_ =0;
119 }
120
121 ADD_THIS_TRANSLATOR (Rhythmic_column_engraver);
122