2 score-engraver.cc -- implement Score_engraver
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
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"
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 "stream-event.hh"
27 Score_engraver::Score_engraver ()
34 Score_engraver::derived_mark () const
37 scm_gc_mark (pscore_->self_scm ());
38 Engraver_group::derived_mark ();
41 IMPLEMENT_LISTENER (Score_engraver, prepare);
43 Score_engraver::prepare (SCM)
45 precomputed_recurse_over_translators (context (), START_TRANSLATION_TIMESTEP, DOWN);
48 IMPLEMENT_LISTENER (Score_engraver, finish);
50 Score_engraver::finish (SCM)
52 recurse_over_translators (context (), &Translator::finalize,
53 &Translator_group::finalize,
57 #define MUSIC_FONT "emmentaler-20"
63 Score_engraver::initialize ()
65 Font_metric *fm = all_fonts_global->find_otf (MUSIC_FONT);
68 error (_f ("cannot find `%s'", MUSIC_FONT ".otf")
70 + _ ("Music font has not been installed properly.")
72 + _f ("Search path `%s'", global_path.to_string ().c_str ())
77 pscore_ = new Paper_score (dynamic_cast<Output_def *> (context ()->get_output_def ()));
78 pscore_->unprotect ();
79 context ()->set_property ("output", pscore_->self_scm ());
81 SCM props = updated_grob_properties (context (), ly_symbol2scm ("System"));
83 Object_key const *sys_key = context ()->get_grob_key ("System");
84 pscore_->typeset_system (new System (props, sys_key));
86 system_ = pscore_->root_system ();
87 context ()->set_property ("rootSystem", system_->self_scm ());
89 Engraver_group::initialize ();
93 Score_engraver::connect_to_context (Context *c)
95 Engraver_group::connect_to_context (c);
97 Dispatcher *d = c->get_global_context ()->event_source ();
98 d->add_listener (GET_LISTENER (one_time_step), ly_symbol2scm ("OneTimeStep"));
99 d->add_listener (GET_LISTENER (prepare), ly_symbol2scm ("Prepare"));
100 d->add_listener (GET_LISTENER (finish), ly_symbol2scm ("Finish"));
104 Score_engraver::disconnect_from_context ()
106 Dispatcher *d = context ()->get_global_context ()->event_source ();
107 d->remove_listener (GET_LISTENER (one_time_step), ly_symbol2scm ("OneTimeStep"));
108 d->remove_listener (GET_LISTENER (prepare), ly_symbol2scm ("Prepare"));
109 d->remove_listener (GET_LISTENER (finish), ly_symbol2scm ("Finish"));
111 Engraver_group::disconnect_from_context ();
115 Score_engraver::finalize ()
117 Engraver_group::finalize ();
122 IMPLEMENT_LISTENER(Score_engraver, one_time_step);
124 Score_engraver::one_time_step (SCM)
126 if (!to_boolean (context ()->get_property ("skipTypesetting")))
128 precomputed_recurse_over_translators (context (), PROCESS_MUSIC, UP);
129 Engraver_group::do_announces ();
132 precomputed_recurse_over_translators (context (), STOP_TRANSLATION_TIMESTEP, UP);
137 Score_engraver::announce_grob (Grob_info info)
139 Engraver_group::announce_grob (info);
140 if (info.start_end () == START)
142 pscore_->root_system ()->typeset_grob (info.grob ());
143 elems_.push_back (info.grob ());
148 Score_engraver::typeset_all ()
150 for (vsize i = 0; i < elems_.size (); i++)
152 Grob *elem = elems_[i];
154 if (!elem->get_parent (Y_AXIS))
155 Axis_group_interface::add_element (system_, elem);
160 ADD_TRANSLATOR_GROUP (Score_engraver,
161 /* doc */ "Top level engraver. Takes care of generating columns and the complete system (ie. System) "
163 "This engraver decides whether a column is breakable. The default is "
164 "that a column is always breakable. However, every Bar_engraver "
165 "that does not have a barline at a certain point will set "
166 "forbidBreaks to stop linebreaks. In practice, this "
167 "means that you can make a breakpoint by creating a barline (assuming "
168 "that there are no beams or notes that prevent a breakpoint.) ",
173 "currentMusicalColumn "
174 "currentCommandColumn "
175 "verticallySpacedContexts",