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
);
29 Property_engraver::do_creation_processing ()
31 SCM plist
= get_property ("Generic_property_list", 0);
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_
);
54 Property_engraver::apply_properties (SCM p
, Score_element
*e
)
56 for (; gh_pair_p (p
); p
= gh_cdr (p
))
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
);
63 SCM preset
= scm_assq(prop_sym
, e
->element_property_alist_
);
64 if (preset
!= SCM_BOOL_F
)
67 SCM val
= get_property (prop_sym
, 0);
68 if (val
!= SCM_UNDEFINED
69 && gh_apply (type_p
, scm_listify (val
, SCM_UNDEFINED
))
71 e
->set_elt_property (ly_scm2string (elt_prop_name
), val
);
75 ADD_THIS_TRANSLATOR(Property_engraver
);