]> git.donarmstrong.com Git - lilypond.git/blob - lily/folded-repeat-iterator.cc
* configure.in: Test for and accept lmodern if EC fonts not found.
[lilypond.git] / lily / folded-repeat-iterator.cc
1 /*   
2      folded-repeat-iterator.cc --  implement Folded_repeat_iterator
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 1999--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "folded-repeat-iterator.hh"
11
12 #include "input.hh"
13 #include "repeated-music.hh"
14 #include "music-list.hh"
15 #include "simultaneous-music-iterator.hh"
16 #include "context.hh"
17
18 Folded_repeat_iterator::Folded_repeat_iterator ()
19 {
20   main_iter_ = 0;
21   alternative_iter_ = 0;
22 }
23
24 bool
25 Folded_repeat_iterator::ok () const
26 {
27   return main_iter_ || alternative_iter_;
28 }
29 void
30 Folded_repeat_iterator::do_quit ()
31 {
32   if (main_iter_)main_iter_->quit ();
33   if (alternative_iter_)alternative_iter_->quit ();
34 }
35
36 Moment
37 Folded_repeat_iterator::pending_moment () const
38 {
39   if (main_iter_)
40     {
41       return main_iter_->pending_moment ();
42     }
43   else
44     return main_length_mom_ + alternative_iter_->pending_moment ();
45 }
46
47 void
48 Folded_repeat_iterator::construct_children ()
49 {
50   Repeated_music  *  mus = dynamic_cast<Repeated_music*> (get_music ());
51   main_iter_ = unsmob_iterator (get_iterator (mus->body ()));
52   if (!main_iter_->ok ())
53     {
54       leave_body ();
55       enter_alternative ();
56     }
57 }
58
59 void
60 Folded_repeat_iterator::process (Moment m)
61 {
62   if (!m.to_bool () )
63     {
64       bool success = try_music (get_music ());
65       if (!success)
66         get_music ()->origin ()->warning (_ ("no one to print a repeat brace"));
67     }
68   
69   if (main_iter_)
70     {
71       main_iter_->process (m);
72       if (!main_iter_->ok ())
73         leave_body ();
74     }
75
76   if (!main_iter_ && !alternative_iter_)
77     {
78       enter_alternative ();
79     }
80   
81   if (alternative_iter_)
82     {
83       alternative_iter_->process (m - main_length_mom_);
84       if (!alternative_iter_->ok ())
85         {
86           alternative_iter_->quit ();
87           alternative_iter_ =0;
88         }
89     }
90 }
91
92 void
93 Folded_repeat_iterator::leave_body ()
94 {
95   Repeated_music *  mus = dynamic_cast<Repeated_music *> (get_music ());
96
97   main_iter_->quit ();
98   main_iter_ = 0;
99   main_length_mom_ +=  mus->body ()->get_length ();
100 }
101
102 void
103 Folded_repeat_iterator::enter_alternative ()
104 {
105   Repeated_music *  mus = dynamic_cast<Repeated_music *> (get_music ());  
106   if (mus->alternatives ())
107     {
108       /*
109         ugh.
110       */ 
111       Simultaneous_music_iterator * s = new Simultaneous_music_iterator;
112       s->create_separate_contexts_ = true;
113       s->init_translator (mus, get_outlet ());
114       
115       alternative_iter_ = s;
116       alternative_iter_->construct_children ();
117
118       scm_gc_unprotect_object (s->self_scm ());
119     }
120 }
121
122
123 Music_iterator*
124 Folded_repeat_iterator::try_music_in_children (Music * m) const
125 {
126   if (main_iter_)
127     {
128       return main_iter_->try_music (m);
129     }
130   if (alternative_iter_)
131     return alternative_iter_->try_music (m);
132   return 0;
133 }
134 void
135 Folded_repeat_iterator::derived_mark ()const
136 {
137   if (main_iter_)
138     scm_gc_mark (main_iter_->self_scm ());
139   if (alternative_iter_)
140     scm_gc_mark (alternative_iter_->self_scm ());
141 }
142
143 void
144 Folded_repeat_iterator::derived_substitute (Context *f, Context *t) 
145 {
146   if (main_iter_)
147     main_iter_->substitute_outlet (f,t);
148   if (alternative_iter_)
149     alternative_iter_->substitute_outlet (f,t);
150 }
151
152 IMPLEMENT_CTOR_CALLBACK (Folded_repeat_iterator);