2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2010 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 #include "engraver.hh"
23 #include "international.hh"
25 #include "paper-column.hh"
26 #include "score-engraver.hh"
28 #include "stream-event.hh"
32 Engraver::get_daddy_engraver () const
34 return dynamic_cast<Engraver_group
*> (get_daddy_translator ());
38 Engraver::announce_grob (Grob_info inf
)
40 get_daddy_engraver ()->announce_grob (inf
);
44 Engraver::announce_end_grob (Grob_info inf
)
46 get_daddy_engraver ()->announce_grob (inf
);
50 CAUSE is the object (typically a Stream_event object) that
51 was the reason for making E.
54 Engraver::announce_grob (Grob
*e
, SCM cause
)
56 /* TODO: Remove Music code when it's no longer needed */
57 if (Music
*m
= unsmob_music (cause
))
59 cause
= m
->to_event ()->unprotect ();
61 if (unsmob_stream_event (cause
) || unsmob_grob (cause
))
62 e
->set_property ("cause", cause
);
64 Grob_info
i (this, e
);
66 Engraver_group
*g
= get_daddy_engraver ();
73 CAUSE is the object (typically a grob or stream-event object) that
74 was the reason for ending E. */
76 Engraver::announce_end_grob (Grob
*e
, SCM cause
)
78 /* TODO: Remove Music code when it's no longer needed */
79 if (Music
*m
= unsmob_music (cause
))
81 cause
= m
->to_event ()->unprotect ();
83 if (e
->get_property ("cause") == SCM_EOL
84 && (unsmob_stream_event (cause
) || unsmob_grob (cause
)))
85 e
->set_property ("cause", cause
);
87 Grob_info
i (this, e
);
90 Engraver_group
*g
= get_daddy_engraver ();
101 static SCM creation_callback
= SCM_EOL
;
102 LY_DEFINE (ly_set_grob_creation_callback
, "ly:set-grob-creation-callback",
104 "Specify a procedure that will be called every time a new grob"
105 " is created. The callback will receive as arguments the grob"
106 " that was created, the name of the C++ source file that caused"
107 " the grob to be created, and the corresponding line number in"
108 " the C++ source file.")
110 LY_ASSERT_TYPE (ly_is_procedure
, cb
, 1);
112 creation_callback
= cb
;
114 return SCM_UNSPECIFIED
;
119 Engraver::internal_make_grob (SCM symbol
,
121 char const * /* name */,
132 SCM props
= updated_grob_properties (context (), symbol
);
136 SCM handle
= scm_sloppy_assq (ly_symbol2scm ("meta"), props
);
137 SCM klass
= scm_cdr (scm_sloppy_assq (ly_symbol2scm ("class"), scm_cdr (handle
)));
139 if (klass
== ly_symbol2scm ("Item"))
140 grob
= new Item (props
);
141 else if (klass
== ly_symbol2scm ("Spanner"))
142 grob
= new Spanner (props
);
143 else if (klass
== ly_symbol2scm ("Paper_column"))
144 grob
= new Paper_column (props
);
147 announce_grob (grob
, cause
);
150 if (ly_is_procedure (creation_callback
))
151 scm_apply_0 (creation_callback
,
152 scm_list_n (grob
->self_scm (), scm_from_locale_string (file
),
153 scm_from_int (line
), scm_from_locale_string (fun
), SCM_UNDEFINED
));
160 Engraver::internal_make_item (SCM x
, SCM cause
,
162 char const *file
, int line
, char const *fun
)
164 Item
*it
= dynamic_cast<Item
*> (internal_make_grob (x
, cause
, name
, file
, line
, fun
));
170 Engraver::internal_make_column (SCM x
, char const *name
,
171 char const *file
, int line
, char const *fun
)
173 return dynamic_cast<Paper_column
*> (internal_make_grob (x
, SCM_EOL
, name
, file
, line
, fun
));
177 Engraver::internal_make_spanner (SCM x
, SCM cause
, char const *name
,
178 char const *file
, int line
, char const *fun
)
180 Spanner
*sp
= dynamic_cast<Spanner
*> (internal_make_grob (x
, cause
, name
, file
, line
, fun
));
186 unsmob_engraver (SCM eng
)
188 return dynamic_cast<Engraver
*> (unsmob_translator (eng
));
192 ly_is_grob_cause (SCM obj
)
194 return unsmob_grob (obj
) || unsmob_stream_event (obj
) || (obj
== SCM_EOL
);
197 #include "translator.icc"
199 ADD_TRANSLATOR (Engraver
,
201 "Base class for engravers. Does nothing, so it is not used.",