From: hanwen Date: Wed, 26 Oct 2005 10:14:41 +0000 (+0000) Subject: * lily/beam.cc (calc_least_squares_dy): use property callback. X-Git-Tag: release/2.7.16^2~34 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=3632f1298501884906fc75509ae3c2155f479e1b;p=lilypond.git * lily/beam.cc (calc_least_squares_dy): use property callback. * lily/beam-concave.cc (calc_concaveness): use property callback. --- diff --git a/ChangeLog b/ChangeLog index 8bf927ddc5..6ed69971e3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2005-10-26 Han-Wen Nienhuys + * lily/beam.cc (calc_least_squares_dy): use property callback. + + * lily/beam-concave.cc (calc_concaveness): use property callback. + * ly/paper-defaults.ly: move fixed dimensions from paper.scm 2005-10-25 Jan Nieuwenhuizen diff --git a/lily/beam-concave.cc b/lily/beam-concave.cc index f8b31f460a..7c38e96aa1 100644 --- a/lily/beam-concave.cc +++ b/lily/beam-concave.cc @@ -57,7 +57,7 @@ is_concave_single_notes (Array const &positions, Direction beam_dir) } Real -calc_concaveness (Array const &positions, Direction beam_dir) +calc_positions_concaveness (Array const &positions, Direction beam_dir) { Real dy = positions.top () - positions[0]; Real slope = dy / Real (positions.size () - 1); @@ -80,9 +80,10 @@ calc_concaveness (Array const &positions, Direction beam_dir) return concaveness; } -MAKE_SCHEME_CALLBACK (Beam, check_concave, 1); + +MAKE_SCHEME_CALLBACK (Beam, calc_concaveness, 1); SCM -Beam::check_concave (SCM smob) +Beam::calc_concaveness (SCM smob) { Grob *me = unsmob_grob (smob); @@ -90,7 +91,7 @@ Beam::check_concave (SCM smob) = extract_grob_array (me, "stems"); if (is_knee (me)) - return SCM_UNSPECIFIED; + return scm_from_double (0.0); Direction beam_dir = CENTER; for (int i = stems.size (); i--;) @@ -125,8 +126,12 @@ Beam::check_concave (SCM smob) far_positions.push ((int) rint (posns[-beam_dir])); } + Real concaveness = 0.0; + if (is_concave_single_notes (far_positions, beam_dir)) { + (void) me->get_property ("least-squares-dy"); // ugh. dependency handling. + Drul_array pos = ly_scm2interval (me->get_property ("positions")); Real r = linear_combination (pos, 0.0); @@ -136,11 +141,9 @@ Beam::check_concave (SCM smob) } else { - Real concaveness = (calc_concaveness (far_positions, beam_dir) - + calc_concaveness (close_positions, beam_dir)) / 2; - - me->set_property ("concaveness", scm_from_double (concaveness)); + concaveness = (calc_positions_concaveness (far_positions, beam_dir) + + calc_positions_concaveness (close_positions, beam_dir)) / 2; } - return SCM_UNSPECIFIED; + return scm_from_double (concaveness); } diff --git a/lily/beam.cc b/lily/beam.cc index 32d6a08be5..acc4807492 100644 --- a/lily/beam.cc +++ b/lily/beam.cc @@ -769,11 +769,11 @@ set_minimum_dy (Grob *me, Real *dy) } /* - Compute a first approximation to the beam slope. + Compute a first approximation to the beam slope. */ -MAKE_SCHEME_CALLBACK (Beam, least_squares, 1); +MAKE_SCHEME_CALLBACK (Beam, calc_least_squares_dy, 1); SCM -Beam::least_squares (SCM smob) +Beam::calc_least_squares_dy (SCM smob) { Grob *me = unsmob_grob (smob); @@ -783,7 +783,7 @@ Beam::least_squares (SCM smob) if (count < 1) { me->set_property ("positions", ly_interval2scm (pos)); - return SCM_UNSPECIFIED; + return scm_from_double (0.0); } Array x_posns; @@ -814,7 +814,7 @@ Beam::least_squares (SCM smob) Real y = 0; Real slope = 0; Real dy = 0; - + Real ldy = 0.0; if (!ideal.delta ()) { Interval chord (Stem::chord_start_y (first_visible_stem (me)), @@ -842,8 +842,7 @@ Beam::least_squares (SCM smob) slope esp. of the first part of a broken beam should predict where the second part goes. */ - me->set_property ("least-squares-dy", - scm_from_double (pos[RIGHT] - pos[LEFT])); + ldy = pos[RIGHT] - pos[LEFT]; } else { @@ -864,7 +863,8 @@ Beam::least_squares (SCM smob) dy = slope * dx; set_minimum_dy (me, &dy); - me->set_property ("least-squares-dy", scm_from_double (dy)); + + ldy = dy; pos = Interval (y, (y + dy)); } @@ -875,7 +875,7 @@ Beam::least_squares (SCM smob) me->set_property ("positions", ly_interval2scm (pos)); - return SCM_UNSPECIFIED; + return scm_from_double (ldy); } /* @@ -991,11 +991,16 @@ Beam::slope_damping (SCM smob) if (visible_stem_count (me) <= 1) return SCM_UNSPECIFIED; + /* trigger callback. */ + (void) me->get_property ("least-squares-dy"); + SCM s = me->get_property ("damping"); Real damping = scm_to_double (s); if (damping) { + Real concaveness = robust_scm2double (me->get_property ("concaveness"), 0.0); + Drul_array pos = ly_scm2interval (me->get_property ("positions")); scale_drul (&pos, Staff_symbol_referencer::staff_space (me)); @@ -1011,8 +1016,6 @@ Beam::slope_damping (SCM smob) Real slope = dy && dx ? dy / dx : 0; - Real concaveness = robust_scm2double (me->get_property ("concaveness"), 0.0); - slope = 0.6 * tanh (slope) / (damping + concaveness); Real damped_dy = slope * dx; diff --git a/lily/include/beam.hh b/lily/include/beam.hh index 1fdf5732af..d688cacd36 100644 --- a/lily/include/beam.hh +++ b/lily/include/beam.hh @@ -59,10 +59,10 @@ public: DECLARE_SCHEME_CALLBACK (print, (SCM)); DECLARE_SCHEME_CALLBACK (calc_direction, (SCM)); DECLARE_SCHEME_CALLBACK (calc_positions, (SCM)); + DECLARE_SCHEME_CALLBACK (calc_least_squares_dy, (SCM)); + DECLARE_SCHEME_CALLBACK (calc_concaveness, (SCM)); /* position callbacks */ - DECLARE_SCHEME_CALLBACK (least_squares, (SCM)); - DECLARE_SCHEME_CALLBACK (check_concave, (SCM)); DECLARE_SCHEME_CALLBACK (slope_damping, (SCM)); DECLARE_SCHEME_CALLBACK (shift_region_to_valid, (SCM)); DECLARE_SCHEME_CALLBACK (quanting, (SCM)); diff --git a/scm/define-grobs.scm b/scm/define-grobs.scm index 9284ff078a..189d9bdf9c 100644 --- a/scm/define-grobs.scm +++ b/scm/define-grobs.scm @@ -285,12 +285,12 @@ ;; todo: clean this up a bit: the list is getting ;; rather long. (gap . 0.8) - (position-callbacks . (,Beam::least_squares - ,Beam::check_concave - ,Beam::slope_damping + + (position-callbacks . (,Beam::slope_damping ,Beam::shift_region_to_valid ,Beam::quanting)) - + (least-squares-dy . ,Beam::calc_least_squares_dy) + (concaveness . ,Beam::calc_concaveness) (positions . ,Beam::calc_positions) (direction . ,Beam::calc_direction) (stencil . ,Beam::print)