]> git.donarmstrong.com Git - lilypond.git/blob - lily/engraver.cc
Improve and correct documentation strings.
[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 "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"
19
20 Engraver_group *
21 Engraver::get_daddy_engraver () const
22 {
23   return dynamic_cast<Engraver_group *> (get_daddy_translator ());
24 }
25
26 void
27 Engraver::announce_grob (Grob_info inf)
28 {
29   get_daddy_engraver ()->announce_grob (inf);
30 }
31
32 void
33 Engraver::announce_end_grob (Grob_info inf)
34 {
35   get_daddy_engraver ()->announce_grob (inf);
36 }
37
38 /*
39   CAUSE is the object (typically a Stream_event object)  that
40   was the reason for making E.
41 */
42 void
43 Engraver::announce_grob (Grob *e, SCM cause)
44 {
45   /* TODO: Remove Music code when it's no longer needed */
46   if (Music *m = unsmob_music (cause))
47     {
48       cause = m->to_event ()->unprotect ();
49     }
50   if (unsmob_stream_event (cause) || unsmob_grob (cause))
51     e->set_property ("cause", cause);
52
53   Grob_info i (this, e);
54
55   Engraver_group *g = get_daddy_engraver ();
56   if (g)
57     g->announce_grob (i);
58 }
59
60
61 /*
62   CAUSE is the object (typically a Music object)  that
63   was the reason for making E.
64 */
65 void
66 Engraver::announce_end_grob (Grob *e, SCM cause)
67 {
68   /* TODO: Remove Music code when it's no longer needed */
69   if (Music *m = unsmob_music (cause))
70     {
71       cause = m->to_event ()->unprotect ();
72     }
73   if (unsmob_stream_event (cause) || unsmob_grob (cause))
74     e->set_property ("cause", cause);
75
76   Grob_info i (this, e);
77
78   i.start_end_ = STOP;
79   Engraver_group *g = get_daddy_engraver ();
80   if (g)
81     g->announce_grob (i);
82 }
83
84
85 Engraver::Engraver ()
86 {
87 }
88
89 #ifndef NDEBUG
90 static SCM creation_callback = SCM_EOL;
91 LY_DEFINE (ly_set_grob_creation_callback, "ly:set-grob-creation-callback",
92            1, 0, 0, (SCM cb),
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.")
98 {
99   LY_ASSERT_TYPE (ly_is_procedure, cb, 1);
100
101   creation_callback = cb;
102
103   return SCM_UNSPECIFIED;
104 }
105 #endif
106
107 Grob *
108 Engraver::internal_make_grob (SCM symbol, SCM cause, char const *name, char const *file, int line, char const *fun)
109 {
110   (void) file;
111   (void) fun;
112   (void) line;
113   (void) name;
114   
115   SCM props = updated_grob_properties (context (), symbol);
116
117   Grob *grob = 0;
118
119   SCM handle = scm_sloppy_assq (ly_symbol2scm ("meta"), props);
120   SCM klass = scm_cdr (scm_sloppy_assq (ly_symbol2scm ("class"), scm_cdr (handle)));
121
122   if (klass == ly_symbol2scm ("Item"))
123     grob = new Item (props);
124   else if (klass == ly_symbol2scm ("Spanner"))
125     grob = new Spanner (props);
126   else if (klass == ly_symbol2scm ("Paper_column"))
127     grob = new Paper_column (props);
128
129   assert (grob);
130   announce_grob (grob, cause);
131
132 #ifndef NDEBUG
133   if (ly_is_procedure (creation_callback))
134     scm_apply_0 (creation_callback,
135                  scm_list_n (grob->self_scm (), scm_from_locale_string (file),
136                              scm_from_int (line), scm_from_locale_string (fun), SCM_UNDEFINED));
137 #endif
138
139   return grob;
140 }
141
142 Item *
143 Engraver::internal_make_item (SCM x, SCM cause,
144                               char const *name,
145                               char const *file, int line, char const *fun)
146 {
147   Item *it = dynamic_cast<Item *> (internal_make_grob (x, cause, name, file, line, fun));
148   assert (it);
149   return it;
150 }
151
152 Paper_column *
153 Engraver::internal_make_column (SCM x, char const *name,
154                                 char const *file, int line, char const *fun)
155 {
156   return dynamic_cast<Paper_column *> (internal_make_grob (x, SCM_EOL, name, file, line, fun));
157 }
158
159 Spanner *
160 Engraver::internal_make_spanner (SCM x, SCM cause, char const *name, char const *file, int line, char const *fun)
161 {
162   Spanner *sp = dynamic_cast<Spanner *> (internal_make_grob (x, cause, name, file, line, fun));
163   assert (sp);
164   return sp;
165 }
166
167 #include "translator.icc"
168
169 ADD_TRANSLATOR (Engraver,
170                 "Base class for engravers. Does nothing, so it is not used.",
171                 "",
172                 "",
173                 "");
174