]> git.donarmstrong.com Git - lilypond.git/blob - lily/percent-repeat-iterator.cc
release: 1.5.0
[lilypond.git] / lily / percent-repeat-iterator.cc
1 /*   
2   percent-repeat-iterator.cc --  implement Percent_repeat_iterator
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "percent-repeat-iterator.hh"
11 #include "repeated-music.hh"
12 #include "input.hh"
13
14 IMPLEMENT_CTOR_CALLBACK (Percent_repeat_iterator);
15
16
17 Percent_repeat_iterator::Percent_repeat_iterator ()
18 {
19   
20 }
21
22 Percent_repeat_iterator::Percent_repeat_iterator (Percent_repeat_iterator const & p)
23   : Music_iterator (p)
24 {
25   child_iter_p_ = p.child_iter_p_ ? p.child_iter_p_->clone (): 0;
26   finish_mom_ = p.finish_mom_ ;
27 }
28
29 bool
30 Percent_repeat_iterator::ok () const
31 {
32   return child_iter_p_;
33 }
34
35 void
36 Percent_repeat_iterator::construct_children ()
37 {
38   Repeated_music * mus =dynamic_cast<Repeated_music *> (music_l ());
39   finish_mom_ = mus->length_mom ();
40   child_iter_p_ = get_iterator_p (mus->body ());
41 }
42
43
44 void
45 Percent_repeat_iterator::process (Moment m)
46 {
47   if (!m)
48     {
49       Music_iterator *yeah = try_music (music_l ());
50       if (yeah)
51         set_translator (yeah->report_to_l ());
52       else
53         music_l ()->origin ()->warning ( _ ("no one to print a percent"));
54     }
55   
56   if (child_iter_p_->ok ())
57     child_iter_p_->process (m);
58
59   if (finish_mom_ <= m )
60     {
61       delete child_iter_p_;
62       child_iter_p_ = 0;
63     }
64 }
65
66 Moment
67 Percent_repeat_iterator::pending_moment ()const
68 {
69   if (child_iter_p_->ok ())
70     return child_iter_p_->pending_moment ();
71   else
72     return finish_mom_ ;
73 }
74
75 Music_iterator*
76 Percent_repeat_iterator::try_music_in_children (Music *m) const
77 {
78   return child_iter_p_->try_music (m);
79 }
80
81
82 Percent_repeat_iterator::~Percent_repeat_iterator ()
83 {
84   delete child_iter_p_;
85 }