]> git.donarmstrong.com Git - lilypond.git/blob - lily/output-property-engraver.cc
e852d666fa646094b553c1a7d48b04ca80bc7527
[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 TRANSLATOR_DECLARATIONS(Output_property_engraver);
17 protected:
18
19   /*
20     should do this with \once and \push ?
21
22
23       \property Voice.outputProperties \push #pred = #modifier
24
25       where both MODIFIER and PRED are functions taking a
26       grob.
27       
28    */
29
30   
31   Link_array<Music> props_;
32
33   virtual void stop_translation_timestep ();
34   virtual void acknowledge_grob (Grob_info);
35   virtual bool try_music (Music*);
36 };
37
38
39 bool
40 Output_property_engraver::try_music (Music* m)
41 {
42   if (m->get_mus_property ("iterator-ctor") ==
43       Output_property_music_iterator::constructor_cxx_function)
44     {
45       props_.push (m);
46       return true;
47     }
48   return false;
49 }
50
51 void
52 Output_property_engraver::acknowledge_grob (Grob_info inf)
53 {
54   for (int i=props_.size (); i--;)
55     {
56       Music * o = props_[i];
57       SCM pred = o->get_mus_property ("predicate");
58       
59       /*
60         should typecheck pred. 
61        */
62       SCM result=gh_apply (pred,
63                            scm_list_n (inf.grob_l_->self_scm (), SCM_UNDEFINED));
64       if (to_boolean (result))
65         {
66           SCM sym = o->get_mus_property ("grob-property");
67           SCM val = o->get_mus_property ("grob-value");
68           inf.grob_l_->internal_set_grob_property (sym, val);
69         }
70     }
71 }
72
73 void
74 Output_property_engraver::stop_translation_timestep ()
75 {
76   props_.clear ();
77 }
78
79 Output_property_engraver::Output_property_engraver()
80 {
81 }
82
83 ENTER_DESCRIPTION(Output_property_engraver,
84 /* descr */       "Interpret Music of Output_property type, and apply a function
85 to any Graphic objects that satisfies the predicate.",
86 /* creats*/       "",
87 /* acks  */       "grob-interface",
88 /* reads */       "",
89 /* write */       "");