--- /dev/null
+
+\score { \context Staff \notes \repeat volta 3 c1 \alternative { d1 e1 }}
--- /dev/null
+\score { \notes \context Voice {
+ \repeat volta 3 c1
+ \alternative { d f } e4 } }
w = sneaky_insert_extra_moment (w);
prepare (w);
- iter->process (w);
+ if (iter->ok ())
+ iter->process (w);
one_time_step ();
}
Moment body_length_mom () const;
Moment alternatives_length_mom (bool fold) const;
+ Moment alternatives_volta_length_mom () const;
DECLARE_SCHEME_CALLBACK(unfolded_music_length, (SCM));
DECLARE_SCHEME_CALLBACK(volta_music_length, (SCM));
-/*
- unfolded-repeat-iterator.hh -- declare Unfolded_repeat_iterator
-
- source file of the GNU LilyPond music typesetter
-
- (c) 1999--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
-
- */
-#ifndef UNFOLDED_REPEAT_ITERATOR_HH
-#define UNFOLDED_REPEAT_ITERATOR_HH
-
-#include "music-iterator.hh"
-
-/**
- Iterate repeats. First do body, then alternatives one by one,
- optionally interspersed by the body.
- */
-class Unfolded_repeat_iterator : public Music_iterator
-{
- void add_repeat_command (SCM);
-
-public:
- VIRTUAL_COPY_CONS (Music_iterator);
- /**
- How often have we done the body (assuming bodies are interspersed.)?
- */
- int done_count_;
- static SCM constructor_cxx_function;
-
- /*
- are we now busy doing the body?
-
- */
- bool do_main_b_;
-
- /*
- are we doing volta's?
- */
- bool volta_b_;
-
- /** How far have we progressed into the repeat.
- This excludes the elt currently being iterated.
- */
- Moment here_mom_;
- int alternative_count_i_;
- Music_iterator * current_iter_p_;
-
- /// pointer to the alternative that will be processed next.
- SCM alternative_cons_;
- ~Unfolded_repeat_iterator();
- Unfolded_repeat_iterator ();
- Unfolded_repeat_iterator (Unfolded_repeat_iterator const &);
-protected:
- virtual void construct_children ();
- virtual Moment pending_moment () const;
- virtual void process (Moment);
- virtual Music_iterator *try_music_in_children (Music *) const;
- virtual void skip (Moment);
- virtual SCM get_music (Moment) const;
-
- virtual bool ok () const;
- virtual void next_element (bool side_effect);
-};
-
-class Volta_repeat_iterator : public Unfolded_repeat_iterator
-{
-public:
- Volta_repeat_iterator ();
- static SCM constructor_cxx_function;
- VIRTUAL_COPY_CONS(Music_iterator);
-};
-
-
-#endif /* UNFOLDED_REPEAT_ITERATOR_HH */
+#error
return m;
}
+/*
+ Sum all duration of all available alternatives. This is for the case
+ of volta repeats, where the alternatives are iterated just as they
+ were entered. */
+Moment
+Repeated_music::alternatives_volta_length_mom () const
+{
+ SCM p = alternatives ()->music_list ();
+ Moment m;
+ while (gh_pair_p (p))
+ {
+ m = m + unsmob_music (gh_car (p))->length_mom ();
+ p = gh_cdr (p);
+ }
+ return m;
+}
+
Moment
Repeated_music::body_length_mom () const
{
Repeated_music::volta_music_length (SCM m)
{
Repeated_music* r = dynamic_cast<Repeated_music*> (unsmob_music (m));
- Moment l = r->body_length_mom () + r->alternatives_length_mom (false);
+ Moment l = r->body_length_mom () + r->alternatives_volta_length_mom ();
return l.smobbed_copy ();
}
Sequential_music_iterator::descend_to_child ()
{
Translator_group * child_report = child_report = iter_p_->report_to_l ();
+ Translator_group * me_report = report_to_l ();
+
if (dynamic_cast<Grace_iterator*> (iter_p_))
child_report = child_report->daddy_trans_l_;
-
- if (report_to_l()->depth_i () < child_report->depth_i ())
+
+ Translator_group * c = child_report;
+ while (c && c != me_report)
+ {
+ c= c->daddy_trans_l_;
+ }
+
+ if (c == me_report)
set_translator (child_report);
}
*/
-
+/*
+ This is too hairy. Maybe split into subclasses for volta and full
+ unfold?
+
+ */
+#include "music-iterator.hh"
#include "repeated-music.hh"
#include "music-list.hh"
-#include "unfolded-repeat-iterator.hh"
#include "debug.hh"
#include "translator-group.hh"
+/**
+ Iterate repeats. First do body, then alternatives one by one,
+ optionally interspersed by the body.
+ */
+class Unfolded_repeat_iterator : public Music_iterator
+{
+ void add_repeat_command (SCM);
+
+public:
+ VIRTUAL_COPY_CONS (Music_iterator);
+ /**
+ How often have we done the body (assuming bodies are interspersed.)?
+
+ In volta: the number to print in the bracket.
+ */
+ int done_count_;
+ static SCM constructor_cxx_function;
+
+ /*
+ are we now busy doing the body?
+
+ */
+ bool do_main_b_;
+
+ /*
+ are we doing volta's?
+ */
+ bool volta_b_;
+
+ /** How far have we progressed into the repeat.
+ This excludes the elt currently being iterated.
+ */
+ Moment here_mom_;
+ int alternative_count_i_;
+ Music_iterator * current_iter_p_;
+
+ /// pointer to the alternative that will be processed next.
+ SCM alternative_cons_;
+ ~Unfolded_repeat_iterator();
+ Unfolded_repeat_iterator ();
+ Unfolded_repeat_iterator (Unfolded_repeat_iterator const &);
+protected:
+ virtual void construct_children ();
+ virtual Moment pending_moment () const;
+ virtual void process (Moment);
+ virtual Music_iterator *try_music_in_children (Music *) const;
+ virtual void skip (Moment);
+ virtual SCM get_music (Moment) const;
+
+ virtual bool ok () const;
+ virtual void next_element (bool side_effect);
+};
+
+class Volta_repeat_iterator : public Unfolded_repeat_iterator
+{
+public:
+ Volta_repeat_iterator ();
+ static SCM constructor_cxx_function;
+ VIRTUAL_COPY_CONS(Music_iterator);
+};
+
+
+
Unfolded_repeat_iterator::~Unfolded_repeat_iterator ()
{
delete current_iter_p_;
if (volta_b_)
{
- String repstr = to_str (done_count_ + 1);
+ String repstr = to_str (done_count_ + 1) + ".";
+
+ /*
+ we're coming in from main, so we're always on the first repeat.
+ */
+ assert (done_count_ == 0);
+
+ if (done_count_ == 0
+ && alternative_count_i_ < repmus->repeat_count ())
+ {
+ done_count_ += repmus->repeat_count () - alternative_count_i_;
+ repstr = "1.--" + to_str (done_count_ + 1) + ".";
+ }
+
if (do_repcommands)
add_repeat_command (gh_list (ly_symbol2scm ("volta"),
ly_str02scm (repstr.ch_C()), SCM_UNDEFINED));
{
if (do_repcommands)
{
- String repstr = to_str (done_count_ + 1);
+ String repstr = to_str (done_count_ + 1) + ".";
add_repeat_command (gh_list (ly_symbol2scm ("volta"),
ly_str02scm (repstr.ch_C()), SCM_UNDEFINED));
add_repeat_command (ly_symbol2scm ("end-repeat"));
bool
Unfolded_repeat_iterator::ok () const
{
- return current_iter_p_ ;
+ return current_iter_p_;
}
Moment
current_iter_p_ = get_iterator_p (unsmob_music (gh_car (alternative_cons_)));
do_main_b_ = false;
}
+
+ while (current_iter_p_ && !current_iter_p_-> ok())
+ {
+ next_element(true);
+ }
}
/*