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