2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2015 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 "grob-properties.hh"
24 #include "international.hh"
26 #include "paper-column.hh"
27 #include "score-engraver.hh"
29 #include "stream-event.hh"
33 Engraver::get_daddy_engraver () const
35 return dynamic_cast<Engraver_group *> (get_daddy_translator ());
39 Engraver::announce_grob (Grob_info inf)
41 get_daddy_engraver ()->announce_grob (inf);
45 Engraver::announce_end_grob (Grob_info inf)
47 inf.start_end_ = STOP;
48 get_daddy_engraver ()->announce_grob (inf);
52 Engraver::make_grob_info (Grob *e, SCM cause)
54 /* TODO: Remove Music code when it's no longer needed */
55 if (Music *m = unsmob<Music> (cause))
57 cause = m->to_event ()->unprotect ();
59 if (scm_is_null (e->get_property ("cause"))
60 && (unsmob<Stream_event> (cause) || unsmob<Grob> (cause)))
61 e->set_property ("cause", cause);
63 return Grob_info (this, e);
67 CAUSE is the object (typically a Stream_event object) that
68 was the reason for making E.
71 Engraver::announce_grob (Grob *e, SCM cause)
73 announce_grob (make_grob_info (e, cause));
77 CAUSE is the object (typically a grob or stream-event object) that
78 was the reason for ending E. */
80 Engraver::announce_end_grob (Grob *e, SCM cause)
82 announce_end_grob (make_grob_info (e, cause));
90 static SCM creation_callback = SCM_EOL;
91 LY_DEFINE (ly_set_grob_creation_callback, "ly:set-grob-creation-callback",
93 "Specify a procedure that will be called every time a new grob"
94 " is created. The callback will receive as arguments the grob"
95 " that was created, the name of the C++ source file that caused"
96 " the grob to be created, and the corresponding line number in"
97 " the C++ source file.")
99 LY_ASSERT_TYPE (ly_is_procedure, cb, 1);
101 creation_callback = cb;
103 return SCM_UNSPECIFIED;
108 Engraver::internal_make_grob (SCM symbol,
110 char const * /* name */,
121 SCM props = Grob_property_info (context (), symbol).updated ();
125 SCM handle = scm_sloppy_assq (ly_symbol2scm ("meta"), props);
126 SCM klass = scm_cdr (scm_sloppy_assq (ly_symbol2scm ("class"), scm_cdr (handle)));
128 if (scm_is_eq (klass, ly_symbol2scm ("Item")))
129 grob = new Item (props);
130 else if (scm_is_eq (klass, ly_symbol2scm ("Spanner")))
131 grob = new Spanner (props);
132 else if (scm_is_eq (klass, ly_symbol2scm ("Paper_column")))
133 grob = new Paper_column (props);
136 announce_grob (grob, cause);
139 if (ly_is_procedure (creation_callback))
140 scm_call_4 (creation_callback,
141 grob->self_scm (), scm_from_utf8_string (file),
142 scm_from_int (line), scm_from_ascii_string (fun));
149 Engraver::internal_make_item (SCM x, SCM cause,
151 char const *file, int line, char const *fun)
153 Item *it = dynamic_cast<Item *> (internal_make_grob (x, cause, name, file, line, fun));
159 Engraver::internal_make_column (SCM x, char const *name,
160 char const *file, int line, char const *fun)
162 return dynamic_cast<Paper_column *> (internal_make_grob (x, SCM_EOL, name, file, line, fun));
166 Engraver::internal_make_spanner (SCM x, SCM cause, char const *name,
167 char const *file, int line, char const *fun)
169 Spanner *sp = dynamic_cast<Spanner *> (internal_make_grob (x, cause, name, file, line, fun));
175 ly_is_grob_cause (SCM obj)
177 return unsmob<Grob> (obj) || unsmob<Stream_event> (obj) || scm_is_null (obj);
180 #include "translator.icc"
182 ADD_TRANSLATOR (Engraver,
184 "Base class for engravers. Does nothing, so it is not used.",