Hi Neil, thanks a lot for your further very helpful ideas. Attached is a patch for a new approach which implements your suggestion to define a new property. It's called 'shifted-towards-stem and can take any real value, where 0.0 means to keep the default position (centered on the note-head) and 1.0 means centered on the stem (intermediate values are of course possible). I also added a check whether the grob in question actually possesses a stem, so it works well for skips, too (perhaps there is a more Lilypond-ish way of doing things but as far as I could test, it works).
Since Reinhold said it would be best to make the shifting optional and off by default, I didn't set any properties in script.scm. But the shifting can of course be overridden in the .ly file itself (see attached example). My only question is, how can I set the property for individual script types instead of all scripts at once, i.e. what would I need to write instead of \override Script #'shifted-towards-stem = #'1.0 if I wanted to enable shifting only for staccato marks, say? Max P.S.: In case this gets approved in one form or the other, what would be necessary to document it properly? Add a LSR example, a regression test, something else? Anything I need to keep in mind when writing these?
From 383b8f1bf05af263fb8049bc41b1895e59de3a2d Mon Sep 17 00:00:00 2001 From: Maximilian Albert <[EMAIL PROTECTED](none)> Date: Sun, 7 Dec 2008 15:09:21 +0100 Subject: [PATCH] New grob-property 'shifted-towards-stem (allows scripts to be placed anywhere between the note head and the stem) --- lily/script-interface.cc | 1 + scm/define-grob-properties.scm | 4 ++++ scm/output-lib.scm | 20 +++++++++++++++++++- 3 files changed, 24 insertions(+), 1 deletions(-) diff --git a/lily/script-interface.cc b/lily/script-interface.cc index a525500..8195ccc 100644 --- a/lily/script-interface.cc +++ b/lily/script-interface.cc @@ -129,6 +129,7 @@ ADD_INTERFACE (Script_interface, "positioning-done " "script-priority " "script-stencil " + "shifted-towards-stem " "slur " "slur-padding " ); diff --git a/scm/define-grob-properties.scm b/scm/define-grob-properties.scm index b697af3..98dde0e 100644 --- a/scm/define-grob-properties.scm +++ b/scm/define-grob-properties.scm @@ -551,6 +551,10 @@ value @code{-1} means left aligned, @[EMAIL PROTECTED], and values may also be specified.") (self-alignment-Y ,number? "Like @code{self-alignment-X} but for the [EMAIL PROTECTED]") + (shifted-towards-stem ,number? "Amount by which scripts are shifted +towards the stem if their direction coincides with the stem direction. [EMAIL PROTECTED] means keep the default position (centered on the note head), [EMAIL PROTECTED] means centered on the stem. Interpolated values are possible.") (shorten-pair ,number-pair? "The lengths to shorten a text-spanner on both sides, for example a pedal bracket. Positive values shorten the text-spanner, while negative values lengthen it.") diff --git a/scm/output-lib.scm b/scm/output-lib.scm index b93edda..34768e5 100644 --- a/scm/output-lib.scm +++ b/scm/output-lib.scm @@ -669,4 +669,22 @@ centered, X==1 is at the right, X == -1 is at the left." (define-public (script-interface::calc-x-offset grob) (ly:grob-property grob 'positioning-done) - (ly:self-alignment-interface::centered-on-x-parent grob)) + (let* ((shift (ly:grob-property grob 'shifted-towards-stem)) + (note-head-pos (ly:self-alignment-interface::centered-on-x-parent grob)) + (note-head-grob (ly:grob-parent grob X)) + (stem-grob (ly:grob-object note-head-grob 'stem))) + (+ note-head-pos + ;; If the property 'shifted-towards-stem is defined and the script has the + ;; same direction as the stem, move the script accordingly. Since scripts can + ;; also be over skips, we need to check whether the grob has a stem at all. + (if (or (null? shift) + (null? stem-grob)) + 0.0 + (let* ((dir1 (ly:grob-property grob 'direction)) + (dir2 (ly:grob-property stem-grob 'direction)) + (common-refp (ly:grob-common-refpoint grob stem-grob X)) + (stem-pos (ly:grob-relative-coordinate stem-grob common-refp X))) + (if (equal? dir1 dir2) + (* shift (- stem-pos + note-head-pos)) + 0.0)))))) -- 1.5.4.3
shifted_scripts.ly
Description: Binary data
<<attachment: shifted_scripts.png>>
_______________________________________________ lilypond-devel mailing list lilypond-devel@gnu.org http://lists.gnu.org/mailman/listinfo/lilypond-devel