2 global-translator.cc -- implement global_context
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
13 #include "music-list.hh"
14 #include "music-iterator.hh"
15 #include "global-context.hh"
16 #include "score-context.hh"
17 #include "context-def.hh"
18 #include "output-def.hh"
19 #include "grace-fixup.hh"
21 Global_context::Global_context (Output_def *o, Moment final)
25 definition_ = find_context_def (o, ly_symbol2scm ("Global"));
27 Context_def *globaldef = unsmob_context_def (definition_);
30 programming_error ("No `Global' context found.");
33 globaldef->apply_default_property_operations (this);
34 accepts_list_ = scm_list_1 (ly_symbol2scm ("Score"));
38 Global_context::get_output_def () const
44 Global_context::add_moment_to_process (Moment m)
50 programming_error ("Trying to freeze in time.");
52 for (int i=0; i < extra_mom_pq_.size (); i++)
53 if (extra_mom_pq_[i] == m)
55 extra_mom_pq_.insert (m);
59 Global_context::sneaky_insert_extra_moment (Moment w)
61 while (extra_mom_pq_.size () && extra_mom_pq_.front () <= w)
62 w = extra_mom_pq_.get ();
67 Global_context::get_moments_left () const
69 return extra_mom_pq_.size ();
73 Global_context::prepare (Moment m)
78 if (get_score_context ())
79 get_score_context ()->prepare (m);
83 Global_context::now_mom () const
89 Global_context::get_score_context () const
91 return (ly_c_pair_p (context_list_))
92 ? dynamic_cast<Score_context*> (unsmob_context (ly_car (context_list_)))
97 Global_context::get_output ()
99 return get_score_context ()->get_output ();
103 Global_context::one_time_step ()
105 get_score_context ()->one_time_step ();
106 apply_finalizations ();
111 Global_context::finish ()
113 if (get_score_context ())
114 get_score_context ()->finish ();
118 Global_context::run_iterator_on_me (Music_iterator * iter)
121 prev_mom_ = now_mom_ = iter->pending_moment ();
124 while (iter->ok () || get_moments_left ())
130 w = iter->pending_moment ();
133 w = sneaky_insert_extra_moment (w);
134 if (w.main_part_.is_infinity ())
140 Need this to get grace notes at start of a piece correct.
143 set_property ("measurePosition", w.smobbed_copy ());
152 if (!get_score_context ())
154 SCM key = ly_symbol2scm ("Score");
155 Context_def * t = unsmob_context_def (find_context_def (get_output_def (), key));
157 error (_f ("can't find `%s' context", "Score"));
159 Context *c = t->instantiate (SCM_EOL);
162 Score_context *sc = dynamic_cast<Score_context*> (c);
171 Global_context::apply_finalizations ()
173 SCM lst = get_property ("finalizations");
174 set_property ("finalizations", SCM_EOL);
175 for (SCM s = lst; ly_c_pair_p (s); s = ly_cdr (s))
176 /* TODO: make safe. */
177 scm_primitive_eval (ly_car (s));
180 /* Add a function to execute before stepping to the next time step. */
182 Global_context::add_finalization (SCM x)
184 SCM lst = get_property ("finalizations");
185 lst = scm_cons (x, lst);
186 set_property ("finalizations", lst);
190 Global_context::previous_moment () const
196 Global_context::get_default_interpreter ()
198 if (get_score_context ())
199 return get_score_context ()->get_default_interpreter ();
201 return Context::get_default_interpreter ();