(staff_eligible): new function.
[lilypond.git] / lily / repeated-music.cc
blobc047349fef64d91c11d2fac1c894cede8c70fdec
1 /*
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>
8 */
10 #include "repeated-music.hh"
11 #include "music-list.hh"
12 #include "pitch.hh"
13 #include "warn.hh"
14 #include "music-sequence.hh"
15 #include "scm-option.hh"
17 Music *
18 Repeated_music::body ()const
20 return unsmob_music (get_mus_property ("element"));
23 SCM
24 Repeated_music::alternatives ()const
26 return get_mus_property ("elements");
32 Pitch
33 Repeated_music::to_relative_octave (Pitch p)
35 if (lily_1_8_relative)
37 if (body ())
38 p = body ()->to_relative_octave (p);
40 Pitch last = p ;
41 if (alternatives ())
43 lily_1_8_compatibility_used = true;
45 for (SCM s = alternatives (); gh_pair_p (s); s = ly_cdr (s))
46 unsmob_music (ly_car (s))->to_relative_octave (p);
49 return last;
51 else
53 return Music::to_relative_octave (p);
58 Moment
59 Repeated_music::alternatives_get_length (bool fold) const
61 if (!alternatives ())
62 return 0;
64 if (fold)
65 return Music_sequence::maximum_length (alternatives ());
67 Moment m =0;
68 int done =0;
70 SCM p = alternatives ();
71 while (gh_pair_p (p) && done < repeat_count ())
73 m = m + unsmob_music (ly_car (p))->get_length ();
74 done ++;
75 if (repeat_count () - done < scm_ilength (alternatives ()))
76 p = ly_cdr (p);
78 return m;
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
84 were entered. */
85 Moment
86 Repeated_music::alternatives_volta_get_length () const
88 if (!alternatives ())
89 return 0;
91 Moment m;
92 SCM p = alternatives ();
93 while (gh_pair_p (p))
95 m = m + unsmob_music (ly_car (p))->get_length ();
96 p = ly_cdr (p);
98 return m;
103 Length of the body in THIS. Disregards REPEAT-COUNT.
105 Moment
106 Repeated_music::body_get_length () const
108 Moment m = 0;
109 if (body ())
111 m = body ()->get_length ();
113 return m;
117 Repeated_music::repeat_count () const
119 return gh_scm2int (get_mus_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 ()
156 : 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_mus_property ("element"));
170 if (body)
171 return body->start_mom ().smobbed_copy();
172 else
174 return Music_sequence::minimum_start (me->get_mus_property ("elements")).smobbed_copy();
179 Repeated_music::first_start (SCM m)
181 Music * me = unsmob_music (m);
182 Music * body = unsmob_music (me->get_mus_property ("element"));
184 Moment rv = (body) ? body->start_mom () :
185 Music_sequence::first_start (me->get_mus_property ("elements"));
187 return rv.smobbed_copy ();