From ea2977bafe0df23e13a7249a9fbf522b1a2f12d3 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Thu, 9 Dec 1999 17:08:28 +0100 Subject: [PATCH] patch::: 1.3.10.jcn2 pl 10.jcn2 - fixes for invisible beamed stems - removed steminfo from properties, don't cache Stem_info --- CHANGES | 4 ++ VERSION | 2 +- lily/beam.cc | 126 +++++++++++++++++++++++++------------- lily/include/beam.hh | 11 ++-- lily/include/stem-info.hh | 22 +++++++ lily/include/stem.hh | 3 +- lily/stem.cc | 66 +++++++++----------- 7 files changed, 151 insertions(+), 83 deletions(-) diff --git a/CHANGES b/CHANGES index 9e4c61e8a0..972c92ac2d 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,7 @@ +pl 10.jcn2 + - fixes for invisible beamed stems + - removed steminfo from properties, don't cache Stem_info + pl 10.jcn1 - steminfo to properties - dropped internote dim for stem-beams diff --git a/VERSION b/VERSION index 48ade71e1d..130506112a 100644 --- a/VERSION +++ b/VERSION @@ -2,7 +2,7 @@ PACKAGE_NAME=LilyPond MAJOR_VERSION=1 MINOR_VERSION=3 PATCH_LEVEL=10 -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/beam.cc b/lily/beam.cc index c8c1dd0229..146a47218d 100644 --- a/lily/beam.cc +++ b/lily/beam.cc @@ -13,12 +13,6 @@ [TODO] * center beam symbol * less hairy code - * redo grouping - -TODO: - -The relationship Stem <-> Beam is way too hairy. Let's figure who -needs what, and what information should be available when. */ @@ -36,6 +30,7 @@ needs what, and what information should be available when. #include "paper-def.hh" #include "lookup.hh" #include "group-interface.hh" +#include "cross-staff.hh" Beam::Beam () { @@ -69,6 +64,48 @@ Beam::stem_top ()const return Group_interface__extract_elements ((Beam*) this, (Stem*) 0, "stems")[stem_count () - 1]; } +/* burp */ +int +Beam::visible_stem_count () const +{ + int c = 0; + for (int i = 0; i < stem_count (); i++) + { + if (!stem (i)->invisible_b ()) + c++; + } + return c; +} + +Stem* +Beam::first_visible_stem () const +{ + for (int i = 0; i < stem_count (); i++) + { + Stem* s = stem (i); + if (!s->invisible_b ()) + return s; + } + + assert (0); + // sigh + return 0; +} + +Stem* +Beam::last_visible_stem () const +{ + for (int i = stem_count (); i > 0; i--) + { + Stem* s = stem (i - 1); + if (!s->invisible_b ()) + return s; + } + + assert (0); + // sigh + return 0; +} void Beam::add_stem (Stem*s) @@ -94,7 +131,7 @@ Beam::do_brew_molecule_p () const if (!stem_count ()) return mol_p; - Real x0 = stem (0)->hpos_f (); + Real x0 = first_visible_stem ()->hpos_f (); for (int j=0; j note_delta_f () + extent (X_AXIS).length ())/2.0; + Real w = (first_visible_stem ()->note_delta_f () + extent (X_AXIS).length ())/2.0; return Offset (w, w * slope_f_); } @@ -133,11 +170,12 @@ Beam::auto_knee (SCM gap, bool interstaff_b) int auto_gap_i = gh_scm2int (gap); for (int i=1; i < stem_count (); i++) { - bool is_b = (bool)(stem (i)->get_real ("interstaff-f") - stem (i-1)->get_real ("interstaff-f")); + bool is_b = (bool)(calc_interstaff_dist (stem (i), this) + - calc_interstaff_dist (stem (i-1), this)); int l_y = (int)(stem (i-1)->chord_start_f ()) - + (int)stem (i-1)->get_real ("interstaff-f"); + + (int)calc_interstaff_dist (stem (i-1), this); int r_y = (int)(stem (i)->chord_start_f ()) - + (int)stem (i)->get_real ("interstaff-f"); + + (int)calc_interstaff_dist (stem (i), this); int gap_i = r_y - l_y; /* @@ -157,7 +195,7 @@ Beam::auto_knee (SCM gap, bool interstaff_b) for (int i=0; i < stem_count (); i++) { int y = (int)(stem (i)->chord_start_f ()) - + (int)stem (i)->get_real ("interstaff-f"); + + (int)calc_interstaff_dist (stem (i), this); stem (i)->set_direction ( y < knee_y ? UP : DOWN); stem (i)->set_elt_property ("dir-forced", SCM_BOOL_T); } @@ -200,13 +238,13 @@ Beam::do_print () const void Beam::do_post_processing () { - if (stem_count () < 2) + if (visible_stem_count () < 2) { warning (_ ("beam with less than two stems")); set_elt_property ("transparent", SCM_BOOL_T); return; } - beamify_stems (); + set_stem_shorten (); if (auto_knees ()) { /* @@ -221,7 +259,7 @@ Beam::do_post_processing () set_elt_property ("damping", gh_int2scm(1000)); */ - beamify_stems (); + set_stem_shorten (); } calculate_slope (); set_stemlens (); @@ -325,14 +363,16 @@ Beam::set_direction (Direction d) void Beam::solve_slope () { - assert (stem_count () > 1); + assert (visible_stem_count () > 1); Least_squares l; - Real x0 = stem (0)->hpos_f (); + Real x0 = first_visible_stem ()->hpos_f (); for (int i=0; i < stem_count (); i++) { - l.input.push (Offset (stem (i)->hpos_f () - x0, - stem (i)->get_real ("idealy-f"))); + Stem* s = stem (i); + if (s->invisible_b ()) + continue; + l.input.push (Offset (s->hpos_f () - x0, s->get_info ().idealy_f_)); } l.minimise (slope_f_, left_y_); } @@ -340,7 +380,6 @@ Beam::solve_slope () /* ugh. Naming: this doesn't check, but sets as well. */ - Real Beam::check_stemlengths_f (bool set_b) { @@ -350,44 +389,48 @@ Beam::check_stemlengths_f (bool set_b) Real staffline_f = paper_l ()-> get_var ("stafflinethickness"); Real epsilon_f = staffline_f / 8; Real dy_f = 0.0; - Real x0 = stem (0)->hpos_f (); + Real x0 = first_visible_stem ()->hpos_f (); Real internote_f = paper_l ()->get_var ("interline"); for (int i=0; i < stem_count (); i++) { - Real y = (stem (i)->hpos_f () - x0) * slope_f_ + left_y_; + Stem* s = stem (i); + if (s->invisible_b ()) + continue; + Real y = (s->hpos_f () - x0) * slope_f_ + left_y_; + Stem_info info = s->get_info (); // correct for knee - if (get_direction () != stem (i)->get_direction ()) + if (get_direction () != s->get_direction ()) { y -= get_direction () * (beam_f / 2 + (multiplicity_i_ - 1) * interbeam_f); if (!i - && stem (i)->staff_symbol_l () != stem_top ()->staff_symbol_l ()) - y += get_direction () * (multiplicity_i_ - (stem (i)->flag_i_ - 2) >? 0) + && s->staff_symbol_l () != stem_top ()->staff_symbol_l ()) + y += get_direction () * (multiplicity_i_ - (s->flag_i_ - 2) >? 0) * interbeam_f; } /* caution: stem measures in staff-positions */ if (set_b) - stem (i)->set_stemend ((y - stem (i)->get_real ("interstaff-f")) + s->set_stemend ((y - calc_interstaff_dist (s, this)) / internote_f); y *= get_direction (); - if (y > stem (i)->get_real ("maxy-f")) - dy_f = dy_f get_real ("maxy-f") - y; - if (y < stem (i)->get_real ("miny-f")) + if (y > info.maxy_f_) + dy_f = dy_f ? stem (i)->get_real ("miny-f") - y; + dy_f = dy_f >? info.miny_f_ - y; } } return dy_f; } void -Beam::beamify_stems () +Beam::set_stem_shorten () { if(!stem_count ()) return; @@ -428,13 +471,12 @@ Beam::beamify_stems () continue; } - s->beamify (); if (s->get_direction () == get_direction ()) { if (forced_count_i == total_count_i) - s->set_real ("idealy-f", s->get_real ("idealy-f") - shorten_f); + s->set_real ("shorten", shorten_f); else if (forced_count_i > total_count_i / 2) - s->set_real ("idealy-f", s->get_real ("idealy-f") - shorten_f/2); + s->set_real ("shorten", shorten_f/2); } } } @@ -444,10 +486,10 @@ Beam::calculate_slope () { if (!stem_count ()) slope_f_ = left_y_ = 0; - else if (stem (0)->get_real ("idealy-f") == stem_top ()->get_real ("idealy-f")) + else if (first_visible_stem ()->get_info ().idealy_f_ == last_visible_stem ()->get_info ().idealy_f_) { slope_f_ = 0; - left_y_ = stem (0)->get_real ("idealy-f"); + left_y_ = first_visible_stem ()->get_info ().idealy_f_; left_y_ *= get_direction (); } else @@ -458,13 +500,13 @@ Beam::calculate_slope () /* steep slope running against lengthened stem is suspect */ - Real dx_f = stem (stem_count () -1)->hpos_f () - stem (0)->hpos_f (); + Real dx_f = stem (stem_count () -1)->hpos_f () - first_visible_stem ()->hpos_f (); Real lengthened = paper_l ()->get_var ("beam_lengthened"); Real steep = paper_l ()->get_var ("beam_steep_slope"); - if (((left_y_ - stem (0)->get_real ("idealy-f") > lengthened) + if (((left_y_ - first_visible_stem ()->get_info ().idealy_f_ > lengthened) && (slope_f_ > steep)) - || ((left_y_ + slope_f_ * dx_f - stem_top ()->get_real ("idealy-f") > lengthened) + || ((left_y_ + slope_f_ * dx_f - last_visible_stem ()->get_info ().idealy_f_ > lengthened) && (slope_f_ < -steep))) { slope_f_ = 0; @@ -514,7 +556,7 @@ Beam::quantise_dy () Real staffline_f = paper_l ()->get_var ("stafflinethickness"); Real beam_f = gh_scm2double (get_elt_property ("beam-thickness"));; - Real dx_f = stem (stem_count () -1 )->hpos_f () - stem (0)->hpos_f (); + Real dx_f = stem (stem_count () -1 )->hpos_f () - first_visible_stem ()->hpos_f (); Real dy_f = dx_f * abs (slope_f_); @@ -585,7 +627,7 @@ Beam::quantise_left_y (bool extend_b) Real dy_f = get_direction () * left_y_; - Real beamdx_f = stem (stem_count () -1)->hpos_f () - stem (0)->hpos_f (); + Real beamdx_f = stem (stem_count () -1)->hpos_f () - first_visible_stem ()->hpos_f (); Real beamdy_f = beamdx_f * slope_f_; Array allowed_position; @@ -667,6 +709,7 @@ Beam::do_add_processing () } while ((flip (&d)) != LEFT); } +#if 0 /* Why? */ @@ -675,6 +718,7 @@ Beam::do_add_processing () stem (0)->beams_i_drul_[LEFT] =0; stem (stem_count () -1)->beams_i_drul_[RIGHT] =0; } +#endif } diff --git a/lily/include/beam.hh b/lily/include/beam.hh index 67c443eee6..d3d3c71afd 100644 --- a/lily/include/beam.hh +++ b/lily/include/beam.hh @@ -28,9 +28,12 @@ slope_quantisation: 'none, 'normal or 'traditional class Beam : public Directional_spanner { public: - int stem_count ()const; - Stem * stem (int )const; - Stem* Beam::stem_top ()const; + int stem_count () const; + Stem* stem (int) const; + Stem* stem_top () const; + int visible_stem_count () const; + Stem* first_visible_stem () const; + Stem* last_visible_stem () const; /** the slope of the beam in (staffpositions) per (X-dimension, in PT). @@ -59,7 +62,7 @@ protected: Offset center () const; Direction get_default_dir () const; void set_direction (Direction); - void beamify_stems (); + void set_stem_shorten (); bool auto_knee (SCM gap, bool interstaff_b); bool auto_knees (); diff --git a/lily/include/stem-info.hh b/lily/include/stem-info.hh index e69de29bb2..096671a6d5 100644 --- a/lily/include/stem-info.hh +++ b/lily/include/stem-info.hh @@ -0,0 +1,22 @@ +/* + stem-info.hh -- declare Stem_info + + source file of the GNU LilyPond music typesetter + + (c) 1997--1999 Jan Nieuwenhuizen +*/ + + +#ifndef STEM_INFO_HH +#define STEM_INFO_HH + +#include "real.hh" + +struct Stem_info +{ + Real idealy_f_; + Real miny_f_; + Real maxy_f_; +}; + +#endif // STEM_INFO_HH diff --git a/lily/include/stem.hh b/lily/include/stem.hh index 6f6fd75782..3f4a19197b 100644 --- a/lily/include/stem.hh +++ b/lily/include/stem.hh @@ -12,6 +12,7 @@ #include "molecule.hh" #include "staff-symbol-referencer.hh" #include "directional-element.hh" +#include "stem-info.hh" /**the rule attached to the ball. takes care of: @@ -69,7 +70,7 @@ public: /// ensure that this Stem also encompasses the Notehead #n# void add_head (Rhythmic_head*n); - void beamify (); + Stem_info get_info () const; Real hpos_f () const; Real chord_start_f () const; diff --git a/lily/stem.cc b/lily/stem.cc index 74b92dd89d..9f9ab098e9 100644 --- a/lily/stem.cc +++ b/lily/stem.cc @@ -402,23 +402,16 @@ Stem::beam_l ()const } -/* - stupid name: we're calculating and setting (caching??) - some stem length parameters for beamed stem -*/ -void -Stem::beamify () +Stem_info +Stem::get_info () const { assert (beam_l ()); - SCM bd = remove_elt_property ("beam-dir"); + SCM bd = get_elt_property ("beam-dir"); Real internote_f = staff_line_leading_f ()/2; Direction beam_dir; - Real idealy_f; - Real interstaff_f; - Real maxy_f; - Real miny_f; + Stem_info info; if (gh_number_p (bd)) { @@ -433,10 +426,10 @@ Stem::beamify () Real interbeam_f = paper_l ()->interbeam_f (beam_l ()->multiplicity_i_); Real beam_f = gh_scm2double (beam_l ()->get_elt_property ("beam-thickness")); - idealy_f = chord_start_f (); + info.idealy_f_ = chord_start_f (); // for simplicity, we calculate as if dir == UP - idealy_f *= beam_dir; + info.idealy_f_ *= beam_dir; bool grace_b = get_elt_property ("grace") != SCM_UNDEFINED; bool no_extend_b = get_elt_property ("no-stem-extend") != SCM_UNDEFINED; @@ -453,14 +446,14 @@ Stem::beamify () { if (beam_l ()->multiplicity_i_) { - idealy_f += beam_f; - idealy_f += (beam_l ()->multiplicity_i_ - 1) * interbeam_f; + info.idealy_f_ += beam_f; + info.idealy_f_ += (beam_l ()->multiplicity_i_ - 1) * interbeam_f; } - miny_f = idealy_f; - maxy_f = INT_MAX; + info.miny_f_ = info.idealy_f_; + info.maxy_f_ = INT_MAX; - idealy_f += stem_f; - miny_f += min_stem_f; + info.idealy_f_ += stem_f; + info.miny_f_ += min_stem_f; /* lowest beam of (UP) beam must never be lower than second staffline @@ -475,34 +468,35 @@ Stem::beamify () if (!grace_b && !no_extend_b) { //highest beam of (UP) beam must never be lower than middle staffline - miny_f = miny_f >? 0; + info.miny_f_ = info.miny_f_ >? 0; //lowest beam of (UP) beam must never be lower than second staffline - miny_f = miny_f >? (- 2 * internote_f - beam_f + info.miny_f_ = info.miny_f_ >? (- 2 * internote_f - beam_f + (beam_l ()->multiplicity_i_ > 0) * beam_f + interbeam_f * (beam_l ()->multiplicity_i_ - 1)); } } else /* knee */ { - idealy_f -= beam_f; - maxy_f = idealy_f; - miny_f = -INT_MAX; + info.idealy_f_ -= beam_f; + info.maxy_f_ = info.idealy_f_; + info.miny_f_ = -INT_MAX; - idealy_f -= stem_f; - maxy_f -= min_stem_f; + info.idealy_f_ -= stem_f; + info.maxy_f_ -= min_stem_f; } - idealy_f = maxy_f ? idealy_f; + info.idealy_f_ = info.maxy_f_ ? info.idealy_f_; + + Real interstaff_f = calc_interstaff_dist (this, beam_l ()); + info.idealy_f_ += interstaff_f * beam_dir; - interstaff_f = calc_interstaff_dist (this, beam_l ()); - idealy_f += interstaff_f * beam_dir; - miny_f += interstaff_f * beam_dir; - maxy_f += interstaff_f * beam_dir; + SCM s = get_elt_property ("shorten"); + if (s != SCM_UNDEFINED) + info.idealy_f_ -= gh_double2scm (s); + info.miny_f_ += interstaff_f * beam_dir; + info.maxy_f_ += interstaff_f * beam_dir; - set_elt_property ("interstaff-f", gh_double2scm (interstaff_f)); - set_elt_property ("idealy-f", gh_double2scm (idealy_f)); - set_elt_property ("miny-f", gh_double2scm (miny_f)); - set_real ("maxy-f", gh_double2scm (maxy_f)); + return info; } -- 2.39.5