2 engraver.cc -- implement Engraver
4 Sourcefile of GNU LilyPond music type setter
6 (c) 1997--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
12 #include "international.hh"
13 #include "lilypond-key.hh"
15 #include "paper-column.hh"
16 #include "score-engraver.hh"
18 #include "stream-event.hh"
22 Engraver::get_daddy_engraver () const
24 return dynamic_cast<Engraver_group *> (get_daddy_translator ());
28 Engraver::announce_grob (Grob_info inf)
30 get_daddy_engraver ()->announce_grob (inf);
34 Engraver::announce_end_grob (Grob_info inf)
36 get_daddy_engraver ()->announce_grob (inf);
40 CAUSE is the object (typically a Stream_event object) that
41 was the reason for making E.
44 Engraver::announce_grob (Grob *e, SCM cause)
46 /* TODO: Remove Music code when it's no longer needed */
47 if (Music *m = unsmob_music (cause))
49 cause = m->to_event ()->unprotect ();
51 if (unsmob_stream_event (cause) || unsmob_grob (cause))
52 e->set_property ("cause", cause);
54 Grob_info i (this, e);
56 Engraver_group *g = get_daddy_engraver ();
63 CAUSE is the object (typically a Music object) that
64 was the reason for making E.
67 Engraver::announce_end_grob (Grob *e, SCM cause)
69 /* TODO: Remove Music code when it's no longer needed */
70 if (Music *m = unsmob_music (cause))
72 cause = m->to_event ()->unprotect ();
74 if (unsmob_stream_event (cause) || unsmob_grob (cause))
75 e->set_property ("cause", cause);
77 Grob_info i (this, e);
80 Engraver_group *g = get_daddy_engraver ();
91 static SCM creation_callback = SCM_EOL;
92 LY_DEFINE (ly_set_grob_creation_callback, "ly:set-grob-creation-callback",
94 "Specify a procedure that will be called every time a new grob "
95 "is created. The callback will receive as arguments the grob "
96 "that was created, the name of the C++ source file that caused "
97 "the grob to be created and the corresponding line number in the "
100 SCM_ASSERT_TYPE(ly_is_procedure (cb), cb, SCM_ARG1, __FUNCTION__,
103 creation_callback = cb;
105 return SCM_UNSPECIFIED;
110 Engraver::internal_make_grob (SCM symbol, SCM cause, char const *name, char const *file, int line, char const *fun)
117 SCM props = updated_grob_properties (context (), symbol);
119 Object_key const *key = 0;
122 SCM handle = scm_sloppy_assq (ly_symbol2scm ("meta"), props);
123 SCM klass = scm_cdr (scm_sloppy_assq (ly_symbol2scm ("class"), scm_cdr (handle)));
125 if (klass == ly_symbol2scm ("Item"))
126 grob = new Item (props, key);
127 else if (klass == ly_symbol2scm ("Spanner"))
128 grob = new Spanner (props, key);
129 else if (klass == ly_symbol2scm ("Paper_column"))
130 grob = new Paper_column (props, key);
133 announce_grob (grob, cause);
136 if (ly_is_procedure (creation_callback))
137 scm_apply_0 (creation_callback,
138 scm_list_n (grob->self_scm (), scm_from_locale_string (file),
139 scm_from_int (line), scm_from_locale_string (fun), SCM_UNDEFINED));
146 Engraver::internal_make_item (SCM x, SCM cause,
148 char const *file, int line, char const *fun)
150 Item *it = dynamic_cast<Item *> (internal_make_grob (x, cause, name, file, line, fun));
156 Engraver::internal_make_column (SCM x, char const *name,
157 char const *file, int line, char const *fun)
159 return dynamic_cast<Paper_column *> (internal_make_grob (x, SCM_EOL, name, file, line, fun));
163 Engraver::internal_make_spanner (SCM x, SCM cause, char const *name, char const *file, int line, char const *fun)
165 Spanner *sp = dynamic_cast<Spanner *> (internal_make_grob (x, cause, name, file, line, fun));
170 #include "translator.icc"
172 ADD_TRANSLATOR (Engraver,
173 "Base class for engravers. Does nothing, so it is not used.",