Workaround for broken MusicXML files (percussion clef in MuseScore)
[lilypond.git] / lily / score-engraver.cc
blobeff35efed4173fb2666a69a383970d569f5b495a
1 /*
2 score-engraver.cc -- implement Score_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
9 #include "score-engraver.hh"
11 #include "all-font-metrics.hh"
12 #include "axis-group-interface.hh"
13 #include "context-def.hh"
14 #include "dispatcher.hh"
15 #include "global-context.hh"
16 #include "international.hh"
17 #include "main.hh"
18 #include "open-type-font.hh"
19 #include "output-def.hh"
20 #include "paper-column-engraver.hh"
21 #include "paper-column.hh"
22 #include "paper-score.hh"
23 #include "system.hh"
24 #include "warn.hh"
26 Score_engraver::Score_engraver ()
28 system_ = 0;
29 pscore_ = 0;
32 void
33 Score_engraver::derived_mark () const
35 if (pscore_)
36 scm_gc_mark (pscore_->self_scm ());
37 Engraver_group::derived_mark ();
40 IMPLEMENT_LISTENER (Score_engraver, prepare);
41 void
42 Score_engraver::prepare (SCM)
44 precomputed_recurse_over_translators (context (), START_TRANSLATION_TIMESTEP, DOWN);
47 IMPLEMENT_LISTENER (Score_engraver, finish);
48 void
49 Score_engraver::finish (SCM)
51 recurse_over_translators (context (), &Translator::finalize,
52 &Translator_group::finalize,
53 UP);
56 #define MUSIC_FONT "emmentaler-20"
59 use start/finish?
61 void
62 Score_engraver::initialize ()
64 Font_metric *fm = all_fonts_global->find_otf (MUSIC_FONT);
65 if (!fm)
67 error (_f ("cannot find `%s'", MUSIC_FONT ".otf")
68 + "\n"
69 + _ ("Music font has not been installed properly.")
70 + "\n"
71 + _f ("Search path `%s'", global_path.to_string ().c_str ())
72 + "\n"
73 + _ ("Aborting"));
76 pscore_ = new Paper_score (dynamic_cast<Output_def *> (context ()->get_output_def ()));
77 pscore_->unprotect ();
78 context ()->set_property ("output", pscore_->self_scm ());
80 SCM props = updated_grob_properties (context (), ly_symbol2scm ("System"));
82 pscore_->typeset_system (new System (props));
84 system_ = pscore_->root_system ();
85 context ()->set_property ("rootSystem", system_->self_scm ());
87 Engraver_group::initialize ();
90 void
91 Score_engraver::connect_to_context (Context *c)
93 Engraver_group::connect_to_context (c);
95 Dispatcher *d = c->get_global_context ()->event_source ();
96 d->add_listener (GET_LISTENER (one_time_step), ly_symbol2scm ("OneTimeStep"));
97 d->add_listener (GET_LISTENER (prepare), ly_symbol2scm ("Prepare"));
98 d->add_listener (GET_LISTENER (finish), ly_symbol2scm ("Finish"));
102 uncovered:
104 check_removal always returns false for Score contexts, it has been that way
105 since I joined the project. There is a reason for this: The typeset score is
106 stored in the Score_engraver, which in turn is accessed through the
107 Global_context returned by ly:run-translator. So the score-translator must be
108 connected to the score-context after run-translator finishes.
110 I plan to change this: we should junk run-translator, and instead keep track
111 of both context and translator in the SCM code, and access the typeset score
112 directly via the created global-translator. Then it would be possible to
113 disconnect score-translators at iteration time. -es
115 void
116 Score_engraver::disconnect_from_context ()
118 Dispatcher *d = context ()->get_global_context ()->event_source ();
119 d->remove_listener (GET_LISTENER (one_time_step), ly_symbol2scm ("OneTimeStep"));
120 d->remove_listener (GET_LISTENER (prepare), ly_symbol2scm ("Prepare"));
121 d->remove_listener (GET_LISTENER (finish), ly_symbol2scm ("Finish"));
123 Engraver_group::disconnect_from_context ();
126 void
127 Score_engraver::finalize ()
129 Engraver_group::finalize ();
131 typeset_all ();
134 IMPLEMENT_LISTENER (Score_engraver, one_time_step);
135 void
136 Score_engraver::one_time_step (SCM)
138 if (!to_boolean (context ()->get_property ("skipTypesetting")))
140 precomputed_recurse_over_translators (context (), PROCESS_MUSIC, UP);
141 Engraver_group::do_announces ();
144 precomputed_recurse_over_translators (context (), STOP_TRANSLATION_TIMESTEP, UP);
145 typeset_all ();
148 void
149 Score_engraver::announce_grob (Grob_info info)
151 Engraver_group::announce_grob (info);
152 if (info.start_end () == START)
154 pscore_->root_system ()->typeset_grob (info.grob ());
155 elems_.push_back (info.grob ());
159 void
160 Score_engraver::typeset_all ()
162 for (vsize i = 0; i < elems_.size (); i++)
164 Grob *elem = elems_[i];
166 if (!elem->get_parent (Y_AXIS))
167 Axis_group_interface::add_element (system_, elem);
169 elems_.clear ();
172 ADD_TRANSLATOR_GROUP (Score_engraver,
173 /* doc */
174 "The top-level engraver. Takes care of generating"
175 " columns and the complete system (i.e.,"
176 " @code{System}).\n"
177 "\n"
178 "This engraver decides whether a column is breakable."
179 " The default is that a column is always breakable."
180 " However, every @code{Bar_engraver} that does not have"
181 " a bar line at a certain point sets @code{forbidBreaks}"
182 " to stop line breaks. In practice, this means that you"
183 " can make a break point by creating a bar line"
184 " (assuming that there are no beams or notes that"
185 " prevent a break point).",
187 /* create */
188 "System ",
190 /* read */
191 "currentMusicalColumn "
192 "currentCommandColumn "
193 "verticallySpacedContexts ",
195 /* write */