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