From 42688099e519fe7ed3b004ea3343f40a6920a24f Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Wed, 13 Sep 2000 16:09:08 +0200 Subject: [PATCH] patch::: 1.3.85.jcn5 1.3.85.jcn5 =========== * Modified part-combiner to use new get_music ()/next () music iterator functionality. --- CHANGES | 6 + VERSION | 2 +- lily/include/interpretation-context-handle.hh | 10 +- lily/include/music-iterator.hh | 81 +++++---- lily/include/part-combine-music-iterator.hh | 3 - lily/include/simple-music-iterator.hh | 10 +- lily/interpretation-context-handle.cc | 43 +++-- lily/music-iterator.cc | 2 +- lily/music-wrapper-iterator.cc | 2 +- lily/part-combine-music-iterator.cc | 158 ++++++++---------- lily/request-chord-iterator.cc | 16 +- lily/sequential-music-iterator.cc | 2 +- lily/translator-group.cc | 3 +- 13 files changed, 171 insertions(+), 167 deletions(-) diff --git a/CHANGES b/CHANGES index d2632bd90b..39df550cb1 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,9 @@ +1.3.85.jcn5 +=========== + +* Modified part-combiner to use new get_music ()/next () music iterator + functionality. + 1.3.85.jcn4 =========== diff --git a/VERSION b/VERSION index 606e08f2f9..988cb0b614 100644 --- a/VERSION +++ b/VERSION @@ -2,7 +2,7 @@ PACKAGE_NAME=LilyPond MAJOR_VERSION=1 MINOR_VERSION=3 PATCH_LEVEL=85 -MY_PATCH_LEVEL=jcn4 +MY_PATCH_LEVEL=jcn5 # use the above to send patches: MY_PATCH_LEVEL is always empty for a # released version. diff --git a/lily/include/interpretation-context-handle.hh b/lily/include/interpretation-context-handle.hh index fc15f7a19d..cb788f124a 100644 --- a/lily/include/interpretation-context-handle.hh +++ b/lily/include/interpretation-context-handle.hh @@ -13,18 +13,20 @@ class Interpretation_context_handle { - Translator_group * report_to_l_; -public: - void down (); - void up (Translator_group*); public: ~Interpretation_context_handle (); Interpretation_context_handle (); + Interpretation_context_handle* clone () const; void set_translator (Translator_group*); bool try_music (Music *); void operator =(Interpretation_context_handle const&); Interpretation_context_handle (Interpretation_context_handle const&); Translator_group * report_to_l () const; + +private: + Translator_group * report_to_l_; + void down (); + void up (Translator_group*); }; #endif /* INTERPRETATION_CONTEXT_HANDLE_HH */ diff --git a/lily/include/music-iterator.hh b/lily/include/music-iterator.hh index 81b1bfe0bc..87644b494f 100644 --- a/lily/include/music-iterator.hh +++ b/lily/include/music-iterator.hh @@ -26,47 +26,12 @@ */ class Music_iterator { - //private: -public: - Interpretation_context_handle handle_; - -protected: - Music * music_l_; - - /// ugh. JUNKME - bool first_b_; - - /** - Do the actual printing. This should be overriden in derived classes. It - is called by #print#, in the public interface - */ - virtual void do_print() const; - - /** - Find a bottom notation context to deliver requests to. - */ - virtual Translator_group* get_req_translator_l(); - - /** - Get an iterator for MUS, inheriting the translation unit from THIS. - */ - Music_iterator* get_iterator_p (Music *mus) const; - - /** Do the actual move. This should be overriden in derived - classes. It is called by #process_and_next#, the public interface - */ - virtual void do_process_and_next (Moment until); - - - virtual Music_iterator* try_music_in_children (Music *) const; - public: VIRTUAL_COPY_CONS (Music_iterator); - Music_iterator(); + Music_iterator (); Music_iterator (Music_iterator const&); - virtual ~Music_iterator(); - + virtual ~Music_iterator (); /** Do the reporting. Will try MUSIC_L_ in its own translator first, @@ -77,7 +42,7 @@ public: /** The translation unit that we this iterator is reporting to now. */ - Translator_group*report_to_l() const; + Translator_group*report_to_l () const; void set_translator (Translator_group*); @@ -88,11 +53,11 @@ public: void init_translator (Music *, Translator_group *); /// Find the next interesting point in time. - virtual Moment next_moment() const; + virtual Moment next_moment () const; ///Are we finished with this piece of music? - virtual bool ok() const; + virtual bool ok () const; virtual Music* get_music (); virtual bool next (); @@ -104,8 +69,40 @@ public: Construct sub-iterators, and set the translator to report to. */ - virtual void construct_children(); - void print() const; + virtual void construct_children (); + void print () const; + +protected: + Music * music_l_; + + /// ugh. JUNKME + bool first_b_; + + /** + Do the actual printing. This should be overriden in derived classes. It + is called by #print#, in the public interface + */ + virtual void do_print () const; + + /** + Find a bottom notation context to deliver requests to. + */ + virtual Translator_group* get_req_translator_l (); + + /** + Get an iterator for MUS, inheriting the translation unit from THIS. + */ + Music_iterator* get_iterator_p (Music *) const; + + /** Do the actual move. This should be overriden in derived + classes. It is called by #process_and_next#, the public interface + */ + virtual void do_process_and_next (Moment until); + + virtual Music_iterator* try_music_in_children (Music *) const; + +private: + Interpretation_context_handle handle_; }; #endif // MUSIC_ITERATOR_HH diff --git a/lily/include/part-combine-music-iterator.hh b/lily/include/part-combine-music-iterator.hh index caf7b4dcd7..d43a00a72d 100644 --- a/lily/include/part-combine-music-iterator.hh +++ b/lily/include/part-combine-music-iterator.hh @@ -33,11 +33,8 @@ private: Music_iterator * first_iter_p_; Music_iterator * second_iter_p_; - Moment now_; Moment first_until_; Moment second_until_; - - bool combined_b_; }; #endif /* PART_COMBINE_MUSIC_ITERATOR_HH */ diff --git a/lily/include/simple-music-iterator.hh b/lily/include/simple-music-iterator.hh index 1fa5bb7d16..324c9b952a 100644 --- a/lily/include/simple-music-iterator.hh +++ b/lily/include/simple-music-iterator.hh @@ -1,14 +1,13 @@ /* - request-iterator.hh -- declare Request_iterator + simple-music-iterator.hh -- declare Simple_music_iterator source file of the GNU LilyPond music typesetter (c) 2000 Han-Wen Nienhuys - */ -#ifndef REQUEST_ITERATOR_HH -#define REQUEST_ITERATOR_HH +#ifndef SIMPLE_MUSIC_ITERATOR_HH +#define SIMPLE_MUSIC_ITERATOR_HH #include "music-iterator.hh" @@ -18,9 +17,10 @@ public: VIRTUAL_COPY_CONS (Music_iterator); Simple_music_iterator (); Simple_music_iterator (Simple_music_iterator const &); + protected: virtual void do_process_and_next (Moment ); }; -#endif /* REQUEST_ITERATOR_HH */ +#endif /* SIMPLE_MUSIC_ITERATOR_HH */ diff --git a/lily/interpretation-context-handle.cc b/lily/interpretation-context-handle.cc index b6a403ea2d..e5b056e601 100644 --- a/lily/interpretation-context-handle.cc +++ b/lily/interpretation-context-handle.cc @@ -11,6 +11,32 @@ #include "interpretation-context-handle.hh" #include "translator-group.hh" +Interpretation_context_handle::Interpretation_context_handle() +{ + report_to_l_ =0; +} + +Interpretation_context_handle::Interpretation_context_handle (Interpretation_context_handle const&s) +{ + report_to_l_ =0; + if (s.report_to_l_) + up (s.report_to_l_ ); +} + +Interpretation_context_handle* +Interpretation_context_handle::clone () const +{ + Interpretation_context_handle* handle = new Interpretation_context_handle; + handle->report_to_l_ = this->report_to_l_; + return handle; +} + +Interpretation_context_handle::~Interpretation_context_handle () +{ + if (report_to_l_) + down (); +} + void Interpretation_context_handle::up (Translator_group*t) { @@ -31,13 +57,6 @@ Interpretation_context_handle::try_music (Music *m) return report_to_l_->try_music (m); } -Interpretation_context_handle::Interpretation_context_handle (Interpretation_context_handle const&s) -{ - report_to_l_ =0; - if (s.report_to_l_) - up (s.report_to_l_ ); -} - void Interpretation_context_handle::operator = (Interpretation_context_handle const &s) { @@ -61,14 +80,4 @@ Interpretation_context_handle::report_to_l ()const return report_to_l_; } -Interpretation_context_handle::Interpretation_context_handle() -{ - report_to_l_ =0; -} - -Interpretation_context_handle::~Interpretation_context_handle () -{ - if (report_to_l_) - down (); -} diff --git a/lily/music-iterator.cc b/lily/music-iterator.cc index e0978106da..bae22a94af 100644 --- a/lily/music-iterator.cc +++ b/lily/music-iterator.cc @@ -49,7 +49,7 @@ Music_iterator::Music_iterator () Music_iterator::Music_iterator (Music_iterator const& src) { first_b_ = src.first_b_; - handle_ = src.handle_; + handle_ = *src.handle_.clone (); music_l_ = src.music_l_; } diff --git a/lily/music-wrapper-iterator.cc b/lily/music-wrapper-iterator.cc index 4aa13bd9a2..396e9c4657 100644 --- a/lily/music-wrapper-iterator.cc +++ b/lily/music-wrapper-iterator.cc @@ -19,7 +19,7 @@ Music_wrapper_iterator::Music_wrapper_iterator () Music_wrapper_iterator::Music_wrapper_iterator (Music_wrapper_iterator const &src) : Music_iterator (src) { - child_iter_p_ = src.child_iter_p_; + child_iter_p_ = src.child_iter_p_->clone (); } Music_wrapper_iterator::~Music_wrapper_iterator () diff --git a/lily/part-combine-music-iterator.cc b/lily/part-combine-music-iterator.cc index ab2ec18b9a..b5c3780961 100644 --- a/lily/part-combine-music-iterator.cc +++ b/lily/part-combine-music-iterator.cc @@ -15,9 +15,6 @@ Part_combine_music_iterator::Part_combine_music_iterator () { - combined_b_ = true; - - now_ = 0; first_iter_p_ = 0; second_iter_p_ = 0; first_until_ = 0; @@ -123,86 +120,64 @@ Part_combine_music_iterator::do_process_and_next (Moment m) { Part_combine_music const * p = dynamic_cast (music_l_); - /* - TODO: - - * Maybe we need a Skip_engraver? - - (check): can this all be handled now? - - Maybe different modes exist? - - * Wind instruments (Flute I/II) - * Hymnals: - - - Rules for Hymnals/SATB (John Henckel ): - - 1. if S and A differ by less than a third, the stems should be up/down. - 2. else if S and A have different values, the stems should be up/down. - 3. else if A sings "la" or higher, both S and A stems should be down. - 4. else both stems should be up - - * This may get really tricky: combining voices/staffs: string instruments - - */ - - /* - Huh? - */ - now_ = next_moment (); - Music *first_music; - Music_iterator* first_next = first_iter_p_->clone (); - //first_next->next (); - if (first_next->ok ()) - first_music = first_next->get_music (); -#if 0 - delete first_next; -#else - //URGURURGU - first_next->handle_.down (); -#endif - - Music *second_music; - Music_iterator* second_next = second_iter_p_->clone (); - //second_next->next (); - if (second_next->ok ()) - second_music = second_next->get_music (); -#if 0 - delete second_next; -#else - //URGURURGU - second_next->handle_.down (); -#endif + Moment now = next_moment (); Array first_pitches; Array first_durations; - if (Music_sequence* m = dynamic_cast (first_music)) + if (first_iter_p_->ok ()) { - for (SCM s = m->music_list (); gh_pair_p (s); s = gh_cdr (s)) + Music_iterator* i = first_iter_p_->clone (); + Moment until = i->next_moment (); + + /* Urg, silly first_b_ stuff */ + if (now && i->next ()) + until = i->next_moment (); + + /* How about a 'now_moment ()' for iterators? */ + for (; i->ok () && i->next_moment () == until; i->next ()) { - Music *u = unsmob_music (gh_car (s)); - if (Melodic_req *r = dynamic_cast (u)) - first_pitches.push (r->pitch_); - if (Rhythmic_req *r = dynamic_cast (u)) - first_durations.push (r->duration_); + if (Music_sequence* m = dynamic_cast (i->get_music ())) + { + for (SCM s = m->music_list (); gh_pair_p (s); s = gh_cdr (s)) + { + Music *u = unsmob_music (gh_car (s)); + if (Melodic_req *r = dynamic_cast (u)) + first_pitches.push (r->pitch_); + if (Rhythmic_req *r = dynamic_cast (u)) + first_durations.push (r->duration_); + } + } } } Array second_pitches; Array second_durations; - if (Music_sequence* m = dynamic_cast (second_music)) + if (second_iter_p_->ok ()) { - for (SCM s = m->music_list (); gh_pair_p (s); s = gh_cdr (s)) + Music_iterator* i = second_iter_p_->clone (); + Moment until = i->next_moment (); + + /* Urg, silly second_b_ stuff */ + if (now && i->next ()) + until = i->next_moment (); + + /* How about a 'now_moment ()' for iterators? */ + for (; i->ok () && i->next_moment () == until; i->next ()) { - Music *u = unsmob_music (gh_car (s)); - if (Melodic_req *r = dynamic_cast (u)) - second_pitches.push (r->pitch_); - if (Rhythmic_req *r = dynamic_cast (u)) - second_durations.push (r->duration_); + if (Music_sequence* m = dynamic_cast (i->get_music ())) + { + for (SCM s = m->music_list (); gh_pair_p (s); s = gh_cdr (s)) + { + Music *u = unsmob_music (gh_car (s)); + if (Melodic_req *r = dynamic_cast (u)) + second_pitches.push (r->pitch_); + if (Rhythmic_req *r = dynamic_cast (u)) + second_durations.push (r->duration_); + } + } } } - + SCM interval = SCM_BOOL_F; if (first_pitches.size () && second_pitches.size ()) { @@ -214,7 +189,7 @@ Part_combine_music_iterator::do_process_and_next (Moment m) if (first_durations.size ()) { first_durations.sort (Duration::compare); - Moment new_until = now_ + first_durations.top ().length_mom (); + Moment new_until = now + first_durations.top ().length_mom (); if (new_until > first_until_) first_until_ = new_until; } @@ -222,16 +197,31 @@ Part_combine_music_iterator::do_process_and_next (Moment m) if (second_durations.size ()) { second_durations.sort (Duration::compare); - Moment new_until = now_ + second_durations.top ().length_mom (); + Moment new_until = now + second_durations.top ().length_mom (); if (new_until > second_until_) second_until_ = new_until; } +#if 0 /* DEBUG */ + printf ("now: %s\n", now.str ().ch_C ()); + printf ("first: "); + for (int i = 0; i < first_pitches.size (); i++) + { + printf ("%s, ", first_pitches[i].str ().ch_C ()); + } + printf ("\nsecond: "); + for (int i = 0; i < second_pitches.size (); i++) + { + printf ("%s, ", second_pitches[i].str ().ch_C ()); + } + printf ("\n"); +#endif + Translator_group * fir = first_iter_p_->report_to_l (); Translator_group * sir = second_iter_p_->report_to_l (); bool solo_b = (first_pitches.empty () != second_pitches.empty ()) - && !(first_until_ > now_ && second_until_ > now_); + && !(first_until_ > now && second_until_ > now); bool unirhythm_b = !solo_b && !compare (&first_durations, &second_durations); bool unison_b = unirhythm_b && !first_pitches.empty () @@ -254,26 +244,23 @@ Part_combine_music_iterator::do_process_and_next (Moment m) split_interval_b = true; } - /* - URG, dememberme - */ - combined_b_ = first_iter_p_->report_to_l ()->daddy_trans_l_ + bool combined_b = first_iter_p_->report_to_l ()->daddy_trans_l_ == second_iter_p_->report_to_l ()->daddy_trans_l_; - String to_id = combined_b_ ? "one" : "two"; - if ((!unirhythm_b && combined_b_) - || (split_interval_b && combined_b_) - || (solo_b && combined_b_) - /*|| (unisilence_b && combined_b_) */ + String to_id = combined_b ? "one" : "two"; + if ((!unirhythm_b && combined_b) + || (split_interval_b && combined_b) + || (solo_b && combined_b) + /*|| (unisilence_b && combined_b) */ || ((unirhythm_b || unison_b || unisilence_b) - && !combined_b_ && !split_interval_b && !solo_b)) + && !combined_b && !split_interval_b && !solo_b)) { - combined_b_ = !combined_b_; - to_id = combined_b_ ? "one" : "two"; + combined_b = !combined_b; + to_id = combined_b ? "one" : "two"; change_to (second_iter_p_, p->what_str_, to_id); } - if (!combined_b_) + if (!combined_b) sir = second_iter_p_->report_to_l (); SCM b = unirhythm_b ? SCM_BOOL_T : SCM_BOOL_F; @@ -315,7 +302,6 @@ Part_combine_music_iterator::do_process_and_next (Moment m) second_iter_p_->process_and_next (m); Music_iterator::do_process_and_next (m); - now_ = next_moment (); } Music_iterator* diff --git a/lily/request-chord-iterator.cc b/lily/request-chord-iterator.cc index 61e38b3094..f7ae404b92 100644 --- a/lily/request-chord-iterator.cc +++ b/lily/request-chord-iterator.cc @@ -64,17 +64,22 @@ Request_chord_iterator::do_print() const bool Request_chord_iterator::next () { - first_b_ = false; - // last_b_ = true; + if (first_b_) + first_b_ = false; + else + last_b_ = true; return ok (); } void Request_chord_iterator::do_process_and_next (Moment mom) { +#if 0 // URG - // if (ok ()) - if (first_b_) + //if (first_b_) +#else + if (ok ()) +#endif { for (SCM s = dynamic_cast (get_music ())->music_list (); gh_pair_p (s); s = gh_cdr (s)) { @@ -92,8 +97,9 @@ Request_chord_iterator::do_process_and_next (Moment mom) } next (); +#if 0 // URG if (mom >= elt_length_mom_) last_b_ = true; - +#endif } diff --git a/lily/sequential-music-iterator.cc b/lily/sequential-music-iterator.cc index 3e89e02522..8ba2fa20db 100644 --- a/lily/sequential-music-iterator.cc +++ b/lily/sequential-music-iterator.cc @@ -24,7 +24,7 @@ Sequential_music_iterator::Sequential_music_iterator (Sequential_music_iterator { cursor_ = src.cursor_; here_mom_ = src.here_mom_; - iter_p_ = src.iter_p_; + iter_p_ = src.iter_p_->clone (); } Sequential_music_iterator::~Sequential_music_iterator() diff --git a/lily/translator-group.cc b/lily/translator-group.cc index dc1b92025a..94905795cf 100644 --- a/lily/translator-group.cc +++ b/lily/translator-group.cc @@ -33,7 +33,8 @@ Translator_group::properties_dict () const Translator_group::~Translator_group () { - assert (removable_b()); + + //assert (removable_b()); } -- 2.39.5