]> git.donarmstrong.com Git - lilypond.git/blob - lily/repeated-music.cc
* Documentation/user/refman.itely: remove superfluous -'s
[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--2003 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7   
8  */
9
10 #include "repeated-music.hh"
11 #include "music-list.hh"
12 #include "pitch.hh"
13 #include "warn.hh"
14 #include "music-sequence.hh"
15
16 Music *
17 Repeated_music::body ()const
18 {
19   return unsmob_music (get_mus_property ("element"));
20 }
21
22 SCM
23 Repeated_music::alternatives ()const
24 {
25   return get_mus_property ("elements");
26 }
27
28
29
30
31 Pitch
32 Repeated_music::to_relative_octave (Pitch p)
33 {
34   if (lily_1_8_relative)
35     {
36       if (body ())
37         p = body ()->to_relative_octave (p);
38
39       Pitch last = p ; 
40       if (alternatives ())
41         for (SCM s = alternatives (); gh_pair_p (s);  s = ly_cdr (s))
42           unsmob_music (ly_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 (gh_pair_p (p) && done < repeat_count ())
68     {
69       m = m + unsmob_music (ly_car (p))->get_length ();
70       done ++;
71       if (repeat_count () - done < scm_ilength (alternatives ()))
72         p = ly_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 (gh_pair_p (p))
90     {
91       m = m + unsmob_music (ly_car (p))->get_length ();
92       p = ly_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 gh_scm2int (get_mus_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 ()
152   : Music ()
153 {
154 }
155
156
157 MAKE_SCHEME_CALLBACK (Repeated_music,minimum_start, 1);
158 MAKE_SCHEME_CALLBACK (Repeated_music,first_start, 1);
159
160 SCM
161 Repeated_music::minimum_start (SCM m)
162 {
163   Music * me = unsmob_music (m);
164   Music * body = unsmob_music (me->get_mus_property ("element"));
165
166   if (body)
167     return body->start_mom ().smobbed_copy();
168   else
169     {
170       return Music_sequence::minimum_start (me->get_mus_property ("elements")).smobbed_copy();
171     }
172 }
173
174 SCM
175 Repeated_music::first_start (SCM m)
176 {
177   Music * me = unsmob_music (m);
178   Music * body = unsmob_music (me->get_mus_property ("element"));
179
180   Moment rv =  (body) ? body->start_mom () :
181     Music_sequence::first_start (me->get_mus_property ("elements"));
182
183   return rv.smobbed_copy ();
184 }