]> git.donarmstrong.com Git - lilypond.git/blob - lily/property-engraver.cc
patch::: 1.3.1.hwn1
[lilypond.git] / lily / property-engraver.cc
1 /*   
2   property-engraver.cc --  implement Property engraver
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "lily-guile.hh"
11 #include "engraver.hh"
12 #include "protected-scm.hh"
13 #include "dictionary.hh"
14 #include "score-element.hh"
15
16 class Property_engraver : public Engraver
17 {
18   Dictionary<Protected_scm> prop_dict_;
19   void apply_properties (SCM, Score_element*);
20
21 protected:
22   virtual void acknowledge_element (Score_element_info ei);
23   virtual void do_creation_processing ();
24
25   VIRTUAL_COPY_CONS(Translator);
26 };
27
28 void
29 Property_engraver::do_creation_processing ()
30 {
31   SCM plist = get_property ("Generic_property_list", 0);
32   for (; SCM_NIMP (plist); plist = gh_cdr (plist))
33     {
34       SCM elt_props = gh_car (plist);
35       prop_dict_[ly_scm2string (gh_car (elt_props))] = gh_cdr (elt_props);
36     }
37 }
38
39 void
40 Property_engraver::acknowledge_element (Score_element_info i)
41 {
42   if (prop_dict_.elem_b (i.elem_l_->name()))
43     {
44       SCM p = prop_dict_[i.elem_l_->name()];
45       apply_properties (p,i.elem_l_);
46     }
47   if (prop_dict_.elem_b ("all"))
48     {
49       apply_properties (prop_dict_["all"], i.elem_l_);
50     }
51 }
52
53 void
54 Property_engraver::apply_properties (SCM p, Score_element *e)
55 {  
56   for (; SCM_NIMP (p); p = gh_cdr (p))
57     {
58       SCM entry = gh_car (p);
59       SCM prop_sym = gh_car (entry);
60       SCM type_p   = gh_cadr (entry);
61       SCM elt_prop_name = gh_caddr (entry);
62
63       /*
64         urg scm <-> symbol-string
65        */
66       if (e->get_elt_property (ly_scm2string (elt_prop_name)) != SCM_UNDEFINED)
67         continue;
68       
69       SCM val = get_property (prop_sym, 0);
70       if (val != SCM_UNDEFINED
71           && gh_apply (type_p, scm_listify (val, SCM_UNDEFINED))
72           == SCM_BOOL_T)
73         e->set_elt_property (ly_scm2string (elt_prop_name), val);
74     }
75 }
76
77 ADD_THIS_TRANSLATOR(Property_engraver);