]> git.donarmstrong.com Git - lilypond.git/blob - lily/repeated-music.cc
release: 1.1.50
[lilypond.git] / lily / 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     return 0;
93   
94   if  (fold_b_)
95     alternatives_p_->maximum_length ();
96
97   Moment m =0;
98   int done =0;
99   Cons<Music> *p = alternatives_p_->music_p_list_p_->head_;
100   while (p && done < repeats_i_)
101     {
102       m = m + p->car_->length_mom ();
103       done ++;
104       if (repeats_i_ - done < alternatives_p_->length_i ())
105         p = p->next_;
106     }
107   return m;
108 }
109
110 Moment
111 New_repeated_music::length_mom () const
112 {
113   Moment m =0;
114   if (fold_b_)
115     {
116       if (repeat_body_p_)
117         m += repeat_body_p_->length_mom ();
118     }
119   else
120     {
121       Moment beg = (repeat_body_p_) ? repeat_body_p_->length_mom () : Rational(0);
122       if (!semi_fold_b_)
123         beg *=  Rational (repeats_i_);
124       m += beg;
125     }
126
127   m += alternatives_length_mom ();
128   return m;
129 }
130