]> git.donarmstrong.com Git - lilypond.git/blob - lily/output-property-engraver.cc
* lily/include/translator.hh (class Translator): remove
[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--2005 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   DECLARE_ACKNOWLEDGER(grob)
20
21   void stop_translation_timestep ();
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       if (ly_is_procedure (pred))
46         {
47           /*
48             should typecheck pred. 
49           */
50           SCM result = scm_call_1 (pred, inf.grob ()->self_scm ());
51           if (to_boolean (result))
52             {
53               SCM sym = o->get_property ("grob-property");
54               SCM val = o->get_property ("grob-value");
55               inf.grob ()->internal_set_property (sym, val);
56             }
57         }
58       else
59         {
60           Context * d = inf.context ();
61           SCM proc = o->get_property ("procedure");
62           scm_call_3 (proc,
63                       inf.grob ()->self_scm (),
64                       d->self_scm (), 
65                       context ()->self_scm ());
66         }
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 #include "translator.icc"
81 ADD_ACKNOWLEDGER(Output_property_engraver,grob)
82 ADD_TRANSLATOR (Output_property_engraver,
83 /* descr */       "Interpret Music of Output_property type, and apply a function "
84 " to any Graphic objects that satisfies the predicate.",
85 /* creats*/       "",
86 /* accepts */     "layout-instruction",
87 /* reads */       "",
88 /* write */       "");