2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1998--2012 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 #include "music-sequence.hh"
23 #include "program-option.hh"
28 transpose_music_list (SCM lst, Pitch rq)
30 for (SCM s = lst; scm_is_pair (s); s = scm_cdr (s))
31 unsmob_music (scm_car (s))->transpose (rq);
35 Music_sequence::cumulative_length (SCM l)
40 for (SCM s = l; scm_is_pair (s); s = scm_cdr (s))
42 Moment l = unsmob_music (scm_car (s))->get_length ();
43 if (last_len.grace_part_ && l.main_part_)
44 last_len.grace_part_ = Rational (0);
45 cumulative += last_len;
49 last_len.grace_part_ = Rational (0);
50 cumulative += last_len;
56 Music_sequence::maximum_length (SCM l)
59 for (SCM s = l; scm_is_pair (s); s = scm_cdr (s))
61 Music *m = unsmob_music (scm_car (s));
63 programming_error ("Music sequence should have music elements");
66 Moment l = m->get_length ();
74 MAKE_SCHEME_CALLBACK (Music_sequence, maximum_length_callback, 1);
76 Music_sequence::maximum_length_callback (SCM m)
78 Music *me = unsmob_music (m);
79 return maximum_length (me->get_property ("elements")).smobbed_copy ();
82 MAKE_SCHEME_CALLBACK (Music_sequence, cumulative_length_callback, 1);
84 Music_sequence::cumulative_length_callback (SCM m)
86 Music *me = unsmob_music (m);
87 return cumulative_length (me->get_property ("elements")).smobbed_copy ();
90 MAKE_SCHEME_CALLBACK (Music_sequence, minimum_start_callback, 1);
92 Music_sequence::minimum_start_callback (SCM m)
94 Music *me = unsmob_music (m);
95 return minimum_start (me->get_property ("elements")).smobbed_copy ();
98 MAKE_SCHEME_CALLBACK (Music_sequence, first_start_callback, 1);
100 Music_sequence::first_start_callback (SCM m)
102 Music *me = unsmob_music (m);
103 return first_start (me->get_property ("elements")).smobbed_copy ();
107 music_list_to_relative (SCM l, Pitch p, bool ret_first)
113 for (SCM s = l; scm_is_pair (s); s = scm_cdr (s))
115 if (Music *m = unsmob_music (scm_car (s)))
117 last = m->to_relative_octave (last);
123 return (ret_first) ? first : last;
127 compress_music_list (SCM l, Moment m)
129 for (SCM s = l; scm_is_pair (s); s = scm_cdr (s))
130 unsmob_music (scm_car (s))->compress (m);
134 Music_sequence::minimum_start (SCM l)
138 for (SCM s = l; scm_is_pair (s); s = scm_cdr (s))
139 m = min (m, unsmob_music (scm_car (s))->start_mom ());
144 Music_sequence::first_start (SCM l)
147 for (SCM s = l; scm_is_pair (s); s = scm_cdr (s))
149 Music *mus = unsmob_music (scm_car (s));
150 Moment start = mus->start_mom ();
151 if (mus->get_length ().to_bool () || start.to_bool ())
157 MAKE_SCHEME_CALLBACK (Music_sequence, simultaneous_relative_callback, 2);
159 Music_sequence::simultaneous_relative_callback (SCM music, SCM pitch)
161 Music *me = unsmob_music (music);
162 Pitch p = *unsmob_pitch (pitch);
164 SCM elts = me->get_property ("elements");
165 SCM copied = SCM_EOL;
166 if (lily_1_8_relative)
167 copied = ly_music_deep_copy (elts);
169 Pitch retval = music_list_to_relative (elts, p, false);
171 if (lily_1_8_relative)
174 Pitch retval_1_8 = music_list_to_relative (copied, p, true);
175 if (retval_1_8 != retval)
176 lily_1_8_compatibility_used = true;
181 return retval.smobbed_copy ();
184 MAKE_SCHEME_CALLBACK (Music_sequence, event_chord_relative_callback, 2);
186 Music_sequence::event_chord_relative_callback (SCM music, SCM pitch)
188 Music *me = unsmob_music (music);
189 Pitch p = *unsmob_pitch (pitch);
190 return music_list_to_relative (me->get_property ("elements"),
191 p, true).smobbed_copy ();
194 MAKE_SCHEME_CALLBACK (Music_sequence, repeated_chord_relative_callback, 2);
196 Music_sequence::repeated_chord_relative_callback (SCM music, SCM pitch)
198 Music *me = unsmob_music (music);
199 Music *repeated_chord = unsmob_music (me->get_property ("element"));
200 Music *original_chord = unsmob_music (me->get_property ("original-chord"));
202 /* A repeated chord octave is not computed from the previous pitch,
203 * (this function `pitch' argument), but from the original chord, so
204 * that repeated chords have the same octave have the original chord,
205 * even though other simple notes have been entered meanwhile.
207 assert (repeated_chord);
209 /* Get the original chord first pitch */
212 for (SCM s = original_chord->get_property ("elements"); scm_is_pair (s); s = scm_cdr (s))
214 if (Music *m = unsmob_music (scm_car (s)))
216 p = unsmob_pitch (m->get_property ("pitch"));
222 /* Use the `pitch' argument if no pitch found in original chord. */
224 p = unsmob_pitch (pitch);
226 /* Change the first note pitch to -1, to avoid octaviation. Indeed,
227 * the first pitch should be the same as the original chord first
229 for (SCM s = repeated_chord->get_property ("elements"); scm_is_pair (s); s = scm_cdr (s))
231 if (Music *m = unsmob_music (scm_car (s)))
233 Pitch *first_pitch = unsmob_pitch (m->get_property ("pitch"));
236 Pitch new_pitch = Pitch (-1,
237 first_pitch->get_notename (),
238 first_pitch->get_alteration ());
239 m->set_property ("pitch", new_pitch.smobbed_copy ());
244 music_list_to_relative (repeated_chord->get_property ("elements"), *p, true).smobbed_copy ();
245 /* Return `pitch' instead of the repeated chord first pitch,
246 * because `pitch' is the last explicitly entered pitch */