]> git.donarmstrong.com Git - lilypond.git/blob - lily/rhythmic-column-engraver.cc
Merge branch 'lilypond/translation' of ssh://git.sv.gnu.org/srv/git/lilypond into...
[lilypond.git] / lily / rhythmic-column-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1997--2011 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
6   LilyPond is free software: you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation, either version 3 of the License, or
9   (at your option) any later version.
10
11   LilyPond is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "engraver.hh"
21 #include "rhythmic-head.hh"
22 #include "stem.hh"
23 #include "note-column.hh"
24 #include "item.hh"
25 #include "dot-column.hh"
26 #include "pointer-group-interface.hh"
27
28 #include "translator.icc"
29
30 /*
31   this engraver  glues together stems, rests and note heads into a NoteColumn
32   grob.
33
34   It also generates spacing objects.  Originally, we have tried to
35   have the spacing functionality at different levels.
36
37   - by simply using the sequence of Separation-item as
38   spacing-sequences (at staff level). Unfortunately, this fucks up if
39   there are different kinds of tuplets in different voices (8th and
40   8ths triplets combined made the program believe there were 1/12 th
41   notes.).
42
43   Doing it in a separate engraver using timing info is generally
44   complicated (start/end time management), and fucks up if a voice
45   changes staff.
46
47   Now we do it from here again. This has the problem that voices can
48   appear and disappear at will, leaving lots of loose ends (the note
49   spacing engraver don't know where to connect the last note of the
50   voice on the right with), but we don't complain about those, and let
51   the default spacing do its work.
52 */
53
54 class Rhythmic_column_engraver : public Engraver
55 {
56   vector<Grob *> rheads_;
57   Grob *stem_;
58   Grob *flag_;
59   Grob *note_column_;
60   Grob *arpeggio_;
61
62   TRANSLATOR_DECLARATIONS (Rhythmic_column_engraver);
63 protected:
64
65   DECLARE_ACKNOWLEDGER (stem);
66   DECLARE_ACKNOWLEDGER (flag);
67   DECLARE_ACKNOWLEDGER (rhythmic_head);
68   DECLARE_ACKNOWLEDGER (arpeggio);
69   void process_acknowledged ();
70   void stop_translation_timestep ();
71 };
72
73 Rhythmic_column_engraver::Rhythmic_column_engraver ()
74 {
75
76   stem_ = 0;
77   flag_ = 0;
78   note_column_ = 0;
79   arpeggio_ = 0;
80 }
81
82 void
83 Rhythmic_column_engraver::process_acknowledged ()
84 {
85   if (rheads_.size ())
86     {
87       if (!note_column_)
88         note_column_ = make_item ("NoteColumn", rheads_[0]->self_scm ());
89
90       for (vsize i = 0; i < rheads_.size (); i++)
91         if (!rheads_[i]->get_parent (X_AXIS))
92           Note_column::add_head (note_column_, rheads_[i]);
93
94       rheads_.resize (0);
95     }
96
97   if (note_column_)
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       if (flag_)
112         Pointer_group_interface::add_grob (note_column_, ly_symbol2scm ("elements"), flag_);
113     }
114 }
115
116 void
117 Rhythmic_column_engraver::acknowledge_stem (Grob_info i)
118 {
119   stem_ = i.grob ();
120 }
121
122 void
123 Rhythmic_column_engraver::acknowledge_flag (Grob_info i)
124 {
125   flag_ = i.grob ();
126 }
127
128 void
129 Rhythmic_column_engraver::acknowledge_rhythmic_head (Grob_info i)
130 {
131   rheads_.push_back (i.grob ());
132 }
133
134 void
135 Rhythmic_column_engraver::acknowledge_arpeggio (Grob_info i)
136 {
137   arpeggio_ = i.grob ();
138 }
139
140 void
141 Rhythmic_column_engraver::stop_translation_timestep ()
142 {
143   note_column_ = 0;
144   stem_ = 0;
145   arpeggio_ = 0;
146   flag_ = 0;
147 }
148
149 ADD_ACKNOWLEDGER (Rhythmic_column_engraver, stem);
150 ADD_ACKNOWLEDGER (Rhythmic_column_engraver, flag);
151 ADD_ACKNOWLEDGER (Rhythmic_column_engraver, rhythmic_head);
152 ADD_ACKNOWLEDGER (Rhythmic_column_engraver, arpeggio);
153
154 ADD_TRANSLATOR (Rhythmic_column_engraver,
155                 /* doc */
156                 "Generate @code{NoteColumn}, an object that groups stems,"
157                 " note heads, and rests.",
158
159                 /* create */
160                 "NoteColumn ",
161
162                 /* read */
163                 "",
164
165                 /* write */
166                 ""
167                );