]> git.donarmstrong.com Git - lilypond.git/blob - lily/global-translator.cc
0c079c40d223d89d80c7cde2e8de5818f6ef7446
[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 void
76 Global_translator::start ()
77 {
78 }
79 void
80 Global_translator::finish ()
81 {
82 }
83
84 void
85 Global_translator::run_iterator_on_me (Music_iterator * iter)
86 {
87   if (iter-> ok ())
88     prev_mom_ = now_mom_ = iter->pending_moment ();
89
90   bool first = true;
91   while (iter->ok () || get_moments_left ())
92     {
93       Moment w;
94       w.set_infinite (1);
95       if (iter->ok ())
96         {
97           w = iter->pending_moment ();
98         }
99
100       w = sneaky_insert_extra_moment (w);
101       
102       //      printf ("proccing %s\n ",       w.string ().to_str0 ());
103
104
105       
106       if (first)
107         {
108           first = false;
109           set_property ("measurePosition", w.smobbed_copy ());
110         }
111
112       prepare (w);
113       if (iter->ok ())
114         iter->process (w);
115       
116       one_time_step ();
117     }
118 }