Use scalar instead of embedded_scm for context mod overrides.
[lilypond/mpolesky.git] / lily / repeated-music.cc
blob7a004c82633e03e16dc5d09ba254fb84179b0c20
1 /*
2 repeated-music.cc -- implement Repeated_music
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
9 #include "repeated-music.hh"
10 #include "music-sequence.hh"
11 #include "pitch.hh"
12 #include "warn.hh"
13 #include "program-option.hh"
15 Music *
16 Repeated_music::body (Music *me)
18 return unsmob_music (me->get_property ("element"));
21 SCM
22 Repeated_music::alternatives (Music *me)
24 return me->get_property ("elements");
27 MAKE_SCHEME_CALLBACK (Repeated_music, relative_callback, 2);
28 SCM
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"));
36 if (body)
37 p = body->to_relative_octave (p);
39 Pitch last = 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 ();
50 else
51 return me->generic_to_relative_octave (p).smobbed_copy ();
54 Moment
55 Repeated_music::alternatives_get_length (Music *me, bool fold)
57 SCM alternative_list = alternatives (me);
58 int len = scm_ilength (alternative_list);
59 if (len <= 0)
60 return 0;
62 if (fold)
63 return Music_sequence::maximum_length (alternative_list);
65 Moment m = 0;
66 int done = 0;
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 ();
73 done++;
74 if (count - done < len)
75 p = scm_cdr (p);
77 return m;
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
83 were entered. */
84 Moment
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.
93 Moment
94 Repeated_music::body_get_length (Music *me)
96 Moment m = 0;
97 if (Music *body = unsmob_music (me->get_property ("element")))
98 m = body->get_length ();
99 return m;
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"));
145 if (body)
146 return body->start_mom ().smobbed_copy ();
147 else
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 ();