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