* lily/music-iterator.cc (quit, do_quit): new function: break link
[lilypond.git] / lily / music-sequence.cc
blob44ec103c4092f7f8ab39769b6f6d80fec7125302
1 /*
2 music-sequence.cc -- implement Music_sequence
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
9 #include "music-list.hh"
10 #include "warn.hh"
11 #include "pitch.hh"
14 SCM
15 Music_sequence::music_list ()const
17 return get_mus_property ("elements");
21 Ugh this sucks. Linear. do not use.
23 void
24 Music_sequence::append_music (Music *m)
26 set_mus_property ("elements",
27 gh_append2 (music_list (), gh_cons (m->self_scm (), SCM_EOL)));
28 scm_gc_unprotect_object (m->self_scm ());
31 Music_sequence::Music_sequence (SCM l)
32 : Music (l)
36 void
37 Music_sequence::transpose (Pitch rq)
39 transpose_list (music_list (), rq);
42 void
43 Music_sequence::transpose_list (SCM l, Pitch rq)
45 for (SCM s = l; gh_pair_p (s); s = ly_cdr (s))
46 unsmob_music (ly_car (s))->transpose (rq);
49 Moment
50 Music_sequence::cumulative_length (SCM l)
52 Moment cumulative;
53 Moment last_len;
55 for (SCM s = l; gh_pair_p (s); s = ly_cdr (s))
57 Moment l = unsmob_music (ly_car (s))->length_mom ();
58 if (last_len.grace_part_ && l.main_part_)
60 last_len.grace_part_ = Rational (0);
62 cumulative += last_len;
63 last_len = l;
66 last_len.grace_part_ = Rational (0);
67 cumulative += last_len;
69 return cumulative;
72 Pitch
73 Music_sequence::to_relative_octave (Pitch p)
75 return do_relative_octave (p, false);
79 Moment
80 Music_sequence::maximum_length (SCM l)
82 Moment dur = 0;
83 for (SCM s = l; gh_pair_p (s); s = ly_cdr (s))
85 Music * m = unsmob_music (ly_car (s));
86 Moment l = m->length_mom ();
87 dur = dur >? l;
90 return dur;
94 Pitch
95 Music_sequence::do_relative_octave (Pitch p, bool ret_first)
97 Pitch retval;
98 int count=0;
100 Pitch last = p;
101 for (SCM s = music_list (); gh_pair_p (s); s = ly_cdr (s))
103 Music *m = unsmob_music (ly_car (s));
104 if (!m)
106 programming_error ("Music_sequence should only contain music!");
108 else
110 last = m->to_relative_octave (last);
111 if (!count ++)
112 retval = last;
116 if (!ret_first)
117 retval = last;
119 return retval;
122 void
123 Music_sequence::compress (Moment m)
125 compress_list (music_list (), m);
128 void
129 Music_sequence::compress_list (SCM l, Moment m)
131 for (SCM s = l; gh_pair_p (s); s = ly_cdr (s))
132 unsmob_music (ly_car (s))->compress (m);
135 ADD_MUSIC (Music_sequence);
137 Music_sequence::Music_sequence ()
138 : Music (SCM_EOL)
143 Moment
144 Music_sequence::minimum_start (SCM l)
146 Moment m;
148 for (SCM s = l; gh_pair_p (s); s = ly_cdr (s))
150 m = m <? unsmob_music (ly_car (s))->start_mom ();
152 return m;
155 Moment
156 Music_sequence::first_start (SCM l)
158 Moment m;
160 for (SCM s = l; gh_pair_p (s); s = ly_cdr (s))
162 Music * mus = unsmob_music (ly_car (s));
163 Moment l = mus->length_mom ();
164 Moment s = mus->start_mom ();
165 if (l.to_bool () || s.to_bool ())
166 return s;
168 return m;