2 music-sequence.cc -- implement Music_sequence
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2001 Han-Wen Nienhuys <hanwen@cs.uu.nl>
9 #include "music-list.hh"
15 Music_sequence::truncate (int k
)
17 SCM l
= get_mus_property ("elements");
26 for (; gh_pair_p (s
) && k
--; s
= gh_cdr (s
))
31 gh_set_cdr_x (s
, SCM_EOL
);
34 set_mus_property ("elements", l
);
38 Music_sequence::music_list ()const
40 return get_mus_property ("elements");
44 Ugh this sucks. Linear. do not use.
47 Music_sequence::append_music (Music
*m
)
49 set_mus_property ("elements",
50 gh_append2 (music_list (), gh_cons (m
->self_scm (), SCM_EOL
)));
51 scm_unprotect_object (m
->self_scm ());
54 Music_sequence::Music_sequence (SCM l
)
60 Music_sequence::transpose (Pitch rq
)
62 for (SCM s
= music_list (); gh_pair_p (s
); s
= gh_cdr (s
))
63 unsmob_music (gh_car (s
))->transpose (rq
);
70 Music_sequence::cumulative_length () const
75 for (SCM s
= music_list (); gh_pair_p (s
); s
= gh_cdr (s
))
77 Moment l
= unsmob_music (gh_car (s
))->length_mom ();
78 if (last_len
.grace_mom_
&& l
.main_part_
)
80 last_len
.grace_mom_
= Rational (0);
82 cumulative
+= last_len
;
86 last_len
.grace_mom_
= Rational (0);
87 cumulative
+= last_len
;
93 Music_sequence::to_relative_octave (Pitch p
)
95 return do_relative_octave (p
, false);
100 Music_sequence::maximum_length () const
103 for (SCM s
= music_list (); gh_pair_p (s
); s
= gh_cdr (s
))
104 dur
= dur
>? unsmob_music (gh_car (s
))->length_mom ();
109 Music_sequence::length_i () const
111 return scm_ilength (music_list ());
115 Music_sequence::do_relative_octave (Pitch p
, bool ret_first
)
121 for (SCM s
= music_list (); gh_pair_p (s
); s
= gh_cdr (s
))
123 last
= unsmob_music (gh_car (s
))->to_relative_octave (last
);
135 Music_sequence::compress (Moment m
)
137 for (SCM s
= music_list (); gh_pair_p (s
); s
= gh_cdr (s
))
138 unsmob_music (gh_car (s
))->compress (m
);
141 ADD_MUSIC (Music_sequence
);
143 Music_sequence::Music_sequence ()
150 Music_sequence::minimum_start () const
154 for (SCM s
= music_list (); gh_pair_p (s
); s
= gh_cdr (s
))
156 m
= m
<? unsmob_music (gh_car (s
))->start_mom ();
162 Music_sequence::first_start () const
166 for (SCM s
= music_list (); gh_pair_p (s
); s
= gh_cdr (s
))
168 Music
* mus
= unsmob_music (gh_car (s
));
169 Moment l
= mus
->length_mom ();
172 return mus
->start_mom ();
173 else if (l
.grace_mom_
)
175 m
.grace_mom_
= - l
.grace_mom_
;