2 repeated-music.cc -- implement Repeated_music
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "repeated-music.hh"
11 #include "music-list.hh"
14 #include "music-sequence.hh"
17 Repeated_music::body ()const
19 return unsmob_music (get_mus_property ("element"));
23 Repeated_music::alternatives ()const
25 return get_mus_property ("elements");
29 Repeated_music::Repeated_music (SCM l)
32 set_mus_property ("type", ly_symbol2scm ("repeated-music"));
37 Repeated_music::to_relative_octave (Pitch p)
40 p = body ()->to_relative_octave (p);
44 for (SCM s = alternatives (); gh_pair_p (s); s = ly_cdr (s))
45 unsmob_music (ly_car (s))->to_relative_octave (p);
52 Repeated_music::transpose (Pitch p)
55 body ()->transpose (p);
57 Music_sequence::transpose_list (get_mus_property ("elements"), p);
61 Repeated_music::compress (Moment p)
64 body ()->compress (p);
66 Music_sequence::compress_list (alternatives (), p);
70 Repeated_music::alternatives_length_mom (bool fold) const
76 return Music_sequence::maximum_length (alternatives ());
81 SCM p = alternatives ();
82 while (gh_pair_p (p) && done < repeat_count ())
84 m = m + unsmob_music (ly_car (p))->length_mom ();
86 if (repeat_count () - done < scm_ilength (alternatives ()))
93 Sum all duration of all available alternatives. This is for the case
94 of volta repeats, where the alternatives are iterated just as they
97 Repeated_music::alternatives_volta_length_mom () const
103 SCM p = alternatives ();
104 while (gh_pair_p (p))
106 m = m + unsmob_music (ly_car (p))->length_mom ();
114 Length of the body in THIS. Disregards REPEAT-COUNT.
117 Repeated_music::body_length_mom () const
122 m = body ()->length_mom ();
128 Repeated_music::repeat_count () const
130 return gh_scm2int (get_mus_property ("repeat-count"));
134 MAKE_SCHEME_CALLBACK (Repeated_music,unfolded_music_length, 1);
135 MAKE_SCHEME_CALLBACK (Repeated_music,folded_music_length, 1);
136 MAKE_SCHEME_CALLBACK (Repeated_music,volta_music_length, 1);
139 Repeated_music::unfolded_music_length (SCM m)
141 Repeated_music* r = dynamic_cast<Repeated_music*> (unsmob_music (m));
143 Moment l = Moment (r->repeat_count ()) * r->body_length_mom () + r->alternatives_length_mom (false);
144 return l.smobbed_copy ();
148 Repeated_music::folded_music_length (SCM m)
150 Repeated_music* r = dynamic_cast<Repeated_music*> (unsmob_music (m));
152 Moment l = r->body_length_mom () + r->alternatives_length_mom (true);
153 return l.smobbed_copy ();
157 Repeated_music::volta_music_length (SCM m)
159 Repeated_music* r = dynamic_cast<Repeated_music*> (unsmob_music (m));
160 Moment l = r->body_length_mom () + r->alternatives_volta_length_mom ();
161 return l.smobbed_copy ();
164 ADD_MUSIC (Repeated_music);
166 Repeated_music::Repeated_music ()
169 set_mus_property ("type", ly_symbol2scm ("repeated-music"));
173 MAKE_SCHEME_CALLBACK (Repeated_music,minimum_start, 1);
174 MAKE_SCHEME_CALLBACK (Repeated_music,first_start, 1);
177 Repeated_music::minimum_start (SCM m)
179 Music * me = unsmob_music (m);
180 Music * body = unsmob_music (me->get_mus_property ("element"));
183 return body->start_mom ().smobbed_copy();
186 return Music_sequence::minimum_start (me->get_mus_property ("elements")).smobbed_copy();
191 Repeated_music::first_start (SCM m)
193 Music * me = unsmob_music (m);
194 Music * body = unsmob_music (me->get_mus_property ("element"));
196 Moment rv = (body) ? body->start_mom () :
197 Music_sequence::first_start (me->get_mus_property ("elements"));
199 return rv.smobbed_copy ();