From ebf33ab24c66b23917006ed8dcb4e91eb51ea739 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Fri, 4 Nov 2005 00:20:58 +0000 Subject: [PATCH] (set_stem_lengths): force direction callback. (print): read quantized-positions, so we can force Beam::set_stem_lengths to occur. (rest_collision_callback): use common X parent. --- ChangeLog | 7 +++++++ lily/beam.cc | 30 +++++++++++++++++++----------- lily/include/beam.hh | 2 +- lily/stem.cc | 29 ++++++++++++++++------------- scm/define-grobs.scm | 5 +++-- 5 files changed, 46 insertions(+), 27 deletions(-) diff --git a/ChangeLog b/ChangeLog index 16e8e3293b..5d7b6a9b42 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2005-11-04 Han-Wen Nienhuys + + * lily/beam.cc (set_stem_lengths): force direction callback. + (print): read quantized-positions, so we can force + Beam::set_stem_lengths to occur. + (rest_collision_callback): use common X parent. + 2005-11-03 Jan Nieuwenhuizen * flower/file-path.cc (find): Bugfix: Return name of file found. diff --git a/lily/beam.cc b/lily/beam.cc index 8c88457dfc..71930f2e07 100644 --- a/lily/beam.cc +++ b/lily/beam.cc @@ -217,7 +217,6 @@ Beam::connect_beams (Grob *me) Slice last_int; last_int.set_empty (); - // SCM last_beaming = SCM_EOL; SCM last_beaming = scm_cons (SCM_EOL, scm_list_1 (scm_from_int (0))); Direction last_dir = CENTER; for (int i = 0; i < stems.size (); i++) @@ -303,7 +302,7 @@ Beam::print (SCM grob) dx = stems.top ()->relative_coordinate (xcommon, X_AXIS) - x0; } - SCM posns = me->get_property ("positions"); + SCM posns = me->get_property ("quantized-positions"); Drul_array pos; if (!is_number_pair (posns)) { @@ -1073,11 +1072,16 @@ Beam::calc_stem_y (Grob *me, Grob *s, Grob ** common, Hmm. At this time, beam position and slope are determined. Maybe, stem directions and length should set to relative to the chord's position of the beam. */ -MAKE_SCHEME_CALLBACK(Beam, set_stem_lengths, 2); +MAKE_SCHEME_CALLBACK(Beam, set_stem_lengths, 1); SCM -Beam::set_stem_lengths (SCM smob, SCM posns) +Beam::set_stem_lengths (SCM smob) { Grob *me = unsmob_grob (smob); + + /* trigger callback. */ + (void) me->get_property ("direction"); + + SCM posns = me->get_property ("positions"); extract_grob_set (me, "stems", stems); if (!stems.size ()) @@ -1094,13 +1098,12 @@ Beam::set_stem_lengths (SCM smob, SCM posns) bool gap = false; Real thick = 0.0; if (scm_is_number (me->get_property ("gap-count")) - &&scm_to_int (me->get_property ("gap-count"))) + && scm_to_int (me->get_property ("gap-count"))) { gap = true; thick = get_thickness (me); } - // ugh -> use commonx Grob *fvs = first_visible_stem (me); Grob *lvs = last_visible_stem (me); @@ -1142,7 +1145,6 @@ Beam::set_beaming (Grob *me, Beaming_info_list const *beaming) /* Don't overwrite user settings. */ - do { Grob *stem = stems[i]; @@ -1267,13 +1269,19 @@ Beam::rest_collision_callback (SCM smob, SCM prev_offset) Real dy = pos[RIGHT] - pos[LEFT]; - // ugh -> use commonx - Real x0 = first_visible_stem (beam)->relative_coordinate (0, X_AXIS); - Real dx = last_visible_stem (beam)->relative_coordinate (0, X_AXIS) - x0; + Drul_array visible_stems (first_visible_stem (beam), + last_visible_stem (beam)); + + Grob *common = visible_stems[RIGHT] + ->common_refpoint (visible_stems[LEFT], X_AXIS); + + Real x0 = visible_stems[LEFT]->relative_coordinate (common, X_AXIS); + Real dx = visible_stems[RIGHT]->relative_coordinate (common, X_AXIS) - x0; Real slope = dy && dx ? dy / dx : 0; Direction d = get_grob_direction (stem); - Real stem_y = pos[LEFT] + (stem->relative_coordinate (0, X_AXIS) - x0) * slope; + Real stem_y = pos[LEFT] + + (stem->relative_coordinate (common, X_AXIS) - x0) * slope; Real beam_translation = get_beam_translation (beam); Real beam_thickness = Beam::get_thickness (beam); diff --git a/lily/include/beam.hh b/lily/include/beam.hh index e26dc1fff4..a044a1fd8c 100644 --- a/lily/include/beam.hh +++ b/lily/include/beam.hh @@ -61,12 +61,12 @@ public: DECLARE_SCHEME_CALLBACK (calc_positions, (SCM)); DECLARE_SCHEME_CALLBACK (calc_least_squares_positions, (SCM, SCM)); DECLARE_SCHEME_CALLBACK (calc_concaveness, (SCM)); + DECLARE_SCHEME_CALLBACK (set_stem_lengths, (SCM)); /* position callbacks */ DECLARE_SCHEME_CALLBACK (shift_region_to_valid, (SCM, SCM)); DECLARE_SCHEME_CALLBACK (slope_damping, (SCM, SCM)); DECLARE_SCHEME_CALLBACK (quanting, (SCM, SCM)); - DECLARE_SCHEME_CALLBACK (set_stem_lengths, (SCM,SCM)); static Real score_slopes_dy (Real, Real, Real, Real, Real, bool, Beam_quant_parameters const *); diff --git a/lily/stem.cc b/lily/stem.cc index e6183a63b7..9cdaaa2568 100644 --- a/lily/stem.cc +++ b/lily/stem.cc @@ -229,7 +229,7 @@ Stem::calc_stem_end_position (SCM smob) if (!head_count (me)) return scm_from_double (0.0); - + Real ss = Staff_symbol_referencer::staff_space (me); int durlog = duration_log (me); Array a; @@ -239,13 +239,14 @@ Stem::calc_stem_end_position (SCM smob) Direction dir = get_grob_direction (me); Interval hp = head_positions (me); - Real st = dir ? hp[dir] + dir * length : 0; + Real stem_end = dir ? hp[dir] + dir * length : 0; /* TODO: change name to extend-stems to staff/center/'() */ bool no_extend_b = to_boolean (me->get_property ("no-stem-extend")); - if (!no_extend_b && dir * st < 0) - st = 0.0; + if (!no_extend_b && dir * stem_end < 0) + stem_end = 0.0; + /* Make a little room if we have a upflag and there is a dot. previous approach was to lengthen the stem. This is not good typesetting practice. */ @@ -263,7 +264,7 @@ Stem::calc_stem_end_position (SCM smob) /* Very gory: add myself to the X-support of the parent, which should be a dot-column. */ - if (dir * (st + flagy - dp) < 0.5) + if (dir * (stem_end + flagy - dp) < 0.5) { Grob *par = dots->get_parent (X_AXIS); @@ -279,7 +280,7 @@ Stem::calc_stem_end_position (SCM smob) } } - return scm_from_double (st); + return scm_from_double (stem_end); } @@ -507,8 +508,12 @@ Stem::height (SCM smob) beam->get_property ("positions"); } - /* FIXME uncached? */ - Interval iv = me->get_stencil () ? me->get_stencil ()->extent (Y_AXIS) : Interval(); + /* + Can't get_stencil(), since that would cache stencils too early. + This causes problems with beams. + */ + Stencil *stencil = unsmob_stencil (print (smob)); + Interval iv = stencil ? stencil->extent (Y_AXIS) : Interval(); if (beam) { if (dir == CENTER) @@ -679,13 +684,13 @@ Stem::print (SCM smob) Interval stem_y (min (y1, y2), max (y2, y1)); - if (Grob *hed = support_head (me)) + if (Grob *head = support_head (me)) { /* must not take ledgers into account. */ - Interval head_height = hed->extent (hed, Y_AXIS); - Real y_attach = Note_head::stem_attachment_coordinate (hed, Y_AXIS); + Interval head_height = head->extent (head, Y_AXIS); + Real y_attach = Note_head::stem_attachment_coordinate (head, Y_AXIS); y_attach = head_height.linear_combination (y_attach); stem_y[Direction (-d)] += d * y_attach / half_space; @@ -942,11 +947,9 @@ ADD_INTERFACE (Stem, "stem-interface", "should be shortened. The list gives an amount depending on the number " "of flags/beams." "@end table\n" - , /* properties */ - "avoid-note-head " "beam " "beaming " diff --git a/scm/define-grobs.scm b/scm/define-grobs.scm index afbd73bf7e..27123ad246 100644 --- a/scm/define-grobs.scm +++ b/scm/define-grobs.scm @@ -290,9 +290,10 @@ Beam::slope_damping Beam::shift_region_to_valid Beam::quanting - Beam::set_stem_lengths )))) - + + ;; this is a hack to set stem lengths, if positions is set. + (quantized-positions . ,Beam::set_stem_lengths) (concaveness . ,Beam::calc_concaveness) (direction . ,Beam::calc_direction) (stencil . ,Beam::print) -- 2.39.5