]> git.donarmstrong.com Git - lilypond.git/blob - lily/rhythmic-column-engraver.cc
* flower
[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
81           if (last_spacing_)
82             {
83               Pointer_group_interface::add_grob (last_spacing_,
84                                                  ly_symbol2scm ("right-items"),
85                                                  note_column_);
86             }
87
88         }
89
90       for (int i = 0; i < rheads_.size (); i++)
91         {
92           if (!rheads_[i]->get_parent (X_AXIS))
93             Note_column::add_head (note_column_, rheads_[i]);
94         }
95       rheads_.set_size (0);
96     }
97
98   if (note_column_)
99     {
100       if (dotcol_
101           && !dotcol_->get_parent (X_AXIS))
102         {
103           Note_column::set_dotcol (note_column_, dotcol_);
104         }
105
106       if (stem_
107           && !stem_->get_parent (X_AXIS))
108         {
109           Note_column::set_stem (note_column_, stem_);
110           stem_ = 0;
111         }
112
113     }
114 }
115
116 void
117 Rhythmic_column_engraver::acknowledge_grob (Grob_info i)
118 {
119   Item *item = dynamic_cast<Item *> (i.grob_);
120   if (!item || item->get_parent (X_AXIS))
121     return;
122   if (Stem::has_interface (item))
123     {
124       stem_ = item;
125     }
126   else if (Rhythmic_head::has_interface (item))
127     {
128       rheads_.push (item);
129     }
130   else if (Dot_column::has_interface (item))
131     {
132       dotcol_ = item;
133     }
134 }
135
136 void
137 Rhythmic_column_engraver::stop_translation_timestep ()
138 {
139   note_column_ = 0;
140
141   if (spacing_)
142     {
143       last_spacing_ = spacing_;
144       spacing_ = 0;
145     }
146
147   dotcol_ = 0;
148   stem_ = 0;
149 }
150
151 ADD_TRANSLATOR (Rhythmic_column_engraver,
152                 /* descr */ "Generates NoteColumn, an objects that groups stems, noteheads and rests.",
153                 /* creats*/ "NoteColumn NoteSpacing",
154                 /* accepts */ "",
155                 /* acks  */ "stem-interface rhythmic-head-interface dot-column-interface",
156                 /* reads */ "",
157                 /* write */ "");