From 76fc550ad24948eb3615ac2da52e22500d092e23 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Tue, 19 Sep 2000 12:00:47 +0200 Subject: [PATCH] patch::: 1.3.87.jcn2 1.3.87.jcn2 =========== * Added skip (M) to music-iterator which fixes ugly non-const hack of get-music (M). --- CHANGES | 6 +++++ VERSION | 2 +- lily/include/music-iterator.hh | 8 +++--- lily/include/simple-music-iterator.hh | 3 ++- lily/music-iterator.cc | 6 +++++ lily/request-chord-iterator.cc | 10 ++----- lily/sequential-music-iterator.cc | 39 +++++++++++---------------- lily/simple-music-iterator.cc | 10 +++++-- 8 files changed, 43 insertions(+), 41 deletions(-) diff --git a/CHANGES b/CHANGES index 243f56c9aa..79a11c4078 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,9 @@ +1.3.87.jcn2 +=========== + +* Added skip (M) to music-iterator which fixes ugly non-const hack + of get-music (M). + 1.3.87.jcn1 =========== diff --git a/VERSION b/VERSION index f9581647fb..4055f6ef3f 100644 --- a/VERSION +++ b/VERSION @@ -2,7 +2,7 @@ PACKAGE_NAME=LilyPond MAJOR_VERSION=1 MINOR_VERSION=3 PATCH_LEVEL=87 -MY_PATCH_LEVEL=jcn1 +MY_PATCH_LEVEL=jcn2 # use the above to send patches: MY_PATCH_LEVEL is always empty for a # released version. diff --git a/lily/include/music-iterator.hh b/lily/include/music-iterator.hh index 2f9c6cf7cc..25d099eccc 100644 --- a/lily/include/music-iterator.hh +++ b/lily/include/music-iterator.hh @@ -35,13 +35,10 @@ thus changing the state of the interpretation context. get_music (M) -- return all events starting at M (pre: no events - before M). Side effects: + before M). - * This removes all events at M from the pending queue. + skip (M) -- remove all events at M from the pending queue. - Because next (M) is rolled into process () as a side effect, - we need to roll next (M) into get_music too. Urg. - */ class Music_iterator { @@ -75,6 +72,7 @@ public: virtual bool ok () const; virtual SCM get_music (Moment until)const; virtual void process (Moment until); + virtual void skip (Moment until); /** Construct sub-iterators, and set the translator to diff --git a/lily/include/simple-music-iterator.hh b/lily/include/simple-music-iterator.hh index 6d86c1c35c..c9b861dce3 100644 --- a/lily/include/simple-music-iterator.hh +++ b/lily/include/simple-music-iterator.hh @@ -21,7 +21,8 @@ public: Simple_music_iterator (); Simple_music_iterator (Simple_music_iterator const &); virtual void process (Moment); - virtual bool ok()const; + virtual bool ok ()const; + virtual void skip (Moment); virtual Moment pending_moment ()const; virtual void construct_children (); }; diff --git a/lily/music-iterator.cc b/lily/music-iterator.cc index 51ae61f1ce..3806c4e7f7 100644 --- a/lily/music-iterator.cc +++ b/lily/music-iterator.cc @@ -85,6 +85,12 @@ Music_iterator::pending_moment () const } +void +Music_iterator::skip (Moment) +{ + assert (0); +} + void Music_iterator::process (Moment) { diff --git a/lily/request-chord-iterator.cc b/lily/request-chord-iterator.cc index 86ab37eaf3..080240a8b5 100644 --- a/lily/request-chord-iterator.cc +++ b/lily/request-chord-iterator.cc @@ -46,11 +46,8 @@ Request_chord_iterator::elt_l () const } SCM -Request_chord_iterator::get_music (Moment m) const +Request_chord_iterator::get_music (Moment) const { - Request_chord_iterator* urg = (Request_chord_iterator*)this; - urg->last_processed_mom_ = m; - urg->last_processed_mom_.set_infinite (1); SCM s = SCM_EOL; if (music_l_) { @@ -60,7 +57,6 @@ Request_chord_iterator::get_music (Moment m) const { s = gh_cons (gh_car (m) , s); } - urg->music_l_ = 0; } return s; } @@ -68,7 +64,6 @@ Request_chord_iterator::get_music (Moment m) const void Request_chord_iterator::process (Moment m) { - last_processed_mom_ = m; if (music_l_) { for (SCM s = dynamic_cast (music_l_)->music_list (); @@ -86,7 +81,6 @@ Request_chord_iterator::process (Moment m) mus->origin ()->warning (_f ("Huh? Not a Request: `%s'", classname (mus))); } - - music_l_ =0; } + skip (m); } diff --git a/lily/sequential-music-iterator.cc b/lily/sequential-music-iterator.cc index 82051844b4..18d9a4915a 100644 --- a/lily/sequential-music-iterator.cc +++ b/lily/sequential-music-iterator.cc @@ -90,45 +90,36 @@ Sequential_music_iterator::set_sequential_music_translator() SCM -Sequential_music_iterator::get_music (Moment until)const +Sequential_music_iterator::get_music (Moment until) const { -#if 1 - /* - FIXME: get_music () is const, so we must operate on a copy of child-iter. - - hmm, part-combiner does work on a copy; why copy again? - Also, simply `working on a copy' doesn't work: if request-chord's - get_music doesn't do next (), we'll stay in this loop forever? - */ - - Sequential_music_iterator* urg = (Sequential_music_iterator*)this; + Sequential_music_iterator* i = dynamic_cast (this->clone ()); SCM s = SCM_EOL; while (1) { - Moment local_until = until - here_mom_; - while (urg->iter_p_->ok ()) + Moment local_until = until - i->here_mom_; + while (i->iter_p_->ok ()) { - Moment here = iter_p_->pending_moment (); + Moment here = i->iter_p_->pending_moment (); if (here != local_until) - return s; + goto finalise; - s = gh_append2 (urg->iter_p_->get_music (local_until), s); + s = gh_append2 (i->iter_p_->get_music (local_until), s); + i->iter_p_->skip (local_until); } - if (!urg->iter_p_->ok ()) + if (!i->iter_p_->ok ()) { - urg->leave_element (); + i->leave_element (); - if (gh_pair_p (urg->cursor_)) - urg->start_next_element (); + if (gh_pair_p (i->cursor_)) + i->start_next_element (); else - return s; + goto finalise; } } + finalise: + delete i; return s; -#else - return SCM_EOL; -#endif } void diff --git a/lily/simple-music-iterator.cc b/lily/simple-music-iterator.cc index e919d4b5a0..b185f8ac24 100644 --- a/lily/simple-music-iterator.cc +++ b/lily/simple-music-iterator.cc @@ -45,6 +45,13 @@ Simple_music_iterator::pending_moment ()const return length_mom_; } +void +Simple_music_iterator::skip (Moment m) +{ + music_l_ = 0; + last_processed_mom_ = m; +} + void Simple_music_iterator::process (Moment m) { @@ -60,6 +67,5 @@ Simple_music_iterator::process (Moment m) classname (music_l_))); } #endif - music_l_ = 0; - last_processed_mom_ = m; + skip (m); } -- 2.39.2