]> git.donarmstrong.com Git - lilypond.git/blob - lily/stanza-number-align-engraver.cc
e16560d263a724a3869243a3e7a7934cd9338f97
[lilypond.git] / lily / stanza-number-align-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2004--2012 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 "context.hh"
21 #include "engraver.hh"
22 #include "note-head.hh"
23 #include "lyric-extender.hh"
24 #include "pointer-group-interface.hh"
25 #include "side-position-interface.hh"
26
27 #include "translator.icc"
28
29 class Stanza_number_align_engraver : public Engraver
30 {
31 public:
32   TRANSLATOR_DECLARATIONS (Stanza_number_align_engraver);
33
34 protected:
35   vector<Grob *> lyrics_;
36   vector<Grob *> stanza_numbers_;
37
38   DECLARE_ACKNOWLEDGER (lyric_syllable);
39   DECLARE_ACKNOWLEDGER (stanza_number);
40   void stop_translation_timestep ();
41 };
42
43 Stanza_number_align_engraver::Stanza_number_align_engraver ()
44 {
45 }
46
47 void
48 Stanza_number_align_engraver::acknowledge_lyric_syllable (Grob_info gi)
49 {
50   Grob *h = gi.grob ();
51   lyrics_.push_back (h);
52 }
53
54 void
55 Stanza_number_align_engraver::acknowledge_stanza_number (Grob_info gi)
56 {
57   Grob *h = gi.grob ();
58   stanza_numbers_.push_back (h);
59 }
60
61 void
62 Stanza_number_align_engraver::stop_translation_timestep ()
63 {
64   for (vsize i = lyrics_.size (); i--;)
65     for (vsize j = stanza_numbers_.size (); j--;)
66       Side_position_interface::add_support (stanza_numbers_[j], lyrics_[i]);
67
68   stanza_numbers_.clear ();
69   lyrics_.clear ();
70 }
71
72 ADD_ACKNOWLEDGER (Stanza_number_align_engraver, lyric_syllable);
73 ADD_ACKNOWLEDGER (Stanza_number_align_engraver, stanza_number);
74
75 ADD_TRANSLATOR (Stanza_number_align_engraver,
76                 /* doc */
77                 "This engraver ensures that stanza numbers are neatly"
78                 " aligned.",
79
80                 /* create */
81                 "",
82
83                 /* read */
84                 "",
85
86                 /* write */
87                 "");
88