2 global-translator.cc -- implement Global_translator
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
13 #include "music-list.hh"
14 #include "music-iterator.hh"
15 #include "global-translator.hh"
17 Global_translator::Global_translator ()
22 Global_translator::add_moment_to_process (Moment m)
28 programming_error ("Trying to freeze in time.");
30 for (int i=0; i < extra_mom_pq_.size (); i++)
31 if (extra_mom_pq_[i] == m)
33 extra_mom_pq_.insert (m);
37 Global_translator::sneaky_insert_extra_moment (Moment w)
39 while (extra_mom_pq_.size () && extra_mom_pq_.front () <= w)
40 w = extra_mom_pq_.get ();
45 Global_translator::get_moments_left () const
47 return extra_mom_pq_.size ();
51 Global_translator::prepare (Moment m)
58 Global_translator::now_mom () const
66 Global_translator::get_output ()
72 Global_translator::one_time_step ()
77 Global_translator::start ()
81 Global_translator::finish ()
86 Global_translator::run_iterator_on_me (Music_iterator * iter)
89 prev_mom_ = now_mom_ = iter->pending_moment ();
92 while (iter->ok () || get_moments_left ())
98 w = iter->pending_moment ();
101 w = sneaky_insert_extra_moment (w);
103 // printf ("proccing %s\n ", w.to_string ().to_str0 ());
107 set_property ("measurePosition", w.smobbed_copy ());
119 Global_translator::apply_finalizations ()
121 SCM lst = get_property ("finalizations");
122 set_property ("finalizations" , SCM_EOL);
123 for (SCM s = lst ; gh_pair_p (s); s = gh_cdr (s))
125 scm_primitive_eval (gh_car (s));
130 Add a function to execute before stepping to the next time step.
133 Global_translator::add_finalization (SCM x)
135 SCM lst = get_property ("finalizations");
136 lst = scm_cons (x, lst);
137 set_property ("finalizations" ,lst);
142 Translator::top_translator()const
144 if (dynamic_cast<Global_translator*>((Translator*)this))
145 return dynamic_cast<Global_translator*> ((Translator*)this);
148 return daddy_trans_->top_translator ();
150 programming_error ("No top translator!");