From d27ef155547da87c6cceb5c67839e9fe469a90f2 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sun, 13 Aug 2000 20:05:00 +0200 Subject: [PATCH] patch::: 1.3.77.jcn3 1.3.77.jcn3 =========== * First try at combining parts: part-combine* --- Generated by janneke@gnu.org, From = lilypond-1.3.77.jcn2, To = lilypond-1.3.77.jcn3 usage cd lilypond-source-dir; patch -E -p1 < lilypond-1.3.77.jcn3.diff Patches do not contain automatically generated files or (urg) empty directories, i.e., you should rerun autoconf, configure --- CHANGES | 13 +- VERSION | 2 +- input/test/part-combine.ly | 18 ++ lily/include/part-combine-music-iterator.hh | 40 ++++ lily/include/part-combine-music.hh | 35 +++ lily/music-iterator.cc | 4 + lily/my-lily-lexer.cc | 1 + lily/parser.yy | 12 +- lily/part-combine-music-iterator.cc | 238 ++++++++++++++++++++ lily/part-combine-music.cc | 65 ++++++ 10 files changed, 425 insertions(+), 3 deletions(-) create mode 100644 input/test/part-combine.ly create mode 100644 lily/include/part-combine-music-iterator.hh create mode 100644 lily/include/part-combine-music.hh create mode 100644 lily/part-combine-music-iterator.cc create mode 100644 lily/part-combine-music.cc diff --git a/CHANGES b/CHANGES index bc42e868b4..76c1d7e6d9 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,15 @@ ---- ../lilypond-1.3.77.jcn1/CHANGES Wed Aug 9 23:30:23 2000 +--- ../lilypond-1.3.77.jcn2/CHANGES Sun Aug 13 15:50:59 2000 +++ b/CHANGES Sun Aug 13 20:05:00 2000 +@@ -1,3 +1,9 @@ +1.3.77.jcn3 +=========== + +* First try at combining parts: part-combine* + + + * fixed problem with HaraKiri + + * fixed problem with dynamicDirection--- ../lilypond-1.3.77.jcn1/CHANGES Wed Aug 9 23:30:23 2000 ++ b/CHANGES Sun Aug 13 15:50:59 2000 @@ -1,3 +1,10 @@ * fixed problem with HaraKiri diff --git a/VERSION b/VERSION index 30db784b63..02d85c324e 100644 --- a/VERSION +++ b/VERSION @@ -2,7 +2,7 @@ PACKAGE_NAME=LilyPond MAJOR_VERSION=1 MINOR_VERSION=3 PATCH_LEVEL=77 -MY_PATCH_LEVEL=jcn2 +MY_PATCH_LEVEL=jcn3 # use the above to send patches: MY_PATCH_LEVEL is always empty for a # released version. diff --git a/input/test/part-combine.ly b/input/test/part-combine.ly new file mode 100644 index 0000000000..d228cd703d --- /dev/null +++ b/input/test/part-combine.ly @@ -0,0 +1,18 @@ +\score{ + \context Staff = first < + \context Voice=first { \skip 1; } + \context Voice=second { \skip 1; } + + \context Voice=first \partcombine Voice + \context Thread \notes\relative c'' + { + c4 d e f + c4 d e f + } + \context Thread \notes\relative c'' + { + a b c d + a4. b8 c4 d + } + > +} diff --git a/lily/include/part-combine-music-iterator.hh b/lily/include/part-combine-music-iterator.hh new file mode 100644 index 0000000000..60cbebc8fc --- /dev/null +++ b/lily/include/part-combine-music-iterator.hh @@ -0,0 +1,40 @@ +/* + part-combine-music-iterator.hh -- declare Part_combine_music_iterator + + source file of the GNU LilyPond music typesetter + + (c) 2000 Jan Nieuwenhuizen + + */ + +#ifndef PART_COMBINE_MUSIC_ITERATOR_HH +#define PART_COMBINE_MUSIC_ITERATOR_HH + +#include "music-iterator.hh" + +class Part_combine_music_iterator : public Music_iterator +{ +public: + Part_combine_music_iterator (); + +protected: + virtual void construct_children (); + virtual Moment next_moment () const; + virtual void do_process_and_next (Moment); + virtual Music_iterator *try_music_in_children (Music *) const; + + virtual bool ok () const; + virtual void do_print () const; + virtual ~Part_combine_music_iterator (); + +private: + void change_to (Music_iterator*, String, String); + + Music_iterator * first_iter_p_; + Music_iterator * second_iter_p_; + + bool combined_b_; +}; + +#endif /* PART_COMBINE_MUSIC_ITERATOR_HH */ + diff --git a/lily/include/part-combine-music.hh b/lily/include/part-combine-music.hh new file mode 100644 index 0000000000..102de3ad06 --- /dev/null +++ b/lily/include/part-combine-music.hh @@ -0,0 +1,35 @@ +/* + part-combine-music.hh -- declare Part_combine_music + + source file of the GNU LilyPond music typesetter + + (c) 2000 Jan Nieuwenhuizen + + */ + +#ifndef PART_COMBINE_MUSIC_HH +#define PART_COMBINE_MUSIC_HH + +#include "music.hh" + + +class Part_combine_music : public Music +{ +public: + VIRTUAL_COPY_CONS (Music); + Part_combine_music (String, Music*, Music*); + + Music * first_l () const; + Music * second_l () const; + + virtual void transpose (Musical_pitch); + virtual void do_print () const; + virtual Moment length_mom () const; + virtual Musical_pitch to_relative_octave (Musical_pitch); + virtual void compress (Moment); + + String what_str_; +}; + +#endif /* PART_COMBINE_MUSIC_HH */ + diff --git a/lily/music-iterator.cc b/lily/music-iterator.cc index d3a92834e7..9e88aeb12b 100644 --- a/lily/music-iterator.cc +++ b/lily/music-iterator.cc @@ -34,6 +34,8 @@ #include "lyric-combine-music-iterator.hh" #include "auto-change-music.hh" #include "auto-change-iterator.hh" +#include "part-combine-music.hh" +#include "part-combine-music-iterator.hh" #include "request.hh" #include "request-iterator.hh" #include "output-property.hh" @@ -146,6 +148,8 @@ Music_iterator::static_get_iterator_p (Music *m) p = new Grace_iterator; else if (dynamic_cast (m)) p = new Auto_change_iterator; + else if (dynamic_cast (m)) + p = new Part_combine_music_iterator; else if (dynamic_cast (m)) p = new Music_wrapper_iterator; else if (Repeated_music * n = dynamic_cast (m)) diff --git a/lily/my-lily-lexer.cc b/lily/my-lily-lexer.cc index 9020ae1659..4bd5a30495 100644 --- a/lily/my-lily-lexer.cc +++ b/lily/my-lily-lexer.cc @@ -66,6 +66,7 @@ static Keyword_ent the_key_tab[]={ {"remove", REMOVE}, {"repeat", REPEAT}, {"addlyrics", ADDLYRICS}, + {"partcombine", PARTCOMBINE}, {"score", SCORE}, {"script", SCRIPT}, {"skip", SKIP}, diff --git a/lily/parser.yy b/lily/parser.yy index 5c4632ac72..215dd69394 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -41,6 +41,7 @@ #include "mudela-version.hh" #include "grace-music.hh" #include "auto-change-music.hh" +#include "part-combine-music.hh" #include "output-property.hh" bool @@ -168,6 +169,7 @@ yylex (YYSTYPE *s, void * v_l) %token REMOVE %token REPEAT %token ADDLYRICS +%token PARTCOMBINE %token SCM_T %token SCORE %token SCRIPT @@ -237,7 +239,7 @@ yylex (YYSTYPE *s, void * v_l) %type embedded_scm scalar %type Music Sequential_music Simultaneous_music Music_sequence -%type relative_music re_rhythmed_music +%type relative_music re_rhythmed_music part_combined_music %type property_def translator_change %type Music_list %type music_output_def_body @@ -757,6 +759,7 @@ Composite_music: } | relative_music { $$ = $1; } | re_rhythmed_music { $$ = $1; } + | part_combined_music { $$ = $1; } ; relative_music: @@ -773,6 +776,13 @@ re_rhythmed_music: } ; +part_combined_music: + PARTCOMBINE STRING Music Music { + Part_combine_music * p = new Part_combine_music (ly_scm2string ($2), $3, $4); + $$ = p; + } + ; + translator_change: TRANSLATOR STRING '=' STRING { Change_translator * t = new Change_translator; diff --git a/lily/part-combine-music-iterator.cc b/lily/part-combine-music-iterator.cc new file mode 100644 index 0000000000..33bea70d14 --- /dev/null +++ b/lily/part-combine-music-iterator.cc @@ -0,0 +1,238 @@ +/* + part-combine-music-iterator.cc -- implement Part_combine_music_iterator + + source file of the GNU LilyPond music typesetter + + (c) 2000 Jan Nieuwenhuizen + */ + +#include "part-combine-music.hh" +#include "part-combine-music-iterator.hh" +#include "translator-group.hh" +#include "musical-request.hh" +#include "warn.hh" + +Part_combine_music_iterator::Part_combine_music_iterator () +{ + combined_b_ = false; + + first_iter_p_ = 0; + second_iter_p_ = 0; +} + +Part_combine_music_iterator::~Part_combine_music_iterator () +{ + delete second_iter_p_; + delete first_iter_p_; +} + +Moment +Part_combine_music_iterator::next_moment () const +{ + Moment first_next = first_iter_p_->next_moment (); + Moment second_next = second_iter_p_->next_moment (); + return first_next ok (); +} + +void +Part_combine_music_iterator::do_print () const +{ + first_iter_p_->print (); + second_iter_p_->print (); +} + +void +Part_combine_music_iterator::construct_children () +{ + Part_combine_music const * m = dynamic_cast (music_l_); + + first_iter_p_ = get_iterator_p (m->first_l ()); + second_iter_p_ = get_iterator_p (m->second_l ()); +} + +void +Part_combine_music_iterator::change_to (Music_iterator *it, String to_type, + String to_id) +{ + Translator_group * current = it->report_to_l (); + Translator_group * last = 0; + + /* + Cut & Paste from from Auto_change_iterator from Change_iterator (ugh). + + TODO: abstract this function + */ + + /* find the type of translator that we're changing. + + If \translator Staff = bass, then look for Staff = * + */ + while (current && current->type_str_ != to_type) + { + last = current; + current = current->daddy_trans_l_; + } + + if (current && current->id_str_ == to_id) + { + String msg; + msg += _ ("Can't switch translators, I'm there already"); + } + + if (current) + if (last) + { + Translator_group * dest = + it->report_to_l ()->find_create_translator_l (to_type, to_id); + current->remove_translator_p (last); + dest->add_translator (last); + } + else + { + /* + We could change the current translator's id, but that would make + errors hard to catch + + last->translator_id_str_ = change_l ()->change_to_id_str_; + */ + error (_f ("I'm one myself: `%s'", to_type.ch_C ())); + } + else + error (_f ("none of these in my family: `%s'", to_id.ch_C ())); +} + +Pitch_interrogate_req* first_spanish_inquisition; // nobody expects it +Pitch_interrogate_req* second_spanish_inquisition; // won't strike twice + +void +Part_combine_music_iterator::do_process_and_next (Moment m) +{ + Moment first_next = first_iter_p_->next_moment (); + Moment second_next = second_iter_p_->next_moment (); + +#if 0 + if (first_next > m || second_next > m) + return; +#endif + + /* + different rhythm for combined voices: separate + same rhythm for separated voices: combine + */ + if ((first_next != second_next && combined_b_) + || (first_next == second_next && !combined_b_)) + { + combined_b_ = !combined_b_; + String to_id = combined_b_ ? "first" : "second"; + + Part_combine_music const * p = dynamic_cast (music_l_); + + change_to (second_iter_p_, p->what_str_, to_id); + + /* + A quick ugly hack to see if it works.. + */ +#if 0 + Translator_group * fd = + first_iter_p_->report_to_l ()->find_create_translator_l (p->what_str_, + "first"); + Translator_group * sd = + second_iter_p_->report_to_l ()->find_create_translator_l (p->what_str_, + to_id); +#else + Translator_group * fd = first_iter_p_->report_to_l (); + Translator_group * sd = second_iter_p_->report_to_l (); +#endif + + if (combined_b_) + { + fd->set_property ("verticalDirection", gh_int2scm (0)); + fd->set_property ("noteHeadStyle", ly_symbol2scm ("default")); + } + else + { + fd->set_property ("verticalDirection", gh_int2scm (1)); + fd->set_property ("noteHeadStyle", ly_symbol2scm ("diamond")); + sd->set_property ("verticalDirection", gh_int2scm (-1)); + } + } + + first_iter_p_->process_and_next (m); + second_iter_p_->process_and_next (m); + + Music_iterator::do_process_and_next (m); + + +#if 0 + + /* + TODO: + + * when combining two threads: check pitches, request stem directions + + * a2-engraver to put texts a2/Solo/SoloII as appropriate. + + * maybe the a2-engraver should set the stem directions, iso us? + + + 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 + + */ + + if (!first_spanish_inquisition) + first_spanish_inquisition = new Pitch_interrogate_req; + Music_iterator* fit = first_iter_p_->try_music (first_spanish_inquisition); + + if (!second_spanish_inquisition) + second_spanish_inquisition = new Pitch_interrogate_req; + Music_iterator* sit = second_iter_p_->try_music (second_spanish_inquisition); + + if (fit && first_spanish_inquisition->pitch_arr_.size ()) + { + Musical_pitch p = spanish_inquisition->pitch_arr_[0]; + Direction s = Direction (sign(p.steps ())); + if (s != where_dir_) + { + where_dir_ = s; + String to_id = (s >= 0) ? "up" : "down"; + Part_combine_music const * auto_mus = dynamic_cast (music_l_); + + change_to (it, auto_mus->what_str_, to_id); + } + } + + first_spanish_inquisition->pitch_arr_.clear (); + second_spanish_inquisition->pitch_arr_.clear (); +#endif +} + +Music_iterator* +Part_combine_music_iterator::try_music_in_children (Music *m) const +{ + Music_iterator * i = first_iter_p_->try_music (m); + if (i) + return i; + else + return second_iter_p_->try_music (m); +} + diff --git a/lily/part-combine-music.cc b/lily/part-combine-music.cc new file mode 100644 index 0000000000..41127ac741 --- /dev/null +++ b/lily/part-combine-music.cc @@ -0,0 +1,65 @@ +/* + part-combine-music.cc -- implement Part_combine_music + + source file of the GNU LilyPond music typesetter + + (c) 2000 Jan Nieuwenhuizen + + */ + +#include "part-combine-music.hh" +#include "musical-pitch.hh" + +Part_combine_music::Part_combine_music (String what, Music * f, Music * s) +{ + what_str_ = what; + set_mus_property ("first", f->self_scm ()); + set_mus_property ("second", s->self_scm ()); +} + + +void +Part_combine_music::transpose (Musical_pitch p) +{ + first_l ()->transpose (p); + second_l () ->transpose (p); +} + +void +Part_combine_music::do_print () const +{ + first_l ()->print(); + second_l () ->print (); +} + +Moment +Part_combine_music::length_mom () const +{ + return first_l ()->length_mom (); +} + +Musical_pitch +Part_combine_music::to_relative_octave (Musical_pitch p) +{ + p = first_l ()->to_relative_octave (p); + return second_l ()->to_relative_octave (p); +} + +void +Part_combine_music::compress (Moment m) +{ + first_l ()->compress (m); + second_l ()->compress (m); +} + +Music* +Part_combine_music::first_l () const +{ + return unsmob_music (get_mus_property ("first")); +} + +Music* +Part_combine_music::second_l () const +{ + return unsmob_music (get_mus_property ("second")); +} -- 2.39.2