]> git.donarmstrong.com Git - lilypond.git/blob - lily/repeated-music.cc
release: 1.2.12
[lilypond.git] / lily / repeated-music.cc
1 /*   
2   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 "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   volta_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   volta_fold_b_ = s.volta_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   DEBUG_OUT << "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
71 void
72 Repeated_music::transpose (Musical_pitch p)
73 {
74   if (repeat_body_p_)
75     repeat_body_p_->transpose (p);
76
77   if (alternatives_p_)
78     alternatives_p_->transpose (p);  
79 }
80
81 void
82 Repeated_music::compress (Moment p)
83 {
84   if (repeat_body_p_)
85     repeat_body_p_->compress (p);
86
87   if (alternatives_p_)
88     alternatives_p_->compress (p);  
89 }
90
91 Moment
92 Repeated_music::alternatives_length_mom () const
93 {
94   if (!alternatives_p_ )
95     return 0;
96   
97   if  (fold_b_)
98     return alternatives_p_->maximum_length ();
99
100   Moment m =0;
101   int done =0;
102   Cons<Music> *p = alternatives_p_->music_p_list_p_->head_;
103   while (p && done < repeats_i_)
104     {
105       m = m + p->car_->length_mom ();
106       done ++;
107       if (volta_fold_b_
108           || repeats_i_ - done < alternatives_p_->length_i ())
109         p = p->next_;
110     }
111   return m;
112 }
113
114 Moment
115 Repeated_music::length_mom () const
116 {
117   Moment m =0;
118   if (fold_b_)
119     {
120       if (repeat_body_p_)
121         m += repeat_body_p_->length_mom ();
122     }
123   else
124     {
125       Moment beg = (repeat_body_p_) ? repeat_body_p_->length_mom () : Rational(0);
126       if (!volta_fold_b_)
127         beg *=  Rational (repeats_i_);
128       m += beg;
129     }
130
131   m += alternatives_length_mom ();
132   return m;
133 }
134