[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: feature requests: scalable \shape values; (stem) for \shapeII
From: |
Thomas Morley |
Subject: |
Re: feature requests: scalable \shape values; (stem) for \shapeII |
Date: |
Sun, 11 Oct 2020 10:04:15 +0200 |
Am Mi., 7. Okt. 2020 um 10:35 Uhr schrieb Martín Rincón Botero
<martinrinconbotero@gmail.com>:
>
> Now that we’ve been talking about \shape and \shapeII, I would like to ask if
> it’s possible that values put for \shape(II) could scale according to staff
> size. Whenever I have a smaller staff, whatever values work for a 20 points
> staff are too much for smaller staves (either with a smaller font size or
> with \magnify). It would be great, from a user perspective, that a (0 . 1)
> value would produce a similar/proportional result no matter the size of the
> staff, instead of being always in a different “scale” every time you have
> different staff sizes (so that you have to put smaller values for smaller
> staves). That would also be useful if you decide later to increase or
> decrease the font size used.
Hi Martín,
\shape adds your settings to the calculated control-points of the curve.
Though, those control-points are calculated differently depending on
staff-space.
Look at the example below, you will notice the default control-points
are always different.
In the attached image I let print the second and third control-point.
\layout {
\context {
\Voice
\override NoteHead.stencil = #point-stencil
}
}
mus = { b'1_~ b'1 }
\new Staff \with { \magnifyStaff #4 } \mus
\new Staff \with { \magnifyStaff #1 } \mus
\new Staff \with { \magnifyStaff #1/4 } \mus
This means \shape always gets different control-points to work with,
thus the result will never be consistent even for scaled
offset-values.
Nevertheless, it's not too hard to code a shape-version, which will
scale it's offset-values according to current staff-space:
\version "2.20.0"
shape-h =
#(define-music-function (offsets item)
(list? key-list-or-music?)
(_i "Offset control-points of @var{item} by @var{offsets}. The
argument is a list of number pairs or list of such lists. Each
element of a pair represents an offset to one of the coordinates of a
control-point. If @var{item} is a string, the result is
@code{\\once\\override} for the specified grob type. If @var{item} is
a music expression, the result is the same music expression with an
appropriate tweak applied.")
(define (shape-curve grob coords)
(let* ((orig (ly:grob-original grob))
(siblings (if (ly:spanner? grob)
(ly:spanner-broken-into orig) '()))
(total-found (length siblings))
(staff-space (ly:staff-symbol-staff-space grob))
(offsets
(map
(lambda (offset)
(if (number-pair? offset)
(cons (car offset) (* (cdr offset) staff-space))
offset))
offsets)))
(define (offset-control-points offsets)
(if (null? offsets)
coords
(map coord-translate coords offsets)))
(define (helper sibs offs)
(if (pair? offs)
(if (eq? (car sibs) grob)
(offset-control-points (car offs))
(helper (cdr sibs) (cdr offs)))
coords))
;; we work with lists of lists
(if (or (null? offsets)
(not (list? (car offsets))))
(set! offsets (list offsets)))
(if (>= total-found 2)
(helper siblings offsets)
(offset-control-points (car offsets)))))
(once (propertyTweak 'control-points
(grob-transformer 'control-points shape-curve)
item)))
\layout {
\context {
\Voice
\override NoteHead.stencil = #point-stencil
}
}
mus = { b'1 \shape-h #'((0 . 1) (0 . 0) (0 . 0) (0 . 0)) _~ b'1 }
\new Staff \with { \magnifyStaff #4 } \mus
\new Staff \with { \magnifyStaff #1 } \mus
\new Staff \with { \magnifyStaff #1/4 } \mus
See second image.
Cheers,
Harm
atest-105.cropped.pdf
Description: Adobe PDF document
atest-105-scaled-shape.cropped.pdf
Description: Adobe PDF document