2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1999--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 #include "repeated-music.hh"
21 #include "music-sequence.hh"
24 #include "program-option.hh"
27 Repeated_music::body (Music *me)
29 return unsmob<Music> (me->get_property ("element"));
33 Repeated_music::alternatives (Music *me)
35 return me->get_property ("elements");
39 Repeated_music::alternatives_get_length (Music *me, bool fold)
41 SCM alternative_list = alternatives (me);
42 int len = scm_ilength (alternative_list);
47 return Music_sequence::maximum_length (alternative_list);
51 int count = robust_scm2int (me->get_property ("repeat-count"), 0);
53 SCM p = alternative_list;
54 while (scm_is_pair (p) && done < count)
56 m = m + unsmob<Music> (scm_car (p))->get_length ();
58 if (count - done < len)
65 Sum all duration of all available alternatives. This is for the case
66 of volta repeats, where the alternatives are iterated just as they
69 Repeated_music::alternatives_volta_get_length (Music *me)
71 return Music_sequence::cumulative_length (alternatives (me));
75 Length of the body in THIS. Disregards REPEAT-COUNT.
78 Repeated_music::body_get_length (Music *me)
81 if (Music *body = unsmob<Music> (me->get_property ("element")))
82 m = body->get_length ();
86 MAKE_SCHEME_CALLBACK (Repeated_music, unfolded_music_length, 1);
89 Repeated_music::unfolded_music_length (SCM m)
91 Music *me = unsmob<Music> (m);
93 Moment l = Moment (repeat_count (me)) * body_get_length (me) + alternatives_get_length (me, false);
94 return l.smobbed_copy ();
97 MAKE_SCHEME_CALLBACK (Repeated_music, folded_music_length, 1);
99 Repeated_music::folded_music_length (SCM m)
101 Music *me = unsmob<Music> (m);
103 Moment l = body_get_length (me) + alternatives_get_length (me, true);
104 return l.smobbed_copy ();
108 Repeated_music::repeat_count (Music *me)
110 return scm_to_int (me->get_property ("repeat-count"));
113 MAKE_SCHEME_CALLBACK (Repeated_music, volta_music_length, 1);
115 Repeated_music::volta_music_length (SCM m)
117 Music *me = unsmob<Music> (m);
118 Moment l = body_get_length (me) + alternatives_volta_get_length (me);
119 return l.smobbed_copy ();
122 MAKE_SCHEME_CALLBACK (Repeated_music, minimum_start, 1);
124 Repeated_music::minimum_start (SCM m)
126 Music *me = unsmob<Music> (m);
127 Music *body = unsmob<Music> (me->get_property ("element"));
130 return body->start_mom ().smobbed_copy ();
132 return Music_sequence::minimum_start (me->get_property ("elements")).smobbed_copy ();
135 MAKE_SCHEME_CALLBACK (Repeated_music, first_start, 1);
137 Repeated_music::first_start (SCM m)
139 Music *me = unsmob<Music> (m);
140 Music *body = unsmob<Music> (me->get_property ("element"));
142 Moment rv = (body) ? body->start_mom ()
143 : Music_sequence::first_start (me->get_property ("elements"));
145 return rv.smobbed_copy ();