]> git.donarmstrong.com Git - lilypond.git/blob - lily/property-engraver.cc
patch::: 1.3.18.jcn1
[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 ADD_THIS_TRANSLATOR (Property_engraver);
29
30 void
31 Property_engraver::do_creation_processing ()
32 {
33   SCM plist = get_property ("Generic_property_list", 0);
34   for (; SCM_NIMP (plist); plist = gh_cdr (plist))
35     {
36       SCM elt_props = gh_car (plist);
37       prop_dict_[ly_scm2string (gh_car (elt_props))] = gh_cdr (elt_props);
38     }
39 }
40
41 void
42 Property_engraver::acknowledge_element (Score_element_info i)
43 {
44   if (prop_dict_.elem_b (i.elem_l_->name()))
45     {
46       SCM p = prop_dict_[i.elem_l_->name()];
47       apply_properties (p,i.elem_l_);
48     }
49   if (prop_dict_.elem_b ("all"))
50     {
51       apply_properties (prop_dict_["all"], i.elem_l_);
52     }
53 }
54
55 void
56 Property_engraver::apply_properties (SCM p, Score_element *e)
57 {  
58   for (; gh_pair_p (p); p = gh_cdr (p))
59     {
60       SCM entry = gh_car (p);
61       SCM prop_sym = gh_car (entry);
62       SCM type_p   = gh_cadr (entry);
63       SCM elt_prop_name = gh_caddr (entry);
64
65       SCM preset = scm_assq(prop_sym, e->element_property_alist_);
66       if (preset != SCM_BOOL_F)
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_symbol2string (elt_prop_name), val);
74     }
75 }