source file of the GNU LilyPond music typesetter
- (c) 1998 Jan Nieuwenhuizen <janneke@gnu.org>
+ (c) 1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
*/
#include "repeated-music.hh"
+#include "music-list.hh"
#include "musical-pitch.hh"
+#include "debug.hh"
-//Repeated_music::Repeated_music (Music* r, int n, Music_list* a)
-Repeated_music::Repeated_music (Music* r, int n, Sequential_music* a)
+Repeated_music::Repeated_music(Music *beg, int times, Music_sequence * alts)
{
- repeats_i_ = n;
- repeat_p_ = r;
- alternative_p_ = a;
+ repeat_body_p_ = beg;
+ fold_b_ = false;
+ repeats_i_ = times;
+ alternatives_p_ = alts;
+ volta_fold_b_ = true;
+ if (alts)
+ alts->music_p_list_p_->truncate (times);
}
-Repeated_music::~Repeated_music ()
+Repeated_music::Repeated_music (Repeated_music const &s)
+ : Music (s)
{
- delete repeat_p_;
- delete alternative_p_;
+ repeats_i_ = s.repeats_i_;
+ fold_b_ = s.fold_b_;
+ volta_fold_b_ = s.volta_fold_b_;
+
+ repeat_body_p_ = s.repeat_body_p_ ? s.repeat_body_p_->clone () : 0;
+ alternatives_p_ = s.alternatives_p_
+ ? dynamic_cast<Music_sequence*> (s.alternatives_p_->clone ()):0;
}
-Repeated_music::Repeated_music (Repeated_music const& s)
- : Music (s)
+Repeated_music::~Repeated_music ()
{
- repeat_p_ = (s.repeat_p_) ? s.repeat_p_->clone () : 0;
- // urg?
-// alternative_p_ = (Sequential_music*)(s.alternative_p_) ? s.alternative_p_->clone () : 0;
+ delete repeat_body_p_;
+ delete alternatives_p_;
}
void
Repeated_music::do_print () const
{
- if (repeat_p_)
- repeat_p_->print ();
- if (alternative_p_)
- alternative_p_->print ();
+#ifndef NPRINT
+ DEBUG_OUT << "Fold = " << fold_b_ << " reps: " << repeats_i_;
+
+ if (repeat_body_p_)
+ repeat_body_p_->print();
+
+ if (alternatives_p_)
+ alternatives_p_->print();
+#endif
+}
+
+Musical_pitch
+Repeated_music::to_relative_octave (Musical_pitch p)
+{
+ if (repeat_body_p_)
+ p = repeat_body_p_->to_relative_octave (p);
+
+ if (alternatives_p_)
+ p = alternatives_p_->do_relative_octave (p, false);
+ return p;
}
+
+
void
Repeated_music::transpose (Musical_pitch p)
{
- if (repeat_p_)
- repeat_p_->transpose (p);
- if (alternative_p_)
- alternative_p_->transpose (p);
+ if (repeat_body_p_)
+ repeat_body_p_->transpose (p);
+
+ if (alternatives_p_)
+ alternatives_p_->transpose (p);
+}
+
+void
+Repeated_music::compress (Moment p)
+{
+ if (repeat_body_p_)
+ repeat_body_p_->compress (p);
+
+ if (alternatives_p_)
+ alternatives_p_->compress (p);
}
Moment
-Repeated_music::duration () const
+Repeated_music::alternatives_length_mom () const
{
- Moment m;
- if (repeat_p_)
- m += repeat_p_->duration ();
- if (alternative_p_)
- m += alternative_p_->duration ();
+ if (!alternatives_p_ )
+ return 0;
+
+ if (fold_b_)
+ return alternatives_p_->maximum_length ();
+
+ Moment m =0;
+ int done =0;
+ Cons<Music> *p = alternatives_p_->music_p_list_p_->head_;
+ while (p && done < repeats_i_)
+ {
+ m = m + p->car_->length_mom ();
+ done ++;
+ if (volta_fold_b_
+ || repeats_i_ - done < alternatives_p_->length_i ())
+ p = p->next_;
+ }
+ return m;
+}
+
+Moment
+Repeated_music::length_mom () const
+{
+ Moment m =0;
+ if (fold_b_)
+ {
+ if (repeat_body_p_)
+ m += repeat_body_p_->length_mom ();
+ }
+ else
+ {
+ Moment beg = (repeat_body_p_) ? repeat_body_p_->length_mom () : Rational(0);
+ if (!volta_fold_b_)
+ beg *= Rational (repeats_i_);
+ m += beg;
+ }
+
+ m += alternatives_length_mom ();
return m;
}