]> git.donarmstrong.com Git - lilypond.git/blob - lily/rhythmic-column-engraver.cc
tweaks to spacing and include spring.cc
[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--2007 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   Grob *arpeggio_;
50
51   TRANSLATOR_DECLARATIONS (Rhythmic_column_engraver);
52 protected:
53
54   DECLARE_ACKNOWLEDGER (dot_column);
55   DECLARE_ACKNOWLEDGER (stem);
56   DECLARE_ACKNOWLEDGER (rhythmic_head);
57   DECLARE_ACKNOWLEDGER (arpeggio);
58   void process_acknowledged ();
59   void stop_translation_timestep ();
60 };
61
62 Rhythmic_column_engraver::Rhythmic_column_engraver ()
63 {
64
65   stem_ = 0;
66   note_column_ = 0;
67   dotcol_ = 0;
68   arpeggio_ = 0;
69 }
70
71
72 void
73 Rhythmic_column_engraver::process_acknowledged ()
74 {
75   if (rheads_.size ())
76     {
77       if (!note_column_)
78         {
79           note_column_ = make_item ("NoteColumn", rheads_[0]->self_scm ());
80         }
81
82       for (vsize i = 0; i < rheads_.size (); i++)
83         {
84           if (!rheads_[i]->get_parent (X_AXIS))
85             Note_column::add_head (note_column_, rheads_[i]);
86
87           if (Grob *dot = unsmob_grob (rheads_[i]->get_object ("dot")))
88             Pointer_group_interface::add_grob (note_column_, ly_symbol2scm ("elements"), dot);
89         }
90       rheads_.resize (0);
91     }
92
93   if (note_column_)
94     {
95       if (dotcol_
96           && !dotcol_->get_parent (X_AXIS))
97         Note_column::set_dotcol (note_column_, dotcol_);
98
99       if (stem_
100           && !stem_->get_parent (X_AXIS))
101         {
102           Note_column::set_stem (note_column_, stem_);
103           stem_ = 0;
104         }
105
106       if (arpeggio_)
107         {
108           Pointer_group_interface::add_grob (note_column_, ly_symbol2scm ("elements"), arpeggio_);
109           note_column_->set_object ("arpeggio", arpeggio_->self_scm ());
110         }
111     }
112 }
113
114 void
115 Rhythmic_column_engraver::acknowledge_stem (Grob_info i)
116 {
117   stem_ = i.grob ();
118 }
119
120 void
121 Rhythmic_column_engraver::acknowledge_rhythmic_head (Grob_info i)
122 {
123   rheads_.push_back (i.grob ());
124 }
125
126 void
127 Rhythmic_column_engraver::acknowledge_dot_column (Grob_info i)
128 {
129   dotcol_ = i.grob ();
130 }
131
132 void
133 Rhythmic_column_engraver::acknowledge_arpeggio (Grob_info i)
134 {
135   arpeggio_ = i.grob ();
136 }
137
138 void
139 Rhythmic_column_engraver::stop_translation_timestep ()
140 {
141   note_column_ = 0;
142   dotcol_ = 0;
143   stem_ = 0;
144   arpeggio_ = 0;
145 }
146
147 ADD_ACKNOWLEDGER (Rhythmic_column_engraver, dot_column);
148 ADD_ACKNOWLEDGER (Rhythmic_column_engraver, stem);
149 ADD_ACKNOWLEDGER (Rhythmic_column_engraver, rhythmic_head);
150 ADD_ACKNOWLEDGER (Rhythmic_column_engraver, arpeggio);
151
152 ADD_TRANSLATOR (Rhythmic_column_engraver,
153                 /* doc */ "Generates NoteColumn, an objects that groups stems, noteheads and rests.",
154                 /* create */ "NoteColumn",
155                 /* read */ "",
156                 /* write */ "");