]> git.donarmstrong.com Git - lilypond.git/blob - lily/repeated-music.cc
d00a93210718b6d931fcdf93166e0846b8a027eb
[lilypond.git] / lily / repeated-music.cc
1 /*   
2   new-repeated-music.cc --  implement 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 Repeated_music::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   if (alts)
23     alts->music_p_list_p_->truncate (times);
24 }
25
26 Repeated_music::Repeated_music (Repeated_music const &s)
27   : Music (s)
28 {
29   repeats_i_ = s.repeats_i_;
30   fold_b_ = s.fold_b_;
31   semi_fold_b_ = s.semi_fold_b_;
32   
33   repeat_body_p_ = s.repeat_body_p_ ? s.repeat_body_p_->clone () : 0;
34   alternatives_p_ = s.alternatives_p_
35     ? dynamic_cast<Music_sequence*> (s.alternatives_p_->clone ()):0;
36 }
37
38 Repeated_music::~Repeated_music ()
39 {
40   delete repeat_body_p_;
41   delete alternatives_p_;
42 }
43
44 void
45 Repeated_music::do_print () const
46 {
47 #ifndef NPRINT
48   DOUT << "Fold = " << fold_b_ << " reps: " << repeats_i_;
49
50   if (repeat_body_p_)
51     repeat_body_p_->print();
52   
53   if (alternatives_p_)
54     alternatives_p_->print();
55 #endif
56 }
57
58 Musical_pitch
59 Repeated_music::to_relative_octave (Musical_pitch p)
60 {
61   if (repeat_body_p_)
62     p = repeat_body_p_->to_relative_octave (p);
63
64   if (alternatives_p_)
65     p = alternatives_p_->do_relative_octave (p, true);
66   return p;
67 }
68
69
70 void
71 Repeated_music::transpose (Musical_pitch p)
72 {
73   if (repeat_body_p_)
74     repeat_body_p_->transpose (p);
75
76   if (alternatives_p_)
77     alternatives_p_->transpose (p);  
78 }
79
80 void
81 Repeated_music::compress (Moment p)
82 {
83   if (repeat_body_p_)
84     repeat_body_p_->compress (p);
85
86   if (alternatives_p_)
87     alternatives_p_->compress (p);  
88 }
89
90 Moment
91 Repeated_music::alternatives_length_mom () const
92 {
93   if (!alternatives_p_ )
94     return 0;
95   
96   if  (fold_b_)
97     alternatives_p_->maximum_length ();
98
99   Moment m =0;
100   int done =0;
101   Cons<Music> *p = alternatives_p_->music_p_list_p_->head_;
102   while (p && done < repeats_i_)
103     {
104       m = m + p->car_->length_mom ();
105       done ++;
106       if (repeats_i_ - done < alternatives_p_->length_i ())
107         p = p->next_;
108     }
109   return m;
110 }
111
112 Moment
113 Repeated_music::length_mom () const
114 {
115   Moment m =0;
116   if (fold_b_)
117     {
118       if (repeat_body_p_)
119         m += repeat_body_p_->length_mom ();
120     }
121   else
122     {
123       Moment beg = (repeat_body_p_) ? repeat_body_p_->length_mom () : Rational(0);
124       if (!semi_fold_b_)
125         beg *=  Rational (repeats_i_);
126       m += beg;
127     }
128
129   m += alternatives_length_mom ();
130   return m;
131 }
132