]> git.donarmstrong.com Git - lilypond.git/blob - lily/balloon-engraver.cc
Doc-es: various updates.
[lilypond.git] / lily / balloon-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2006--2015 Han-Wen Nienhuys <hanwen@lilypond.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 "stream-event.hh"
23 #include "item.hh"
24
25 #include "translator.icc"
26
27 class Balloon_engraver : public Engraver
28 {
29   TRANSLATOR_DECLARATIONS (Balloon_engraver);
30
31   void listen_annotate_output (Stream_event *);
32   void acknowledge_grob (Grob_info);
33   vector<Stream_event *> events_;
34
35   void stop_translation_timestep ();
36
37   void balloonify (Grob *, Stream_event *);
38 };
39
40 void
41 Balloon_engraver::listen_annotate_output (Stream_event *ev)
42 {
43   events_.push_back (ev);
44 }
45
46 void
47 Balloon_engraver::stop_translation_timestep ()
48 {
49   events_.clear ();
50 }
51
52 Balloon_engraver::Balloon_engraver (Context *c)
53   : Engraver (c)
54 {
55 }
56
57 void
58 Balloon_engraver::balloonify (Grob *g, Stream_event *event)
59 {
60   Grob *b = make_item ("BalloonTextItem", event->self_scm ());
61   b->set_property ("text", event->get_property ("text"));
62   b->set_parent (g, Y_AXIS);
63   b->set_parent (g, X_AXIS);
64 }
65
66 void
67 Balloon_engraver::acknowledge_grob (Grob_info info)
68 {
69   Stream_event *cause = info.event_cause ();
70
71   SCM arts = cause ? cause->get_property ("articulations") : SCM_EOL;
72   for (SCM s = arts; scm_is_pair (s); s = scm_cdr (s))
73     {
74       Stream_event *e = unsmob<Stream_event> (scm_car (s));
75       if (e->in_event_class ("annotate-output-event"))
76         {
77           balloonify (info.grob (), e);
78         }
79     }
80
81   for (vsize i = 0; i < events_.size (); i++)
82     {
83       if (info.grob ()->name () == ly_symbol2string (events_[i]->get_property ("symbol")))
84         balloonify (info.grob (), events_[i]);
85     }
86 }
87
88
89 void
90 Balloon_engraver::boot ()
91 {
92   ADD_LISTENER (Balloon_engraver, annotate_output);
93   ADD_ACKNOWLEDGER (Balloon_engraver, grob);
94 }
95
96 ADD_TRANSLATOR (Balloon_engraver,
97                 /* doc */
98                 "Create balloon texts.",
99
100                 /* create */
101                 "BalloonTextItem ",
102
103                 /*read*/
104                 "",
105
106                 /*write*/
107                 ""
108                );