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.
93 Moment mom = d->get_length ();
94 return mom.smobbed_copy ();
96 return maximum_length (me->get_property ("elements")).smobbed_copy ();
99 MAKE_SCHEME_CALLBACK (Music_sequence, cumulative_length_callback, 1);
101 Music_sequence::cumulative_length_callback (SCM m)
103 Music *me = unsmob_music (m);
104 return cumulative_length (me->get_property ("elements")).smobbed_copy ();
107 MAKE_SCHEME_CALLBACK (Music_sequence, minimum_start_callback, 1);
109 Music_sequence::minimum_start_callback (SCM m)
111 Music *me = unsmob_music (m);
112 return minimum_start (me->get_property ("elements")).smobbed_copy ();
115 MAKE_SCHEME_CALLBACK (Music_sequence, first_start_callback, 1);
117 Music_sequence::first_start_callback (SCM m)
119 Music *me = unsmob_music (m);
120 return first_start (me->get_property ("elements")).smobbed_copy ();
124 music_list_to_relative (SCM l, Pitch p, bool ret_first)
130 for (SCM s = l; scm_is_pair (s); s = scm_cdr (s))
132 if (Music *m = unsmob_music (scm_car (s)))
134 last = m->to_relative_octave (last);
140 return (ret_first) ? first : last;
144 compress_music_list (SCM l, Moment m)
146 for (SCM s = l; scm_is_pair (s); s = scm_cdr (s))
147 unsmob_music (scm_car (s))->compress (m);
151 Music_sequence::minimum_start (SCM l)
155 for (SCM s = l; scm_is_pair (s); s = scm_cdr (s))
156 m = min (m, unsmob_music (scm_car (s))->start_mom ());
161 Music_sequence::first_start (SCM l)
164 for (SCM s = l; scm_is_pair (s); s = scm_cdr (s))
166 Music *mus = unsmob_music (scm_car (s));
167 Moment start = mus->start_mom ();
168 if (mus->get_length ().to_bool () || start.to_bool ())
174 MAKE_SCHEME_CALLBACK (Music_sequence, simultaneous_relative_callback, 2);
176 Music_sequence::simultaneous_relative_callback (SCM music, SCM pitch)
178 Music *me = unsmob_music (music);
179 Pitch p = *unsmob_pitch (pitch);
181 SCM elts = me->get_property ("elements");
182 SCM copied = SCM_EOL;
183 if (lily_1_8_relative)
184 copied = ly_music_deep_copy (elts);
186 Pitch retval = music_list_to_relative (elts, p, false);
188 if (lily_1_8_relative)
191 Pitch retval_1_8 = music_list_to_relative (copied, p, true);
192 if (retval_1_8 != retval)
193 lily_1_8_compatibility_used = true;
198 return retval.smobbed_copy ();
201 MAKE_SCHEME_CALLBACK (Music_sequence, event_chord_relative_callback, 2);
203 Music_sequence::event_chord_relative_callback (SCM music, SCM pitch)
205 Music *me = unsmob_music (music);
206 Pitch p = *unsmob_pitch (pitch);
207 return music_list_to_relative (me->get_property ("elements"),
208 p, true).smobbed_copy ();