]> git.donarmstrong.com Git - lilypond.git/blob - lily/rhythmic-column-engraver.cc
release: 1.5.26
[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           spacing_ = new Item (get_property ("NoteSpacing"));
63           spacing_->set_grob_property ("left-item", note_column_->self_scm ());
64           announce_grob (spacing_, 0);
65
66           if (last_spacing_)
67             {
68               last_spacing_->set_grob_property ("right-item" , note_column_->self_scm ());
69             }
70         }
71
72       for (int i=0; i < rhead_l_arr_.size (); i++)
73         {
74           if (!rhead_l_arr_[i]->get_parent (X_AXIS))
75             Note_column::add_head (note_column_, rhead_l_arr_[i]);
76         }
77       rhead_l_arr_.set_size (0);
78     }
79
80   
81   if (note_column_)
82     {
83       if (dotcol_l_
84           && !dotcol_l_->get_parent (X_AXIS))
85         {
86           Note_column::set_dotcol (note_column_, dotcol_l_);
87         }
88
89       if (stem_l_
90           && !stem_l_->get_parent (X_AXIS))
91         {
92           Note_column::set_stem (note_column_, stem_l_);
93           stem_l_ = 0;
94         }
95
96     }
97 }
98
99 void
100 Rhythmic_column_engraver::acknowledge_grob (Grob_info i)
101 {
102   Item * item =  dynamic_cast <Item *> (i.grob_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 }
116
117 void
118 Rhythmic_column_engraver::stop_translation_timestep ()
119 {
120   if (note_column_) 
121     {
122       typeset_grob (note_column_);
123       note_column_ =0;
124     }
125
126   if (spacing_)
127     {
128       typeset_grob (spacing_);
129       last_spacing_ = spacing_;
130       spacing_ =0;
131     }
132 }
133
134 void
135 Rhythmic_column_engraver::start_translation_timestep ()
136 {
137   dotcol_l_ =0;
138   stem_l_ =0;
139 }
140
141
142
143 ENTER_DESCRIPTION(Rhythmic_column_engraver,
144 /* descr */       "Generates NoteColumn, an objects that groups stems, noteheads and rests.",
145 /* creats*/       "NoteColumn",
146 /* acks  */       "stem-interface rhythmic-head-interface dot-column-interface",
147 /* reads */       "",
148 /* write */       "");