]> git.donarmstrong.com Git - lilypond.git/blob - lily/property-engraver.cc
d2eb399759599ea8d4fdd132366f846302c57626
[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 (; gh_pair_p (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       SCM preset = scm_assq(prop_sym, e->element_property_alist_);
64       if (preset != SCM_BOOL_F)
65         continue;
66   
67       SCM val = get_property (prop_sym, 0);
68       if (val != SCM_UNDEFINED
69           && gh_apply (type_p, scm_listify (val, SCM_UNDEFINED))
70           == SCM_BOOL_T)
71         e->set_elt_property (ly_symbol2string (elt_prop_name), val);
72     }
73 }
74
75 ADD_THIS_TRANSLATOR(Property_engraver);