]> git.donarmstrong.com Git - lilypond.git/blob - lily/output-property-engraver.cc
(Composite_music): new transpose syntax,
[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--2002 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->is_mus_type ("layout-instruction"))
43     {
44       props_.push (m);
45       return true;
46     }
47   return false;
48 }
49
50 void
51 Output_property_engraver::acknowledge_grob (Grob_info inf)
52 {
53   for (int i=props_.size (); i--;)
54     {
55       Music * o = props_[i];
56       SCM pred = o->get_mus_property ("predicate");
57       
58       /*
59         should typecheck pred. 
60        */
61       SCM result=gh_apply (pred,
62                            scm_list_n (inf.grob_->self_scm (), SCM_UNDEFINED));
63       if (to_boolean (result))
64         {
65           SCM sym = o->get_mus_property ("grob-property");
66           SCM val = o->get_mus_property ("grob-value");
67           inf.grob_->internal_set_grob_property (sym, val);
68         }
69     }
70 }
71
72 void
73 Output_property_engraver::stop_translation_timestep ()
74 {
75   props_.clear ();
76 }
77
78 Output_property_engraver::Output_property_engraver()
79 {
80 }
81
82 ENTER_DESCRIPTION(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 /* acks  */       "grob-interface",
88 /* reads */       "",
89 /* write */       "");