]> git.donarmstrong.com Git - lilypond.git/blob - lily/global-translator.cc
* VERSION (MY_PATCH_LEVEL): make 1.7.0
[lilypond.git] / lily / global-translator.cc
1 /*
2   global-translator.cc -- implement Global_translator
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8 #include <stdio.h>
9
10 #include "warn.hh"
11 #include "music.hh"
12 #include "request.hh"
13 #include "music-list.hh"
14 #include "music-iterator.hh"
15 #include "global-translator.hh"
16
17 Global_translator::Global_translator ()
18 {
19 }
20
21 void
22 Global_translator::add_moment_to_process (Moment m)
23 {
24   if (m  > final_mom_)
25     return;
26
27   if (m < now_mom_)
28     programming_error ("Trying to freeze in time.");
29   
30   for (int i=0; i <  extra_mom_pq_.size (); i++)
31     if (extra_mom_pq_[i] == m)
32       return;
33   extra_mom_pq_.insert (m);
34 }
35
36 Moment
37 Global_translator::sneaky_insert_extra_moment (Moment w)
38 {
39   while (extra_mom_pq_.size () && extra_mom_pq_.front () <= w)
40     w = extra_mom_pq_.get ();
41   return w;
42 }
43
44 int
45 Global_translator::get_moments_left () const
46 {
47   return extra_mom_pq_.size ();
48 }
49
50 void
51 Global_translator::prepare (Moment m)
52 {
53   prev_mom_  = now_mom_;
54   now_mom_ = m;
55 }
56
57 Moment
58 Global_translator::now_mom () const
59 {
60   return now_mom_;
61 }
62
63
64
65 Music_output*
66 Global_translator::get_output ()
67 {
68   return 0;
69 }
70
71 void
72 Global_translator::one_time_step ()
73 {
74 }
75
76 void
77 Global_translator::start ()
78 {
79 }
80 void
81 Global_translator::finish ()
82 {
83 }
84
85 void
86 Global_translator::run_iterator_on_me (Music_iterator * iter)
87 {
88   if (iter-> ok ())
89     prev_mom_ = now_mom_ = iter->pending_moment ();
90
91   bool first = true;
92   while (iter->ok () || get_moments_left ())
93     {
94       Moment w;
95       w.set_infinite (1);
96       if (iter->ok ())
97         {
98           w = iter->pending_moment ();
99         }
100
101       w = sneaky_insert_extra_moment (w);
102       
103       //      printf ("proccing %s\n ",       w.string ().to_str0 ());
104       if (first)
105         {
106           first = false;
107           set_property ("measurePosition", w.smobbed_copy ());
108         }
109
110       prepare (w);
111       if (iter->ok ())
112         iter->process (w);
113       
114       one_time_step ();
115     }
116 }
117
118 void
119 Global_translator::apply_finalizations ()
120 {
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))
124     {
125       scm_primitive_eval (gh_car (s));
126     }
127 }
128
129 /*
130    Add a function to execute before stepping to the next time step.
131  */
132 void
133 Global_translator::add_finalization (SCM x)
134 {
135   SCM lst = get_property ("finalizations");
136   lst = scm_cons (x, lst);
137   set_property ("finalizations" ,lst); 
138 }
139
140
141 Global_translator *
142 Translator::top_translator()const
143 {
144   if (dynamic_cast<Global_translator*>((Translator*)this))
145     return dynamic_cast<Global_translator*> ((Translator*)this);
146
147   if (daddy_trans_)
148     return daddy_trans_->top_translator ();
149
150   programming_error ("No top translator!");
151   return 0;
152 }