From aeffdc00640754855d3ace4fda106693adb62eb6 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Tue, 27 Jan 2004 00:37:42 +0000 Subject: [PATCH] * lily/side-position-interface.cc (out_of_staff): move contents of out_of_staff into aligned_side. * input/regression/measure-grouping.ly: fix warning. * lily/side-position-interface.cc: add staff-padding support to Side_position_interface::aligned_side. * lily/system-start-delimiter-engraver.cc (process_music): whoops, one get_property too many. * flower/include/drul-array.hh (linear_combination): new function (scale_drul): new function * lily/beam.cc: use Drul_array iso. interval, because *= operations on empty intervals are silly. --- ChangeLog | 19 +++++++++ VERSION | 2 +- flower/include/drul-array.hh | 15 +++++++ flower/include/interval.hh | 4 +- flower/interval.cc | 1 + input/regression/measure-grouping.ly | 5 +-- lily/beam-quanting.cc | 9 ++-- lily/beam.cc | 56 ++++++++++++------------- lily/include/beam.hh | 2 +- lily/include/lily-guile.hh | 1 + lily/lily-guile.cc | 7 ++++ lily/side-position-interface.cc | 43 ++++++++++--------- lily/staff-symbol.cc | 2 - lily/system-start-delimiter-engraver.cc | 2 +- scm/define-grobs.scm | 6 +-- 15 files changed, 104 insertions(+), 70 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1a02b08fed..d4c2f81d9a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2004-01-27 Han-Wen Nienhuys + + * lily/side-position-interface.cc (out_of_staff): move contents of + out_of_staff into aligned_side. + + * input/regression/measure-grouping.ly: fix warning. + + * lily/side-position-interface.cc: add staff-padding support to + Side_position_interface::aligned_side. + + * lily/system-start-delimiter-engraver.cc (process_music): whoops, + one get_property too many. + + * flower/include/drul-array.hh (linear_combination): new function + (scale_drul): new function + + * lily/beam.cc: use Drul_array iso. interval, because *= + operations on empty intervals are silly. + 2004-01-26 Jan Nieuwenhuizen * lily/note-heads-engraver.cc (process_music): use robust_scm2int diff --git a/VERSION b/VERSION index aaa77e5b2b..044df009bc 100644 --- a/VERSION +++ b/VERSION @@ -2,5 +2,5 @@ PACKAGE_NAME=LilyPond MAJOR_VERSION=2 MINOR_VERSION=1 PATCH_LEVEL=15 -MY_PATCH_LEVEL= +MY_PATCH_LEVEL=hwn1 diff --git a/flower/include/drul-array.hh b/flower/include/drul-array.hh index 0e4dc34e21..7078bdaa0c 100644 --- a/flower/include/drul-array.hh +++ b/flower/include/drul-array.hh @@ -11,6 +11,7 @@ #define DRUL_ARRAY_HH #include "direction.hh" +#include "real.hh" #include @@ -50,4 +51,18 @@ struct Drul_array } }; +template +void +scale_drul (Drul_array * dr, T x) +{ + dr->elem (LEFT) *= x; + dr->elem (RIGHT) *= x; +} + +inline Real +linear_combination (Drul_array const &d, Real x) +{ + return ((1.0 - x) * Real (d.elem (LEFT)) + (x + 1.0) * Real (d.elem (RIGHT))) * 0.5; +} + #endif // DRUL_ARRAY_HH diff --git a/flower/include/interval.hh b/flower/include/interval.hh index 413b6b78d5..7168a2d51b 100644 --- a/flower/include/interval.hh +++ b/flower/include/interval.hh @@ -88,7 +88,9 @@ struct Interval_t : public Drul_array { } Real linear_combination (Real x) const { - return ((1.0 - x) * Real (elem (LEFT)) + (x + 1.0) * Real (elem (RIGHT))) * 0.5; + Drul_array da (elem (LEFT), + elem (RIGHT)); + return ::linear_combination (da, x); } String to_string () const; diff --git a/flower/interval.cc b/flower/interval.cc index 10239516e6..8e34952be7 100644 --- a/flower/interval.cc +++ b/flower/interval.cc @@ -39,3 +39,4 @@ Interval_t::T_to_string (int i) template INTERVAL__INSTANTIATE (int); template INTERVAL__INSTANTIATE (Real); + diff --git a/input/regression/measure-grouping.ly b/input/regression/measure-grouping.ly index a416e5a8bb..6662a20f4a 100644 --- a/input/regression/measure-grouping.ly +++ b/input/regression/measure-grouping.ly @@ -3,8 +3,7 @@ { texidoc = "The @code{Measure_grouping_engraver} adds triangles and -brackets above beats when you set beatGrouping. This shows a fragment -of Steve Martland's Dance Works. " +brackets above beats when you set beatGrouping. " } @@ -22,7 +21,7 @@ of Steve Martland's Dance Works. " \time 2/4 c,8 g'4 g8~ #(set-time-signature 5 8 '(3 2)) - g8 a4 g a-> + g8 a4 g a4.-> } \paper { raggedright = ##t diff --git a/lily/beam-quanting.cc b/lily/beam-quanting.cc index ae084a2ddf..178d8da484 100644 --- a/lily/beam-quanting.cc +++ b/lily/beam-quanting.cc @@ -274,15 +274,14 @@ Beam::quanting (SCM smob) if (debug_beam_quanting_flag && gh_pair_p (inspect_quants)) { - Real il = gh_scm2double (gh_car (inspect_quants)); - Real ir = gh_scm2double (gh_cdr (inspect_quants)); + Drul_array ins = ly_scm2interval (inspect_quants); int i = 0; Real mindist = 1e6; for (; i < qscores.size(); i ++) { - Real d =fabs (qscores[i].yl-il) + fabs (qscores[i].yr - ir); + Real d =fabs (qscores[i].yl- ins[LEFT]) + fabs (qscores[i].yr - ins[RIGHT]); if (d < mindist) { best_idx = i; @@ -295,8 +294,8 @@ Beam::quanting (SCM smob) #endif me->set_grob_property ("positions", - gh_cons (gh_double2scm (qscores[best_idx].yl), - gh_double2scm (qscores[best_idx].yr))); + ly_interval2scm (Drul_array (qscores[best_idx].yl, + qscores[best_idx].yr))); #if DEBUG_QUANTING if (debug_beam_quanting_flag) { diff --git a/lily/beam.cc b/lily/beam.cc index 60b6944a80..c6e6f1112d 100644 --- a/lily/beam.cc +++ b/lily/beam.cc @@ -10,8 +10,6 @@ /* TODO: - * Use Number_pair i.s.o Interval to represent (yl, yr). - - Determine auto knees based on positions if it's set by the user. - the code is littered with * and / staff_space calls for @@ -46,8 +44,6 @@ Notes: #include "spanner.hh" #include "warn.hh" - - bool debug_beam_quanting_flag; @@ -332,24 +328,24 @@ Beam::brew_molecule (SCM grob) } SCM posns = me->get_grob_property ("positions"); - Interval pos; + Drul_array pos; if (!is_number_pair (posns)) { programming_error ("No beam posns"); pos = Interval (0,0); } else - pos= ly_scm2interval (posns); - + pos= ly_scm2realdrul (posns); - pos *= Staff_symbol_referencer::staff_space (me); - Real dy = pos.delta (); + scale_drul ( &pos, Staff_symbol_referencer::staff_space (me)); + + Real dy = pos[RIGHT] - pos[LEFT]; Real dydx = (dy && dx) ? dy/dx : 0; Real thick = get_thickness (me); Real bdy = get_beam_translation (me); - SCM last_beaming = SCM_EOL;; + SCM last_beaming = SCM_EOL; Real last_xposn = -1; Real last_stem_width = -1 ; @@ -932,7 +928,7 @@ Beam::least_squares (SCM smob) /* "position" is relative to the staff. */ - pos *= 1/ Staff_symbol_referencer::staff_space (me); + scale_drul (&pos, 1/ Staff_symbol_referencer::staff_space (me)); me->set_grob_property ("positions", ly_interval2scm (pos)); @@ -982,11 +978,11 @@ Beam::shift_region_to_valid (SCM grob) Real dx = lvs->relative_coordinate (commonx, X_AXIS) - x0; - Interval pos = ly_scm2interval ( me->get_grob_property ("positions")); + Drul_array pos = ly_scm2interval ( me->get_grob_property ("positions")); - pos *= Staff_symbol_referencer::staff_space (me); + scale_drul (&pos, Staff_symbol_referencer::staff_space (me)); - Real dy = pos.delta(); + Real dy = pos[RIGHT] - pos[LEFT]; Real y = pos[LEFT]; Real dydx =dy/dx; @@ -1038,8 +1034,8 @@ Beam::shift_region_to_valid (SCM grob) y = feasible_left_point.center (); } - pos = Interval (y, (y+dy)); - pos *= 1/ Staff_symbol_referencer::staff_space (me); + pos = Drul_array (y, (y+dy)); + scale_drul (&pos, 1/ Staff_symbol_referencer::staff_space (me)); me->set_grob_property ("positions", ly_interval2scm (pos)); return SCM_UNSPECIFIED; @@ -1162,11 +1158,11 @@ Beam::check_concave (SCM smob) /* TODO: some sort of damping iso -> plain horizontal */ if (concaveness1 || concaveness2 > r2) { - Interval pos = ly_scm2interval (me->get_grob_property ("positions")); - Real r = pos.linear_combination (0); + Drul_array pos = ly_scm2interval (me->get_grob_property ("positions")); + Real r = linear_combination (pos, 0); r /= Staff_symbol_referencer::staff_space (me); - me->set_grob_property ("positions", ly_interval2scm (Interval (r, r))); + me->set_grob_property ("positions", ly_interval2scm (Drul_array (r, r))); me->set_grob_property ("least-squares-dy", gh_double2scm (0)); } @@ -1190,10 +1186,10 @@ Beam::slope_damping (SCM smob) if (damping) { - Interval pos = ly_scm2interval (me->get_grob_property ("positions")); - pos *= Staff_symbol_referencer::staff_space (me); + Drul_array pos = ly_scm2interval (me->get_grob_property ("positions")); + scale_drul (&pos, Staff_symbol_referencer::staff_space (me)); - Real dy = pos.delta (); + Real dy = pos[RIGHT] - pos[LEFT]; Grob *fvs = first_visible_stem (me); Grob *lvs = last_visible_stem (me); @@ -1210,7 +1206,7 @@ Beam::slope_damping (SCM smob) pos[LEFT] += (dy - damped_dy) / 2; pos[RIGHT] -= (dy - damped_dy) / 2; - pos *= 1/ Staff_symbol_referencer::staff_space (me); + scale_drul (&pos, 1/Staff_symbol_referencer::staff_space (me)); me->set_grob_property ("positions", ly_interval2scm (pos)); } @@ -1241,13 +1237,13 @@ where_are_the_whole_beams(SCM beaming) Real Beam::calc_stem_y (Grob *me, Grob* s, Grob ** common, Real xl, Real xr, - Interval pos, bool french) + Drul_array pos, bool french) { Real beam_translation = get_beam_translation (me); Real r = s->relative_coordinate (common[X_AXIS], X_AXIS) - xl; - Real dy = pos.delta (); + Real dy = pos[RIGHT] - pos[LEFT]; Real dx = xr - xl; Real stem_y_beam0 = (dy && dx ? r / dx @@ -1294,9 +1290,9 @@ Beam::set_stem_lengths (Grob *me) for (int a = 2; a--;) common[a] = common_refpoint_of_array (stems, me, Axis(a)); - Interval pos = ly_scm2interval (me->get_grob_property ("positions")); + Drul_array pos = ly_scm2realdrul (me->get_grob_property ("positions")); Real staff_space = Staff_symbol_referencer::staff_space (me); - pos *= staff_space; + scale_drul (&pos, staff_space); bool gap = false; Real thick =0.0; @@ -1473,16 +1469,16 @@ Beam::rest_collision_callback (SCM element_smob, SCM axis) || !Beam::visible_stem_count (beam)) return gh_double2scm (0.0); - Interval pos (0, 0); + Drul_array pos (0, 0); SCM s = beam->get_grob_property ("positions"); if (gh_pair_p (s) && gh_number_p (ly_car (s))) pos = ly_scm2interval (s); Real staff_space = Staff_symbol_referencer::staff_space (rest); - pos *= staff_space; + scale_drul (&pos, staff_space); - Real dy = pos.delta (); + Real dy = pos[RIGHT] - pos[LEFT]; // ugh -> use commonx Real x0 = first_visible_stem (beam)->relative_coordinate (0, X_AXIS); diff --git a/lily/include/beam.hh b/lily/include/beam.hh index ed610a9975..a3c34ea86e 100644 --- a/lily/include/beam.hh +++ b/lily/include/beam.hh @@ -67,7 +67,7 @@ private: static void set_stem_shorten (Grob*); static Real calc_stem_y (Grob*, Grob* s, Grob**c, Real, Real, - Interval pos, bool french); + Drul_array pos, bool french); static void set_stem_lengths (Grob*); static int forced_stem_count (Grob*); }; diff --git a/lily/include/lily-guile.hh b/lily/include/lily-guile.hh index 353d1fe798..1a8883b9ab 100644 --- a/lily/include/lily-guile.hh +++ b/lily/include/lily-guile.hh @@ -156,6 +156,7 @@ Offset ly_scm2offset (SCM); SCM ly_assoc_chain (SCM key, SCM achain); SCM ly_assoc_cdr (SCM key, SCM alist); Interval ly_scm2interval (SCM); +Drul_array ly_scm2realdrul (SCM); Slice int_list_to_slice (SCM l); SCM ly_interval2scm (Drul_array); diff --git a/lily/lily-guile.cc b/lily/lily-guile.cc index a7c8b58919..104fffc3ba 100644 --- a/lily/lily-guile.cc +++ b/lily/lily-guile.cc @@ -253,6 +253,13 @@ ly_scm2interval (SCM p) gh_scm2double (ly_cdr (p))); } +Drul_array +ly_scm2realdrul (SCM p) +{ + return Drul_array (gh_scm2double (ly_car (p)), + gh_scm2double (ly_cdr (p))); +} + SCM ly_interval2scm (Drul_array i) { diff --git a/lily/side-position-interface.cc b/lily/side-position-interface.cc index 081d84d993..42ae7dfd04 100644 --- a/lily/side-position-interface.cc +++ b/lily/side-position-interface.cc @@ -107,6 +107,9 @@ Side_position_interface::general_side_position (Grob * me, Axis a, bool use_exte if (fabs (total_off) > 100 CM) programming_error ("Huh ? Improbable staff side dim."); + + + return gh_double2scm (total_off); } @@ -193,6 +196,23 @@ Side_position_interface::aligned_side (SCM element_smob, SCM axis) } o += - iv[-d]; } + + Grob * st = Staff_symbol_referencer::get_staff_symbol (me); + if (st && a == Y_AXIS + && gh_number_p (me->get_grob_property ("staff-padding"))) + { + Real padding= + Staff_symbol_referencer::staff_space (me) + * gh_scm2double (me->get_grob_property ("staff-padding")); + + Grob *common = me->common_refpoint (st, Y_AXIS); + + Interval staff_size = st->extent (common, Y_AXIS); + Interval me_ext = me->extent (common, a); + Real diff = d*staff_size[d] + padding - d*(o + iv[-d]); + o += (d* (diff >? 0)); + } + return gh_double2scm (o); } @@ -205,28 +225,7 @@ MAKE_SCHEME_CALLBACK (Side_position_interface,out_of_staff,2); SCM Side_position_interface::out_of_staff (SCM element_smob, SCM axis) { - Grob *me = unsmob_grob (element_smob); - Axis a = (Axis) gh_scm2int (axis); - - Grob * st = Staff_symbol_referencer::get_staff_symbol (me); - - if (!st) - return gh_int2scm (0); - - SCM scm_padding = me->get_grob_property ("staff-padding"); - if (!gh_number_p (scm_padding)) - return gh_int2scm (0); - - Real padding= - Staff_symbol_referencer::staff_space (me) - * gh_scm2double (scm_padding); - - Grob *common = me->common_refpoint (st, Y_AXIS); - Direction d = Side_position_interface::get_direction (me); - Interval staff_size = st->extent (common, Y_AXIS); - Interval me_ext = me->extent (common, a); - Real diff = d*staff_size[d] + padding - d*me_ext[-d]; - return gh_double2scm (d* (diff >? 0)); + return gh_double2scm (0); } void diff --git a/lily/staff-symbol.cc b/lily/staff-symbol.cc index 011e330c86..9a3c034352 100644 --- a/lily/staff-symbol.cc +++ b/lily/staff-symbol.cc @@ -114,8 +114,6 @@ Staff_symbol::get_line_thickness (Grob* me) Real Staff_symbol::get_ledger_line_thickness (Grob * me) { - Real lt = me->get_paper ()->get_realvar (ly_symbol2scm ("linethickness")); - SCM lt_pair = me->get_grob_property ("ledger-line-thickness"); Offset z = robust_scm2offset (lt_pair, Offset (1.0, 0.1)); diff --git a/lily/system-start-delimiter-engraver.cc b/lily/system-start-delimiter-engraver.cc index 049bcb1d85..f5865c343c 100644 --- a/lily/system-start-delimiter-engraver.cc +++ b/lily/system-start-delimiter-engraver.cc @@ -73,7 +73,7 @@ System_start_delimiter_engraver::process_music () if (!delim_) { SCM delim_name =get_property ("systemStartDelimiter"); - delim_ = internal_make_spanner (internal_get_property (delim_name)); + delim_ = internal_make_spanner (delim_name); delim_->set_bound (LEFT, unsmob_grob (get_property ("currentCommandColumn"))); announce_grob (delim_, SCM_EOL); diff --git a/scm/define-grobs.scm b/scm/define-grobs.scm index dcdb696410..395eab13f4 100644 --- a/scm/define-grobs.scm +++ b/scm/define-grobs.scm @@ -536,8 +536,7 @@ )) (MeasureGrouping . ( - (Y-offset-callbacks . (,Side_position_interface::out_of_staff - ,Side_position_interface::aligned_side)) + (Y-offset-callbacks . (,Side_position_interface::aligned_side)) (molecule-callback . ,Measure_grouping::brew_molecule) (padding . 2) (direction . 1) @@ -1074,8 +1073,7 @@ (OttavaBracket . ( - (Y-offset-callbacks . (,Side_position_interface::out_of_staff - ,Side_position_interface::aligned_side)) + (Y-offset-callbacks . (,Side_position_interface::aligned_side)) (molecule-callback . ,Ottava_bracket::brew_molecule) (font-shape . italic) (font-family . roman) -- 2.39.5