]> git.donarmstrong.com Git - lilypond.git/blob - lily/footnote-engraver.cc
Issue 4550 (1/2) Avoid "using namespace std;" in included files
[lilypond.git] / lily / footnote-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2011--2015 Mike Solomon <mike@mikesolomon.org>
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
22 #include "music.hh"
23 #include "stream-event.hh"
24 #include "international.hh"
25 #include "item.hh"
26 #include "pointer-group-interface.hh"
27 #include "spanner.hh"
28 #include "system.hh"
29
30 #include "translator.icc"
31
32 using std::vector;
33
34 class Footnote_engraver : public Engraver
35 {
36   TRANSLATOR_DECLARATIONS (Footnote_engraver);
37
38   DECLARE_ACKNOWLEDGER (grob);
39   DECLARE_END_ACKNOWLEDGER (grob);
40
41   vector<Drul_array<Spanner *> > annotated_spanners_;
42
43   void finalize ();
44
45   void footnotify (Grob *, SCM);
46 };
47
48 void
49 Footnote_engraver::finalize ()
50 {
51   annotated_spanners_.clear ();
52 }
53
54 Footnote_engraver::Footnote_engraver ()
55 {
56 }
57
58 void
59 Footnote_engraver::footnotify (Grob *g, SCM cause)
60 {
61   Spanner *s = dynamic_cast<Spanner *>(g);
62
63   if (s)
64     {
65       Spanner *b = make_spanner ("FootnoteSpanner", cause);
66       b->set_parent (s, Y_AXIS);
67       b->set_parent (s, X_AXIS);
68       Grob *bound = unsmob<Grob> (get_property ("currentMusicalColumn"));
69       b->set_bound (LEFT, bound);
70       annotated_spanners_.push_back (Drul_array<Spanner *> (s, b));
71     }
72   else
73     {
74       Grob *b = make_item ("FootnoteItem", cause);
75       b->set_parent (g, Y_AXIS);
76       b->set_parent (g, X_AXIS);
77     }
78 }
79
80 void
81 Footnote_engraver::acknowledge_grob (Grob_info info)
82 {
83   Music *mus = unsmob<Music> (info.grob ()->get_property ("footnote-music"));
84
85   if (mus)
86     {
87       if (!mus->is_mus_type ("footnote-event"))
88         {
89           mus->origin ()->programming_error (_ ("Must be footnote-event."));
90           return;
91         }
92
93       footnotify (info.grob (), mus->to_event ()->unprotect ());
94
95       // This grob has exhausted its footnote
96       info.grob ()->set_property ("footnote-music", SCM_EOL);
97
98       return;
99     }
100 }
101
102 void
103 Footnote_engraver::acknowledge_end_grob (Grob_info info)
104 {
105   Spanner *s = dynamic_cast<Spanner *>(info.grob ());
106
107   if (s)
108     for (vsize i = 0; i < annotated_spanners_.size (); i++)
109       {
110         if (annotated_spanners_[i][LEFT] == s)
111           {
112             Grob *bound = unsmob<Grob> (get_property ("currentMusicalColumn"));
113             annotated_spanners_[i][RIGHT]->set_bound (RIGHT, bound);
114             break;
115           }
116       }
117 }
118
119 ADD_ACKNOWLEDGER (Footnote_engraver, grob);
120 ADD_END_ACKNOWLEDGER (Footnote_engraver, grob);
121
122 ADD_TRANSLATOR (Footnote_engraver,
123                 /* doc */
124                 "Create footnote texts.",
125
126                 /* create */
127                 "FootnoteItem "
128                 "FootnoteSpanner ",
129
130                 /*read*/
131                 "currentMusicalColumn ",
132
133                 /*write*/
134                 ""
135                );