2 property-engraver.cc -- implement Property engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2000 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);
29 Property_engraver::do_creation_processing ()
31 SCM plist = get_property ("Generic_property_list");
32 for (; SCM_NIMP (plist); plist = gh_cdr (plist))
34 SCM elt_props = gh_car (plist);
35 prop_dict_[ly_scm2string (gh_car (elt_props))] = gh_cdr (elt_props);
40 Property_engraver::acknowledge_element (Score_element_info i)
42 if (prop_dict_.elem_b (i.elem_l_->name()))
44 SCM p = prop_dict_[i.elem_l_->name()];
45 apply_properties (p,i.elem_l_);
47 if (prop_dict_.elem_b ("all"))
49 apply_properties (prop_dict_["all"], i.elem_l_);
55 Property_engraver::apply_properties (SCM p, Score_element *e)
57 for (; gh_pair_p (p); p = gh_cdr (p))
60 Try each property in order; earlier descriptions take
61 precedence over later ones, and we don't touch elt-properties if
65 SCM entry = gh_car (p);
66 SCM prop_sym = gh_car (entry);
67 SCM type_p = gh_cadr (entry);
68 SCM elt_prop_sym = gh_caddr (entry);
70 SCM preset = scm_assq(elt_prop_sym, e->element_property_alist_);
71 if (preset != SCM_BOOL_F)
74 SCM val = get_property (prop_sym);
77 if (val == SCM_UNDEFINED)
78 ; // Not defined in context.
79 else if (gh_apply (type_p, scm_listify (val, SCM_UNDEFINED))
80 == SCM_BOOL_T) // defined and right type: do it
81 e->set_elt_property (ly_symbol2string (elt_prop_sym), val);
84 we don't print a warning if VAL == #f, because we would
85 get lots of warnings when we restore stuff to default, eg.
87 slurDash = #1 [...] slurDash = ##f
89 should not cause "type error: slurDash expects number not
93 if (val != SCM_BOOL_F)
94 { // not the right type: error message.
95 SCM errport = scm_current_error_port ();
96 warning (_("Wrong type for property"));
97 scm_display (prop_sym, errport);
98 scm_puts (", type predicate: ", errport);
99 scm_display (type_p, errport);
100 scm_puts (", value found: ", errport);
101 scm_display (val, errport);
102 scm_puts (" type: ", errport);
103 scm_display (ly_type (val), errport);
104 scm_puts ("\n", errport);
109 ADD_THIS_TRANSLATOR(Property_engraver);