]> git.donarmstrong.com Git - lilypond.git/blob - lily/percent-repeat-iterator.cc
3bce52030a378bdcc88e23b230561664591fc502
[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--2002  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.child_iter_ ? p.child_iter_->clone (): 0;
26   finish_mom_ = p.finish_mom_ ;
27 }
28
29 bool
30 Percent_repeat_iterator::ok () const
31 {
32   return child_iter_;
33 }
34
35 void
36 Percent_repeat_iterator::construct_children ()
37 {
38   Repeated_music * mus =dynamic_cast<Repeated_music *> (get_music ());
39   finish_mom_ = mus->length_mom ();
40   child_iter_ = get_iterator (mus->body ());
41 }
42
43
44 void
45 Percent_repeat_iterator::process (Moment m)
46 {
47   if (!m.to_bool ())
48     {
49       Music_iterator *yeah = try_music (get_music ());
50       if (yeah)
51         set_translator (yeah->report_to ());
52       else
53         get_music ()->origin ()->warning ( _ ("no one to print a percent"));
54     }
55   
56   if (child_iter_->ok ())
57     child_iter_->process (m);
58
59   if (finish_mom_ <= m )
60     {
61       delete child_iter_;
62       child_iter_ = 0;
63     }
64 }
65
66 Moment
67 Percent_repeat_iterator::pending_moment ()const
68 {
69   if (child_iter_->ok ())
70     return child_iter_->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_->try_music (m);
79 }
80
81
82 Percent_repeat_iterator::~Percent_repeat_iterator ()
83 {
84   delete child_iter_;
85 }