From d755c3361f6a53ee9b40013e0ee7df69aab56f3d Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Mon, 5 Jun 2006 13:57:04 +0000 Subject: [PATCH] *** empty log message *** --- ChangeLog | 23 +++++++++ VERSION | 2 +- input/regression/spacing-section.ly | 26 ++++++++++ lily/include/input.hh | 5 +- lily/include/paper-column.hh | 2 + lily/input.cc | 9 ++++ lily/music-iterator.cc | 5 +- lily/paper-column.cc | 8 ++++ lily/spacing-engraver.cc | 73 +++++++++++++++++++++-------- lily/spacing-spanner.cc | 19 ++++++-- ly/spanners-init.ly | 2 + scm/define-music-types.scm | 18 ++++--- 12 files changed, 157 insertions(+), 35 deletions(-) create mode 100644 input/regression/spacing-section.ly diff --git a/ChangeLog b/ChangeLog index d5c84f3ce2..d229094c97 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,29 @@ 2006-06-05 Han-Wen Nienhuys + * input/regression/spacing-section.ly: new file. + + * lily/input.cc (programming_error): new function. + + * lily/spacing-engraver.cc (try_music): new function. Accept + spacing-section-event + + * lily/spacing-spanner.cc (set_springs): take slices of all + columns for spacing. + + * lily/include/paper-column.hh (class Paper_column): add + Paper_column::compare. + + * ly/spanners-init.ly (newSpacingSection): add newSpacingSection. + + * scm/define-music-types.scm (music-descriptions): add + SpacingSectionEvent + + * lily/music-iterator.cc (report_event): use programming_error for + sending non-event error. + + * lily/input.cc (programming_error): new function + * buildscripts/output-distance.py (main): use compare-XXX for compare files. (main): --threshold option, default at 0.30 diff --git a/VERSION b/VERSION index 404fb35970..56bf762d10 100644 --- a/VERSION +++ b/VERSION @@ -1,6 +1,6 @@ PACKAGE_NAME=LilyPond MAJOR_VERSION=2 MINOR_VERSION=9 -PATCH_LEVEL=7 +PATCH_LEVEL=8 MY_PATCH_LEVEL= diff --git a/input/regression/spacing-section.ly b/input/regression/spacing-section.ly new file mode 100644 index 0000000000..1b6f5d72ab --- /dev/null +++ b/input/regression/spacing-section.ly @@ -0,0 +1,26 @@ +\header { + + texidoc = "New sections for spacing can be started with +@code{\newSpacingSection}. In this example, a section is started at +the 4/16, and a 16th in the second section takes as much space as a +8th in first section." + +} + +\paper +{ + ragged-right = ##t + } +\version "2.9.8" +\relative { + \time 2/4 + c4 c8 c + c8 c c4 c16[ c c8] c4 + + \newSpacingSection + \time 4/16 + c8[ c16 c] + c16[ c c8] +} + + diff --git a/lily/include/input.hh b/lily/include/input.hh index e1b4169841..e211dc15c3 100644 --- a/lily/include/input.hh +++ b/lily/include/input.hh @@ -27,14 +27,17 @@ public: char const *end () const; void set (Source_file *, char const *, char const *); - void warning (string) const; // should use member func? + void warning (string) const; + void programming_error (string) const; void non_fatal_error (string) const; void error (string) const; void message (string) const; void set_spot (Input const &); void step_forward (); void set_location (Input const &, Input const &); + Input spot () const; + string location_string () const; string line_number_string () const; string file_string ()const; diff --git a/lily/include/paper-column.hh b/lily/include/paper-column.hh index 6ef3daacc4..d21828c374 100644 --- a/lily/include/paper-column.hh +++ b/lily/include/paper-column.hh @@ -30,6 +30,8 @@ public: virtual Paper_column *get_column () const; virtual System *get_system () const; + static int compare (Grob * const &a, + Grob * const &b); int get_rank () const { return rank_; } void set_rank (int); diff --git a/lily/input.cc b/lily/input.cc index 1379f1c7b5..5ab2be4c78 100644 --- a/lily/input.cc +++ b/lily/input.cc @@ -75,6 +75,15 @@ Input::message (string s) const ::message (s); } + +void +Input::programming_error (string s) const +{ + message (_f ("programming error: %s", s.c_str ())); + message (_ ("continuing, cross fingers") + "\n"); +} + + void Input::warning (string s) const { diff --git a/lily/music-iterator.cc b/lily/music-iterator.cc index fcfd2fc1f4..83838427df 100644 --- a/lily/music-iterator.cc +++ b/lily/music-iterator.cc @@ -165,8 +165,11 @@ Music_iterator::report_event (Music *m) { descend_to_bottom_context (); + /* + FIXME: then don't do it. + */ if (!m->is_mus_type ("event")) - m->origin ()->warning (_f ("Sending non-event to context")); + m->origin ()->programming_error (_f ("Sending non-event to context")); m->send_to_context (get_outlet ()); } diff --git a/lily/paper-column.cc b/lily/paper-column.cc index 525dca36b8..fccdba6e7f 100644 --- a/lily/paper-column.cc +++ b/lily/paper-column.cc @@ -65,6 +65,14 @@ Paper_column::Paper_column (Paper_column const &src, int count) rank_ = src.rank_; } +int +Paper_column::compare (Grob * const &a, + Grob * const &b) +{ + return sign (dynamic_cast (a)->rank_ + - dynamic_cast (b)->rank_); +} + Moment Paper_column::when_mom (Grob *me) { diff --git a/lily/spacing-engraver.cc b/lily/spacing-engraver.cc index d567cb6ebc..b3ca575393 100644 --- a/lily/spacing-engraver.cc +++ b/lily/spacing-engraver.cc @@ -32,9 +32,21 @@ struct Rhythmic_tuple static int time_compare (Rhythmic_tuple const &, Rhythmic_tuple const &); }; -/* - TODO: allow starting & stopping of spacing regions. -*/ +inline int +compare (Rhythmic_tuple const &a, Rhythmic_tuple const &b) +{ + return Rhythmic_tuple::time_compare (a, b); +} + +int +Rhythmic_tuple::time_compare (Rhythmic_tuple const &h1, + Rhythmic_tuple const &h2) +{ + return (h1.end_ - h2.end_).main_part_.sign (); +} + +/****************************************************************/ + /* Acknowledge rhythmic elements, for initializing spacing fields in the columns. @@ -46,7 +58,8 @@ class Spacing_engraver : public Engraver vector stopped_durations_; Moment now_; Spanner *spacing_; - + Music *start_section_; + TRANSLATOR_DECLARATIONS (Spacing_engraver); protected: @@ -57,39 +70,55 @@ protected: void start_translation_timestep (); void stop_translation_timestep (); void process_music (); + virtual void finalize (); + virtual bool try_music (Music *m); + + void start_spanner (); + void stop_spanner (); }; -inline int -compare (Rhythmic_tuple const &a, Rhythmic_tuple const &b) +Spacing_engraver::Spacing_engraver () { - return Rhythmic_tuple::time_compare (a, b); + spacing_ = 0; + start_section_ = 0; } -int -Rhythmic_tuple::time_compare (Rhythmic_tuple const &h1, - Rhythmic_tuple const &h2) +bool +Spacing_engraver::try_music (Music *m) { - return (h1.end_ - h2.end_).main_part_.sign (); + start_section_ = m; + return true; } -Spacing_engraver::Spacing_engraver () +void +Spacing_engraver::process_music () { - spacing_ = 0; + if (start_section_ && spacing_) + stop_spanner (); + + if (!spacing_) + start_spanner (); } void -Spacing_engraver::process_music () +Spacing_engraver::start_spanner () { - if (!spacing_) - { - spacing_ = make_spanner ("SpacingSpanner", SCM_EOL); - spacing_->set_bound (LEFT, unsmob_grob (get_property ("currentCommandColumn"))); - } + assert (!spacing_); + + spacing_ = make_spanner ("SpacingSpanner", SCM_EOL); + spacing_->set_bound (LEFT, + unsmob_grob (get_property ("currentCommandColumn"))); } void Spacing_engraver::finalize () +{ + stop_spanner (); +} + +void +Spacing_engraver::stop_spanner () { if (spacing_) { @@ -186,8 +215,11 @@ Spacing_engraver::stop_translation_timestep () void Spacing_engraver::start_translation_timestep () { + start_section_ = 0; + now_ = now_mom (); stopped_durations_.clear (); + while (playing_durations_.size () && playing_durations_.front ().end_ < now_) playing_durations_.delmin (); while (playing_durations_.size () && playing_durations_.front ().end_ == now_) @@ -203,7 +235,8 @@ ADD_TRANSLATOR (Spacing_engraver, "bookkeeping of shortest starting and playing notes ", /* create */ "SpacingSpanner", - /* accept */ "", + /* accept */ + "spacing-section-event ", /* read */ "currentMusicalColumn " "currentCommandColumn " diff --git a/lily/spacing-spanner.cc b/lily/spacing-spanner.cc index 4c301b6a64..5aca100961 100644 --- a/lily/spacing-spanner.cc +++ b/lily/spacing-spanner.cc @@ -56,13 +56,20 @@ MAKE_SCHEME_CALLBACK (Spacing_spanner, set_springs, 1); SCM Spacing_spanner::set_springs (SCM smob) { - Grob *me = unsmob_grob (smob); + Spanner *me = unsmob_spanner (smob); /* can't use get_system() ? --hwn. */ vector all (get_root_system (me)->columns ()); + vsize start = binary_search (all, (Grob*)me->get_bound (LEFT), + &Paper_column::compare); + vsize end = binary_search (all, (Grob*) me->get_bound (RIGHT), + &Paper_column::compare); + all = vector::vector (all.begin () + start, + all.begin () + end + 1); + set_explicit_neighbor_columns (all); Spacing_options options; @@ -489,15 +496,17 @@ ADD_INTERFACE (Spacing_spanner, "spacing-spanner-interface", "head width) A 16th note is followed by 0.5 note head width. The\n" "quarter note is followed by 3 NHW, the half by 4 NHW, etc.\n", + "average-spacing-wishes " + "base-shortest-duration " + "common-shortest-duration " "grace-space-factor " + "packed-spacing " + "shortest-duration-space " "spacing-increment " - "base-shortest-duration " "strict-note-spacing " - "shortest-duration-space " - "common-shortest-duration " "uniform-stretching " - "packed-spacing " + ); ADD_INTERFACE (Spacing_interface, "spacing-interface", diff --git a/ly/spanners-init.ly b/ly/spanners-init.ly index d2493903c9..43d0ef0cb6 100644 --- a/ly/spanners-init.ly +++ b/ly/spanners-init.ly @@ -91,3 +91,5 @@ sostenutoUp = #(make-span-event 'SostenutoEvent STOP) %crescpoco = \set crescendoText = "cresc. poco a poco" %decresc = \set crescendoText = "decr." %dim = \set crescendoText = "dim." + +newSpacingSection = #(make-event-chord (list (make-music 'SpacingSectionEvent))) diff --git a/scm/define-music-types.scm b/scm/define-music-types.scm index 69c654b019..fe31b3d40f 100644 --- a/scm/define-music-types.scm +++ b/scm/define-music-types.scm @@ -160,7 +160,12 @@ Syntax: @var{note}\\cr (types . (general-music extender-event event)) )) - + (Event + . ( + (description . "Atomic music event.") + (types . (general-music event)) + )) + (EventChord . ( (description . "Internally used to group a set of events.") @@ -414,12 +419,6 @@ goes down).") (description . "Ties for starting a second volta bracket.") (types . (general-music event repeat-tie-event)) )) - (Event - . ( - (description . "Atomic music event.") - (types . (general-music event)) - )) - (RestEvent . ( (description . "A Rest. @@ -594,6 +593,11 @@ Syntax: @code{s}@var{duration}") (types . (general-music event rhythmic-event skip-event)) )) + + (SpacingSectionEvent + . ((description . "Start a new spacing section") + (types . (general-music event spacing-section-event)))) + (SpanEvent . ( (description . "Event for anything that is started at a different time than stopped.") -- 2.39.2