]> git.donarmstrong.com Git - lilypond.git/blob - lily/score-engraver.cc
Run grand replace for 2015.
[lilypond.git] / lily / score-engraver.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 1997--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
5
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.
10
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.
15
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/>.
18 */
19
20 #include "score-engraver.hh"
21
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 "grob-properties.hh"
28 #include "international.hh"
29 #include "main.hh"
30 #include "open-type-font.hh"
31 #include "output-def.hh"
32 #include "paper-column-engraver.hh"
33 #include "paper-column.hh"
34 #include "paper-score.hh"
35 #include "system.hh"
36 #include "warn.hh"
37
38 Score_engraver::Score_engraver ()
39 {
40   system_ = 0;
41   pscore_ = 0;
42 }
43
44 void
45 Score_engraver::derived_mark () const
46 {
47   if (pscore_)
48     scm_gc_mark (pscore_->self_scm ());
49   Engraver_group::derived_mark ();
50 }
51
52 IMPLEMENT_LISTENER (Score_engraver, prepare);
53 void
54 Score_engraver::prepare (SCM)
55 {
56   precomputed_recurse_over_translators (context (), START_TRANSLATION_TIMESTEP, DOWN);
57 }
58
59 IMPLEMENT_LISTENER (Score_engraver, finish);
60 void
61 Score_engraver::finish (SCM)
62 {
63   recurse_over_translators (context (), &Translator::finalize,
64                             &Translator_group::finalize,
65                             UP);
66 }
67
68 #define MUSIC_FONT "emmentaler-20"
69
70 /*
71   use start/finish?
72 */
73 void
74 Score_engraver::initialize ()
75 {
76   Font_metric *fm = all_fonts_global->find_otf (MUSIC_FONT);
77   if (!fm)
78     {
79       error (_f ("cannot find `%s'", MUSIC_FONT ".otf")
80              + "\n"
81              + _ ("Music font has not been installed properly.")
82              + "\n"
83              + _f ("Search path `%s'", global_path.to_string ().c_str ())
84              + "\n"
85              + _ ("Aborting"));
86     }
87
88   pscore_ = new Paper_score (dynamic_cast<Output_def *> (context ()->get_output_def ()));
89   pscore_->unprotect ();
90   context ()->set_property ("output", pscore_->self_scm ());
91
92   SCM props = Grob_property_info (context (), ly_symbol2scm ("System")).updated ();
93
94   pscore_->typeset_system (new System (props));
95
96   system_ = pscore_->root_system ();
97   context ()->set_property ("rootSystem", system_->self_scm ());
98
99   Engraver_group::initialize ();
100 }
101
102 void
103 Score_engraver::connect_to_context (Context *c)
104 {
105   Engraver_group::connect_to_context (c);
106
107   Dispatcher *d = c->get_global_context ()->event_source ();
108   d->add_listener (GET_LISTENER (one_time_step), ly_symbol2scm ("OneTimeStep"));
109   d->add_listener (GET_LISTENER (prepare), ly_symbol2scm ("Prepare"));
110   d->add_listener (GET_LISTENER (finish), ly_symbol2scm ("Finish"));
111 }
112
113 /*
114   uncovered:
115
116   check_removal always returns false for Score contexts, it has been that way
117 since I joined the project. There is a reason for this: The typeset score is
118 stored in the Score_engraver, which in turn is accessed through the
119 Global_context returned by ly:run-translator. So the score-translator must be
120 connected to the score-context after run-translator finishes.
121
122 I plan to change this: we should junk run-translator, and instead keep track
123 of both context and translator in the SCM code, and access the typeset score
124 directly via the created global-translator. Then it would be possible to
125 disconnect score-translators at iteration time. -es
126  */
127 void
128 Score_engraver::disconnect_from_context ()
129 {
130   Dispatcher *d = context ()->get_global_context ()->event_source ();
131   d->remove_listener (GET_LISTENER (one_time_step), ly_symbol2scm ("OneTimeStep"));
132   d->remove_listener (GET_LISTENER (prepare), ly_symbol2scm ("Prepare"));
133   d->remove_listener (GET_LISTENER (finish), ly_symbol2scm ("Finish"));
134
135   Engraver_group::disconnect_from_context ();
136 }
137
138 void
139 Score_engraver::finalize ()
140 {
141   Engraver_group::finalize ();
142
143   typeset_all ();
144 }
145
146 IMPLEMENT_LISTENER (Score_engraver, one_time_step);
147 void
148 Score_engraver::one_time_step (SCM)
149 {
150   if (!to_boolean (context ()->get_property ("skipTypesetting")))
151     {
152       precomputed_recurse_over_translators (context (), PROCESS_MUSIC, UP);
153       Engraver_group::do_announces ();
154     }
155
156   precomputed_recurse_over_translators (context (), STOP_TRANSLATION_TIMESTEP, UP);
157   typeset_all ();
158 }
159
160 void
161 Score_engraver::announce_grob (Grob_info info)
162 {
163   Engraver_group::announce_grob (info);
164   if (info.start_end () == START)
165     {
166       pscore_->root_system ()->typeset_grob (info.grob ());
167       elems_.push_back (info.grob ());
168     }
169 }
170
171 void
172 Score_engraver::typeset_all ()
173 {
174   for (vsize i = 0; i < elems_.size (); i++)
175     {
176       Grob *elem = elems_[i];
177
178       if (!elem->get_parent (Y_AXIS))
179         Axis_group_interface::add_element (system_, elem);
180     }
181   elems_.clear ();
182 }
183
184 ADD_TRANSLATOR_GROUP (Score_engraver,
185                       /* doc */
186                       "The top-level engraver.  Takes care of generating"
187                       " columns and the complete system (i.e.,"
188                       " @code{System}).\n"
189                       "\n"
190                       "This engraver decides whether a column is breakable."
191                       "  The default is that a column is always breakable."
192                       "  However, every @code{Bar_engraver} that does not have"
193                       " a bar line at a certain point sets @code{forbidBreaks}"
194                       " to stop line breaks.  In practice, this means that you"
195                       " can make a break point by creating a bar line"
196                       " (assuming that there are no beams or notes that"
197                       " prevent a break point).",
198
199                       /* create */
200                       "System ",
201
202                       /* read */
203                       "currentMusicalColumn "
204                       "currentCommandColumn ",
205
206                       /* write */
207                       ""
208                      );