lilypond-1.3.74
[lilypond.git] / lily / repeated-music.cc
blob2e8e0e3d0204ece0397d25e1b17a86c6d2ffebd6
1 /*
2 repeated-music.cc -- implement Repeated_music
4 source file of the GNU LilyPond music typesetter
6 (c) 1999--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
10 #include "repeated-music.hh"
11 #include "music-list.hh"
12 #include "musical-pitch.hh"
13 #include "debug.hh"
15 Music *
16 Repeated_music::body ()const
18 return unsmob_music (get_mus_property ("body"));
21 Music_sequence*
22 Repeated_music::alternatives ()const
24 return dynamic_cast<Music_sequence*> (unsmob_music (get_mus_property ("alternatives")));
27 Repeated_music::Repeated_music(Music *beg, int times, Music_sequence * alts)
29 set_mus_property ("body", beg->self_scm ());
30 fold_b_ = false;
31 repeats_i_ = times;
32 volta_fold_b_ = true;
33 if (alts)
35 alts->truncate (times);
36 set_mus_property ("alternatives", alts->self_scm ());
40 Repeated_music::Repeated_music (Repeated_music const &s)
41 : Music (s)
43 repeats_i_ = s.repeats_i_;
44 fold_b_ = s.fold_b_;
45 volta_fold_b_ = s.volta_fold_b_;
46 type_ = s.type_;
50 void
51 Repeated_music::do_print () const
53 #ifndef NPRINT
54 DEBUG_OUT << "Fold = " << fold_b_ << " reps: " << repeats_i_;
56 if (body ())
57 body ()->print();
59 if (alternatives ())
60 alternatives ()->print();
61 #endif
64 Musical_pitch
65 Repeated_music::to_relative_octave (Musical_pitch p)
67 if (body ())
68 p = body ()->to_relative_octave (p);
70 Musical_pitch last = p ;
71 if (alternatives ())
72 for (SCM s = alternatives ()->music_list (); gh_pair_p (s); s = gh_cdr (s))
73 unsmob_music (gh_car (s))->to_relative_octave (p);
76 return last;
79 void
80 Repeated_music::transpose (Musical_pitch p)
82 if (body ())
83 body ()->transpose (p);
85 if (alternatives ())
86 alternatives ()->transpose (p);
89 void
90 Repeated_music::compress (Moment p)
92 if (body ())
93 body ()->compress (p);
95 if (alternatives ())
96 alternatives ()->compress (p);
99 Moment
100 Repeated_music::alternatives_length_mom () const
102 if (!alternatives () )
103 return 0;
105 if (fold_b_)
106 return alternatives ()->maximum_length ();
108 Moment m =0;
109 int done =0;
111 SCM p = alternatives ()->music_list ();
112 while (gh_pair_p (p) && done < repeats_i_)
114 m = m + unsmob_music (gh_car (p))->length_mom ();
115 done ++;
116 if (volta_fold_b_
117 || repeats_i_ - done < alternatives ()->length_i ())
118 p = gh_cdr (p);
120 return m;
123 Moment
124 Repeated_music::body_length_mom () const
126 Moment m = 0;
127 if (body ())
129 m = body ()->length_mom ();
130 if (!fold_b_ && !volta_fold_b_)
131 m *= Rational (repeats_i_);
133 return m;
136 Moment
137 Repeated_music::length_mom () const
139 return body_length_mom () + alternatives_length_mom ();