]> git.donarmstrong.com Git - lilypond.git/blob - lily/new-repeated-music.cc
release: 1.1.43
[lilypond.git] / lily / new-repeated-music.cc
1 /*   
2   new-repeated-music.cc --  implement New_repeated_music
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "new-repeated-music.hh"
11 #include "music-list.hh"
12 #include "musical-pitch.hh"
13 #include "debug.hh"
14
15 New_repeated_music::New_repeated_music(Music *beg, int times, Music_sequence * alts)
16 {
17   repeat_body_p_ = beg;
18   fold_b_ = false;
19   repeats_i_ = times;
20   alternatives_p_ = alts;
21   semi_fold_b_ = true;
22 }
23
24 New_repeated_music::New_repeated_music (New_repeated_music const &s)
25   : Music (s)
26 {
27   repeats_i_ = s.repeats_i_;
28   fold_b_ = s.fold_b_;
29   semi_fold_b_ = s.semi_fold_b_;
30   
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;
34 }
35
36 New_repeated_music::~New_repeated_music ()
37 {
38   delete repeat_body_p_;
39   delete alternatives_p_;
40 }
41
42 void
43 New_repeated_music::do_print () const
44 {
45 #ifndef NPRINT
46   DOUT << "Fold = " << fold_b_ << " reps: " << repeats_i_;
47
48   if (repeat_body_p_)
49     repeat_body_p_->print();
50   
51   if (alternatives_p_)
52     alternatives_p_->print();
53 #endif
54 }
55
56 Musical_pitch
57 New_repeated_music::to_relative_octave (Musical_pitch p)
58 {
59   if (repeat_body_p_)
60     p = repeat_body_p_->to_relative_octave (p);
61
62   if (alternatives_p_)
63     p = alternatives_p_->do_relative_octave (p, true);
64   return p;
65 }
66
67
68 void
69 New_repeated_music::transpose (Musical_pitch p)
70 {
71   if (repeat_body_p_)
72     repeat_body_p_->transpose (p);
73
74   if (alternatives_p_)
75     alternatives_p_->transpose (p);  
76 }
77
78 void
79 New_repeated_music::compress (Moment p)
80 {
81   if (repeat_body_p_)
82     repeat_body_p_->compress (p);
83
84   if (alternatives_p_)
85     alternatives_p_->compress (p);  
86 }
87
88 Moment
89 New_repeated_music::alternatives_length_mom () const
90 {
91   if (alternatives_p_)
92     {
93       return  (fold_b_)
94         ? alternatives_p_->maximum_length ()
95         : alternatives_p_->cumulative_length ();
96     }
97   return 0; 
98 }
99
100 Moment
101 New_repeated_music::length_mom () const
102 {
103   Moment m =0;
104   if (fold_b_)
105     {
106       if (repeat_body_p_)
107         m += repeat_body_p_->length_mom ();
108     }
109   else
110     {
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;
115     }
116
117   m += alternatives_length_mom ();
118   return m;
119 }
120