2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1998--2015 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 if (Prob *p = unsmob<Prob> (scm_car (s)))
38 Music_sequence::cumulative_length (SCM l)
43 for (SCM s = l; scm_is_pair (s); s = scm_cdr (s))
45 Moment l = unsmob<Music> (scm_car (s))->get_length ();
46 if (last_len.grace_part_ && l.main_part_)
47 last_len.grace_part_ = Rational (0);
48 cumulative += last_len;
52 last_len.grace_part_ = Rational (0);
53 cumulative += last_len;
59 Music_sequence::maximum_length (SCM l)
62 for (SCM s = l; scm_is_pair (s); s = scm_cdr (s))
64 Music *m = unsmob<Music> (scm_car (s));
66 programming_error ("Music sequence should have music elements");
69 Moment l = m->get_length ();
77 MAKE_SCHEME_CALLBACK (Music_sequence, maximum_length_callback, 1);
79 Music_sequence::maximum_length_callback (SCM m)
81 Music *me = unsmob<Music> (m);
82 return maximum_length (me->get_property ("elements")).smobbed_copy ();
85 MAKE_SCHEME_CALLBACK (Music_sequence, event_chord_length_callback, 1);
87 Music_sequence::event_chord_length_callback (SCM m)
89 Music *me = unsmob<Music> (m);
90 Duration *d = unsmob<Duration> (me->get_property ("duration"));
91 // Preset duration is used in chord repetitions.
94 Moment mom = d->get_length ();
95 return mom.smobbed_copy ();
97 return maximum_length (me->get_property ("elements")).smobbed_copy ();
100 MAKE_SCHEME_CALLBACK (Music_sequence, cumulative_length_callback, 1);
102 Music_sequence::cumulative_length_callback (SCM m)
104 Music *me = unsmob<Music> (m);
105 return cumulative_length (me->get_property ("elements")).smobbed_copy ();
108 MAKE_SCHEME_CALLBACK (Music_sequence, minimum_start_callback, 1);
110 Music_sequence::minimum_start_callback (SCM m)
112 Music *me = unsmob<Music> (m);
113 return minimum_start (me->get_property ("elements")).smobbed_copy ();
116 MAKE_SCHEME_CALLBACK (Music_sequence, first_start_callback, 1);
118 Music_sequence::first_start_callback (SCM m)
120 Music *me = unsmob<Music> (m);
121 return first_start (me->get_property ("elements")).smobbed_copy ();
125 music_list_to_relative (SCM l, Pitch p, bool ret_first)
131 for (SCM s = l; scm_is_pair (s); s = scm_cdr (s))
133 if (Music *m = unsmob<Music> (scm_car (s)))
135 last = m->to_relative_octave (last);
141 return (ret_first) ? first : last;
145 compress_music_list (SCM l, Moment m)
147 for (SCM s = l; scm_is_pair (s); s = scm_cdr (s))
148 unsmob<Music> (scm_car (s))->compress (m);
152 Music_sequence::minimum_start (SCM l)
156 for (SCM s = l; scm_is_pair (s); s = scm_cdr (s))
157 m = min (m, unsmob<Music> (scm_car (s))->start_mom ());
162 Music_sequence::first_start (SCM l)
165 for (SCM s = l; scm_is_pair (s); s = scm_cdr (s))
167 Music *mus = unsmob<Music> (scm_car (s));
168 Moment start = mus->start_mom ();
169 if (mus->get_length ().to_bool () || start.to_bool ())
175 MAKE_SCHEME_CALLBACK (Music_sequence, simultaneous_relative_callback, 2);
177 Music_sequence::simultaneous_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, false).smobbed_copy ();
185 MAKE_SCHEME_CALLBACK (Music_sequence, event_chord_relative_callback, 2);
187 Music_sequence::event_chord_relative_callback (SCM music, SCM pitch)
189 Music *me = unsmob<Music> (music);
190 Pitch p = *unsmob<Pitch> (pitch);
191 return music_list_to_relative (me->get_property ("elements"),
192 p, true).smobbed_copy ();