lilypond-1.3.130
[lilypond.git] / lily / music-sequence.cc
blob5ce5b1a8b9baeff18e7f72929cfe73471bfb2a41
1 /*
2 music-sequence.cc -- implement Music_sequence
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
9 #include "music-list.hh"
10 #include "debug.hh"
11 #include "pitch.hh"
14 void
15 Music_sequence::truncate (int k)
17 SCM l = get_mus_property ("elements");
18 if (k == 0)
20 l = SCM_EOL;
22 else
24 SCM s = l;
25 k--;
26 for (; gh_pair_p (s) && k--; s = gh_cdr (s))
29 if (gh_pair_p (s))
31 gh_set_cdr_x (s, SCM_EOL);
34 set_mus_property ("elements", l);
37 SCM
38 Music_sequence::music_list ()const
40 return get_mus_property ("elements");
44 Ugh this sucks. Linear. do not use.
46 void
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)
55 : Music (l)
59 void
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);
69 Moment
70 Music_sequence::cumulative_length () const
72 Moment last=0;
73 for (SCM s = music_list (); gh_pair_p (s); s = gh_cdr (s))
74 last += unsmob_music (gh_car (s))->length_mom ();
75 return last;
78 Pitch
79 Music_sequence::to_relative_octave (Pitch p)
81 return do_relative_octave (p, false);
85 Moment
86 Music_sequence::maximum_length () const
88 Moment dur = 0;
89 for (SCM s = music_list (); gh_pair_p (s); s = gh_cdr (s))
90 dur = dur >? unsmob_music (gh_car (s))->length_mom ();
92 return dur;
94 int
95 Music_sequence::length_i () const
97 return scm_ilength (music_list ());
100 Pitch
101 Music_sequence::do_relative_octave (Pitch p, bool ret_first)
103 Pitch retval;
104 int count=0;
106 Pitch last = p;
107 for (SCM s = music_list (); gh_pair_p (s); s = gh_cdr (s))
109 last = unsmob_music (gh_car (s))->to_relative_octave (last);
110 if (!count ++ )
111 retval = last;
114 if (!ret_first)
115 retval = last;
117 return retval;
120 void
121 Music_sequence::compress (Moment m)
123 for (SCM s = music_list (); gh_pair_p (s); s = gh_cdr (s))
124 unsmob_music (gh_car (s))->compress (m);