]> git.donarmstrong.com Git - lilypond.git/blob - lily/output-property-engraver.cc
Merge branch 'master' of /home/jcharles/GIT/Lily/. into translation
[lilypond.git] / lily / output-property-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2000--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 "engraver.hh"
21 #include "context.hh"
22 #include "grob.hh"
23 #include "stream-event.hh"
24
25 #include "translator.icc"
26
27
28 class Output_property_engraver : public Engraver
29 {
30   TRANSLATOR_DECLARATIONS (Output_property_engraver);
31 protected:
32   vector<Stream_event*> props_;
33   
34   void acknowledge_grob (Grob_info);
35   void listen_apply_output (Stream_event *);
36
37   void stop_translation_timestep ();
38 };
39
40 void
41 Output_property_engraver::listen_apply_output (Stream_event *ev)
42 {
43   /*
44     UGH. Only swallow the output property event in the context
45     it was intended for. This is inelegant but not inefficient.
46   */
47   if (context ()->is_alias (ev->get_property ("context-type")))
48     props_.push_back (ev);
49 }
50
51 void
52 Output_property_engraver::acknowledge_grob (Grob_info inf)
53 {
54   for (vsize i = props_.size (); i--;)
55     {
56       Stream_event *o = props_[i];
57       Context *d = inf.context ();
58       SCM grob = o->get_property ("symbol");
59       if (scm_is_symbol (grob)
60           && ly_symbol2string (grob) != inf.grob ()->name ())
61         continue;
62       SCM proc = o->get_property ("procedure");
63       scm_call_3 (proc,
64                   inf.grob ()->self_scm (),
65                   d->self_scm (), 
66                   context ()->self_scm ());
67     }
68 }
69
70 void
71 Output_property_engraver::stop_translation_timestep ()
72 {
73   props_.clear ();
74 }
75
76 Output_property_engraver::Output_property_engraver ()
77 {
78 }
79
80 void
81 Output_property_engraver::boot ()
82 {
83   ADD_LISTENER (Output_property_engraver, apply_output);
84   ADD_ACKNOWLEDGER (Output_property_engraver, grob);
85 }
86
87 ADD_TRANSLATOR (Output_property_engraver,
88                 /* doc */
89                 "Apply a procedure to any grob acknowledged.",
90                 
91                 /* create */
92                 "",
93                 
94                 /* read */
95                 "",
96                 
97                 /* write */
98                 ""
99                 );