]> git.donarmstrong.com Git - lilypond.git/blob - lily/rhythmic-column-engraver.cc
(class Phrasing_slur_engraver):
[lilypond.git] / lily / rhythmic-column-engraver.cc
1 /*
2   rhythmic-column-engraver.cc -- implement Rhythmic_column_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "engraver.hh"
10 #include "rhythmic-head.hh"
11 #include "stem.hh"
12 #include "note-column.hh"
13 #include "dot-column.hh"
14 #include "pointer-group-interface.hh"
15
16 #include "translator.icc"
17
18 /*
19   this engraver  glues together stems, rests and note heads into a NoteColumn
20   grob.
21
22   It also generates spacing objects.  Originally, we have tried to
23   have the spacing functionality at different levels.
24
25   - by simply using the sequence of Separation-item as
26   spacing-sequences (at staff level). Unfortunately, this fucks up if
27   there are different kinds of tuplets in different voices (8th and
28   8ths triplets combined made the program believe there were 1/12 th
29   notes.).
30
31   Doing it in a separate engraver using timing info is generally
32   complicated (start/end time management), and fucks up if a voice
33   changes staff.
34
35   Now we do it from here again. This has the problem that voices can
36   appear and disappear at will, leaving lots of loose ends (the note
37   spacing engraver don't know where to connect the last note of the
38   voice on the right with), but we don't complain about those, and let
39   the default spacing do its work.
40 */
41
42 class Rhythmic_column_engraver : public Engraver
43 {
44   Link_array<Grob> rheads_;
45   Grob *stem_;
46   Grob *note_column_;
47   Grob *dotcol_;
48
49   Grob *last_spacing_;
50   Grob *spacing_;
51
52   void add_spacing_item (Grob*);
53   
54   TRANSLATOR_DECLARATIONS (Rhythmic_column_engraver);
55 protected:
56
57   DECLARE_ACKNOWLEDGER (dot_column);
58   DECLARE_ACKNOWLEDGER (stem);
59   DECLARE_ACKNOWLEDGER (rhythmic_head);
60   void process_acknowledged ();
61   void stop_translation_timestep ();
62 };
63
64 Rhythmic_column_engraver::Rhythmic_column_engraver ()
65 {
66   spacing_ = 0;
67   last_spacing_ = 0;
68
69   stem_ = 0;
70   note_column_ = 0;
71   dotcol_ = 0;
72 }
73
74 void
75 Rhythmic_column_engraver::add_spacing_item (Grob *g)
76 {
77   if (spacing_)
78     {
79       Pointer_group_interface::add_grob (spacing_,
80                                          ly_symbol2scm ("left-items"),
81                                          g);
82
83       if (last_spacing_)
84         {
85           Pointer_group_interface::add_grob (last_spacing_,
86                                              ly_symbol2scm ("right-items"),
87                                              g);
88         }
89     }
90 }
91 void
92 Rhythmic_column_engraver::process_acknowledged ()
93 {
94   if (rheads_.size ())
95     {
96       if (!note_column_)
97         {
98           note_column_ = make_item ("NoteColumn", rheads_[0]->self_scm ());
99
100           spacing_ = make_item ("NoteSpacing", SCM_EOL);
101           add_spacing_item (note_column_);
102         }
103
104       for (int i = 0; i < rheads_.size (); i++)
105         {
106           if (!rheads_[i]->get_parent (X_AXIS))
107             Note_column::add_head (note_column_, rheads_[i]);
108         }
109       rheads_.set_size (0);
110     }
111
112   if (note_column_)
113     {
114       if (dotcol_
115           && !dotcol_->get_parent (X_AXIS))
116         {
117           Note_column::set_dotcol (note_column_, dotcol_);
118         }
119
120       if (stem_
121           && !stem_->get_parent (X_AXIS))
122         {
123           Note_column::set_stem (note_column_, stem_);
124           stem_ = 0;
125         }
126     }
127 }
128
129 void
130 Rhythmic_column_engraver::acknowledge_stem (Grob_info i)
131 {
132   stem_ = i.grob();
133 }
134
135 void
136 Rhythmic_column_engraver::acknowledge_rhythmic_head (Grob_info i)
137 {
138   rheads_.push (i.grob ());
139 }
140
141 void
142 Rhythmic_column_engraver::acknowledge_dot_column (Grob_info i)
143 {
144   dotcol_ = i.grob ();
145 }
146
147 void
148 Rhythmic_column_engraver::stop_translation_timestep ()
149 {
150   note_column_ = 0;
151
152   if (spacing_)
153     {
154       last_spacing_ = spacing_;
155       spacing_ = 0;
156     }
157
158   dotcol_ = 0;
159   stem_ = 0;
160 }
161
162
163 ADD_ACKNOWLEDGER (Rhythmic_column_engraver, dot_column);
164 ADD_ACKNOWLEDGER (Rhythmic_column_engraver, stem);
165 ADD_ACKNOWLEDGER (Rhythmic_column_engraver, rhythmic_head);
166
167 ADD_TRANSLATOR (Rhythmic_column_engraver,
168                 /* doc */ "Generates NoteColumn, an objects that groups stems, noteheads and rests.",
169                 /* create */ "NoteColumn NoteSpacing",
170                 /* accept */ "",
171                 /* read */ "",
172                 /* write */ "");