2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1997--2010 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 #include "score-engraver.hh"
22 #include "all-font-metrics.hh"
23 #include "axis-group-interface.hh"
24 #include "context-def.hh"
25 #include "dispatcher.hh"
26 #include "global-context.hh"
27 #include "international.hh"
29 #include "open-type-font.hh"
30 #include "output-def.hh"
31 #include "paper-column-engraver.hh"
32 #include "paper-column.hh"
33 #include "paper-score.hh"
37 Score_engraver::Score_engraver ()
44 Score_engraver::derived_mark () const
47 scm_gc_mark (pscore_
->self_scm ());
48 Engraver_group::derived_mark ();
51 IMPLEMENT_LISTENER (Score_engraver
, prepare
);
53 Score_engraver::prepare (SCM
)
55 precomputed_recurse_over_translators (context (), START_TRANSLATION_TIMESTEP
, DOWN
);
58 IMPLEMENT_LISTENER (Score_engraver
, finish
);
60 Score_engraver::finish (SCM
)
62 recurse_over_translators (context (), &Translator::finalize
,
63 &Translator_group::finalize
,
67 #define MUSIC_FONT "emmentaler-20"
73 Score_engraver::initialize ()
75 Font_metric
*fm
= all_fonts_global
->find_otf (MUSIC_FONT
);
78 error (_f ("cannot find `%s'", MUSIC_FONT
".otf")
80 + _ ("Music font has not been installed properly.")
82 + _f ("Search path `%s'", global_path
.to_string ().c_str ())
87 pscore_
= new Paper_score (dynamic_cast<Output_def
*> (context ()->get_output_def ()));
88 pscore_
->unprotect ();
89 context ()->set_property ("output", pscore_
->self_scm ());
91 SCM props
= updated_grob_properties (context (), ly_symbol2scm ("System"));
93 pscore_
->typeset_system (new System (props
));
95 system_
= pscore_
->root_system ();
96 context ()->set_property ("rootSystem", system_
->self_scm ());
98 Engraver_group::initialize ();
102 Score_engraver::connect_to_context (Context
*c
)
104 Engraver_group::connect_to_context (c
);
106 Dispatcher
*d
= c
->get_global_context ()->event_source ();
107 d
->add_listener (GET_LISTENER (one_time_step
), ly_symbol2scm ("OneTimeStep"));
108 d
->add_listener (GET_LISTENER (prepare
), ly_symbol2scm ("Prepare"));
109 d
->add_listener (GET_LISTENER (finish
), ly_symbol2scm ("Finish"));
115 check_removal always returns false for Score contexts, it has been that way
116 since I joined the project. There is a reason for this: The typeset score is
117 stored in the Score_engraver, which in turn is accessed through the
118 Global_context returned by ly:run-translator. So the score-translator must be
119 connected to the score-context after run-translator finishes.
121 I plan to change this: we should junk run-translator, and instead keep track
122 of both context and translator in the SCM code, and access the typeset score
123 directly via the created global-translator. Then it would be possible to
124 disconnect score-translators at iteration time. -es
127 Score_engraver::disconnect_from_context ()
129 Dispatcher
*d
= context ()->get_global_context ()->event_source ();
130 d
->remove_listener (GET_LISTENER (one_time_step
), ly_symbol2scm ("OneTimeStep"));
131 d
->remove_listener (GET_LISTENER (prepare
), ly_symbol2scm ("Prepare"));
132 d
->remove_listener (GET_LISTENER (finish
), ly_symbol2scm ("Finish"));
134 Engraver_group::disconnect_from_context ();
138 Score_engraver::finalize ()
140 Engraver_group::finalize ();
145 IMPLEMENT_LISTENER (Score_engraver
, one_time_step
);
147 Score_engraver::one_time_step (SCM
)
149 if (!to_boolean (context ()->get_property ("skipTypesetting")))
151 precomputed_recurse_over_translators (context (), PROCESS_MUSIC
, UP
);
152 Engraver_group::do_announces ();
155 precomputed_recurse_over_translators (context (), STOP_TRANSLATION_TIMESTEP
, UP
);
160 Score_engraver::announce_grob (Grob_info info
)
162 Engraver_group::announce_grob (info
);
163 if (info
.start_end () == START
)
165 pscore_
->root_system ()->typeset_grob (info
.grob ());
166 elems_
.push_back (info
.grob ());
171 Score_engraver::typeset_all ()
173 for (vsize i
= 0; i
< elems_
.size (); i
++)
175 Grob
*elem
= elems_
[i
];
177 if (!elem
->get_parent (Y_AXIS
))
178 Axis_group_interface::add_element (system_
, elem
);
183 ADD_TRANSLATOR_GROUP (Score_engraver
,
185 "The top-level engraver. Takes care of generating"
186 " columns and the complete system (i.e.,"
189 "This engraver decides whether a column is breakable."
190 " The default is that a column is always breakable."
191 " However, every @code{Bar_engraver} that does not have"
192 " a bar line at a certain point sets @code{forbidBreaks}"
193 " to stop line breaks. In practice, this means that you"
194 " can make a break point by creating a bar line"
195 " (assuming that there are no beams or notes that"
196 " prevent a break point).",
202 "currentMusicalColumn "
203 "currentCommandColumn "
204 "verticallySpacedContexts ",