2 music-sequence.cc -- implement Music_sequence
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2009 Han-Wen Nienhuys <hanwen@xs4all.nl>
9 #include "music-sequence.hh"
12 #include "program-option.hh"
17 transpose_music_list (SCM lst
, Pitch rq
)
19 for (SCM s
= lst
; scm_is_pair (s
); s
= scm_cdr (s
))
20 unsmob_music (scm_car (s
))->transpose (rq
);
24 Music_sequence::cumulative_length (SCM l
)
29 for (SCM s
= l
; scm_is_pair (s
); s
= scm_cdr (s
))
31 Moment l
= unsmob_music (scm_car (s
))->get_length ();
32 if (last_len
.grace_part_
&& l
.main_part_
)
33 last_len
.grace_part_
= Rational (0);
34 cumulative
+= last_len
;
38 last_len
.grace_part_
= Rational (0);
39 cumulative
+= last_len
;
45 Music_sequence::maximum_length (SCM l
)
48 for (SCM s
= l
; scm_is_pair (s
); s
= scm_cdr (s
))
50 Music
*m
= unsmob_music (scm_car (s
));
52 programming_error ("Music sequence should have music elements");
55 Moment l
= m
->get_length ();
63 MAKE_SCHEME_CALLBACK (Music_sequence
, maximum_length_callback
, 1);
65 Music_sequence::maximum_length_callback (SCM m
)
67 Music
*me
= unsmob_music (m
);
68 return maximum_length (me
->get_property ("elements")).smobbed_copy ();
71 MAKE_SCHEME_CALLBACK (Music_sequence
, cumulative_length_callback
, 1);
73 Music_sequence::cumulative_length_callback (SCM m
)
75 Music
*me
= unsmob_music (m
);
76 return cumulative_length (me
->get_property ("elements")).smobbed_copy ();
79 MAKE_SCHEME_CALLBACK (Music_sequence
, minimum_start_callback
, 1);
81 Music_sequence::minimum_start_callback (SCM m
)
83 Music
*me
= unsmob_music (m
);
84 return minimum_start (me
->get_property ("elements")).smobbed_copy ();
87 MAKE_SCHEME_CALLBACK (Music_sequence
, first_start_callback
, 1);
89 Music_sequence::first_start_callback (SCM m
)
91 Music
*me
= unsmob_music (m
);
92 return first_start (me
->get_property ("elements")).smobbed_copy ();
96 music_list_to_relative (SCM l
, Pitch p
, bool ret_first
)
102 for (SCM s
= l
; scm_is_pair (s
); s
= scm_cdr (s
))
104 if (Music
*m
= unsmob_music (scm_car (s
)))
106 last
= m
->to_relative_octave (last
);
112 return (ret_first
) ? first
: last
;
116 compress_music_list (SCM l
, Moment m
)
118 for (SCM s
= l
; scm_is_pair (s
); s
= scm_cdr (s
))
119 unsmob_music (scm_car (s
))->compress (m
);
123 Music_sequence::minimum_start (SCM l
)
127 for (SCM s
= l
; scm_is_pair (s
); s
= scm_cdr (s
))
128 m
= min (m
, unsmob_music (scm_car (s
))->start_mom ());
133 Music_sequence::first_start (SCM l
)
137 for (SCM s
= l
; scm_is_pair (s
); s
= scm_cdr (s
))
139 Music
*mus
= unsmob_music (scm_car (s
));
140 Moment l
= mus
->get_length ();
141 Moment s
= mus
->start_mom ();
142 if (l
.to_bool () || s
.to_bool ())
148 MAKE_SCHEME_CALLBACK (Music_sequence
, simultaneous_relative_callback
, 2);
150 Music_sequence::simultaneous_relative_callback (SCM music
, SCM pitch
)
152 Music
*me
= unsmob_music (music
);
153 Pitch p
= *unsmob_pitch (pitch
);
155 SCM elts
= me
->get_property ("elements");
156 SCM copied
= SCM_EOL
;
157 if (lily_1_8_relative
)
158 copied
= ly_music_deep_copy (elts
);
160 Pitch retval
= music_list_to_relative (elts
, p
, false);
162 if (lily_1_8_relative
)
165 Pitch retval_1_8
= music_list_to_relative (copied
, p
, true);
166 if (retval_1_8
!= retval
)
167 lily_1_8_compatibility_used
= true;
172 return retval
.smobbed_copy ();
175 MAKE_SCHEME_CALLBACK (Music_sequence
, event_chord_relative_callback
, 2);
177 Music_sequence::event_chord_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
, true).smobbed_copy ();