]> git.donarmstrong.com Git - lilypond.git/blob - lily/engraver.cc
Coverage fixes: remove tweak registration/application, gnome backend,
[lilypond.git] / lily / engraver.cc
1 /*
2   engraver.cc -- implement Engraver
3
4   Sourcefile of GNU LilyPond music type setter
5
6   (c) 1997--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "engraver.hh"
10
11 #include "context.hh"
12 #include "international.hh"
13 #include "lilypond-key.hh"
14 #include "music.hh"
15 #include "paper-column.hh"
16 #include "score-engraver.hh"
17 #include "spanner.hh"
18 #include "stream-event.hh"
19 #include "warn.hh"
20
21 Engraver_group *
22 Engraver::get_daddy_engraver () const
23 {
24   return dynamic_cast<Engraver_group *> (get_daddy_translator ());
25 }
26
27 void
28 Engraver::announce_grob (Grob_info inf)
29 {
30   get_daddy_engraver ()->announce_grob (inf);
31 }
32
33 void
34 Engraver::announce_end_grob (Grob_info inf)
35 {
36   get_daddy_engraver ()->announce_grob (inf);
37 }
38
39 /*
40   CAUSE is the object (typically a Stream_event object)  that
41   was the reason for making E.
42 */
43 void
44 Engraver::announce_grob (Grob *e, SCM cause)
45 {
46   /* TODO: Remove Music code when it's no longer needed */
47   if (Music *m = unsmob_music (cause))
48     {
49       cause = m->to_event ()->unprotect ();
50     }
51   if (unsmob_stream_event (cause) || unsmob_grob (cause))
52     e->set_property ("cause", cause);
53
54   Grob_info i (this, e);
55
56   Engraver_group *g = get_daddy_engraver ();
57   if (g)
58     g->announce_grob (i);
59 }
60
61
62 /*
63   CAUSE is the object (typically a Music object)  that
64   was the reason for making E.
65 */
66 void
67 Engraver::announce_end_grob (Grob *e, SCM cause)
68 {
69   /* TODO: Remove Music code when it's no longer needed */
70   if (Music *m = unsmob_music (cause))
71     {
72       cause = m->to_event ()->unprotect ();
73     }
74   if (unsmob_stream_event (cause) || unsmob_grob (cause))
75     e->set_property ("cause", cause);
76
77   Grob_info i (this, e);
78
79   i.start_end_ = STOP;
80   Engraver_group *g = get_daddy_engraver ();
81   if (g)
82     g->announce_grob (i);
83 }
84
85
86 Engraver::Engraver ()
87 {
88 }
89
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 the "
98            "C++ source file.")
99 {
100   SCM_ASSERT_TYPE(ly_is_procedure (cb), cb, SCM_ARG1, __FUNCTION__,
101                   "procedure");
102
103   creation_callback = cb;
104
105   return SCM_UNSPECIFIED;
106 }
107 #endif
108
109 Grob *
110 Engraver::internal_make_grob (SCM symbol, SCM cause, char const *name, char const *file, int line, char const *fun)
111 {
112   (void) file;
113   (void) fun;
114   (void) line;
115   
116   SCM props = updated_grob_properties (context (), symbol);
117
118   Object_key const *key = 0;
119   Grob *grob = 0;
120
121   SCM handle = scm_sloppy_assq (ly_symbol2scm ("meta"), props);
122   SCM klass = scm_cdr (scm_sloppy_assq (ly_symbol2scm ("class"), scm_cdr (handle)));
123
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);
130
131   assert (grob);
132   announce_grob (grob, cause);
133
134 #ifndef NDEBUG
135   if (ly_is_procedure (creation_callback))
136     scm_apply_0 (creation_callback,
137                  scm_list_n (grob->self_scm (), scm_from_locale_string (file),
138                              scm_from_int (line), scm_from_locale_string (fun), SCM_UNDEFINED));
139 #endif
140
141   return grob;
142 }
143
144 Item *
145 Engraver::internal_make_item (SCM x, SCM cause,
146                               char const *name,
147                               char const *file, int line, char const *fun)
148 {
149   Item *it = dynamic_cast<Item *> (internal_make_grob (x, cause, name, file, line, fun));
150   assert (it);
151   return it;
152 }
153
154 Paper_column *
155 Engraver::internal_make_column (SCM x, char const *name,
156                                 char const *file, int line, char const *fun)
157 {
158   return dynamic_cast<Paper_column *> (internal_make_grob (x, SCM_EOL, name, file, line, fun));
159 }
160
161 Spanner *
162 Engraver::internal_make_spanner (SCM x, SCM cause, char const *name, char const *file, int line, char const *fun)
163 {
164   Spanner *sp = dynamic_cast<Spanner *> (internal_make_grob (x, cause, name, file, line, fun));
165   assert (sp);
166   return sp;
167 }
168
169 #include "translator.icc"
170
171 ADD_TRANSLATOR (Engraver,
172                 "Base class for engravers. Does nothing, so it is not used.",
173                 "",
174                 "",
175                 "");
176