]> git.donarmstrong.com Git - lilypond.git/blob - lily/output-property-engraver.cc
(DECLARE_EVENT_SWALLOWER): ENTER_DESCRIPTION -> ADD_TRANSLATOR
[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--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "engraver.hh"
11 #include "grob.hh"
12 #include "context.hh"
13
14 class Output_property_engraver : public Engraver
15 {
16 TRANSLATOR_DECLARATIONS (Output_property_engraver);
17 protected:
18   Link_array<Music> props_;
19
20   virtual void stop_translation_timestep ();
21   virtual void acknowledge_grob (Grob_info);
22   virtual bool try_music (Music*);
23 };
24
25
26 bool
27 Output_property_engraver::try_music (Music* m)
28 {
29   if (m->is_mus_type ("layout-instruction"))
30     {
31       props_.push (m);
32       return true;
33     }
34   return false;
35 }
36
37 void
38 Output_property_engraver::acknowledge_grob (Grob_info inf)
39 {
40   for (int i = props_.size (); i--;)
41     {
42       Music * o = props_[i];
43       SCM pred = o->get_property ("predicate");
44
45
46
47       if (ly_c_procedure_p (pred))
48         {
49           /*
50             should typecheck pred. 
51           */
52           SCM result = scm_call_1 (pred, inf.grob_->self_scm ());
53           if (to_boolean (result))
54             {
55               SCM sym = o->get_property ("grob-property");
56               SCM val = o->get_property ("grob-value");
57               inf.grob_->internal_set_property (sym, val);
58             }
59         }
60       else
61         {
62           Context * d =
63             dynamic_cast<Context *> (inf.origin_trans_);
64
65           if (!d)
66             d = dynamic_cast<Context *> (inf.origin_trans_->context ());
67           
68           SCM proc = o->get_property ("procedure");
69           scm_call_3 (proc,
70                       inf.grob_->self_scm (),
71                       d->self_scm (), 
72                       context ()->self_scm ());
73         }
74     }
75 }
76
77 void
78 Output_property_engraver::stop_translation_timestep ()
79 {
80   props_.clear ();
81 }
82
83 Output_property_engraver::Output_property_engraver ()
84 {
85 }
86
87 ADD_TRANSLATOR (Output_property_engraver,
88 /* descr */       "Interpret Music of Output_property type, and apply a function "
89 " to any Graphic objects that satisfies the predicate.",
90 /* creats*/       "",
91 /* accepts */     "layout-instruction",
92 /* acks  */       "grob-interface",
93 /* reads */       "",
94 /* write */       "");