]> git.donarmstrong.com Git - lilypond.git/blob - lily/stanza-number-align-engraver.cc
Web-ja: update introduction
[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--2015 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   void acknowledge_lyric_syllable (Grob_info);
39   void acknowledge_stanza_number (Grob_info);
40   void stop_translation_timestep ();
41 };
42
43 Stanza_number_align_engraver::Stanza_number_align_engraver (Context *c)
44   : Engraver (c)
45 {
46 }
47
48 void
49 Stanza_number_align_engraver::acknowledge_lyric_syllable (Grob_info gi)
50 {
51   Grob *h = gi.grob ();
52   lyrics_.push_back (h);
53 }
54
55 void
56 Stanza_number_align_engraver::acknowledge_stanza_number (Grob_info gi)
57 {
58   Grob *h = gi.grob ();
59   stanza_numbers_.push_back (h);
60 }
61
62 void
63 Stanza_number_align_engraver::stop_translation_timestep ()
64 {
65   for (vsize i = lyrics_.size (); i--;)
66     for (vsize j = stanza_numbers_.size (); j--;)
67       Side_position_interface::add_support (stanza_numbers_[j], lyrics_[i]);
68
69   stanza_numbers_.clear ();
70   lyrics_.clear ();
71 }
72
73
74 void
75 Stanza_number_align_engraver::boot ()
76 {
77   ADD_ACKNOWLEDGER (Stanza_number_align_engraver, lyric_syllable);
78   ADD_ACKNOWLEDGER (Stanza_number_align_engraver, stanza_number);
79 }
80
81 ADD_TRANSLATOR (Stanza_number_align_engraver,
82                 /* doc */
83                 "This engraver ensures that stanza numbers are neatly"
84                 " aligned.",
85
86                 /* create */
87                 "",
88
89                 /* read */
90                 "",
91
92                 /* write */
93                 "");
94