]> git.donarmstrong.com Git - lilypond.git/blob - lily/repeated-music.cc
2e8e0e3d0204ece0397d25e1b17a86c6d2ffebd6
[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--2000 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 Music *
16 Repeated_music::body ()const
17 {
18   return unsmob_music (get_mus_property ("body"));
19 }
20
21 Music_sequence*
22 Repeated_music::alternatives ()const
23 {
24   return dynamic_cast<Music_sequence*>  (unsmob_music (get_mus_property ("alternatives")));
25 }
26
27 Repeated_music::Repeated_music(Music *beg, int times, Music_sequence * alts)
28 {
29   set_mus_property ("body", beg->self_scm ());
30   fold_b_ = false;
31   repeats_i_ = times;
32   volta_fold_b_ = true;
33   if (alts)
34     {
35       alts->truncate (times);
36       set_mus_property ("alternatives", alts->self_scm ());
37     }
38 }
39
40 Repeated_music::Repeated_music (Repeated_music const &s)
41   : Music (s)
42 {
43   repeats_i_ = s.repeats_i_;
44   fold_b_ = s.fold_b_;
45   volta_fold_b_ = s.volta_fold_b_;
46   type_ = s.type_;
47 }
48
49
50 void
51 Repeated_music::do_print () const
52 {
53 #ifndef NPRINT
54   DEBUG_OUT << "Fold = " << fold_b_ << " reps: " << repeats_i_;
55
56   if (body ())
57     body ()->print();
58   
59   if (alternatives ())
60     alternatives ()->print();
61 #endif
62 }
63
64 Musical_pitch
65 Repeated_music::to_relative_octave (Musical_pitch p)
66 {
67   if (body ())
68     p = body ()->to_relative_octave (p);
69
70   Musical_pitch last = p ; 
71   if (alternatives ())
72     for (SCM s = alternatives ()->music_list (); gh_pair_p (s);  s = gh_cdr (s))
73       unsmob_music (gh_car (s))->to_relative_octave (p);
74      
75
76   return last;
77 }
78
79 void
80 Repeated_music::transpose (Musical_pitch p)
81 {
82   if (body ())
83     body ()->transpose (p);
84
85   if (alternatives ())
86     alternatives ()->transpose (p);  
87 }
88
89 void
90 Repeated_music::compress (Moment p)
91 {
92   if (body ())
93     body ()->compress (p);
94
95   if (alternatives ())
96     alternatives ()->compress (p);  
97 }
98
99 Moment
100 Repeated_music::alternatives_length_mom () const
101 {
102   if (!alternatives () )
103     return 0;
104   
105   if  (fold_b_)
106     return alternatives ()->maximum_length ();
107
108   Moment m =0;
109   int done =0;
110
111   SCM p = alternatives ()->music_list ();
112    while (gh_pair_p (p) && done < repeats_i_)
113     {
114       m = m + unsmob_music (gh_car (p))->length_mom ();
115       done ++;
116       if (volta_fold_b_
117           || repeats_i_ - done < alternatives ()->length_i ())
118       p = gh_cdr (p);
119     }
120   return m;
121 }
122
123 Moment
124 Repeated_music::body_length_mom () const
125 {
126   Moment m = 0;
127   if (body ())
128     {
129       m = body ()->length_mom ();
130       if (!fold_b_ && !volta_fold_b_)
131         m *= Rational (repeats_i_);
132     }
133   return m;
134 }
135
136 Moment
137 Repeated_music::length_mom () const
138 {
139   return body_length_mom () + alternatives_length_mom ();
140 }
141