]> git.donarmstrong.com Git - lilypond.git/blob - lily/output-property-engraver.cc
cbef4235a16da1ca50f9c75625c9ecd129146c4e
[lilypond.git] / lily / output-property-engraver.cc
1 /*   
2   output-property-engraver.cc -- implement Output_property_engraver
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 2000--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7   
8  */
9
10 #include "engraver.hh"
11 #include "context.hh"
12 #include "grob.hh"
13 #include "stream-event.hh"
14
15 #include "translator.icc"
16
17
18 class Output_property_engraver : public Engraver
19 {
20   TRANSLATOR_DECLARATIONS (Output_property_engraver);
21 protected:
22   vector<Stream_event*> props_;
23   
24   DECLARE_ACKNOWLEDGER (grob);
25   DECLARE_TRANSLATOR_LISTENER (apply_output);
26
27   void stop_translation_timestep ();
28 };
29
30 IMPLEMENT_TRANSLATOR_LISTENER (Output_property_engraver, apply_output);
31 void
32 Output_property_engraver::listen_apply_output (Stream_event *ev)
33 {
34   /*
35     UGH. Only swallow the output property event in the context
36     it was intended for. This is inelegant but not inefficient.
37   */
38   if (context ()->is_alias (ev->get_property ("context-type")))
39     props_.push_back (ev);
40 }
41
42 void
43 Output_property_engraver::acknowledge_grob (Grob_info inf)
44 {
45   for (vsize i = props_.size (); i--;)
46     {
47       Stream_event *o = props_[i];
48       Context *d = inf.context ();
49       SCM proc = o->get_property ("procedure");
50       scm_call_3 (proc,
51                   inf.grob ()->self_scm (),
52                   d->self_scm (), 
53                   context ()->self_scm ());
54     }
55 }
56
57 void
58 Output_property_engraver::stop_translation_timestep ()
59 {
60   props_.clear ();
61 }
62
63 Output_property_engraver::Output_property_engraver ()
64 {
65 }
66
67 ADD_ACKNOWLEDGER (Output_property_engraver, grob);
68 ADD_TRANSLATOR (Output_property_engraver,
69                 /* doc */
70                 "Apply a procedure to any grob acknowledged.",
71                 
72                 /* create */
73                 "",
74                 
75                 /* read */
76                 "",
77                 
78                 /* write */
79                 ""
80                 );