]> git.donarmstrong.com Git - lilypond.git/blob - lily/repeated-music.cc
* lily/include/transposed-music.hh (class Transposed_music): remove.
[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--2004 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "repeated-music.hh"
11 #include "music-sequence.hh"
12 #include "pitch.hh"
13 #include "warn.hh"
14 #include "scm-option.hh"
15
16 Music *
17 Repeated_music::body ()const
18 {
19   return unsmob_music (get_property ("element"));
20 }
21
22 SCM
23 Repeated_music::alternatives ()const
24 {
25   return get_property ("elements");
26 }
27
28 Pitch
29 Repeated_music::to_relative_octave (Pitch p)
30 {
31   if (lily_1_8_relative)
32     {
33       if (body ())
34         p = body ()->to_relative_octave (p);
35
36       Pitch last = p ; 
37       if (alternatives ())
38         {
39           lily_1_8_compatibility_used = true; 
40
41           for (SCM s = alternatives (); scm_is_pair (s);  s = scm_cdr (s))
42             unsmob_music (scm_car (s))->to_relative_octave (p);
43         }     
44
45       return last;
46     }
47   else
48     {
49       return Music::to_relative_octave (p);
50     }
51 }
52
53
54 Moment
55 Repeated_music::alternatives_get_length (bool fold) const
56 {
57   if (!alternatives ())
58     return 0;
59   
60   if (fold)
61     return Music_sequence::maximum_length (alternatives ());
62
63   Moment m = 0;
64   int done = 0;
65
66   SCM p = alternatives ();
67   while (scm_is_pair (p) && done < repeat_count ())
68     {
69       m = m + unsmob_music (scm_car (p))->get_length ();
70       done ++;
71       if (repeat_count () - done < scm_ilength (alternatives ()))
72         p = scm_cdr (p);
73     }
74   return m;
75 }
76
77 /*
78   Sum all duration of all available alternatives. This is for the case
79   of volta repeats, where the alternatives are iterated just as they
80   were entered.  */
81 Moment
82 Repeated_music::alternatives_volta_get_length () const
83 {
84   if (!alternatives ())
85     return 0;
86
87   Moment m;
88   SCM p = alternatives ();
89   while (scm_is_pair (p))
90     {
91       m = m + unsmob_music (scm_car (p))->get_length ();
92       p = scm_cdr (p);
93     }
94   return m;
95 }
96
97
98 /*
99   Length of the body in THIS. Disregards REPEAT-COUNT. 
100  */
101 Moment
102 Repeated_music::body_get_length () const
103 {
104   Moment m = 0;
105   if (body ())
106     {
107       m = body ()->get_length ();
108     }
109   return m;
110 }
111
112 int
113 Repeated_music::repeat_count () const
114 {
115   return scm_to_int (get_property ("repeat-count"));
116 }
117
118
119 MAKE_SCHEME_CALLBACK (Repeated_music,unfolded_music_length, 1);
120 MAKE_SCHEME_CALLBACK (Repeated_music,folded_music_length, 1);
121 MAKE_SCHEME_CALLBACK (Repeated_music,volta_music_length, 1);
122
123 SCM
124 Repeated_music::unfolded_music_length (SCM m)
125 {
126   Repeated_music* r = dynamic_cast<Repeated_music*> (unsmob_music (m));
127   
128   Moment l = Moment (r->repeat_count ()) * r->body_get_length () + r->alternatives_get_length (false);
129   return l.smobbed_copy ();
130 }
131
132 SCM
133 Repeated_music::folded_music_length (SCM m)
134 {
135   Repeated_music* r = dynamic_cast<Repeated_music*> (unsmob_music (m));
136  
137   Moment l =  r->body_get_length () + r->alternatives_get_length (true);
138   return l.smobbed_copy ();
139 }
140
141 SCM
142 Repeated_music::volta_music_length (SCM m)
143 {
144   Repeated_music* r = dynamic_cast<Repeated_music*> (unsmob_music (m));
145   Moment l =  r->body_get_length () + r->alternatives_volta_get_length ();
146   return l.smobbed_copy ();
147 }
148
149 ADD_MUSIC (Repeated_music);
150
151 Repeated_music::Repeated_music (SCM x)
152   : Music (x)
153 {
154 }
155
156
157 MAKE_SCHEME_CALLBACK (Repeated_music,minimum_start, 1);
158 SCM
159 Repeated_music::minimum_start (SCM m)
160 {
161   Music * me = unsmob_music (m);
162   Music * body = unsmob_music (me->get_property ("element"));
163
164   if (body)
165     return body->start_mom ().smobbed_copy ();
166   else
167     {
168       return Music_sequence::minimum_start (me->get_property ("elements")).smobbed_copy ();
169     }
170 }
171
172 MAKE_SCHEME_CALLBACK (Repeated_music,first_start, 1);
173 SCM
174 Repeated_music::first_start (SCM m)
175 {
176   Music * me = unsmob_music (m);
177   Music * body = unsmob_music (me->get_property ("element"));
178
179   Moment rv =  (body) ? body->start_mom () :
180     Music_sequence::first_start (me->get_property ("elements"));
181
182   return rv.smobbed_copy ();
183 }