]> git.donarmstrong.com Git - lilypond.git/blob - lily/footnote-engraver.cc
Web-ja: update introduction
[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 class Footnote_engraver : public Engraver
33 {
34   TRANSLATOR_DECLARATIONS (Footnote_engraver);
35
36   void acknowledge_grob (Grob_info);
37   void acknowledge_end_grob (Grob_info);
38
39   vector<Drul_array<Spanner *> > annotated_spanners_;
40
41   void finalize ();
42
43   void footnotify (Grob *, SCM);
44 };
45
46 void
47 Footnote_engraver::finalize ()
48 {
49   annotated_spanners_.clear ();
50 }
51
52 Footnote_engraver::Footnote_engraver (Context *c)
53   : Engraver (c)
54 {
55 }
56
57 void
58 Footnote_engraver::footnotify (Grob *g, SCM cause)
59 {
60   Spanner *s = dynamic_cast<Spanner *>(g);
61
62   if (s)
63     {
64       Spanner *b = make_spanner ("FootnoteSpanner", cause);
65       b->set_parent (s, Y_AXIS);
66       b->set_parent (s, X_AXIS);
67       Grob *bound = unsmob<Grob> (get_property ("currentMusicalColumn"));
68       b->set_bound (LEFT, bound);
69       annotated_spanners_.push_back (Drul_array<Spanner *> (s, b));
70     }
71   else
72     {
73       Grob *b = make_item ("FootnoteItem", cause);
74       b->set_parent (g, Y_AXIS);
75       b->set_parent (g, X_AXIS);
76     }
77 }
78
79 void
80 Footnote_engraver::acknowledge_grob (Grob_info info)
81 {
82   Music *mus = unsmob<Music> (info.grob ()->get_property ("footnote-music"));
83
84   if (mus)
85     {
86       if (!mus->is_mus_type ("footnote-event"))
87         {
88           mus->origin ()->programming_error (_ ("Must be footnote-event."));
89           return;
90         }
91
92       footnotify (info.grob (), mus->to_event ()->unprotect ());
93
94       // This grob has exhausted its footnote
95       info.grob ()->set_property ("footnote-music", SCM_EOL);
96
97       return;
98     }
99 }
100
101 void
102 Footnote_engraver::acknowledge_end_grob (Grob_info info)
103 {
104   Spanner *s = dynamic_cast<Spanner *>(info.grob ());
105
106   if (s)
107     for (vsize i = 0; i < annotated_spanners_.size (); i++)
108       {
109         if (annotated_spanners_[i][LEFT] == s)
110           {
111             Grob *bound = unsmob<Grob> (get_property ("currentMusicalColumn"));
112             annotated_spanners_[i][RIGHT]->set_bound (RIGHT, bound);
113             break;
114           }
115       }
116 }
117
118
119 void
120 Footnote_engraver::boot ()
121 {
122   ADD_ACKNOWLEDGER (Footnote_engraver, grob);
123   ADD_END_ACKNOWLEDGER (Footnote_engraver, grob);
124 }
125
126 ADD_TRANSLATOR (Footnote_engraver,
127                 /* doc */
128                 "Create footnote texts.",
129
130                 /* create */
131                 "FootnoteItem "
132                 "FootnoteSpanner ",
133
134                 /*read*/
135                 "currentMusicalColumn ",
136
137                 /*write*/
138                 ""
139                );