]> git.donarmstrong.com Git - lilypond.git/blob - lily/percent-repeat-iterator.cc
Issue 4462/1: Create a module variable access system for C++
[lilypond.git] / lily / percent-repeat-iterator.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2001--2015  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 "context.hh"
22 #include "input.hh"
23 #include "repeated-music.hh"
24 #include "sequential-iterator.hh"
25 #include "lily-imports.hh"
26
27 class Percent_repeat_iterator : public Sequential_iterator
28 {
29 public:
30   DECLARE_CLASSNAME (Percent_repeat_iterator);
31   DECLARE_SCHEME_CALLBACK (constructor, ());
32   Percent_repeat_iterator ();
33 protected:
34   virtual SCM get_music_list () const;
35 };
36
37 IMPLEMENT_CTOR_CALLBACK (Percent_repeat_iterator);
38
39 Percent_repeat_iterator::Percent_repeat_iterator ()
40 {
41 }
42
43 SCM
44 Percent_repeat_iterator::get_music_list () const
45 {
46   Music *mus = get_music ();
47
48   Music *child = Repeated_music::body (mus);
49   SCM length = child->get_length ().smobbed_copy ();
50   SCM child_list = SCM_EOL;
51   Moment measure_len = measure_length (get_outlet ());
52   Moment music_len = robust_scm2moment (length, Moment (0));
53
54   string event_type;
55   SCM slash_count = SCM_EOL;
56
57   if (measure_len == music_len)
58     event_type = "PercentEvent";
59   else if (measure_len * Moment (2) == music_len)
60     event_type = "DoublePercentEvent";
61   else
62     {
63       slash_count = Lily::calc_repeat_slash_count (child->self_scm ());
64       event_type = "RepeatSlashEvent";
65     }
66
67   int repeats = scm_to_int (mus->get_property ("repeat-count"));
68   for (int i = repeats; i > 1; i--)
69     {
70       Music *percent = make_music_by_name (ly_symbol2scm (event_type.c_str ()));
71       percent->set_spot (*mus->origin ());
72       percent->set_property ("length", length);
73       if (repeats > 1)
74         {
75           percent->set_property ("repeat-count", scm_from_int (i));
76           if (event_type == "RepeatSlashEvent")
77             percent->set_property ("slash-count", slash_count);
78         }
79
80       child_list = scm_cons (percent->unprotect (), child_list);
81     }
82
83   child_list = scm_cons (child->self_scm (), child_list);
84
85   return child_list;
86 }