2 music-sequence.cc -- implement Music_sequence
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 #include "scm-option.hh"
13 #include "music-sequence.hh"
16 transpose_music_list (SCM lst, Pitch rq)
18 for (SCM s = lst; scm_is_pair (s); s = scm_cdr (s))
19 unsmob_music (scm_car (s))->transpose (rq);
23 Music_sequence::cumulative_length (SCM l)
28 for (SCM s = l; scm_is_pair (s); s = scm_cdr (s))
30 Moment l = unsmob_music (scm_car (s))->get_length ();
31 if (last_len.grace_part_ && l.main_part_)
33 last_len.grace_part_ = Rational (0);
35 cumulative += last_len;
39 last_len.grace_part_ = Rational (0);
40 cumulative += last_len;
46 Music_sequence::maximum_length (SCM l)
49 for (SCM s = l; scm_is_pair (s); s = scm_cdr (s))
51 Music *m = unsmob_music (scm_car (s));
52 Moment l = m->get_length ();
59 MAKE_SCHEME_CALLBACK (Music_sequence, maximum_length_callback, 1);
61 Music_sequence::maximum_length_callback (SCM m)
63 Music *me = unsmob_music (m);
64 return maximum_length (me->get_property ("elements")).smobbed_copy ();
67 MAKE_SCHEME_CALLBACK (Music_sequence, cumulative_length_callback, 1);
69 Music_sequence::cumulative_length_callback (SCM m)
71 Music *me = unsmob_music (m);
72 return cumulative_length (me->get_property ("elements")).smobbed_copy ();
75 MAKE_SCHEME_CALLBACK (Music_sequence, minimum_start_callback, 1);
77 Music_sequence::minimum_start_callback (SCM m)
79 Music *me = unsmob_music (m);
80 return minimum_start (me->get_property ("elements")).smobbed_copy ();
83 MAKE_SCHEME_CALLBACK (Music_sequence, first_start_callback, 1);
85 Music_sequence::first_start_callback (SCM m)
87 Music *me = unsmob_music (m);
88 return first_start (me->get_property ("elements")).smobbed_copy ();
92 music_list_to_relative (SCM l, Pitch p, bool ret_first)
98 for (SCM s = l; scm_is_pair (s); s = scm_cdr (s))
100 if (Music *m = unsmob_music (scm_car (s)))
102 last = m->to_relative_octave (last);
108 return (ret_first) ? first : last;
112 compress_music_list (SCM l, Moment m)
114 for (SCM s = l; scm_is_pair (s); s = scm_cdr (s))
115 unsmob_music (scm_car (s))->compress (m);
119 Music_sequence::minimum_start (SCM l)
123 for (SCM s = l; scm_is_pair (s); s = scm_cdr (s))
125 m = m <? unsmob_music (scm_car (s))->start_mom ();
131 Music_sequence::first_start (SCM l)
135 for (SCM s = l; scm_is_pair (s); s = scm_cdr (s))
137 Music *mus = unsmob_music (scm_car (s));
138 Moment l = mus->get_length ();
139 Moment s = mus->start_mom ();
140 if (l.to_bool () || s.to_bool ())
146 MAKE_SCHEME_CALLBACK (Music_sequence, simultaneous_relative_callback, 2);
148 Music_sequence::simultaneous_relative_callback (SCM music, SCM pitch)
150 Music *me = unsmob_music (music);
151 Pitch p = *unsmob_pitch (pitch);
153 SCM elts = me->get_property ("elements");
154 SCM copied = SCM_EOL;
155 if (lily_1_8_relative)
156 copied = ly_music_deep_copy (elts);
158 Pitch retval = music_list_to_relative (elts, p, false);
160 if (lily_1_8_relative)
163 Pitch retval_1_8 = music_list_to_relative (copied, p, true);
164 if (retval_1_8 != retval)
165 lily_1_8_compatibility_used = true;
170 return retval.smobbed_copy ();
173 MAKE_SCHEME_CALLBACK (Music_sequence, event_chord_relative_callback, 2);
175 Music_sequence::event_chord_relative_callback (SCM music, SCM pitch)
177 Music *me = unsmob_music (music);
178 Pitch p = *unsmob_pitch (pitch);
179 return music_list_to_relative (me->get_property ("elements"),
180 p, true).smobbed_copy ();