]> git.donarmstrong.com Git - lilypond.git/blob - lily/percent-repeat-iterator.cc
5a9718cb75d77b179ec684d8ac51b852f8de0031
[lilypond.git] / lily / percent-repeat-iterator.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2001--2009  Han-Wen Nienhuys <hanwen@xs4all.nl>
5                   Erik Sandberg <mandolaerik@gmail.com>
6
7   LilyPond is free software: you can redistribute it and/or modify
8   it under the terms of the GNU General Public License as published by
9   the Free Software Foundation, either version 3 of the License, or
10   (at your option) any later version.
11
12   LilyPond is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU General Public License for more details.
16
17   You should have received a copy of the GNU General Public License
18   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "input.hh"
22 #include "repeated-music.hh"
23 #include "sequential-iterator.hh"
24
25 class Percent_repeat_iterator : public Sequential_iterator
26 {
27 public:
28   DECLARE_CLASSNAME (Percent_repeat_iterator);
29   DECLARE_SCHEME_CALLBACK (constructor, ());
30   Percent_repeat_iterator ();
31 protected:
32   virtual SCM get_music_list () const;
33 };
34
35 IMPLEMENT_CTOR_CALLBACK (Percent_repeat_iterator);
36
37 Percent_repeat_iterator::Percent_repeat_iterator ()
38 {
39 }
40
41 SCM
42 Percent_repeat_iterator::get_music_list () const
43 {
44   /* TODO: Distinction between percent, double-percent and slash */
45   Music *mus = get_music ();
46   Music *child = Repeated_music::body (mus);
47   SCM length = child->get_length ().smobbed_copy ();
48   SCM child_list = SCM_EOL;
49
50   int repeats = scm_to_int (mus->get_property ("repeat-count"));
51   for (int i = repeats; i > 1; i--)
52   {
53     Music *percent = make_music_by_name (ly_symbol2scm ("PercentEvent"));
54     percent->set_spot (*mus->origin ());
55     percent->set_property ("length", length);
56     if (repeats > 1)
57       percent->set_property ("repeat-count", scm_int2num (i));
58     
59     child_list = scm_cons (percent->unprotect (), child_list);
60   }
61   
62   child_list = scm_cons (child->self_scm (), child_list);
63
64   return child_list;
65 }