2 repeated-music.cc -- implement Repeated_music
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "repeated-music.hh"
11 #include "music-sequence.hh"
14 #include "scm-option.hh"
17 Repeated_music::body (Music *me)
19 return unsmob_music (me->get_property ("element"));
23 Repeated_music::alternatives (Music *me)
25 return me->get_property ("elements");
28 MAKE_SCHEME_CALLBACK(Repeated_music, relative_callback, 2);
30 Repeated_music::relative_callback (SCM music, SCM pitch)
32 Pitch p = *unsmob_pitch (pitch);
33 Music *me = unsmob_music (music);
34 if (lily_1_8_relative)
36 Music *body = unsmob_music (me->get_property ("element"));
38 p = body->to_relative_octave (p);
41 SCM alternatives = me->get_property ("elements");
43 for (SCM s = alternatives; scm_is_pair (s); s = scm_cdr (s))
45 lily_1_8_compatibility_used = true;
46 unsmob_music (scm_car (s))->to_relative_octave (p);
49 return last.smobbed_copy ();
53 return me->generic_to_relative_octave (p).smobbed_copy ();
59 Repeated_music::alternatives_get_length (Music *me, bool fold)
61 SCM alternative_list = alternatives (me);
62 int len = scm_ilength (alternative_list);
67 return Music_sequence::maximum_length (alternative_list);
71 int count = robust_scm2int (me->get_property ("repeat-count"), 0);
73 SCM p = alternative_list;
74 while (scm_is_pair (p) && done < count)
76 m = m + unsmob_music (scm_car (p))->get_length ();
78 if (count - done < len)
85 Sum all duration of all available alternatives. This is for the case
86 of volta repeats, where the alternatives are iterated just as they
89 Repeated_music::alternatives_volta_get_length (Music *me)
91 return Music_sequence::cumulative_length (alternatives (me));
96 Length of the body in THIS. Disregards REPEAT-COUNT.
99 Repeated_music::body_get_length (Music *me)
102 if (Music *body = unsmob_music (me->get_property ("element")))
104 m = body->get_length ();
110 MAKE_SCHEME_CALLBACK (Repeated_music, unfolded_music_length, 1);
113 Repeated_music::unfolded_music_length (SCM m)
115 Music *me = unsmob_music (m);
117 Moment l = Moment (repeat_count (me)) * body_get_length (me) + alternatives_get_length (me, false);
118 return l.smobbed_copy ();
121 MAKE_SCHEME_CALLBACK (Repeated_music, folded_music_length, 1);
123 Repeated_music::folded_music_length (SCM m)
125 Music *me = unsmob_music (m);
127 Moment l = body_get_length (me) + alternatives_get_length (me, true);
128 return l.smobbed_copy ();
132 Repeated_music::repeat_count (Music *me)
134 return scm_to_int (me->get_property ("repeat-count"));
137 MAKE_SCHEME_CALLBACK (Repeated_music, volta_music_length, 1);
139 Repeated_music::volta_music_length (SCM m)
141 Music *me = unsmob_music (m);
142 Moment l = body_get_length (me) + alternatives_volta_get_length (me);
143 return l.smobbed_copy ();
146 MAKE_SCHEME_CALLBACK (Repeated_music, minimum_start, 1);
148 Repeated_music::minimum_start (SCM m)
150 Music *me = unsmob_music (m);
151 Music *body = unsmob_music (me->get_property ("element"));
154 return body->start_mom ().smobbed_copy ();
157 return Music_sequence::minimum_start (me->get_property ("elements")).smobbed_copy ();
161 MAKE_SCHEME_CALLBACK (Repeated_music, first_start, 1);
163 Repeated_music::first_start (SCM m)
165 Music * me = unsmob_music (m);
166 Music * body = unsmob_music (me->get_property ("element"));
168 Moment rv = (body) ? body->start_mom () :
169 Music_sequence::first_start (me->get_property ("elements"));
171 return rv.smobbed_copy ();