2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 2006--2015 Han-Wen Nienhuys <hanwen@lilypond.org>
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.
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.
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/>.
20 #include "engraver.hh"
22 #include "stream-event.hh"
25 #include "translator.icc"
29 class Balloon_engraver : public Engraver
31 TRANSLATOR_DECLARATIONS (Balloon_engraver);
33 DECLARE_TRANSLATOR_LISTENER (annotate_output);
34 DECLARE_ACKNOWLEDGER (grob);
35 vector<Stream_event *> events_;
37 void stop_translation_timestep ();
39 void balloonify (Grob *, Stream_event *);
42 IMPLEMENT_TRANSLATOR_LISTENER (Balloon_engraver, annotate_output);
44 Balloon_engraver::listen_annotate_output (Stream_event *ev)
46 events_.push_back (ev);
50 Balloon_engraver::stop_translation_timestep ()
55 Balloon_engraver::Balloon_engraver ()
60 Balloon_engraver::balloonify (Grob *g, Stream_event *event)
62 Grob *b = make_item ("BalloonTextItem", event->self_scm ());
63 b->set_property ("text", event->get_property ("text"));
64 b->set_parent (g, Y_AXIS);
65 b->set_parent (g, X_AXIS);
69 Balloon_engraver::acknowledge_grob (Grob_info info)
71 Stream_event *cause = info.event_cause ();
73 SCM arts = cause ? cause->get_property ("articulations") : SCM_EOL;
74 for (SCM s = arts; scm_is_pair (s); s = scm_cdr (s))
76 Stream_event *e = unsmob<Stream_event> (scm_car (s));
77 if (e->in_event_class ("annotate-output-event"))
79 balloonify (info.grob (), e);
83 for (vsize i = 0; i < events_.size (); i++)
85 if (info.grob ()->name () == ly_symbol2string (events_[i]->get_property ("symbol")))
86 balloonify (info.grob (), events_[i]);
90 ADD_ACKNOWLEDGER (Balloon_engraver, grob);
92 ADD_TRANSLATOR (Balloon_engraver,
94 "Create balloon texts.",