[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: drawing glissando line with (gliss) as text across line
From: |
Thomas Morley |
Subject: |
Re: drawing glissando line with (gliss) as text across line |
Date: |
Sun, 26 Jun 2016 15:12:18 +0200 |
2016-06-23 0:44 GMT+02:00 Thomas Morley <address@hidden>:
> 2016-06-22 23:48 GMT+02:00 Ryan Michael <address@hidden>:
>> Interesting. your example works perfectly in itself. But when I port it over
>> to my score I get the following error:
>>
>> Wrong type argument in position 1 (expecting Stencil): ()
>>
>> I believe it calls it on this line:
>>
>> (spanner-stencil-x-length (interval-length (ly:stencil-extent
>> spanner-stencil X)))
>>
>> Here is a gist of the score:
>> https://gist.github.com/ebbnormal/62a8893942a5e6f91735afdf77f2081a
>> I basically make a simple call to \glissandoTextOn as you do before I use
>> \glissando.
>>
>> Any ideas?
>
>
> If the glissando-line is _too_ short in tight layout-situations, it
> will not be printed. Thus no stencil, causing the error.
> Ensuring a reasonable minimum-length, cures the error, but the visual
> output is not convincing.
> Lemme see if I can come up with something better, but I'll likely have
> not no time to work on it before the weekend.
>
> Sorry,
> Harm
Hi Ryan,
below next try.
I'm not really convinced though, see REMARK
\version "2.19.44"
%% REMARK
%% The code below keeps the default glissando-stencil, while adding some
%% text to it. This means the text-stencil needs to be rotated to match the
%% glissando; also some reasonable padding between them needs to be found.
%% It turned out being a pretty difficult task to do so with reasonable
%% exactness and the current code is not always convincing, although usable.
%%
%% TODO
%% Test whether constructing a glissando+text-stencil from scratch causes better
%% results
#(define (radians->degree radians)
(/ (* radians 180) PI))
#(define (sign x)
(if (= x 0)
0
(if (< x 0) -1 1)))
#(define ((gliss-plus-text text) grob)
(if (not (ly:stencil? (ly:line-spanner::print grob)))
#f
(let* ((sys (ly:grob-system grob))
(layout (ly:grob-layout grob))
(line-thickness (ly:output-def-lookup layout 'line-thickness))
(blot-diameter (ly:output-def-lookup layout 'blot-diameter))
(thickness (ly:grob-property grob 'thickness))
(thick
(if (number? thickness)
(/ thickness 10)
line-thickness))
(spanner-stencil (ly:line-spanner::print grob))
(left-bound-info (ly:grob-property grob 'left-bound-info))
(y-left (assoc-get 'Y left-bound-info))
(x-left (assoc-get 'X left-bound-info))
(left-padding (assoc-get 'padding left-bound-info))
(right-bound-info (ly:grob-property grob 'right-bound-info))
(y-right (assoc-get 'Y right-bound-info))
(x-right (assoc-get 'X right-bound-info))
(right-padding (assoc-get 'padding right-bound-info))
(slant (sign (- y-right y-left)))
(spanner-stencil-x-length
(interval-length (ly:stencil-extent spanner-stencil X)))
(spanner-stencil-y-length
(interval-length (ly:stencil-extent spanner-stencil Y)))
;; TODO
;; fiddling around with PI and radians causes some inexactness
(alpha
(radians->degree
(- (/ PI 2)
(angle
(make-rectangular
(- spanner-stencil-y-length
(/ (+ thick blot-diameter) 2))
(- spanner-stencil-x-length
(/ (+ thick blot-diameter) 2)))))))
(spanner-center-X
(interval-center (ly:stencil-extent spanner-stencil X)))
(text-stencil (grob-interpret-markup grob text))
(rotated-text-stil
(ly:stencil-rotate text-stencil (* slant alpha) 0 0))
(text-center-X
(interval-center (ly:stencil-extent rotated-text-stil X)))
(translated-text-stencil
(ly:stencil-translate
rotated-text-stil
;; TODO
;; some correcting values found by try and error
;; how to calculate?
(cons
(+
(/ (+ left-padding right-padding) 2)
(- spanner-center-X text-center-X)
(if (negative? slant) 0.1 -0.6))
(+ (/ (+ y-right y-left) 2)
(if (negative? slant) 0.5 0.6))))))
(ly:stencil-add
spanner-stencil
translated-text-stencil))))
glissandoTextOn = {
\temporary \override Score.Glissando.springs-and-rods =
#ly:spanner::set-spacing-rods
\temporary \override Score.Glissando.minimum-length = 7
\temporary \override Score.Glissando #'stencil =
#(gliss-plus-text
;(markup #:with-color red #:box #:italic #:fontsize -5 "gliss.")
#{
\markup \italic \fontsize #-5 "gliss."
#})
}
glissandoTextOff = \revert Score.Glissando #'stencil
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXAMPLE
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\new Staff
\relative g'' {
\glissandoTextOn
%\override Glissando.thickness = 5
$@(map
(lambda (n)
#{
\override Glissando.extra-dy = #n
g4\glissando ges
%\bar "" \break
#})
(iota 14 -7 1))
$@(map
(lambda (n)
#{
\override Glissando.extra-dy = #n
g4..\glissando g16
%\bar "" \break
#})
(iota 14 -7 1))
\override Score.Glissando.breakable = ##t
\override Score.Glissando.after-line-breaking = ##t
\revert Glissando.extra-dy
\bar "" \break
g1\glissando
\break
<>^"Glissando at line-break is not really supported"
ges,
}
Anyway, hth,
Harm