2 repeated-music.cc -- implement Repeated_music
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2003 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_mus_property ("element"));
24 Repeated_music::alternatives ()const
26 return get_mus_property ("elements");
33 Repeated_music::to_relative_octave (Pitch p)
35 if (lily_1_8_relative)
37 lily_1_8_compatibility_used = true;
39 p = body ()->to_relative_octave (p);
43 for (SCM s = alternatives (); gh_pair_p (s); s = ly_cdr (s))
44 unsmob_music (ly_car (s))->to_relative_octave (p);
51 return Music::to_relative_octave (p);
57 Repeated_music::alternatives_get_length (bool fold) const
63 return Music_sequence::maximum_length (alternatives ());
68 SCM p = alternatives ();
69 while (gh_pair_p (p) && done < repeat_count ())
71 m = m + unsmob_music (ly_car (p))->get_length ();
73 if (repeat_count () - done < scm_ilength (alternatives ()))
80 Sum all duration of all available alternatives. This is for the case
81 of volta repeats, where the alternatives are iterated just as they
84 Repeated_music::alternatives_volta_get_length () const
90 SCM p = alternatives ();
93 m = m + unsmob_music (ly_car (p))->get_length ();
101 Length of the body in THIS. Disregards REPEAT-COUNT.
104 Repeated_music::body_get_length () const
109 m = body ()->get_length ();
115 Repeated_music::repeat_count () const
117 return gh_scm2int (get_mus_property ("repeat-count"));
121 MAKE_SCHEME_CALLBACK (Repeated_music,unfolded_music_length, 1);
122 MAKE_SCHEME_CALLBACK (Repeated_music,folded_music_length, 1);
123 MAKE_SCHEME_CALLBACK (Repeated_music,volta_music_length, 1);
126 Repeated_music::unfolded_music_length (SCM m)
128 Repeated_music* r = dynamic_cast<Repeated_music*> (unsmob_music (m));
130 Moment l = Moment (r->repeat_count ()) * r->body_get_length () + r->alternatives_get_length (false);
131 return l.smobbed_copy ();
135 Repeated_music::folded_music_length (SCM m)
137 Repeated_music* r = dynamic_cast<Repeated_music*> (unsmob_music (m));
139 Moment l = r->body_get_length () + r->alternatives_get_length (true);
140 return l.smobbed_copy ();
144 Repeated_music::volta_music_length (SCM m)
146 Repeated_music* r = dynamic_cast<Repeated_music*> (unsmob_music (m));
147 Moment l = r->body_get_length () + r->alternatives_volta_get_length ();
148 return l.smobbed_copy ();
151 ADD_MUSIC (Repeated_music);
153 Repeated_music::Repeated_music ()
159 MAKE_SCHEME_CALLBACK (Repeated_music,minimum_start, 1);
160 MAKE_SCHEME_CALLBACK (Repeated_music,first_start, 1);
163 Repeated_music::minimum_start (SCM m)
165 Music * me = unsmob_music (m);
166 Music * body = unsmob_music (me->get_mus_property ("element"));
169 return body->start_mom ().smobbed_copy();
172 return Music_sequence::minimum_start (me->get_mus_property ("elements")).smobbed_copy();
177 Repeated_music::first_start (SCM m)
179 Music * me = unsmob_music (m);
180 Music * body = unsmob_music (me->get_mus_property ("element"));
182 Moment rv = (body) ? body->start_mom () :
183 Music_sequence::first_start (me->get_mus_property ("elements"));
185 return rv.smobbed_copy ();