2 repeated-music.cc -- implement Repeated_music
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
9 #include "repeated-music.hh"
10 #include "music-sequence.hh"
13 #include "program-option.hh"
16 Repeated_music::body (Music *me)
18 return unsmob_music (me->get_property ("element"));
22 Repeated_music::alternatives (Music *me)
24 return me->get_property ("elements");
27 MAKE_SCHEME_CALLBACK (Repeated_music, relative_callback, 2);
29 Repeated_music::relative_callback (SCM music, SCM pitch)
31 Pitch p = *unsmob_pitch (pitch);
32 Music *me = unsmob_music (music);
33 if (lily_1_8_relative)
35 Music *body = unsmob_music (me->get_property ("element"));
37 p = body->to_relative_octave (p);
40 SCM alternatives = me->get_property ("elements");
42 for (SCM s = alternatives; scm_is_pair (s); s = scm_cdr (s))
44 lily_1_8_compatibility_used = true;
45 unsmob_music (scm_car (s))->to_relative_octave (p);
48 return last.smobbed_copy ();
51 return me->generic_to_relative_octave (p).smobbed_copy ();
55 Repeated_music::alternatives_get_length (Music *me, bool fold)
57 SCM alternative_list = alternatives (me);
58 int len = scm_ilength (alternative_list);
63 return Music_sequence::maximum_length (alternative_list);
67 int count = robust_scm2int (me->get_property ("repeat-count"), 0);
69 SCM p = alternative_list;
70 while (scm_is_pair (p) && done < count)
72 m = m + unsmob_music (scm_car (p))->get_length ();
74 if (count - done < len)
81 Sum all duration of all available alternatives. This is for the case
82 of volta repeats, where the alternatives are iterated just as they
85 Repeated_music::alternatives_volta_get_length (Music *me)
87 return Music_sequence::cumulative_length (alternatives (me));
91 Length of the body in THIS. Disregards REPEAT-COUNT.
94 Repeated_music::body_get_length (Music *me)
97 if (Music *body = unsmob_music (me->get_property ("element")))
98 m = body->get_length ();
102 MAKE_SCHEME_CALLBACK (Repeated_music, unfolded_music_length, 1);
105 Repeated_music::unfolded_music_length (SCM m)
107 Music *me = unsmob_music (m);
109 Moment l = Moment (repeat_count (me)) * body_get_length (me) + alternatives_get_length (me, false);
110 return l.smobbed_copy ();
113 MAKE_SCHEME_CALLBACK (Repeated_music, folded_music_length, 1);
115 Repeated_music::folded_music_length (SCM m)
117 Music *me = unsmob_music (m);
119 Moment l = body_get_length (me) + alternatives_get_length (me, true);
120 return l.smobbed_copy ();
124 Repeated_music::repeat_count (Music *me)
126 return scm_to_int (me->get_property ("repeat-count"));
129 MAKE_SCHEME_CALLBACK (Repeated_music, volta_music_length, 1);
131 Repeated_music::volta_music_length (SCM m)
133 Music *me = unsmob_music (m);
134 Moment l = body_get_length (me) + alternatives_volta_get_length (me);
135 return l.smobbed_copy ();
138 MAKE_SCHEME_CALLBACK (Repeated_music, minimum_start, 1);
140 Repeated_music::minimum_start (SCM m)
142 Music *me = unsmob_music (m);
143 Music *body = unsmob_music (me->get_property ("element"));
146 return body->start_mom ().smobbed_copy ();
148 return Music_sequence::minimum_start (me->get_property ("elements")).smobbed_copy ();
151 MAKE_SCHEME_CALLBACK (Repeated_music, first_start, 1);
153 Repeated_music::first_start (SCM m)
155 Music *me = unsmob_music (m);
156 Music *body = unsmob_music (me->get_property ("element"));
158 Moment rv = (body) ? body->start_mom ()
159 : Music_sequence::first_start (me->get_property ("elements"));
161 return rv.smobbed_copy ();