]> git.donarmstrong.com Git - lilypond.git/blob - lily/new-repeated-music.cc
c989de90148d0c7a0bf21537494917dff98aedea
[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
14 New_repeated_music::New_repeated_music()
15 {
16   repeat_begin_p_ = 0;
17   unfold_b_ = false;
18   repeats_i_ =0;
19   alternatives_p_ = 0;
20 }
21
22 New_repeated_music::New_repeated_music (New_repeated_music const &s)
23   : Music (s)
24 {
25   repeats_i_ = s.repeats_i_;
26   unfold_b_ = s.unfold_b_;
27
28   repeat_begin_p_ = s.repeat_begin_p_ ? s.repeat_begin_p_->clone () : 0;
29   alternatives_p_ = s.alternatives_p_
30     ? dynamic_cast<Music_sequence*> (s.alternatives_p_->clone ()):0;
31 }
32
33 New_repeated_music::~New_repeated_music ()
34 {
35   delete repeat_begin_p_;
36   delete alternatives_p_;
37 }
38
39 void
40 New_repeated_music::do_print () const
41 {
42   if (repeat_begin_p_)
43     repeat_begin_p_->print();
44   
45   if (alternatives_p_)
46     alternatives_p_->print();
47 }
48
49 Musical_pitch
50 New_repeated_music::to_relative_octave (Musical_pitch p)
51 {
52   if (repeat_begin_p_)
53     p = repeat_begin_p_->to_relative_octave (p);
54
55   if (alternatives_p_)
56     p = alternatives_p_->do_relative_octave (p, true);
57   return p;
58 }
59
60
61 void
62 New_repeated_music::transpose (Musical_pitch p)
63 {
64   if (repeat_begin_p_)
65     repeat_begin_p_->transpose (p);
66
67   if (alternatives_p_)
68     alternatives_p_->transpose (p);  
69 }
70
71 void
72 New_repeated_music::compress (Moment p)
73 {
74   if (repeat_begin_p_)
75     repeat_begin_p_->compress (p);
76
77   if (alternatives_p_)
78     alternatives_p_->compress (p);  
79 }
80
81
82 Moment
83 New_repeated_music::length_mom () const
84 {
85   Moment m =0;
86   if (unfold_b_)
87     {
88       if (repeat_begin_p_)
89         m +=  Rational (repeats_i_) * repeat_begin_p_->length_mom ();
90
91       if (alternatives_p_)
92         m += alternatives_p_->cumulative_length ();
93     }
94   else
95     {
96       if (repeat_begin_p_)
97         m +=  repeat_begin_p_->length_mom ();
98
99       if (alternatives_p_)
100         m += alternatives_p_->maximum_length ();
101     }
102   return m;
103 }
104