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"
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)
116 SCM props = updated_grob_properties (context (), symbol);
118 Object_key const *key = context ()->get_grob_key (name);
121 SCM handle = scm_sloppy_assq (ly_symbol2scm ("meta"), props);
122 SCM klass = scm_cdr (scm_sloppy_assq (ly_symbol2scm ("class"), scm_cdr (handle)));
124 if (klass == ly_symbol2scm ("Item"))
125 grob = new Item (props, key);
126 else if (klass == ly_symbol2scm ("Spanner"))
127 grob = new Spanner (props, key);
128 else if (klass == ly_symbol2scm ("Paper_column"))
129 grob = new Paper_column (props, key);
132 announce_grob (grob, cause);
135 if (ly_is_procedure (creation_callback))
136 scm_apply_0 (creation_callback,
137 scm_list_n (grob->self_scm (), scm_makfrom0str (file),
138 scm_from_int (line), scm_makfrom0str (fun), SCM_UNDEFINED));
145 Engraver::internal_make_item (SCM x, SCM cause,
147 char const *file, int line, char const *fun)
149 Item *it = dynamic_cast<Item *> (internal_make_grob (x, cause, name, file, line, fun));
155 Engraver::internal_make_column (SCM x, char const *name,
156 char const *file, int line, char const *fun)
158 return dynamic_cast<Paper_column *> (internal_make_grob (x, SCM_EOL, name, file, line, fun));
162 Engraver::internal_make_spanner (SCM x, SCM cause, char const *name, char const *file, int line, char const *fun)
164 Spanner *sp = dynamic_cast<Spanner *> (internal_make_grob (x, cause, name, file, line, fun));
169 #include "translator.icc"
171 ADD_TRANSLATOR (Engraver,
172 "Base class for engravers. Does nothing, so it is not used.",