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"
24 #include "duration.hh"
30 transpose_music_list (SCM lst, Pitch rq)
32 for (SCM s = lst; scm_is_pair (s); s = scm_cdr (s))
33 unsmob_music (scm_car (s))->transpose (rq);
37 Music_sequence::cumulative_length (SCM l)
42 for (SCM s = l; scm_is_pair (s); s = scm_cdr (s))
44 Moment l = unsmob_music (scm_car (s))->get_length ();
45 if (last_len.grace_part_ && l.main_part_)
46 last_len.grace_part_ = Rational (0);
47 cumulative += last_len;
51 last_len.grace_part_ = Rational (0);
52 cumulative += last_len;
58 Music_sequence::maximum_length (SCM l)
61 for (SCM s = l; scm_is_pair (s); s = scm_cdr (s))
63 Music *m = unsmob_music (scm_car (s));
65 programming_error ("Music sequence should have music elements");
68 Moment l = m->get_length ();
76 MAKE_SCHEME_CALLBACK (Music_sequence, maximum_length_callback, 1);
78 Music_sequence::maximum_length_callback (SCM m)
80 Music *me = unsmob_music (m);
81 return maximum_length (me->get_property ("elements")).smobbed_copy ();
84 MAKE_SCHEME_CALLBACK (Music_sequence, event_chord_length_callback, 1);
86 Music_sequence::event_chord_length_callback (SCM m)
88 Music *me = unsmob_music (m);
89 Duration *d = unsmob_duration (me->get_property ("duration"));
90 // Preset duration is used in chord repetitions.
92 Moment mom = d->get_length ();
93 return mom.smobbed_copy ();
95 return maximum_length (me->get_property ("elements")).smobbed_copy ();
98 MAKE_SCHEME_CALLBACK (Music_sequence, cumulative_length_callback, 1);
100 Music_sequence::cumulative_length_callback (SCM m)
102 Music *me = unsmob_music (m);
103 return cumulative_length (me->get_property ("elements")).smobbed_copy ();
106 MAKE_SCHEME_CALLBACK (Music_sequence, minimum_start_callback, 1);
108 Music_sequence::minimum_start_callback (SCM m)
110 Music *me = unsmob_music (m);
111 return minimum_start (me->get_property ("elements")).smobbed_copy ();
114 MAKE_SCHEME_CALLBACK (Music_sequence, first_start_callback, 1);
116 Music_sequence::first_start_callback (SCM m)
118 Music *me = unsmob_music (m);
119 return first_start (me->get_property ("elements")).smobbed_copy ();
123 music_list_to_relative (SCM l, Pitch p, bool ret_first)
129 for (SCM s = l; scm_is_pair (s); s = scm_cdr (s))
131 if (Music *m = unsmob_music (scm_car (s)))
133 last = m->to_relative_octave (last);
139 return (ret_first) ? first : last;
143 compress_music_list (SCM l, Moment m)
145 for (SCM s = l; scm_is_pair (s); s = scm_cdr (s))
146 unsmob_music (scm_car (s))->compress (m);
150 Music_sequence::minimum_start (SCM l)
154 for (SCM s = l; scm_is_pair (s); s = scm_cdr (s))
155 m = min (m, unsmob_music (scm_car (s))->start_mom ());
160 Music_sequence::first_start (SCM l)
163 for (SCM s = l; scm_is_pair (s); s = scm_cdr (s))
165 Music *mus = unsmob_music (scm_car (s));
166 Moment start = mus->start_mom ();
167 if (mus->get_length ().to_bool () || start.to_bool ())
173 MAKE_SCHEME_CALLBACK (Music_sequence, simultaneous_relative_callback, 2);
175 Music_sequence::simultaneous_relative_callback (SCM music, SCM pitch)
177 Music *me = unsmob_music (music);
178 Pitch p = *unsmob_pitch (pitch);
180 SCM elts = me->get_property ("elements");
181 SCM copied = SCM_EOL;
182 if (lily_1_8_relative)
183 copied = ly_music_deep_copy (elts);
185 Pitch retval = music_list_to_relative (elts, p, false);
187 if (lily_1_8_relative)
190 Pitch retval_1_8 = music_list_to_relative (copied, p, true);
191 if (retval_1_8 != retval)
192 lily_1_8_compatibility_used = true;
197 return retval.smobbed_copy ();
200 MAKE_SCHEME_CALLBACK (Music_sequence, event_chord_relative_callback, 2);
202 Music_sequence::event_chord_relative_callback (SCM music, SCM pitch)
204 Music *me = unsmob_music (music);
205 Pitch p = *unsmob_pitch (pitch);
206 return music_list_to_relative (me->get_property ("elements"),
207 p, true).smobbed_copy ();