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 "music-output-def.hh"
19 #include "grace-fixup.hh"
21 Global_context::Global_context (Music_output_def *o, Moment final)
25 definition_ = o->find_context_def (ly_symbol2scm ("Global"));
26 unsmob_context_def (definition_)->apply_default_property_operations (this);
27 accepts_list_ = scm_list_1 (ly_symbol2scm ("Score"));
31 Global_context::get_output_def () const
37 Global_context::add_moment_to_process (Moment m)
43 programming_error ("Trying to freeze in time.");
45 for (int i=0; i < extra_mom_pq_.size (); i++)
46 if (extra_mom_pq_[i] == m)
48 extra_mom_pq_.insert (m);
52 Global_context::sneaky_insert_extra_moment (Moment w)
54 while (extra_mom_pq_.size () && extra_mom_pq_.front () <= w)
55 w = extra_mom_pq_.get ();
60 Global_context::get_moments_left () const
62 return extra_mom_pq_.size ();
66 Global_context::prepare (Moment m)
71 if (get_score_context ())
72 get_score_context ()->prepare (m);
76 Global_context::now_mom () const
82 Global_context::get_score_context () const
84 return (is_pair (context_list_))
85 ? dynamic_cast<Score_context*> (unsmob_context (ly_car (context_list_)))
90 Global_context::get_output ()
92 return get_score_context ()->get_output ();
96 Global_context::one_time_step ()
98 get_score_context ()->one_time_step ();
99 apply_finalizations ();
104 Global_context::finish ()
106 if (get_score_context ())
107 get_score_context ()->finish ();
111 Global_context::run_iterator_on_me (Music_iterator * iter)
114 prev_mom_ = now_mom_ = iter->pending_moment ();
117 while (iter->ok () || get_moments_left ())
123 w = iter->pending_moment ();
126 w = sneaky_insert_extra_moment (w);
127 if (w.main_part_.is_infinity ())
133 Need this to get grace notes at start of a piece correct.
136 set_property ("measurePosition", w.smobbed_copy ());
145 if (!get_score_context ())
147 SCM key = ly_symbol2scm ("Score");
148 Context_def * t = unsmob_context_def (get_output_def ()
149 ->find_context_def (key));
151 error (_f ("can't find `%s' context", "Score"));
153 Context *c = t->instantiate (SCM_EOL);
156 Score_context *sc = dynamic_cast<Score_context*> (c);
165 Global_context::apply_finalizations ()
167 SCM lst = get_property ("finalizations");
168 set_property ("finalizations" , SCM_EOL);
169 for (SCM s = lst ; is_pair (s); s = ly_cdr (s))
171 scm_primitive_eval (ly_car (s)); // TODO: make safe.
176 Add a function to execute before stepping to the next time step.
179 Global_context::add_finalization (SCM x)
181 SCM lst = get_property ("finalizations");
182 lst = scm_cons (x, lst);
183 set_property ("finalizations" ,lst);
187 Global_context::previous_moment () const
193 Global_context::get_default_interpreter ()
195 if (get_score_context ())
196 return get_score_context ()->get_default_interpreter ();
198 return Context::get_default_interpreter ();