]> git.donarmstrong.com Git - lilypond.git/blob - lily/rhythmic-column-engraver.cc
release: 1.5.15
[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   TRANSLATOR_DECLARATIONS(Rhythmic_column_engraver);
27 protected:
28
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   
34 };
35
36
37
38 Rhythmic_column_engraver::Rhythmic_column_engraver ()
39 {
40   stem_l_ =0;
41   ncol_p_=0;
42   dotcol_l_ =0;
43 }
44
45
46 void
47 Rhythmic_column_engraver::create_grobs ()
48 {
49   if (rhead_l_arr_.size ())
50     {
51       if (!ncol_p_)
52         {
53           ncol_p_ = new Item (get_property ("NoteColumn"));
54           Note_column::set_interface (ncol_p_);
55           announce_grob (ncol_p_, 0);
56         }
57
58       for (int i=0; i < rhead_l_arr_.size (); i++)
59         {
60           if (!rhead_l_arr_[i]->parent_l (X_AXIS))
61             Note_column::add_head (ncol_p_, rhead_l_arr_[i]);
62         }
63       rhead_l_arr_.set_size (0);
64     }
65
66   
67   if (ncol_p_)
68     {
69       if (dotcol_l_
70           && !dotcol_l_->parent_l (X_AXIS))
71         {
72           Note_column::set_dotcol (ncol_p_, dotcol_l_);
73         }
74
75       if (stem_l_
76           && !stem_l_->parent_l (X_AXIS))
77         {
78           Note_column::set_stem (ncol_p_, stem_l_);
79           stem_l_ = 0;
80         }
81
82     }
83 }
84
85 void
86 Rhythmic_column_engraver::acknowledge_grob (Grob_info i)
87 {
88   Item * item =  dynamic_cast <Item *> (i.grob_l_);
89   if (item && Stem::has_interface (item))
90     {
91       stem_l_ = item;
92     }
93   else if (item && Rhythmic_head::has_interface (item))
94     {
95       rhead_l_arr_.push (item);
96     }
97   else if (item && Dot_column::has_interface (item))
98     {
99       dotcol_l_ = item;
100     }
101 }
102
103 void
104 Rhythmic_column_engraver::stop_translation_timestep ()
105 {
106   if (ncol_p_) 
107     {
108       typeset_grob (ncol_p_);
109       ncol_p_ =0;
110     }
111 }
112
113 void
114 Rhythmic_column_engraver::start_translation_timestep ()
115 {
116   dotcol_l_ =0;
117   stem_l_ =0;
118 }
119
120
121
122 ENTER_DESCRIPTION(Rhythmic_column_engraver,
123 /* descr */       "Generates NoteColumn, an objects that groups stems, noteheads and rests.",
124 /* creats*/       "NoteColumn",
125 /* acks  */       "stem-interface rhythmic-head-interface dot-column-interface",
126 /* reads */       "",
127 /* write */       "");