]> git.donarmstrong.com Git - lilypond.git/blob - lily/rhythmic-column-engraver.cc
release: 1.5.29
[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--2002 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 #include "group-interface.hh"
19
20
21
22 /*
23   this engraver  glues together stems, rests and note heads into a NoteColumn
24   grob.
25
26   It also generates spacing objects.  Originally, we have tried to
27   have the spacing functionality at different levels.
28   
29   - by simply using the sequence of Separation-item as
30   spacing-sequences (at staff level). Unfortunately, this fucks up if
31   there are different kinds of tuplets in different voices (8th and
32   8ths triplets combined made the program believe there were 1/12 th
33   notes.).
34
35   Doing it in a separate engraver using timing info is generally
36   complicated (start/end time management), and fucks up if a voice
37   changes staff.
38
39   Now we do it from here again. This has the problem that voices can
40   appear and disappear at will, leaving lots of loose ends (the note
41   spacing engraver don't know where to connect the last note of the
42   voice on the right with), but we don't complain about those, and let
43   the default spacing do its work.
44
45  */
46
47
48 class Rhythmic_column_engraver :public Engraver
49 {
50   Link_array<Grob> rhead_l_arr_;
51   Grob * stem_l_;
52   Grob * note_column_;
53   Grob * dotcol_l_;
54
55   Grob * last_spacing_;
56   Grob * spacing_;
57   
58   TRANSLATOR_DECLARATIONS(Rhythmic_column_engraver);
59 protected:
60
61   virtual void acknowledge_grob (Grob_info);
62   virtual void create_grobs ();
63   virtual void stop_translation_timestep ();
64   virtual void start_translation_timestep ();
65 };
66
67
68
69 Rhythmic_column_engraver::Rhythmic_column_engraver ()
70 {
71   spacing_ =0 ;
72   last_spacing_ = 0;
73   
74   stem_l_ =0;
75   note_column_=0;
76   dotcol_l_ =0;
77 }
78
79
80 void
81 Rhythmic_column_engraver::create_grobs ()
82 {
83   if (rhead_l_arr_.size ())
84     {
85       if (!note_column_)
86         {
87           note_column_ = new Item (get_property ("NoteColumn"));
88           Note_column::set_interface (note_column_);
89           announce_grob (note_column_, 0);
90
91
92          spacing_ = new Item (get_property ("NoteSpacing"));
93          spacing_->set_grob_property ("left-items", gh_cons (note_column_->self_scm (), SCM_EOL));
94          announce_grob (spacing_, 0);
95
96          if (last_spacing_)
97            {
98              Pointer_group_interface::add_grob (last_spacing_,
99                                                 ly_symbol2scm ("right-items" ),
100                                                 note_column_);
101            }
102
103         }
104
105       for (int i=0; i < rhead_l_arr_.size (); i++)
106         {
107           if (!rhead_l_arr_[i]->get_parent (X_AXIS))
108             Note_column::add_head (note_column_, rhead_l_arr_[i]);
109         }
110       rhead_l_arr_.set_size (0);
111     }
112
113   
114   if (note_column_)
115     {
116       if (dotcol_l_
117           && !dotcol_l_->get_parent (X_AXIS))
118         {
119           Note_column::set_dotcol (note_column_, dotcol_l_);
120         }
121
122       if (stem_l_
123           && !stem_l_->get_parent (X_AXIS))
124         {
125           Note_column::set_stem (note_column_, stem_l_);
126           stem_l_ = 0;
127         }
128
129     }
130 }
131
132 void
133 Rhythmic_column_engraver::acknowledge_grob (Grob_info i)
134 {
135   Item * item =  dynamic_cast <Item *> (i.grob_l_);
136   if (item && Stem::has_interface (item))
137     {
138       stem_l_ = item;
139     }
140   else if (item && Rhythmic_head::has_interface (item))
141     {
142       rhead_l_arr_.push (item);
143     }
144   else if (item && Dot_column::has_interface (item))
145     {
146       dotcol_l_ = item;
147     }
148 }
149
150 void
151 Rhythmic_column_engraver::stop_translation_timestep ()
152 {
153   if (note_column_) 
154     {
155       typeset_grob (note_column_);
156       note_column_ =0;
157     }
158
159   if (spacing_)
160     {
161       typeset_grob (spacing_);
162       last_spacing_ = spacing_;
163       spacing_ =0;
164     }
165 }
166
167 void
168 Rhythmic_column_engraver::start_translation_timestep ()
169 {
170   dotcol_l_ =0;
171   stem_l_ =0;
172 }
173
174
175
176 ENTER_DESCRIPTION(Rhythmic_column_engraver,
177 /* descr */       "Generates NoteColumn, an objects that groups stems, noteheads and rests.",
178 /* creats*/       "NoteColumn NoteSpacing",
179 /* acks  */       "stem-interface rhythmic-head-interface dot-column-interface",
180 /* reads */       "",
181 /* write */       "");