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