Nitpick: ly:spanner-bound grob name slur -> spanner.
[lilypond.git] / lily / engraver.cc
blob7724b1c395a5c68ec5b19398ce08b8bedf2d0cb4
1 /*
2 engraver.cc -- implement Engraver
4 Sourcefile of GNU LilyPond music type setter
6 (c) 1997--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
9 #include "engraver.hh"
11 #include "context.hh"
12 #include "international.hh"
13 #include "music.hh"
14 #include "paper-column.hh"
15 #include "score-engraver.hh"
16 #include "spanner.hh"
17 #include "stream-event.hh"
18 #include "warn.hh"
20 Engraver_group *
21 Engraver::get_daddy_engraver () const
23 return dynamic_cast<Engraver_group *> (get_daddy_translator ());
26 void
27 Engraver::announce_grob (Grob_info inf)
29 get_daddy_engraver ()->announce_grob (inf);
32 void
33 Engraver::announce_end_grob (Grob_info inf)
35 get_daddy_engraver ()->announce_grob (inf);
39 CAUSE is the object (typically a Stream_event object) that
40 was the reason for making E.
42 void
43 Engraver::announce_grob (Grob *e, SCM cause)
45 /* TODO: Remove Music code when it's no longer needed */
46 if (Music *m = unsmob_music (cause))
48 cause = m->to_event ()->unprotect ();
50 if (unsmob_stream_event (cause) || unsmob_grob (cause))
51 e->set_property ("cause", cause);
53 Grob_info i (this, e);
55 Engraver_group *g = get_daddy_engraver ();
56 if (g)
57 g->announce_grob (i);
62 CAUSE is the object (typically a Music object) that
63 was the reason for making E.
65 void
66 Engraver::announce_end_grob (Grob *e, SCM cause)
68 /* TODO: Remove Music code when it's no longer needed */
69 if (Music *m = unsmob_music (cause))
71 cause = m->to_event ()->unprotect ();
73 if (e->get_property ("cause") == SCM_EOL
74 && (unsmob_stream_event (cause) || unsmob_grob (cause)))
75 e->set_property ("cause", cause);
77 Grob_info i (this, e);
79 i.start_end_ = STOP;
80 Engraver_group *g = get_daddy_engraver ();
81 if (g)
82 g->announce_grob (i);
86 Engraver::Engraver ()
90 #ifndef NDEBUG
91 static SCM creation_callback = SCM_EOL;
92 LY_DEFINE (ly_set_grob_creation_callback, "ly:set-grob-creation-callback",
93 1, 0, 0, (SCM cb),
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"
98 " the C++ source file.")
100 LY_ASSERT_TYPE (ly_is_procedure, cb, 1);
102 creation_callback = cb;
104 return SCM_UNSPECIFIED;
106 #endif
108 Grob *
109 Engraver::internal_make_grob (SCM symbol,
110 SCM cause,
111 char const * /* name */,
112 char const *file,
113 int line,
114 char const *fun)
116 #ifdef NDEBUG
117 (void)file;
118 (void)line;
119 (void)fun;
120 #endif
122 SCM props = updated_grob_properties (context (), symbol);
124 Grob *grob = 0;
126 SCM handle = scm_sloppy_assq (ly_symbol2scm ("meta"), props);
127 SCM klass = scm_cdr (scm_sloppy_assq (ly_symbol2scm ("class"), scm_cdr (handle)));
129 if (klass == ly_symbol2scm ("Item"))
130 grob = new Item (props);
131 else if (klass == ly_symbol2scm ("Spanner"))
132 grob = new Spanner (props);
133 else if (klass == ly_symbol2scm ("Paper_column"))
134 grob = new Paper_column (props);
136 assert (grob);
137 announce_grob (grob, cause);
139 #ifndef NDEBUG
140 if (ly_is_procedure (creation_callback))
141 scm_apply_0 (creation_callback,
142 scm_list_n (grob->self_scm (), scm_from_locale_string (file),
143 scm_from_int (line), scm_from_locale_string (fun), SCM_UNDEFINED));
144 #endif
146 return grob;
149 Item *
150 Engraver::internal_make_item (SCM x, SCM cause,
151 char const *name,
152 char const *file, int line, char const *fun)
154 Item *it = dynamic_cast<Item *> (internal_make_grob (x, cause, name, file, line, fun));
155 assert (it);
156 return it;
159 Paper_column *
160 Engraver::internal_make_column (SCM x, char const *name,
161 char const *file, int line, char const *fun)
163 return dynamic_cast<Paper_column *> (internal_make_grob (x, SCM_EOL, name, file, line, fun));
166 Spanner *
167 Engraver::internal_make_spanner (SCM x, SCM cause, char const *name, char const *file, int line, char const *fun)
169 Spanner *sp = dynamic_cast<Spanner *> (internal_make_grob (x, cause, name, file, line, fun));
170 assert (sp);
171 return sp;
174 #include "translator.icc"
176 ADD_TRANSLATOR (Engraver,
177 /* doc */
178 "Base class for engravers. Does nothing, so it is not used.",
180 /* create */
183 /* read */
186 /* write */