lilypond-1.3.69
[lilypond.git] / lily / new-repeated-music.cc
blob15bd06f660febd3888d21bfc681ac39c3d75e93f
1 /*
2 new-repeated-music.cc -- implement New_repeated_music
4 source file of the GNU LilyPond music typesetter
6 (c) 1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
8 */
10 #include "new-repeated-music.hh"
11 #include "music-list.hh"
12 #include "musical-pitch.hh"
13 #include "debug.hh"
15 New_repeated_music::New_repeated_music(Music *beg, int times, Music_sequence * alts)
17 repeat_body_p_ = beg;
18 fold_b_ = false;
19 repeats_i_ = times;
20 alternatives_p_ = alts;
21 semi_fold_b_ = true;
24 New_repeated_music::New_repeated_music (New_repeated_music const &s)
25 : Music (s)
27 repeats_i_ = s.repeats_i_;
28 fold_b_ = s.fold_b_;
29 semi_fold_b_ = s.semi_fold_b_;
31 repeat_body_p_ = s.repeat_body_p_ ? s.repeat_body_p_->clone () : 0;
32 alternatives_p_ = s.alternatives_p_
33 ? dynamic_cast<Music_sequence*> (s.alternatives_p_->clone ()):0;
36 New_repeated_music::~New_repeated_music ()
38 delete repeat_body_p_;
39 delete alternatives_p_;
42 void
43 New_repeated_music::do_print () const
45 #ifndef NPRINT
46 DOUT << "Fold = " << fold_b_ << " reps: " << repeats_i_;
48 if (repeat_body_p_)
49 repeat_body_p_->print();
51 if (alternatives_p_)
52 alternatives_p_->print();
53 #endif
56 Musical_pitch
57 New_repeated_music::to_relative_octave (Musical_pitch p)
59 if (repeat_body_p_)
60 p = repeat_body_p_->to_relative_octave (p);
62 if (alternatives_p_)
63 p = alternatives_p_->do_relative_octave (p, true);
64 return p;
68 void
69 New_repeated_music::transpose (Musical_pitch p)
71 if (repeat_body_p_)
72 repeat_body_p_->transpose (p);
74 if (alternatives_p_)
75 alternatives_p_->transpose (p);
78 void
79 New_repeated_music::compress (Moment p)
81 if (repeat_body_p_)
82 repeat_body_p_->compress (p);
84 if (alternatives_p_)
85 alternatives_p_->compress (p);
88 Moment
89 New_repeated_music::alternatives_length_mom () const
91 if (alternatives_p_)
93 return (fold_b_)
94 ? alternatives_p_->maximum_length ()
95 : alternatives_p_->cumulative_length ();
97 return 0;
100 Moment
101 New_repeated_music::length_mom () const
103 Moment m =0;
104 if (fold_b_)
106 if (repeat_body_p_)
107 m += repeat_body_p_->length_mom ();
109 else
111 Moment beg = (repeat_body_p_) ? repeat_body_p_->length_mom () : Rational(0);
112 if (!semi_fold_b_)
113 beg *= Rational (repeats_i_);
114 m += beg;
117 m += alternatives_length_mom ();
118 return m;