2 repeated-music.cc -- implement Repeated_music
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "repeated-music.hh"
11 #include "music-list.hh"
14 #include "music-sequence.hh"
15 #include "scm-option.hh"
18 Repeated_music::body ()const
20 return unsmob_music (get_property ("element"));
24 Repeated_music::alternatives ()const
26 return get_property ("elements");
33 Repeated_music::to_relative_octave (Pitch p
)
35 if (lily_1_8_relative
)
38 p
= body ()->to_relative_octave (p
);
43 lily_1_8_compatibility_used
= true;
45 for (SCM s
= alternatives (); ly_c_pair_p (s
); s
= ly_cdr (s
))
46 unsmob_music (ly_car (s
))->to_relative_octave (p
);
53 return Music::to_relative_octave (p
);
59 Repeated_music::alternatives_get_length (bool fold
) const
65 return Music_sequence::maximum_length (alternatives ());
70 SCM p
= alternatives ();
71 while (ly_c_pair_p (p
) && done
< repeat_count ())
73 m
= m
+ unsmob_music (ly_car (p
))->get_length ();
75 if (repeat_count () - done
< scm_ilength (alternatives ()))
82 Sum all duration of all available alternatives. This is for the case
83 of volta repeats, where the alternatives are iterated just as they
86 Repeated_music::alternatives_volta_get_length () const
92 SCM p
= alternatives ();
93 while (ly_c_pair_p (p
))
95 m
= m
+ unsmob_music (ly_car (p
))->get_length ();
103 Length of the body in THIS. Disregards REPEAT-COUNT.
106 Repeated_music::body_get_length () const
111 m
= body ()->get_length ();
117 Repeated_music::repeat_count () const
119 return ly_scm2int (get_property ("repeat-count"));
123 MAKE_SCHEME_CALLBACK (Repeated_music
,unfolded_music_length
, 1);
124 MAKE_SCHEME_CALLBACK (Repeated_music
,folded_music_length
, 1);
125 MAKE_SCHEME_CALLBACK (Repeated_music
,volta_music_length
, 1);
128 Repeated_music::unfolded_music_length (SCM m
)
130 Repeated_music
* r
= dynamic_cast<Repeated_music
*> (unsmob_music (m
));
132 Moment l
= Moment (r
->repeat_count ()) * r
->body_get_length () + r
->alternatives_get_length (false);
133 return l
.smobbed_copy ();
137 Repeated_music::folded_music_length (SCM m
)
139 Repeated_music
* r
= dynamic_cast<Repeated_music
*> (unsmob_music (m
));
141 Moment l
= r
->body_get_length () + r
->alternatives_get_length (true);
142 return l
.smobbed_copy ();
146 Repeated_music::volta_music_length (SCM m
)
148 Repeated_music
* r
= dynamic_cast<Repeated_music
*> (unsmob_music (m
));
149 Moment l
= r
->body_get_length () + r
->alternatives_volta_get_length ();
150 return l
.smobbed_copy ();
153 ADD_MUSIC (Repeated_music
);
155 Repeated_music::Repeated_music ()
161 MAKE_SCHEME_CALLBACK (Repeated_music
,minimum_start
, 1);
162 MAKE_SCHEME_CALLBACK (Repeated_music
,first_start
, 1);
165 Repeated_music::minimum_start (SCM m
)
167 Music
* me
= unsmob_music (m
);
168 Music
* body
= unsmob_music (me
->get_property ("element"));
171 return body
->start_mom ().smobbed_copy ();
174 return Music_sequence::minimum_start (me
->get_property ("elements")).smobbed_copy ();
179 Repeated_music::first_start (SCM m
)
181 Music
* me
= unsmob_music (m
);
182 Music
* body
= unsmob_music (me
->get_property ("element"));
184 Moment rv
= (body
) ? body
->start_mom () :
185 Music_sequence::first_start (me
->get_property ("elements"));
187 return rv
.smobbed_copy ();