]> git.donarmstrong.com Git - lilypond.git/blob - lily/percent-repeat-iterator.cc
495f30f33cff535e088a5b4d0ccc65a399d4009c
[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--2006  Han-Wen Nienhuys <hanwen@xs4all.nl>
7                   Erik Sandberg <mandolaerik@gmail.com>
8 */
9
10 #include "input.hh"
11 #include "music.hh"
12 #include "repeated-music.hh"
13 #include "sequential-iterator.hh"
14
15 class Percent_repeat_iterator : public Sequential_iterator
16 {
17 public:
18   DECLARE_CLASSNAME(Percent_repeat_iterator);
19   DECLARE_SCHEME_CALLBACK (constructor, ());
20   Percent_repeat_iterator ();
21 protected:
22   virtual SCM get_music_list () const;
23 };
24
25 IMPLEMENT_CTOR_CALLBACK (Percent_repeat_iterator);
26
27 Percent_repeat_iterator::Percent_repeat_iterator ()
28 {
29 }
30
31 SCM
32 Percent_repeat_iterator::get_music_list () const
33 {
34   /* TODO: Distinction between percent, double-percent and slash */
35   Music *mus = get_music ();
36   Music *child = Repeated_music::body (mus);
37   SCM length = child->get_length ().smobbed_copy ();
38   SCM child_list = SCM_EOL;
39
40   int repeats = scm_to_int (mus->get_property ("repeat-count"));
41   for (int i = repeats; i > 1; i--)
42   {
43     Music *percent = make_music_by_name (ly_symbol2scm ("PercentEvent"));
44     percent->set_spot (*mus->origin ());
45     percent->set_property ("length", length);
46     if (repeats > 1)
47       percent->set_property ("repeat-count", scm_int2num (i));
48     
49     child_list = scm_cons (percent->unprotect (), child_list);
50   }
51   
52   child_list = scm_cons (child->self_scm (), child_list);
53
54   return child_list;
55 }