* lexer-gcc-3.1.sh: Remove.
[lilypond/patrick.git] / lily / volta-repeat-iterator.cc
blob1828dfdbca9b49d062752118c554abfc9cd7737d
1 /*
2 volta-repeat-iterator.cc -- implement Volta_repeat_iterator
4 source file of the GNU LilyPond music typesetter
7 (c) 2002--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
8 */
10 #include "music.hh"
11 #include "sequential-iterator.hh"
12 #include "context.hh"
14 class Volta_repeat_iterator : public Sequential_iterator
16 public:
17 DECLARE_SCHEME_CALLBACK (constructor, ());
18 Volta_repeat_iterator ();
20 void add_repeat_command (SCM);
21 protected:
22 virtual SCM get_music_list () const;
23 virtual void next_element (bool);
24 virtual void construct_children ();
25 virtual void process (Moment);
27 bool first_time_;
28 int alt_count_;
29 int rep_count_;
30 int done_count_;
33 Volta_repeat_iterator::Volta_repeat_iterator ()
35 done_count_ = alt_count_ = rep_count_ = 0;
36 first_time_ = true;
39 SCM
40 Volta_repeat_iterator::get_music_list ()const
42 return scm_cons (get_music ()->get_property ("element"),
43 get_music ()->get_property ("elements"));
46 void
47 Volta_repeat_iterator::construct_children ()
49 Sequential_iterator::construct_children ();
51 SCM alts = get_music ()->get_property ("elements");
53 alt_count_ = scm_ilength (alts);
54 rep_count_ = scm_to_int (get_music ()->get_property ("repeat-count"));
55 done_count_ = 0;
59 TODO: add source information for debugging
61 void
62 Volta_repeat_iterator::add_repeat_command (SCM what)
64 SCM reps = ly_symbol2scm ("repeatCommands");
65 SCM current_reps = SCM_EOL;
66 Context *where = get_outlet ()->where_defined (reps, &current_reps);
68 if (where
69 && current_reps == SCM_EOL || scm_is_pair (current_reps))
71 current_reps = scm_cons (what, current_reps);
72 where->set_property (reps, current_reps);
76 void
77 Volta_repeat_iterator::next_element (bool side_effect)
79 done_count_++;
81 Sequential_iterator::next_element (side_effect);
83 if (side_effect)
85 if (alt_count_)
87 string repstr = to_string (rep_count_ - alt_count_ + done_count_) + ".";
88 if (done_count_ > 1)
90 add_repeat_command (scm_list_n (ly_symbol2scm ("volta"), SCM_BOOL_F, SCM_UNDEFINED));
92 if (done_count_ - 1 < alt_count_)
93 add_repeat_command (ly_symbol2scm ("end-repeat"));
96 if (done_count_ == 1 && alt_count_ < rep_count_)
97 repstr = "1.--" + to_string (rep_count_ - alt_count_ + done_count_) + ".";
99 if (done_count_ <= alt_count_)
100 add_repeat_command (scm_list_n (ly_symbol2scm ("volta"),
101 scm_makfrom0str (repstr.c_str ()), SCM_UNDEFINED));
103 else
104 add_repeat_command (ly_symbol2scm ("end-repeat"));
108 void
109 Volta_repeat_iterator::process (Moment m)
111 if (first_time_)
113 add_repeat_command (ly_symbol2scm ("start-repeat"));
114 first_time_ = false;
116 Sequential_iterator::process (m);
119 IMPLEMENT_CTOR_CALLBACK (Volta_repeat_iterator);