From 28ec8d66e2243ad5bee7591bf8f67d661dd3f125 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Tue, 17 Nov 1998 09:07:48 +0100 Subject: [PATCH] patch::: 1.1.6.jcn1: pats pl6.jcn1 - repeat/alternative music layout --- NEWS | 4 ++ VERSION | 2 +- input/test/repeat.fly | 2 + lily/bar-engraver.cc | 8 +++ lily/include/lily-proto.hh | 28 +++++----- lily/include/music-wrapper-iterator.hh | 14 +++-- lily/include/repeated-music-iterator.hh | 35 +++++++++++++ lily/include/repeated-music.hh | 37 +++++++++++++ lily/include/voice-iterator.hh | 29 ++++++----- lily/music-iterator.cc | 11 ++-- lily/music-wrapper-iterator.cc | 3 +- lily/music.cc | 40 ++++++-------- lily/my-lily-lexer.cc | 3 +- lily/parser.yy | 21 ++++++++ lily/repeated-music-iterator.cc | 69 +++++++++++++++++++++++++ lily/repeated-music.cc | 64 +++++++++++++++++++++++ 16 files changed, 307 insertions(+), 63 deletions(-) create mode 100644 input/test/repeat.fly create mode 100644 lily/include/repeated-music-iterator.hh create mode 100644 lily/include/repeated-music.hh create mode 100644 lily/repeated-music-iterator.cc create mode 100644 lily/repeated-music.cc diff --git a/NEWS b/NEWS index b340ce878b..d3c1f271a6 100644 --- a/NEWS +++ b/NEWS @@ -1,4 +1,8 @@ +pl6.jcn1 + - repeat/alternative music layout +******** +1.1.6 pl5.szmulewicz1 - rtti stuff diff --git a/VERSION b/VERSION index 9fa405bb94..ed84e68a2d 100644 --- a/VERSION +++ b/VERSION @@ -2,7 +2,7 @@ PACKAGE_NAME=LilyPond MAJOR_VERSION=1 MINOR_VERSION=1 PATCH_LEVEL=6 -MY_PATCH_LEVEL= +MY_PATCH_LEVEL=jcn1 # use the above to send patches: MY_PATCH_LEVEL is always empty for a # released version. diff --git a/input/test/repeat.fly b/input/test/repeat.fly new file mode 100644 index 0000000000..f3ab2c0e44 --- /dev/null +++ b/input/test/repeat.fly @@ -0,0 +1,2 @@ +% a'' b c d \repeat 2 { { c c c c } } \alternative { { e e e e } { e e e g } } c c c c +a'' b c d \repeat 2 { { c c c c } } \alternative { { e e e e } } c c c c diff --git a/lily/bar-engraver.cc b/lily/bar-engraver.cc index b9896b4ad3..a0c361907c 100644 --- a/lily/bar-engraver.cc +++ b/lily/bar-engraver.cc @@ -13,6 +13,7 @@ #include "command-request.hh" #include "time-description.hh" #include "engraver-group.hh" +#include "repeated-music.hh" Bar_engraver::Bar_engraver() { @@ -32,6 +33,13 @@ Bar_engraver::do_try_music (Music*r_l) return true; } + else if (Repeated_music * m = dynamic_cast (r_l)) + { + if (bar_req_l_ && bar_req_l_->equal_b (b)) // huh? + return false; + bar_req_l_ = new Bar_req ("|:"); + return true; + } return false; diff --git a/lily/include/lily-proto.hh b/lily/include/lily-proto.hh index 52f3674b52..6febb7f55a 100644 --- a/lily/include/lily-proto.hh +++ b/lily/include/lily-proto.hh @@ -10,17 +10,13 @@ #define LILY_PROTO_HH #include "proto.hh" - struct Absolute_dynamic_req; struct Abbreviation; -struct Abbreviation_req; +struct Abbreviation_beam; struct Abbreviation_beam_req; struct Abbreviation_beam_engraver; -struct Axis_group_element; -struct Axis_group; -struct Translator_group; -struct Translator; -struct Abbreviation_beam; +struct Abbreviation_req; +struct Atom; struct Audio_element; struct Audio_column; struct Audio_item; @@ -28,10 +24,10 @@ struct Audio_key; struct Audio_time_signature; struct Audio_note; struct Audio_note_off; -struct Performance; struct Audio_staff; struct Audio_tempo; -struct Atom; +struct Axis_group_element; +struct Axis_group; struct Bar; struct Bar_column_engraver; struct Bar_column; @@ -120,10 +116,6 @@ struct Lyric_req; struct My_lily_lexer; struct Measure_grouping_req; struct Melodic_req; -struct Time_signature; -struct Time_signature_change_req; -struct Time_signature_engraver; -struct Time_signature_performer; struct Midi_def; struct Midi_duration; struct Midi_header; @@ -167,6 +159,7 @@ struct Paper_outputter; struct Paper_score; struct Paper_stream; struct Partial_measure_req; +struct Performance; struct Performer; struct Plet; struct Plet_engraver; @@ -181,6 +174,8 @@ struct Request; struct Request_column; struct Engraver; struct Relative_octave_music; +struct Repeated_music; +struct Repeated_music_iterator; struct Rest; struct Rest_collision; struct Rest_collision_engraver; @@ -222,7 +217,6 @@ struct Stem; struct Stem_beam_engraver; struct Stem_req; struct String; -struct Atom; struct Symtable; struct Symtables; struct Super_element; @@ -238,6 +232,12 @@ struct Tie; struct Tie_engraver; struct Tie_req; struct Time_description; +struct Time_signature; +struct Time_signature_change_req; +struct Time_signature_engraver; +struct Time_signature_performer; +struct Translator; +struct Translator_group; struct Timing_req; struct Vertical_brace; struct Vertical_spanner; diff --git a/lily/include/music-wrapper-iterator.hh b/lily/include/music-wrapper-iterator.hh index 02a4e97fa0..cae63b2096 100644 --- a/lily/include/music-wrapper-iterator.hh +++ b/lily/include/music-wrapper-iterator.hh @@ -15,17 +15,23 @@ class Music_wrapper_iterator : public Music_iterator { - Music_iterator *child_iter_p_; - Music_wrapper *music_wrapper_l(); public: Music_wrapper_iterator (); - ~Music_wrapper_iterator (); + +protected: + virtual ~Music_wrapper_iterator (); + virtual void do_print () const; virtual void construct_children () ; virtual void do_process_and_next (Moment) ; virtual Moment next_moment () const; + +protected: + virtual Music_wrapper *music_wrapper_l () const; virtual bool ok () const; - + +private: + Music_iterator *child_iter_p_; }; #endif /* MUSIC_WRAPPER_ITERATOR_HH */ diff --git a/lily/include/repeated-music-iterator.hh b/lily/include/repeated-music-iterator.hh new file mode 100644 index 0000000000..ebc356de41 --- /dev/null +++ b/lily/include/repeated-music-iterator.hh @@ -0,0 +1,35 @@ +/* + repeated-music-iterator.hh -- declare Repeated_music_iterator + + source file of the GNU LilyPond music typesetter + + (c) 1998 Jan Nieuwenhuizen + + */ + +#ifndef REPEATED_MUSIC_ITERATOR_HH +#define REPEATED_MUSIC_ITERATOR_HH + +#include "music-wrapper-iterator.hh" +#include "voice-iterator.hh" + +class Repeated_music_iterator : public virtual Music_wrapper_iterator, public virtual Sequential_music_iterator +{ +public: + Repeated_music_iterator(); + +protected: + ~Repeated_music_iterator (); + + virtual Music_wrapper *music_wrapper_l () const; + virtual Sequential_music* sequential_music_l() const; + virtual bool ok () const; + virtual void do_process_and_next (Moment); + virtual void construct_children (); + virtual void start_next_element (); + virtual void leave_element (); +}; + + +#endif /* REPEATED_MUSIC_ITERATOR_HH */ + diff --git a/lily/include/repeated-music.hh b/lily/include/repeated-music.hh new file mode 100644 index 0000000000..4f105cc580 --- /dev/null +++ b/lily/include/repeated-music.hh @@ -0,0 +1,37 @@ +/* + repeated-music.hh -- declare Repeated_music + + source file of the GNU LilyPond music typesetter + + (c) 1998 Jan Nieuwenhuizen + + */ + +#ifndef REPEATED_MUSIC_HH +#define REPEATED_MUSIC_HH + +#include "music-list.hh" + +/** + Repeats and voltas + */ +class Repeated_music : public Music +{ +public: + int repeats_i_; + Music_wrapper* repeat_p_; + Sequential_music* alternative_p_; + + Repeated_music (Music_wrapper *, int n, Sequential_music*); + Repeated_music (Repeated_music const& s); + virtual ~Repeated_music (); + + virtual void do_print () const; + virtual void transpose (Musical_pitch p); + virtual Moment duration () const; + + VIRTUAL_COPY_CONS(Music); +}; + +#endif /* REPEATED_MUSIC_HH */ + diff --git a/lily/include/voice-iterator.hh b/lily/include/voice-iterator.hh index ce9613b3aa..38f8b91473 100644 --- a/lily/include/voice-iterator.hh +++ b/lily/include/voice-iterator.hh @@ -4,36 +4,37 @@ source file of the GNU LilyPond music typesetter (c) 1997--1998 Han-Wen Nienhuys -*/ - -#ifndef Sequential_music_ITER_HH -#define Sequential_music_ITER_HH +*/ +#ifndef SEQUENTIAL_MUSIC_ITER_HH +#define SEQUENTIAL_MUSIC_ITER_HH #include "music-iterator.hh" #include "pcursor.hh" class Sequential_music_iterator : public Music_iterator { - Moment here_mom_; - PCursor *cursor_p_; - Music_iterator * iter_p_; - void start_next_element(); - void leave_element(); - void set_Sequential_music_translator(); -protected: - Sequential_music * sequential_music_l() const; public: Sequential_music_iterator (); protected: + virtual ~Sequential_music_iterator(); + + virtual Sequential_music* sequential_music_l() const; virtual void do_print() const; virtual void construct_children(); - ~Sequential_music_iterator(); virtual void do_process_and_next (Moment); virtual Moment next_moment() const; virtual bool ok() const; + virtual void start_next_element(); + virtual void leave_element(); + +private: + Moment here_mom_; + PCursor *cursor_p_; + Music_iterator * iter_p_; + void set_Sequential_music_translator(); }; -#endif // Sequential_music_ITER_HH +#endif // SEQUENTIAL_MUSIC_ITER_HH diff --git a/lily/music-iterator.cc b/lily/music-iterator.cc index 43891b0560..f78dc6eaa5 100644 --- a/lily/music-iterator.cc +++ b/lily/music-iterator.cc @@ -20,11 +20,8 @@ #include "music-wrapper-iterator.hh" #include "compressed-music-iterator.hh" #include "compressed-music.hh" - - - - - +#include "repeated-music.hh" +#include "repeated-music-iterator.hh" void Music_iterator::do_print() const @@ -150,6 +147,10 @@ Music_iterator::static_get_iterator_p (Music const *m, Translator_group *report_ p = new Compressed_music_iterator; else if (dynamic_cast (m)) p = new Music_wrapper_iterator; + else if (dynamic_cast (m)) + p = new Repeated_music_iterator; + else + assert (0); p->music_l_ = m; if (m->translator_type_str_.length_i ()) diff --git a/lily/music-wrapper-iterator.cc b/lily/music-wrapper-iterator.cc index d5ed47629c..e282bded8c 100644 --- a/lily/music-wrapper-iterator.cc +++ b/lily/music-wrapper-iterator.cc @@ -36,10 +36,11 @@ Music_wrapper_iterator::~Music_wrapper_iterator () } Music_wrapper* -Music_wrapper_iterator::music_wrapper_l () +Music_wrapper_iterator::music_wrapper_l () const { return (Music_wrapper*) music_l_; } + bool Music_wrapper_iterator::ok () const { diff --git a/lily/music.cc b/lily/music.cc index 316cbff1d9..8d7ce5cb88 100644 --- a/lily/music.cc +++ b/lily/music.cc @@ -12,6 +12,20 @@ #include "debug.hh" #include "musical-pitch.hh" +Music::Music() +{ +} + +void +Music::compress (Moment) +{ +} + +void +Music::do_print() const +{ +} + Moment Music::duration () const { @@ -32,34 +46,14 @@ Music::print() const #endif } -void -Music::transpose (Musical_pitch ) -{ - -} - -void -Music::do_print() const -{ -} - - - - - - - -Music::Music() -{ -} - Musical_pitch Music::to_relative_octave (Musical_pitch m) { return m; } -void -Music::compress (Moment) +void +Music::transpose (Musical_pitch ) { } + diff --git a/lily/my-lily-lexer.cc b/lily/my-lily-lexer.cc index 61c1cd028c..7b47c2e3d6 100644 --- a/lily/my-lily-lexer.cc +++ b/lily/my-lily-lexer.cc @@ -25,13 +25,13 @@ static Keyword_ent the_key_tab[]={ {"absdynamic", ABSDYNAMIC}, {"accepts", ACCEPTS}, + {"alternative", ALTERNATIVE}, {"bar", BAR}, {"cadenza", CADENZA}, {"clef", CLEF}, {"cm", CM_T}, {"consists", CONSISTS}, {"duration", DURATION}, -// {"_", EXTENDER}, {"font", FONT}, {"grouping", GROUPING}, {"header", HEADER}, @@ -56,6 +56,7 @@ static Keyword_ent the_key_tab[]={ {"pt", PT_T}, {"relative", RELATIVE}, {"remove", REMOVE}, + {"repeat", REPEAT}, {"scm", SCM_T}, {"scmfile", SCMFILE}, {"score", SCORE}, diff --git a/lily/parser.yy b/lily/parser.yy index 344abe68b2..449c7cc122 100644 --- a/lily/parser.yy +++ b/lily/parser.yy @@ -43,6 +43,7 @@ #include "relative-music.hh" #include "transposed-music.hh" #include "compressed-music.hh" +#include "repeated-music.hh" // mmm Mudela_version oldest_version ("1.0.7"); @@ -158,6 +159,7 @@ yylex (YYSTYPE *s, void * v_l) %token ABSDYNAMIC %token ACCEPTS +%token ALTERNATIVE %token BAR %token BEAMPLET %token CADENZA @@ -194,6 +196,7 @@ yylex (YYSTYPE *s, void * v_l) %token PT_T %token RELATIVE %token REMOVE +%token REPEAT %token SCM_T %token SCMFILE %token SCORE @@ -247,6 +250,7 @@ yylex (YYSTYPE *s, void * v_l) %type open_plet_parens close_plet_parens %type sub_quotes sup_quotes %type simple_element request_chord command_element Simple_music Composite_music +%type Alternative_music Repeated_music %type abbrev_type %type int unsigned %type script_dir @@ -731,6 +735,22 @@ Music: | Composite_music ; +Alternative_music: { + Music_list* m = new Music_list; + $$ = new Sequential_music (m); + } + | ALTERNATIVE '{' Music_list '}' { + $$ = new Sequential_music ($3); + } + ; + +Repeated_music: REPEAT unsigned '{' Music '}' Alternative_music { + Music_wrapper *w= new Music_wrapper ($4); + Sequential_music* s = (Sequential_music*)$6; + $$ = new Repeated_music (w, $2, s); + } + ; + Sequential_music: '{' Music_list '}' { $$ = new Sequential_music ($2); } @@ -766,6 +786,7 @@ Composite_music: $$ = new Compressed_music ($2, $4, $5); } + | Repeated_music { $$ = $1; } | Simultaneous_music { $$ = $1; } | Sequential_music { $$ = $1; } | TRANSPOSE musical_pitch Music { diff --git a/lily/repeated-music-iterator.cc b/lily/repeated-music-iterator.cc new file mode 100644 index 0000000000..67803eb864 --- /dev/null +++ b/lily/repeated-music-iterator.cc @@ -0,0 +1,69 @@ +/* + repeated-music-iterator.cc -- implement Repeated_music_iterator + + source file of the GNU LilyPond music typesetter + + (c) 1998 Jan Nieuwenhuizen + + */ + +#include "repeated-music-iterator.hh" +#include "repeated-music.hh" +#include "musical-request.hh" +#include "translator-group.hh" +#include "command-request.hh" + +Repeated_music_iterator::Repeated_music_iterator () +{ +} + +Repeated_music_iterator::~Repeated_music_iterator () +{ +} + +void +Repeated_music_iterator::construct_children () +{ + Music_wrapper_iterator::construct_children (); + // Sequential_music_iterator::construct_children (); +} + +void +Repeated_music_iterator::do_process_and_next (Moment m) +{ + if (Music_wrapper_iterator::ok ()) + Music_wrapper_iterator::do_process_and_next (m); +// else + //Sequential_music_iterator::do_process_and_next (m); +} + +Music_wrapper* +Repeated_music_iterator::music_wrapper_l () const +{ + return ((Repeated_music*)Music_wrapper_iterator::music_l_)->repeat_p_; +} + +bool +Repeated_music_iterator::ok () const +{ + return Music_wrapper_iterator::ok (); // || Sequential_music_iterator:: ok(); +} + +Sequential_music* +Repeated_music_iterator::sequential_music_l () const +{ + return ((Repeated_music*)Sequential_music_iterator::music_l_)->alternative_p_; +} + +void +Repeated_music_iterator::start_next_element () +{ + // Sequential_music_iterator::start_next_element (); +} + +void +Repeated_music_iterator::leave_element () +{ + // Sequential_music_iterator::leave_element (); +} + diff --git a/lily/repeated-music.cc b/lily/repeated-music.cc new file mode 100644 index 0000000000..ab6aad0817 --- /dev/null +++ b/lily/repeated-music.cc @@ -0,0 +1,64 @@ +/* + repeated-music.cc -- implement Repeated_music + + source file of the GNU LilyPond music typesetter + + (c) 1998 Jan Nieuwenhuizen + + */ + +#include "repeated-music.hh" +#include "music-wrapper.hh" +#include "music-list.hh" + +Repeated_music::Repeated_music (Music_wrapper *r, int n, Sequential_music* a) +{ + repeats_i_ = n; + repeat_p_ = r; + alternative_p_ = a; +} + +Repeated_music::~Repeated_music () +{ + delete repeat_p_; + delete alternative_p_; +} + +Repeated_music::Repeated_music (Repeated_music const& s) + : Music (s) +{ +#if 0 + // urg? + repeat_p_ = (Music_wrapper*)(s.repeat_p_) ? s.repeat_p_->clone () : 0; + alternative_p_ = (Sequential_music*)(s.alternative_p_) ? s.alternative_p_->clone () : 0; +#endif +} + +void +Repeated_music::do_print () const +{ + if (repeat_p_) + repeat_p_->print (); + if (alternative_p_) + alternative_p_->print (); +} + +void +Repeated_music::transpose (Musical_pitch p) +{ + if (repeat_p_) + repeat_p_->transpose (p); + if (alternative_p_) + alternative_p_->transpose (p); +} + +Moment +Repeated_music::duration () const +{ + Moment m; + if (repeat_p_) + m += repeat_p_->duration (); + if (alternative_p_) + m += alternative_p_->duration (); + return m; +} -- 2.39.5