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);
25 accepts_list_ = scm_list_1 (ly_symbol2scm ("Score"));
29 Global_context::get_output_def () const
35 Global_context::add_moment_to_process (Moment m)
41 programming_error ("Trying to freeze in time.");
43 for (int i=0; i < extra_mom_pq_.size (); i++)
44 if (extra_mom_pq_[i] == m)
46 extra_mom_pq_.insert (m);
50 Global_context::sneaky_insert_extra_moment (Moment w)
52 while (extra_mom_pq_.size () && extra_mom_pq_.front () <= w)
53 w = extra_mom_pq_.get ();
58 Global_context::get_moments_left () const
60 return extra_mom_pq_.size ();
64 Global_context::prepare (Moment m)
69 if (get_score_context ())
70 get_score_context ()->prepare (m);
74 Global_context::now_mom () const
80 Global_context::get_score_context () const
82 return (gh_pair_p (context_list_))
83 ? dynamic_cast<Score_context*> (unsmob_context (gh_car (context_list_)))
88 Global_context::get_output ()
90 return get_score_context ()->get_output ();
94 Global_context::one_time_step ()
96 get_score_context ()->one_time_step ();
97 apply_finalizations ();
102 Global_context::finish ()
104 if (get_score_context ())
105 get_score_context ()->finish ();
109 Global_context::run_iterator_on_me (Music_iterator * iter)
112 prev_mom_ = now_mom_ = iter->pending_moment ();
115 while (iter->ok () || get_moments_left ())
121 w = iter->pending_moment ();
124 w = sneaky_insert_extra_moment (w);
125 if (w.main_part_.is_infinity ())
129 // printf ("proccing %s\n ", w.to_string ().to_str0 ());
135 set_property ("measurePosition", w.smobbed_copy ());
144 if (!get_score_context ())
146 SCM key = ly_symbol2scm ("Score");
147 Context_def * t = unsmob_context_def (get_output_def ()
148 ->find_context_def (key));
150 error (_f ("can't find `%s' context", "Score"));
152 Context *c = t->instantiate (SCM_EOL);
155 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 ; gh_pair_p (s); s = gh_cdr (s))
171 scm_primitive_eval (gh_car (s));
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);