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