2 engraver.cc -- implement Engraver
4 Sourcefile of GNU LilyPond music type setter
6 (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
12 #include "international.hh"
14 #include "lilypond-key.hh"
16 #include "paper-column.hh"
17 #include "score-engraver.hh"
19 #include "stream-event.hh"
23 Engraver::get_daddy_engraver () const
25 return dynamic_cast<Engraver_group *> (get_daddy_translator ());
29 Engraver::announce_grob (Grob_info inf)
31 get_daddy_engraver ()->announce_grob (inf);
35 Engraver::announce_end_grob (Grob_info inf)
37 get_daddy_engraver ()->announce_grob (inf);
41 CAUSE is the object (typically a Stream_event object) that
42 was the reason for making E.
45 Engraver::announce_grob (Grob *e, SCM cause)
47 /* TODO: Remove Music code when it's no longer needed */
48 if (Music *m = unsmob_music (cause))
50 cause = m->to_event ()->unprotect ();
52 if (unsmob_stream_event (cause) || unsmob_grob (cause))
53 e->set_property ("cause", cause);
55 Grob_info i (this, e);
57 Engraver_group *g = get_daddy_engraver ();
64 CAUSE is the object (typically a Music object) that
65 was the reason for making E.
68 Engraver::announce_end_grob (Grob *e, SCM cause)
70 /* TODO: Remove Music code when it's no longer needed */
71 if (Music *m = unsmob_music (cause))
73 cause = m->to_event ()->unprotect ();
75 if (unsmob_stream_event (cause) || unsmob_grob (cause))
76 e->set_property ("cause", cause);
78 Grob_info i (this, e);
81 Engraver_group *g = get_daddy_engraver ();
92 static SCM creation_callback = SCM_EOL;
93 LY_DEFINE (ly_set_grob_creation_callback, "ly:set-grob-creation-callback",
95 "Specify a procedure that will be called every time a new grob "
96 "is created. The callback will receive as arguments the grob "
97 "that was created, the name of the C++ source file that caused "
98 "the grob to be created and the corresponding line number in the "
101 SCM_ASSERT_TYPE(ly_is_procedure (cb), cb, SCM_ARG1, __FUNCTION__,
104 creation_callback = cb;
106 return SCM_UNSPECIFIED;
111 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 = context ()->get_grob_key (name);
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_makfrom0str (file),
139 scm_from_int (line), scm_makfrom0str (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.",