Use scalar instead of embedded_scm for context mod overrides.
[lilypond/mpolesky.git] / lily / music-sequence.cc
blob70a2eaa862c9c246dac7bc183511fa45ec1a4f65
1 /*
2 music-sequence.cc -- implement Music_sequence
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
9 #include "music-sequence.hh"
11 #include "warn.hh"
12 #include "program-option.hh"
13 #include "music.hh"
14 #include "input.hh"
16 void
17 transpose_music_list (SCM lst, Pitch rq)
19 for (SCM s = lst; scm_is_pair (s); s = scm_cdr (s))
20 unsmob_music (scm_car (s))->transpose (rq);
23 Moment
24 Music_sequence::cumulative_length (SCM l)
26 Moment cumulative;
27 Moment last_len;
29 for (SCM s = l; scm_is_pair (s); s = scm_cdr (s))
31 Moment l = unsmob_music (scm_car (s))->get_length ();
32 if (last_len.grace_part_ && l.main_part_)
33 last_len.grace_part_ = Rational (0);
34 cumulative += last_len;
35 last_len = l;
38 last_len.grace_part_ = Rational (0);
39 cumulative += last_len;
41 return cumulative;
44 Moment
45 Music_sequence::maximum_length (SCM l)
47 Moment dur = 0;
48 for (SCM s = l; scm_is_pair (s); s = scm_cdr (s))
50 Music *m = unsmob_music (scm_car (s));
51 if (!m)
52 programming_error ("Music sequence should have music elements");
53 else
55 Moment l = m->get_length ();
56 dur = max (dur, l);
60 return dur;
63 MAKE_SCHEME_CALLBACK (Music_sequence, maximum_length_callback, 1);
64 SCM
65 Music_sequence::maximum_length_callback (SCM m)
67 Music *me = unsmob_music (m);
68 return maximum_length (me->get_property ("elements")).smobbed_copy ();
71 MAKE_SCHEME_CALLBACK (Music_sequence, cumulative_length_callback, 1);
72 SCM
73 Music_sequence::cumulative_length_callback (SCM m)
75 Music *me = unsmob_music (m);
76 return cumulative_length (me->get_property ("elements")).smobbed_copy ();
79 MAKE_SCHEME_CALLBACK (Music_sequence, minimum_start_callback, 1);
80 SCM
81 Music_sequence::minimum_start_callback (SCM m)
83 Music *me = unsmob_music (m);
84 return minimum_start (me->get_property ("elements")).smobbed_copy ();
87 MAKE_SCHEME_CALLBACK (Music_sequence, first_start_callback, 1);
88 SCM
89 Music_sequence::first_start_callback (SCM m)
91 Music *me = unsmob_music (m);
92 return first_start (me->get_property ("elements")).smobbed_copy ();
95 Pitch
96 music_list_to_relative (SCM l, Pitch p, bool ret_first)
98 Pitch first = p;
99 int count = 0;
101 Pitch last = p;
102 for (SCM s = l; scm_is_pair (s); s = scm_cdr (s))
104 if (Music *m = unsmob_music (scm_car (s)))
106 last = m->to_relative_octave (last);
107 if (!count++)
108 first = last;
112 return (ret_first) ? first : last;
115 void
116 compress_music_list (SCM l, Moment m)
118 for (SCM s = l; scm_is_pair (s); s = scm_cdr (s))
119 unsmob_music (scm_car (s))->compress (m);
122 Moment
123 Music_sequence::minimum_start (SCM l)
125 Moment m;
127 for (SCM s = l; scm_is_pair (s); s = scm_cdr (s))
128 m = min (m, unsmob_music (scm_car (s))->start_mom ());
129 return m;
132 Moment
133 Music_sequence::first_start (SCM l)
135 Moment m;
137 for (SCM s = l; scm_is_pair (s); s = scm_cdr (s))
139 Music *mus = unsmob_music (scm_car (s));
140 Moment l = mus->get_length ();
141 Moment s = mus->start_mom ();
142 if (l.to_bool () || s.to_bool ())
143 return s;
145 return m;
148 MAKE_SCHEME_CALLBACK (Music_sequence, simultaneous_relative_callback, 2);
150 Music_sequence::simultaneous_relative_callback (SCM music, SCM pitch)
152 Music *me = unsmob_music (music);
153 Pitch p = *unsmob_pitch (pitch);
155 SCM elts = me->get_property ("elements");
156 SCM copied = SCM_EOL;
157 if (lily_1_8_relative)
158 copied = ly_music_deep_copy (elts);
160 Pitch retval = music_list_to_relative (elts, p, false);
162 if (lily_1_8_relative)
165 Pitch retval_1_8 = music_list_to_relative (copied, p, true);
166 if (retval_1_8 != retval)
167 lily_1_8_compatibility_used = true;
169 retval = retval_1_8;
172 return retval.smobbed_copy ();
175 MAKE_SCHEME_CALLBACK (Music_sequence, event_chord_relative_callback, 2);
177 Music_sequence::event_chord_relative_callback (SCM music, SCM pitch)
179 Music *me = unsmob_music (music);
180 Pitch p = *unsmob_pitch (pitch);
181 return music_list_to_relative (me->get_property ("elements"),
182 p, true).smobbed_copy ();