]> git.donarmstrong.com Git - lilypond.git/blob - lily/request-chord-iterator.cc
release: 1.1.58
[lilypond.git] / lily / request-chord-iterator.cc
1 /*
2   request-chord-iterator.cc -- implement Request_chord_iterator
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "translator-group.hh"
10 #include "debug.hh"
11 #include "request-chord-iterator.hh"
12 #include "music-list.hh"
13 #include "request.hh"
14
15
16
17 void
18 Request_chord_iterator::construct_children()
19 {
20   elt_length_mom_ =elt_l ()->length_mom ();
21   get_req_translator_l();
22 }
23
24 Request_chord*
25 Request_chord_iterator::elt_l () const
26 {
27   return (Request_chord*) music_l_;
28 }
29
30 Request_chord_iterator::Request_chord_iterator ()
31 {
32   last_b_ = false;
33   //  cursor_ = elt_l ()->music_p_list_p_->head_;
34   cursor_ = 0;
35 }
36
37
38 bool
39 Request_chord_iterator::ok() const
40 {
41   return (elt_length_mom_ && !last_b_) || first_b_;
42 }
43
44 Moment
45 Request_chord_iterator::next_moment() const
46 {
47   Moment m (0);
48   if  (!first_b_)
49     m = elt_length_mom_;
50   return m;
51 }
52
53 Music*
54 Request_chord_iterator::next_music_l ()
55 {
56   if (first_b_)
57     {
58       cursor_ = elt_l ()->music_p_list_p_->head_;
59       first_b_ = false;
60     }
61   else
62     {
63       if (cursor_)
64         cursor_ = cursor_->next_;
65     }
66   if (cursor_)
67     return cursor_->car_;
68   else
69     return 0;
70 }
71
72 void
73 Request_chord_iterator::do_print() const
74 {
75 #ifndef NPRINT
76   DOUT << "duration: " << elt_length_mom_;
77 #endif
78 }
79
80 void
81 Request_chord_iterator::do_process_and_next (Moment mom)
82 {
83   if (first_b_)
84     {
85       for (Cons<Music> *i = elt_l ()->music_p_list_p_->head_; i; i = i->next_)
86         {
87           if (Request * req_l = dynamic_cast<Request*> (i->car_))
88             {
89               bool gotcha = report_to_l()->try_music (req_l);
90               if (!gotcha)
91                 req_l->warning (_f ("junking request: `%s\'", classname( req_l)));
92             }
93           else
94             i->car_->warning (_f ("Huh? Not a Request: `%s\'",
95                                    classname (i->car_)));
96         }
97       first_b_ = false;
98     }
99
100   if (mom >= elt_length_mom_)
101     last_b_ = true;
102 }