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>
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"
26 Score_engraver::Score_engraver ()
33 Score_engraver::derived_mark () const
36 scm_gc_mark (pscore_
->self_scm ());
37 Engraver_group::derived_mark ();
40 IMPLEMENT_LISTENER (Score_engraver
, prepare
);
42 Score_engraver::prepare (SCM
)
44 precomputed_recurse_over_translators (context (), START_TRANSLATION_TIMESTEP
, DOWN
);
47 IMPLEMENT_LISTENER (Score_engraver
, finish
);
49 Score_engraver::finish (SCM
)
51 recurse_over_translators (context (), &Translator::finalize
,
52 &Translator_group::finalize
,
56 #define MUSIC_FONT "emmentaler-20"
62 Score_engraver::initialize ()
64 Font_metric
*fm
= all_fonts_global
->find_otf (MUSIC_FONT
);
67 error (_f ("cannot find `%s'", MUSIC_FONT
".otf")
69 + _ ("Music font has not been installed properly.")
71 + _f ("Search path `%s'", global_path
.to_string ().c_str ())
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 ();
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"));
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
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 ();
127 Score_engraver::finalize ()
129 Engraver_group::finalize ();
134 IMPLEMENT_LISTENER (Score_engraver
, one_time_step
);
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
);
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 ());
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
);
172 ADD_TRANSLATOR_GROUP (Score_engraver
,
174 "The top-level engraver. Takes care of generating"
175 " columns and the complete system (i.e.,"
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).",
191 "currentMusicalColumn "
192 "currentCommandColumn "
193 "verticallySpacedContexts ",