2 property-engraver.cc -- implement Property engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "lily-guile.hh"
11 #include "engraver.hh"
12 #include "protected-scm.hh"
13 #include "dictionary.hh"
14 #include "score-element.hh"
16 class Property_engraver : public Engraver
18 Dictionary<Protected_scm> prop_dict_;
19 void apply_properties (SCM, Score_element*);
22 virtual void acknowledge_element (Score_element_info ei);
23 virtual void do_creation_processing ();
25 VIRTUAL_COPY_CONS(Translator);
28 ADD_THIS_TRANSLATOR (Property_engraver);
31 Property_engraver::do_creation_processing ()
33 SCM plist = get_property ("Generic_property_list", 0);
34 for (; SCM_NIMP (plist); plist = gh_cdr (plist))
36 SCM elt_props = gh_car (plist);
37 prop_dict_[ly_scm2string (gh_car (elt_props))] = gh_cdr (elt_props);
42 Property_engraver::acknowledge_element (Score_element_info i)
44 if (prop_dict_.elem_b (i.elem_l_->name()))
46 SCM p = prop_dict_[i.elem_l_->name()];
47 apply_properties (p,i.elem_l_);
49 if (prop_dict_.elem_b ("all"))
51 apply_properties (prop_dict_["all"], i.elem_l_);
56 Property_engraver::apply_properties (SCM p, Score_element *e)
58 for (; gh_pair_p (p); p = gh_cdr (p))
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);
65 SCM preset = scm_assq(prop_sym, e->element_property_alist_);
66 if (preset != SCM_BOOL_F)
69 SCM val = get_property (prop_sym, 0);
70 if (val != SCM_UNDEFINED
71 && gh_apply (type_p, scm_listify (val, SCM_UNDEFINED))
73 e->set_elt_property (ly_symbol2string (elt_prop_name), val);