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 "dictionary.hh"
13 #include "score-element.hh"
14 #include "scm-hash.hh"
17 JUNKME: should use pushproperty everywhere.
20 class Property_engraver : public Engraver
25 Scheme_hash_table *prop_dict_; // junkme
26 void apply_properties (SCM, Score_element*);
29 virtual void acknowledge_element (Score_element_info ei);
30 virtual void do_creation_processing ();
31 virtual void do_removal_processing ();
35 VIRTUAL_COPY_CONS(Translator);
40 Property_engraver::Property_engraver()
45 Property_engraver::do_removal_processing()
50 Property_engraver::~Property_engraver ()
53 scm_unprotect_object (prop_dict_->self_scm ());
57 Property_engraver::do_creation_processing ()
59 prop_dict_ = new Scheme_hash_table;
61 SCM plist = get_property ("Generic_property_list");
62 for (; gh_pair_p (plist); plist = gh_cdr (plist))
64 SCM elt_props = gh_car (plist);
65 prop_dict_->set (gh_car (elt_props), gh_cdr (elt_props));
70 Property_engraver::acknowledge_element (Score_element_info i)
72 SCM ifs = i.elem_l_->get_elt_property ("interfaces");
74 for (; gh_pair_p (ifs); ifs = gh_cdr (ifs))
76 if (prop_dict_->try_retrieve (gh_car (ifs), &props))
78 apply_properties (props,i.elem_l_);
82 if (prop_dict_->try_retrieve (ly_symbol2scm ("all"), &props))
84 apply_properties (props, i.elem_l_);
90 Property_engraver::apply_properties (SCM p, Score_element *e)
92 for (; gh_pair_p (p); p = gh_cdr (p))
95 Try each property in order; earlier descriptions take
96 precedence over later ones, and we don't touch elt-properties if
100 SCM entry = gh_car (p);
101 SCM prop_sym = gh_car (entry);
102 SCM type_p = gh_cadr (entry);
103 SCM elt_prop_sym = gh_caddr (entry);
105 SCM preset = scm_assq(elt_prop_sym, e->mutable_property_alist_);
106 if (preset != SCM_BOOL_F)
109 SCM val = get_property (prop_sym);
111 if (val == SCM_UNDEFINED)
112 ; // Not defined in context.
113 else if (gh_apply (type_p, scm_listify (val, SCM_UNDEFINED))
114 == SCM_BOOL_T) // defined and right type: do it
115 e->set_elt_property (elt_prop_sym, val);
119 we don't print a warning if VAL == #f, because we would
120 get lots of warnings when we restore stuff to default, eg.
122 slurDash = #1 [...] slurDash = ##f
124 should not cause "type error: slurDash expects number not
128 if (val != SCM_BOOL_F)
129 { // not the right type: error message.
130 SCM errport = scm_current_error_port ();
131 warning (_("Wrong type for property"));
132 scm_display (prop_sym, errport);
133 scm_puts (", type predicate: ", errport);
134 scm_display (type_p, errport);
135 scm_puts (", value found: ", errport);
136 scm_display (val, errport);
137 scm_puts (" type: ", errport);
138 scm_display (ly_type (val), errport);
139 scm_puts ("\n", errport);
144 ADD_THIS_TRANSLATOR(Property_engraver);