]> git.donarmstrong.com Git - lilypond.git/blob - lily/score-engraver.cc
(finalize): add to instrument
[lilypond.git] / lily / score-engraver.cc
1 /*
2   score-engraver.cc -- implement Score_engraver
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "score-engraver.hh"
10
11 #include "all-font-metrics.hh"
12 #include "axis-group-interface.hh"
13 #include "context-def.hh"
14 #include "global-context.hh"
15 #include "international.hh"
16 #include "main.hh"
17 #include "open-type-font.hh"
18 #include "output-def.hh"
19 #include "paper-column-engraver.hh"
20 #include "paper-column.hh"
21 #include "paper-score.hh"
22 #include "system.hh"
23 #include "warn.hh"
24
25 Score_engraver::Score_engraver ()
26 {
27   system_ = 0;
28   pscore_ = 0;
29 }
30
31 void
32 Score_engraver::derived_mark () const
33 {
34   if (pscore_)
35     scm_gc_mark (pscore_->self_scm ());
36   Score_translator::derived_mark ();
37   Engraver_group::derived_mark ();
38 }
39
40 void
41 Score_engraver::prepare (Moment m)
42 {
43   (void) m;
44
45   precomputed_recurse_over_translators (context (), START_TRANSLATION_TIMESTEP, DOWN);
46 }
47
48 void
49 Score_engraver::finish ()
50 {
51   recurse_over_translators (context (), &Translator::finalize,
52                             &Translator_group::finalize,
53                             UP);
54 }
55
56 #define MUSIC_FONT "emmentaler-20"
57
58 /*
59   use start/finish?
60 */
61 void
62 Score_engraver::initialize ()
63 {
64   Font_metric *fm = all_fonts_global->find_otf (MUSIC_FONT);
65   if (!fm)
66     {
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"));
74     }
75
76   pscore_ = new Paper_score (dynamic_cast<Output_def *> (context ()->get_output_def ()));
77   pscore_->unprotect ();
78
79   SCM props = updated_grob_properties (context (), ly_symbol2scm ("System"));
80
81   Object_key const *sys_key = context ()->get_grob_key ("System");
82   pscore_->typeset_system (new System (props, sys_key));
83   
84   system_ = pscore_->root_system ();
85   context ()->set_property ("rootSystem", system_->self_scm ());
86
87   Engraver_group::initialize ();
88 }
89
90 void
91 Score_engraver::finalize ()
92 {
93   Score_translator::finalize ();
94
95   typeset_all ();
96 }
97
98 void
99 Score_engraver::one_time_step ()
100 {
101   if (!to_boolean (context ()->get_property ("skipTypesetting")))
102     {
103       precomputed_recurse_over_translators (context (), PROCESS_MUSIC, UP);
104       Engraver_group::do_announces ();
105     }
106
107   precomputed_recurse_over_translators (context (), STOP_TRANSLATION_TIMESTEP, UP);
108   typeset_all ();
109 }
110
111 void
112 Score_engraver::announce_grob (Grob_info info)
113 {
114   announce_infos_.push_back (info);
115   pscore_->root_system ()->typeset_grob (info.grob ());
116   elems_.push_back (info.grob ());
117 }
118
119 void
120 Score_engraver::typeset_all ()
121 {
122   for (vsize i = 0; i < elems_.size (); i++)
123     {
124       Grob *elem = elems_[i];
125
126       if (!elem->get_parent (Y_AXIS))
127         Axis_group_interface::add_element (system_, elem);
128     }
129   elems_.clear ();
130 }
131
132 SCM
133 Score_engraver::get_output ()
134 {
135   Music_output *o = pscore_;
136   return o->self_scm ();
137 }
138
139 /*
140   UGH UGH
141 */
142 void
143 Score_engraver::forbid_breaks ()
144 {
145   for (SCM s = simple_trans_list_; scm_is_pair (s); s = scm_cdr (s))
146     {
147       Translator *tr = unsmob_translator (scm_car (s));
148       if (Paper_column_engraver *pce = dynamic_cast<Paper_column_engraver *> (tr))
149         pce->forbid_breaks ();
150     }
151 }
152
153 bool
154 Score_engraver::try_music (Music *m)
155 {
156   if (Engraver_group::try_music (m))
157     return true;
158
159   return false;
160 }
161
162 ADD_TRANSLATOR_GROUP (Score_engraver,
163                       /* doc */ "Top level engraver. Takes care of generating columns and the complete  system (ie. System) "
164                       "\n\n "
165                       "This engraver decides whether a column is breakable. The default is "
166                       "that a column is always breakable. However, when every Bar_engraver "
167                       "that does not have a barline at a certain point will call "
168                       "Score_engraver::forbid_breaks to stop linebreaks.  In practice, this "
169                       "means that you can make a breakpoint by creating a barline (assuming "
170                       "that there are no beams or notes that prevent a breakpoint.) ",
171                       /* create */
172                       "System ",
173
174                       /* accept */
175                       "break-event",
176                       
177                       /* read */
178                       "currentMusicalColumn "
179                       "currentCommandColumn "
180                       "verticallySpacedContexts",
181
182                       /* write */
183                       "");