From 6467c63cd68e815c0175d59b9ef846dd90337510 Mon Sep 17 00:00:00 2001 From: Carl Sorensen Date: Thu, 16 Apr 2009 21:45:13 -0600 Subject: [PATCH 1/1] Update dashed slurs to have variable thickness. Dashed slurs are now written as bezier sandwiches, like regular slurs. Moved dash-period and dash-fraction from properties for slurs, phrasingSlurs, and ties. Created new property dash-definition that contains a list of dash-descriptions for each segment of the slur. Defined new ommands \slurHalfDashed and \slurHalfSolid. Changed bezier-sandwich interface to include thickness parameter that is used for slurs. This required changes to vaticana=ligature. Added extract and split to Bezier class. Adjusted header files to reflect new calling lists. arpeggio.cc is changed because there is a slur-arpeggio type. Adjusted documentation to reflect changes. --- Documentation/user/expressive.itely | 25 ++++ ...aking-slurs-with-complex-dash-structure.ly | 37 ++++++ lily/arpeggio.cc | 2 +- lily/bezier.cc | 53 ++++++++ lily/include/bezier.hh | 2 + lily/include/lookup.hh | 7 +- lily/lookup.cc | 124 ++++++++++-------- lily/slur.cc | 23 ++-- lily/tie.cc | 24 ++-- lily/vaticana-ligature.cc | 6 +- ly/property-init.ly | 34 +++-- python/convertrules.py | 7 +- scm/define-grob-properties.scm | 3 + 13 files changed, 255 insertions(+), 92 deletions(-) create mode 100644 input/new/making-slurs-with-complex-dash-structure.ly diff --git a/Documentation/user/expressive.itely b/Documentation/user/expressive.itely index 23ca4faba3..998461f47c 100644 --- a/Documentation/user/expressive.itely +++ b/Documentation/user/expressive.itely @@ -575,6 +575,26 @@ c4( e g2) g4( e c2) @end lilypond +@funindex \slurHalfDashed +@funindex slurHalfDashed +@funindex \slurHalfSolid +@funindex slurHalfSolid + +Slurs can also be made half-dashed (the first half dashed, the +second half solid) or half-solid (the first half solid, the second +half dashed): + +@lilypond[verbatim,quote,relative=1] +\slurHalfDashed +g4( e c2) +\slurHalfSolid +c4( e g2) +\slurSolid +g4( e c2) +@end lilypond + + + @funindex \slurUp @funindex slurUp @@ -585,6 +605,8 @@ g4( e c2) @code{\slurNeutral}, @code{\slurDashed}, @code{\slurDotted}, +@code{\slurHaldDashed}, +@code{\slurHalfSolid}, @code{\slurSolid}. @endpredefined @@ -597,6 +619,9 @@ g4( e c2) @lilypondfile[verbatim,lilyquote,texidoc,doctitle] {positioning-text-markups-inside-slurs.ly} +@lilypondfile[verbatim,lilyquote,texidoc,doctitle] +{making-slurs-with-complex-dash-structure.ly} + @seealso Music Glossary: @rglos{slur}. diff --git a/input/new/making-slurs-with-complex-dash-structure.ly b/input/new/making-slurs-with-complex-dash-structure.ly new file mode 100644 index 0000000000..fd41dd7c9b --- /dev/null +++ b/input/new/making-slurs-with-complex-dash-structure.ly @@ -0,0 +1,37 @@ +\version "2.13.1" + +\header{ + texidoc = " +Slurs can be made with complex dash patterns by defining +the @code{dash-definition} property. @code{dash-definition} +is a list of @code{dash-elements}. A @code{dash-element} is a +list of parameters defining the dash behavior for a segment of +the slur. + +The slur is defined in terms of the bezier parameter t +which ranges from 0 +at the left end of the slur to 1 at the right end of the slur. +@code{dash-element} is a list @code{(start-t stop-t dash-fraction +dash-period)}. The region of the slur from @code{start-t} to +@code{stop-t} will have a fraction @code{dash-fraction} +of each @code{dash-period} black. @code{dash-period} is +defined in terms of staff spaces. @code{dash-fraction} is +set to 1 for a solid slur. +" + doctitle = "Making slurs with complex dash structure" +} + +\relative c' { + \once \override + Slur #'dash-definition = #'((0 0.3 0.1 0.75) + (0.3 0.6 1 1) + (0.65 1.0 0.4 0.75)) + c( d e f) + \once \override + Slur #'dash-definition = #'((0 0.25 1 1) + (0.3 0.7 0.4 0.75) + (0.75 1.0 1 1)) + c( d e f) +} + + diff --git a/lily/arpeggio.cc b/lily/arpeggio.cc index 7873b5f39c..0265b3dedd 100644 --- a/lily/arpeggio.cc +++ b/lily/arpeggio.cc @@ -165,7 +165,7 @@ Arpeggio::brew_chord_slur (SCM smob) Bezier curve = slur_shape (dy, height_limit, ratio); curve.rotate (M_PI / 2); - Stencil mol (Lookup::slur (curve, lt, lt)); + Stencil mol (Lookup::slur (curve, lt, lt, SCM_UNDEFINED)); mol.translate_axis (heads[LEFT], Y_AXIS); return mol.smobbed_copy (); } diff --git a/lily/bezier.cc b/lily/bezier.cc index 3712b9213e..8f55b3ce50 100644 --- a/lily/bezier.cc +++ b/lily/bezier.cc @@ -265,3 +265,56 @@ Bezier::reverse () b2.control_[CONTROL_COUNT - i - 1] = control_[i]; *this = b2; } + + +/* + Subdivide a bezier at T into LEFT_PART and RIGHT_PART +*/ +void +Bezier::subdivide (Real t, Bezier &left_part, Bezier &right_part) +{ + Offset b2[3]; + Offset b1[2]; + Offset b0; + for (int i = 0; i < 3; i++) + b2[i] = control_[i] + t * (control_[i+1] - control_[i]); + for (int i = 0; i < 2; i++) + b1[i] = b2[i] + t * (b2[i+1] - b2[i]); + b0 = b1[0] + t * (b1[1] - b1[0]); + left_part.control_[0] = control_[0]; + left_part.control_[1] = b2[0]; + left_part.control_[2] = b1[0]; + left_part.control_[3] = b0; + right_part.control_[0] = b0; + right_part.control_[1] = b1[1]; + right_part.control_[2] = b2[2]; + right_part.control_[3] = control_[3]; +} + +/* + Extract a portion of a bezier from T_MIN to T_MAX +*/ + +Bezier +Bezier::extract (Real t_min, Real t_max) +{ + Bezier bez1, bez2, bez3, bez4; + if (t_min == 0.0) + { + for (int i = 0; i < CONTROL_COUNT; i++) + bez2.control_[i] = control_[i]; + } + else + { + subdivide (t_min, bez1, bez2); + } + if (t_max == 1.0) + { + return bez2; + } + else + { + bez2.subdivide ((t_max-t_min)/(1-t_min), bez3, bez4); + return bez3; + } +} diff --git a/lily/include/bezier.hh b/lily/include/bezier.hh index a04d449725..5cfca578c2 100644 --- a/lily/include/bezier.hh +++ b/lily/include/bezier.hh @@ -22,6 +22,8 @@ public: void reverse (); void rotate (Real); void translate (Offset); + void subdivide (Real, Bezier &, Bezier &); + Bezier extract (Real, Real); Real get_other_coordinate (Axis a, Real x) const; vector solve_point (Axis, Real coordinate) const; diff --git a/lily/include/lookup.hh b/lily/include/lookup.hh index 8f0844df71..bfe5d57b03 100644 --- a/lily/include/lookup.hh +++ b/lily/include/lookup.hh @@ -20,10 +20,11 @@ struct Lookup static Stencil rotated_box (Real slope, Real width, Real thick, Real blot); static Stencil round_filled_polygon (vector const &points, Real blotdiameter); static Stencil frame (Box b, Real thick, Real blot); - static Stencil slur (Bezier controls, Real cthick, Real thick); - static Stencil bezier_sandwich (Bezier top_curve, Bezier bottom_curve); + static Stencil slur (Bezier controls, Real cthick, Real thick, + SCM dash_definition); + static Stencil bezier_sandwich (Bezier top_curve, Bezier bottom_curve, + Real thickness); static Stencil beam (Real slope, Real width, Real thick, Real blot); - static Stencil dashed_slur (Bezier b, Real thick, Real dash_period, Real dash_fraction); static Stencil blank (Box b); static Stencil filled_box (Box b); static Stencil round_filled_box (Box b, Real blotdiameter); diff --git a/lily/lookup.cc b/lily/lookup.cc index 014d2ec8ab..f856fa5be9 100644 --- a/lily/lookup.cc +++ b/lily/lookup.cc @@ -86,28 +86,6 @@ Lookup::beam (Real slope, Real width, Real thick, Real blot) return Stencil (b, expr); } -Stencil -Lookup::dashed_slur (Bezier b, Real thick, Real dash_period, Real dash_fraction) -{ - SCM l = SCM_EOL; - - Real on = dash_fraction * dash_period; - Real off = dash_period - on; - - for (int i = 4; i--;) - l = scm_cons (ly_offset2scm (b.control_[i]), l); - - SCM at = (scm_list_n (ly_symbol2scm ("dashed-slur"), - scm_from_double (thick), - scm_from_double (on), - scm_from_double (off), - ly_quote_scm (l), - SCM_UNDEFINED)); - - Box box (b.extent (X_AXIS), b.extent (Y_AXIS)); - return Stencil (box, at); -} - Stencil Lookup::rotated_box (Real slope, Real width, Real thick, Real blot) { @@ -365,47 +343,84 @@ Lookup::frame (Box b, Real thick, Real blot) Make a smooth curve along the points */ Stencil -Lookup::slur (Bezier curve, Real curvethick, Real linethick) +Lookup::slur (Bezier curve, Real curvethick, Real linethick, + SCM dash_details) { + Stencil return_value; + + /* calculate the offset for the two beziers that make the sandwich + * for the slur + */ Real alpha = (curve.control_[3] - curve.control_[0]).arg (); Bezier back = curve; Offset perp = curvethick * complex_exp (Offset (0, alpha + M_PI / 2)) * 0.5; - back.reverse (); back.control_[1] += perp; back.control_[2] += perp; curve.control_[1] -= perp; curve.control_[2] -= perp; - - SCM scontrols[8]; - - for (int i = 0; i < 4; i++) - scontrols[i] = ly_offset2scm (back.control_[i]); - for (int i = 0; i < 4; i++) - scontrols[i + 4] = ly_offset2scm (curve.control_[i]); - - /* - Need the weird order b.o. the way PS want its arguments - */ - int indices[] = {5, 6, 7, 4, 1, 2, 3, 0}; - SCM list = SCM_EOL; - for (int i = 8; i--;) - list = scm_cons (scontrols[indices[i]], list); - - SCM at = (scm_list_n (ly_symbol2scm ("bezier-sandwich"), - ly_quote_scm (list), - scm_from_double (linethick), - SCM_UNDEFINED)); - Box b (curve.extent (X_AXIS), - curve.extent (Y_AXIS)); - - b[X_AXIS].unite (back.extent (X_AXIS)); - b[Y_AXIS].unite (back.extent (Y_AXIS)); - - b.widen (0.5 * linethick, 0.5 * linethick); - return Stencil (b, at); + +/* Bezier test1, test2, test3, test4; + test1 = back.extract(0., 1.0) ; + test2 = curve.extract (0., 1.0); + test3 = back.extract(0.0, 0.2); + test4 = curve.extract (0.0, 0.2); + return_value = bezier_sandwich (test1, test2, linethick); +// return_value.add_stencil ( +// bezier_sandwich (test3, test4, linethick)); + return return_value; */ + + if ((dash_details == SCM_UNDEFINED) || (dash_details == SCM_EOL)) + { /* solid slur */ + return_value = bezier_sandwich (back, curve, linethick); + } + else + { /* dashed or combination slur */ + int num_segments = scm_to_int (scm_length (dash_details)); + for (int i=0; iget_property ("dash-period"); - SCM f = me->get_property ("dash-fraction"); - if (scm_is_number (p) && scm_is_number (f)) - a = Lookup::dashed_slur (one, line_thick, robust_scm2double (p, 1.0), - robust_scm2double (f, 0)); - else + SCM dash_definition = me->get_property ("dash-definition"); +// SCM p = me->get_property ("dash-period"); +// SCM f = me->get_property ("dash-fraction"); +// SCM interval = me->get_property ("dash-interval"); +// if (scm_is_number (p) && scm_is_number (f)) +// a = Lookup::dashed_slur (one, line_thick, robust_scm2double (p, 1.0), +// robust_scm2double (f, 0)); +// else a = Lookup::slur (one, get_grob_direction (me) * base_thick, - line_thick); + line_thick, + dash_definition); +// robust_scm2double (p, 1.0), +// robust_scm2double (f, 0), +// robust_scm2double (interval, 1)); #if DEBUG_SLUR_SCORING SCM annotation = me->get_property ("annotation"); @@ -417,8 +423,7 @@ ADD_INTERFACE (Slur, "annotation " "avoid-slur " /* UGH. */ "control-points " - "dash-fraction " - "dash-period " + "dash-definition " "details " "direction " "eccentricity " diff --git a/lily/tie.cc b/lily/tie.cc index 5c64db6494..955076b663 100644 --- a/lily/tie.cc +++ b/lily/tie.cc @@ -265,17 +265,23 @@ Tie::print (SCM smob) Stencil a; - SCM p = me->get_property ("dash-period"); - SCM f = me->get_property ("dash-fraction"); - if (scm_is_number (p) && scm_is_number (f)) - a = Lookup::dashed_slur (b, - line_thick, - robust_scm2double (p, 1.0), - robust_scm2double (f, 0)); - else + SCM dash_definition = me->get_property ("dash-definition"); +// SCM p = me->get_property ("dash-period"); +// SCM f = me->get_property ("dash-fraction"); +// SCM interval = me->get_property ("dash-interval"); +// if (scm_is_number (p) && scm_is_number (f)) +// a = Lookup::dashed_slur (b, +// line_thick, +// robust_scm2double (p, 1.0), +// robust_scm2double (f, 0)); +// else a = Lookup::slur (b, get_grob_direction (me) * base_thick, - line_thick); + line_thick, + dash_definition); +// robust_scm2double (p, 1.0), +// robust_scm2double (f, 0), +// robust_scm2double (interval, 1.0)); #if DEBUG_TIE_SCORING SCM annotation = me->get_property ("annotation"); diff --git a/lily/vaticana-ligature.cc b/lily/vaticana-ligature.cc index 3a37fb5dce..861e4352a8 100644 --- a/lily/vaticana-ligature.cc +++ b/lily/vaticana-ligature.cc @@ -126,7 +126,7 @@ vaticana_brew_flexa (Grob *me, if (solid) { Stencil solid_head - = Lookup::bezier_sandwich (top_curve, bottom_curve); + = Lookup::bezier_sandwich (top_curve, bottom_curve, 0.0); stencil.add_stencil (solid_head); } else // outline @@ -134,13 +134,13 @@ vaticana_brew_flexa (Grob *me, Bezier inner_top_curve = top_curve; inner_top_curve.translate (Offset (0.0, -line_thickness)); Stencil top_edge - = Lookup::bezier_sandwich (top_curve, inner_top_curve); + = Lookup::bezier_sandwich (top_curve, inner_top_curve, 0.0); stencil.add_stencil (top_edge); Bezier inner_bottom_curve = bottom_curve; inner_bottom_curve.translate (Offset (0.0, +line_thickness)); Stencil bottom_edge - = Lookup::bezier_sandwich (bottom_curve, inner_bottom_curve); + = Lookup::bezier_sandwich (bottom_curve, inner_bottom_curve, 0.0); stencil.add_stencil (bottom_edge); /* diff --git a/ly/property-init.ly b/ly/property-init.ly index 2d50a6c601..184c317d76 100644 --- a/ly/property-init.ly +++ b/ly/property-init.ly @@ -11,16 +11,21 @@ slurDown = \override Slur #'direction = #DOWN slurNeutral = \revert Slur #'direction slurDashed = { - \override Slur #'dash-period = #0.75 - \override Slur #'dash-fraction = #0.4 + \override Slur #'dash-definition = #'((0 1 0.4 0.75)) } slurDotted = { - \override Slur #'dash-period = #0.75 - \override Slur #'dash-fraction = #0.1 + \override Slur #'dash-definition = #'((0 1 0.1 0.75)) +} +slurHalfDashed = { + \override Slur #'dash-definition = #'((0 0.5 0.4 0.75) + (0.5 1 1 1)) +} +slurHalfSolid = { + \override Slur #'dash-definition = #'((0 0.5 1 1) + (0.5 1 0.4 0.75)) } slurSolid = { - \revert Slur #'dash-period - \revert Slur #'dash-fraction + \revert Slur #'dash-definition } @@ -29,16 +34,21 @@ phrasingSlurDown = \override PhrasingSlur #'direction = #DOWN phrasingSlurNeutral = \revert PhrasingSlur #'direction phrasingSlurDashed = { - \override PhrasingSlur #'dash-period = #0.75 - \override PhrasingSlur #'dash-fraction = #0.4 + \override PhrasingSlur #'dash-definition = #'((0 1 0.4 0.75)) } phrasingSlurDotted = { - \override PhrasingSlur #'dash-period = #0.75 - \override PhrasingSlur #'dash-fraction = #0.1 + \override PhrasingSlur #'dash-definition = #'((0 1 0.1 0.75)) +} +phrasingSlurHalfDashed = { + \override PhrasingSlur #'dash-definition = #'((0 0.5 0.4 0.75) + (0.5 1 1 1)) +} +phrasingSlurHalfSolid = { + \override PhrasingSlur #'dash-definition = #'((0 0.5 1 1) + (0.5 1 0.4 0.75)) } phrasingSlurSolid = { - \revert PhrasingSlur #'dash-period - \revert PhrasingSlur #'dash-fraction + \revert PhrasingSlur #'dash-definition } mergeDifferentlyDottedOn = { diff --git a/python/convertrules.py b/python/convertrules.py index 0016b97970..2a70225232 100644 --- a/python/convertrules.py +++ b/python/convertrules.py @@ -2892,13 +2892,18 @@ longer in reversed order.\n")) @rule ((2, 13, 1), _ ("\\bar \".\" now produces a thick barline\n\ -ly:hairpin::after-line-breaking -> ly:spanner::kill-zero-spanned-time")) +ly:hairpin::after-line-breaking -> ly:spanner::kill-zero-spanned-time\n\ +Dash parameters for slurs and ties are now in dash-definition")) def conv(str): if re.search(r'\\bar\s*"."', str): stderr_write ("\n") stderr_write (NOT_SMART % _("\\bar \".\" now produces a thick barline.\n")) stderr_write (UPDATE_MANUALLY) str = re.sub (r'ly:hairpin::after-line-breaking', r'ly:spanner::kill-zero-spanned-time', str) + if (re.search(r'\'dash-fraction', str) or re.search(r'\'dash-period', str): + stderr_write ("\n") + stderr_write (NOT_SMART % _("Dash parameters for slurs and ties are now in \'dash-details.\n")) + stderr_write (UPDATE_MANUALLY) return str # Guidelines to write rules (please keep this at the end of this file) diff --git a/scm/define-grob-properties.scm b/scm/define-grob-properties.scm index 38e7d93d30..8d166a4d23 100644 --- a/scm/define-grob-properties.scm +++ b/scm/define-grob-properties.scm @@ -171,6 +171,9 @@ this should list the control points of a third-order B@'ezier curve.") ;; d ;; (damping ,number? "Amount of beam slope damping.") + (dash-definition ,pair? "List of @code{dash-elements} defining the +dash structure. Each @code{dash-element} has a starting t value, +an ending t-value, a @code{dash-fraction}, and a @code{dash-period}.") (dash-fraction ,number? "Size of the dashes, relative to @code{dash-period}. Should be between @code{0.0} (no line) and @code{1.0} (continuous line).") -- 2.39.2