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"
20 Global_context::Global_context (Music_output_def*o)
23 definition_ = o->find_context_def (ly_symbol2scm ("Global"));
24 unsmob_context_def (definition_)->apply_default_property_operations (this);
28 Global_context::get_output_def () const
34 Global_context::add_moment_to_process (Moment m)
40 programming_error ("Trying to freeze in time.");
42 for (int i=0; i < extra_mom_pq_.size (); i++)
43 if (extra_mom_pq_[i] == m)
45 extra_mom_pq_.insert (m);
49 Global_context::sneaky_insert_extra_moment (Moment w)
51 while (extra_mom_pq_.size () && extra_mom_pq_.front () <= w)
52 w = extra_mom_pq_.get ();
57 Global_context::get_moments_left () const
59 return extra_mom_pq_.size ();
63 Global_context::prepare (Moment m)
68 if (get_score_context ())
69 get_score_context ()->prepare (m);
73 Global_context::now_mom () const
79 Global_context::get_score_context () const
81 return (gh_pair_p (context_list_))
82 ? dynamic_cast<Score_context*> (unsmob_context (gh_car (context_list_)))
87 Global_context::get_output ()
89 return get_score_context ()->get_output ();
93 Global_context::one_time_step ()
95 get_score_context ()->one_time_step ();
96 apply_finalizations ();
101 Global_context::finish ()
103 if (get_score_context ())
104 get_score_context ()->finish ();
108 Global_context::run_iterator_on_me (Music_iterator * iter)
111 prev_mom_ = now_mom_ = iter->pending_moment ();
114 while (iter->ok () || get_moments_left ())
120 w = iter->pending_moment ();
123 w = sneaky_insert_extra_moment (w);
124 if (w.main_part_.is_infinity ())
128 // printf ("proccing %s\n ", w.to_string ().to_str0 ());
134 set_property ("measurePosition", w.smobbed_copy ());
143 if (!get_score_context ())
145 SCM key = ly_symbol2scm ("Score");
146 Context_def * t = unsmob_context_def (get_output_def ()
147 ->find_context_def (key));
149 error (_f ("can't find `%s' context", "Score"));
151 add_context (t->instantiate (SCM_EOL));
153 Score_context *sc = dynamic_cast<Score_context*> (t);
163 Global_context::apply_finalizations ()
165 SCM lst = get_property ("finalizations");
166 set_property ("finalizations" , SCM_EOL);
167 for (SCM s = lst ; gh_pair_p (s); s = gh_cdr (s))
169 scm_primitive_eval (gh_car (s));
174 Add a function to execute before stepping to the next time step.
177 Global_context::add_finalization (SCM x)
179 SCM lst = get_property ("finalizations");
180 lst = scm_cons (x, lst);
181 set_property ("finalizations" ,lst);