From c583d664d2aed5f62cb603dfbb01235ecd2cbd23 Mon Sep 17 00:00:00 2001 From: David Nalesnik Date: Sat, 11 Feb 2017 13:19:16 -0600 Subject: [PATCH] Allow slurs instead of brackets with tuplets Older editions often use slurs with tuplets. This patch creates a new property ('tuplet-slur'), which toggles this notation style. Note that 'bracket-visibility must be set to #t for the slurs to appear with beamed notes. (In the future, 'bracket-visibility might automatically be set to #t.) Support shorten-pair --- lily/tuplet-bracket.cc | 95 +++++++++++++++++++++++++++++++++++------- scm/define-grob-properties.scm | 2 + scm/define-grobs.scm | 1 + 3 files changed, 83 insertions(+), 15 deletions(-) diff --git a/lily/tuplet-bracket.cc b/lily/tuplet-bracket.cc index 340b017..2600d7a 100644 --- a/lily/tuplet-bracket.cc +++ b/lily/tuplet-bracket.cc @@ -58,6 +58,7 @@ #include "lookup.hh" #include "paper-column.hh" #include "moment.hh" +#include "bezier.hh" static Item * get_x_bound_item (Grob *me_grob, Direction hdir, Direction my_dir) @@ -245,6 +246,54 @@ Tuplet_bracket::calc_x_positions (SCM smob) return ly_interval2scm (x_span - me->get_bound (LEFT)->relative_coordinate (commonx, X_AXIS)); } +Bezier +tuplet_slur_shape (Offset l, Offset r, Real h_limit, Real ratio, Direction d) +{ + Real indent; + Real height; + + Real width = (r[X_AXIS] - l[X_AXIS]); + + get_slur_indent_height (&indent, &height, width, h_limit, ratio); + + Bezier curve; + + curve.control_[0] = l; + curve.control_[1] = Offset (l[X_AXIS] + indent, l[Y_AXIS] + height * d); + curve.control_[2] = Offset (r[X_AXIS] - indent, r[Y_AXIS] + height * d); + curve.control_[3] = r; + + return curve; +} + +Stencil +make_tuplet_slur (Grob *me, Offset l, Offset r, Drul_array shorten) +{ + SCM dash_definition = me->get_property ("dash-definition"); + Real lt = me->layout ()->get_dimension (ly_symbol2scm ("line-thickness")); + + Real height_limit = 1.5; + Real ratio = .33; + + Direction dir = get_grob_direction (me); + + Offset dz = r - l; + Real length = dz.length (); + + l += shorten[LEFT] / length * dz; + r -= shorten[RIGHT] / length * dz; + + Bezier curve = tuplet_slur_shape (l, r, height_limit, ratio, dir); + + Stencil mol (Lookup::slur (curve, lt, lt, dash_definition)); + + Grob *tn = unsmob (me->get_object ("tuplet-number")); + Real padding = robust_scm2double (tn->get_property ("padding"), 0.3); + + mol.translate_axis (padding * dir, Y_AXIS); + return mol; +} + /* TODO: @@ -258,6 +307,8 @@ Tuplet_bracket::print (SCM smob) Spanner *me = unsmob (smob); Stencil mol; + bool tuplet_slur = ly_scm2bool (me->get_property ("tuplet-slur")); + extract_grob_set (me, "note-columns", columns); bool equally_long = false; Grob *par_beam = parallel_beam (me, columns, &equally_long); @@ -325,20 +376,32 @@ Tuplet_bracket::print (SCM smob) if (bracket_visibility) { Drul_array zero (0, 0); + + Drul_array shorten + = robust_scm2drul (me->get_property ("shorten-pair"), zero); + Real ss = Staff_symbol_referencer::staff_space (me); + scale_drul (&shorten, ss); + + Stencil brack; + + if (tuplet_slur) { + brack = make_tuplet_slur (me, points[LEFT], points[RIGHT], shorten); + mol.add_stencil (brack); + } + else + { + Drul_array edge_stencils; + Drul_array height = robust_scm2drul (me->get_property ("edge-height"), zero); Drul_array flare = robust_scm2drul (me->get_property ("bracket-flare"), zero); - Drul_array shorten - = robust_scm2drul (me->get_property ("shorten-pair"), zero); - Drul_array edge_stencils; Direction dir = get_grob_direction (me); scale_drul (&height, -ss * dir); scale_drul (&flare, ss); - scale_drul (&shorten, ss); Drul_array connect_to_other = robust_scm2booldrul (me->get_property ("connect-to-neighbor"), @@ -373,15 +436,15 @@ Tuplet_bracket::print (SCM smob) } } - Stencil brack = make_bracket (me, Y_AXIS, - points[RIGHT] - points[LEFT], - height, - /* - 0.1 = more space at right due to italics - TODO: use italic correction of font. - */ - Interval (-0.5, 0.5) * gap + 0.1, - flare, shorten); + brack = make_bracket (me, Y_AXIS, + points[RIGHT] - points[LEFT], + height, + /* + 0.1 = more space at right due to italics + TODO: use italic correction of font. + */ + Interval (-0.5, 0.5) * gap + 0.1, + flare, shorten); for (LEFT_and_RIGHT (d)) { @@ -390,12 +453,13 @@ Tuplet_bracket::print (SCM smob) } mol.add_stencil (brack); + mol.translate (points[LEFT]); } - - mol.translate (points[LEFT]); + } return mol.smobbed_copy (); } + /* should move to lookup? @@ -842,6 +906,7 @@ ADD_INTERFACE (Tuplet_bracket, "note-columns " "padding " "tuplet-number " + "tuplet-slur " "scripts " "shorten-pair " "staff-padding " diff --git a/scm/define-grob-properties.scm b/scm/define-grob-properties.scm index 34450a9..d34a416 100644 --- a/scm/define-grob-properties.scm +++ b/scm/define-grob-properties.scm @@ -1135,6 +1135,8 @@ direction and it is associated with a @code{ScriptColumn} object. @code{0.0} means centered on the note head (the default position of most scripts); @code{1.0} means centered on the stem. Interpolated values are possible.") + (tuplet-slur ,boolean? "Draw a slur instead of a bracket for +tuplets.") (transparent ,boolean? "This makes the grob invisible.") diff --git a/scm/define-grobs.scm b/scm/define-grobs.scm index a04e070..fceb313 100644 --- a/scm/define-grobs.scm +++ b/scm/define-grobs.scm @@ -2611,6 +2611,7 @@ (staff-padding . 0.25) (stencil . ,ly:tuplet-bracket::print) (thickness . 1.6) + (tuplet-slur . #f) (vertical-skylines . ,grob::unpure-vertical-skylines-from-stencil) (X-positions . ,ly:tuplet-bracket::calc-x-positions) -- 2.1.4