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