]> git.donarmstrong.com Git - lilypond.git/blob - lily/output-property-engraver.cc
patch::: 1.3.136.jcn3
[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--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "engraver.hh"
11 #include "grob.hh"
12 #include "output-property-music-iterator.hh"
13
14 class Output_property_engraver : public Engraver
15 {
16 public:
17   VIRTUAL_COPY_CONS (Translator);
18 protected:
19
20   /*
21     should do this with \once and \push ?
22
23
24       \property Voice.outputProperties \push #pred = #modifier
25
26       where both MODIFIER and PRED are functions taking a
27       grob.
28       
29    */
30
31   
32   Link_array<Music> props_;
33
34   virtual void stop_translation_timestep ();
35   virtual void acknowledge_grob (Grob_info);
36   virtual bool try_music (Music*);
37 };
38
39
40 bool
41 Output_property_engraver::try_music (Music* m)
42 {
43   if (m->get_mus_property ("iterator-ctor") ==
44       Output_property_music_iterator::constructor_cxx_function)
45     {
46       props_.push (m);
47       return true;
48     }
49   return false;
50 }
51
52 void
53 Output_property_engraver::acknowledge_grob (Grob_info inf)
54 {
55   for (int i=props_.size (); i--;)
56     {
57       Music * o = props_[i];
58       SCM pred = o->get_mus_property ("predicate");
59       
60       /*
61         should typecheck pred. 
62        */
63       SCM result=gh_apply (pred,
64                            gh_list (inf.elem_l_->self_scm (), SCM_UNDEFINED));
65       if (to_boolean (result))
66         {
67           SCM sym = o->get_mus_property ("symbol");
68           SCM val = o->get_mus_property ("value");
69           inf.elem_l_->set_grob_property (sym, val);
70         }
71     }
72 }
73
74 void
75 Output_property_engraver::stop_translation_timestep ()
76 {
77   props_.clear ();
78 }
79
80 ADD_THIS_TRANSLATOR (Output_property_engraver);