]> git.donarmstrong.com Git - lilypond.git/blob - lily/repeated-music.cc
9ff853a9a64bb443cddec9076bf9c80dc18fafa6
[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 "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(SCM l)
28   : Music (l)
29 {
30   set_mus_property ("type", ly_symbol2scm ("repeated-music"));
31 }
32
33
34 Pitch
35 Repeated_music::to_relative_octave (Pitch p)
36 {
37   if (body ())
38     p = body ()->to_relative_octave (p);
39
40   Pitch last = p ; 
41   if (alternatives ())
42     for (SCM s = alternatives ()->music_list (); gh_pair_p (s);  s = gh_cdr (s))
43       unsmob_music (gh_car (s))->to_relative_octave (p);
44      
45
46   return last;
47 }
48
49 void
50 Repeated_music::transpose (Pitch p)
51 {
52   if (body ())
53     body ()->transpose (p);
54
55   if (alternatives ())
56     alternatives ()->transpose (p);  
57 }
58
59 void
60 Repeated_music::compress (Moment p)
61 {
62   if (body ())
63     body ()->compress (p);
64
65   if (alternatives ())
66     alternatives ()->compress (p);  
67 }
68
69 Moment
70 Repeated_music::alternatives_length_mom (bool fold) const
71 {
72   if (!alternatives () )
73     return 0;
74   
75   if  (fold)
76     return alternatives ()->maximum_length ();
77
78   Moment m =0;
79   int done =0;
80
81   SCM p = alternatives ()->music_list ();
82   while (gh_pair_p (p) && done < repeat_count ())
83     {
84       m = m + unsmob_music (gh_car (p))->length_mom ();
85       done ++;
86       if (repeat_count () - done < alternatives ()->length_i ())
87         p = gh_cdr (p);
88     }
89   return m;
90 }
91
92 Moment
93 Repeated_music::body_length_mom () const
94 {
95   Moment m = 0;
96   if (body ())
97     {
98       m = body ()->length_mom ();
99     }
100   return m;
101 }
102
103 int
104 Repeated_music::repeat_count () const
105 {
106   return gh_scm2int (get_mus_property ("repeat-count"));
107 }
108
109
110 MAKE_SCHEME_CALLBACK(Repeated_music,unfolded_music_length, 1);
111 MAKE_SCHEME_CALLBACK(Repeated_music,folded_music_length, 1);
112 MAKE_SCHEME_CALLBACK(Repeated_music,volta_music_length, 1);
113
114 SCM
115 Repeated_music::unfolded_music_length (SCM m)
116 {
117   Repeated_music* r = dynamic_cast<Repeated_music*> (unsmob_music (m));
118   
119   Moment l = Moment (r->repeat_count ()) * r->body_length_mom () + r->alternatives_length_mom (false);
120   return l.smobbed_copy ();
121 }
122
123 SCM
124 Repeated_music::folded_music_length (SCM m)
125 {
126   Repeated_music* r = dynamic_cast<Repeated_music*> (unsmob_music (m));
127  
128   Moment l =  r->body_length_mom () + r->alternatives_length_mom (true);
129   return l.smobbed_copy ();
130 }
131
132 SCM
133 Repeated_music::volta_music_length (SCM m)
134 {
135   Repeated_music* r = dynamic_cast<Repeated_music*> (unsmob_music (m));
136   Moment l =  r->body_length_mom () + r->alternatives_length_mom (false);
137   return l.smobbed_copy ();
138 }