]> git.donarmstrong.com Git - lilypond.git/blob - lily/score-engraver.cc
Fix some bugs in the dynamic engraver and PostScript backend
[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   Engraver_group::announce_grob (info);
115   if (info.start_end () == START)
116     {
117       pscore_->root_system ()->typeset_grob (info.grob ());
118       elems_.push_back (info.grob ());
119     }
120 }
121
122 void
123 Score_engraver::typeset_all ()
124 {
125   for (vsize i = 0; i < elems_.size (); i++)
126     {
127       Grob *elem = elems_[i];
128
129       if (!elem->get_parent (Y_AXIS))
130         Axis_group_interface::add_element (system_, elem);
131     }
132   elems_.clear ();
133 }
134
135 SCM
136 Score_engraver::get_output ()
137 {
138   Music_output *o = pscore_;
139   return o->self_scm ();
140 }
141
142 bool
143 Score_engraver::try_music (Music *m)
144 {
145   if (Engraver_group::try_music (m))
146     return true;
147
148   return false;
149 }
150
151 ADD_TRANSLATOR_GROUP (Score_engraver,
152                       /* doc */ "Top level engraver. Takes care of generating columns and the complete  system (ie. System) "
153                       "\n\n "
154                       "This engraver decides whether a column is breakable. The default is "
155                       "that a column is always breakable. However, every Bar_engraver "
156                       "that does not have a barline at a certain point will set "
157                       "forbidBreaks to stop linebreaks.  In practice, this "
158                       "means that you can make a breakpoint by creating a barline (assuming "
159                       "that there are no beams or notes that prevent a breakpoint.) ",
160                       /* create */
161                       "System ",
162
163                       /* accept */
164                       "break-event",
165                       
166                       /* read */
167                       "currentMusicalColumn "
168                       "currentCommandColumn "
169                       "verticallySpacedContexts",
170
171                       /* write */
172                       "");