2017-05-05 19:20 GMT+02:00 Lukas-Fabian Moser <[email protected]>:
> Is it possible to force Lilypond to use % as a repeat sign if the repeated
> section does not fill a whole measure?
>
> \relative c' {
> \repeat percent 2 { c4 d }
> \repeat percent 2 { c4 d e f }
> }
>
> Here, the first repeat is a slash /, the second a percent sign %. I'd like
> to have a % sign in both instances (because the manuscript I'm preparing in
> a scientific context uses it that way).
>
> Best
> Lukas
>
>
> Hi Lukas,
attached you'll find a customized rewrite of the RepeatSlash.stencil and a
png of it.
It's further tweakable as you like, several comments inline.
If you always want _one_ slash, it's possible as well, search for the
relevant comment.
Colors are done in layout only to distuingish between 'RepeatSlash' and
'PercentRepeat'
Ralph already pointed you to the NR, an example is included as well.
HTH,
Harm
\version "2.19.56"
#(define (my-repeat-slash-stencil grob)
(let* (
;; The final stencil is a parallelogram with the coordinates
;;
;; B C
;; --------
;; / /
;; / /
;; / /
;; / /
;; --------
;; A D
(slope-prop (ly:grob-property grob 'slope 1))
(slope (/ 1 slope-prop))
(thick (ly:grob-property grob 'thickness 0.48))
(dot-negative-kern (ly:grob-property grob 'dot-negative-kern 0.75))
(slash-negative-kern (ly:grob-property grob 'slash-negative-kern 0.85))
(layout (ly:grob-layout grob))
(staff-space (ly:output-def-lookup layout 'staff-space))
(line-thick (layout-line-thickness grob))
;; hard-coded as 2 staff-spaces
(height (* 2 staff-space))
;;;; The angles of the parallelogram
;; The angle of B-A-D
(small-angle (ly:angle (cons (* height slope) height)))
;; The angle of A-D-C
(large-angle (- 180 small-angle))
;;;; The rectangular heights
;(height-A_D-to-B_C height) ;; ofcourse :)
(height-A_B-to-D_C
(*
(sin (degrees->radians large-angle))
thick))
;; 'height-A_B-to-D_C' is the value of interest here, it needs to be
;; changed to match 'thick'
(new-thick
(* thick (/ thick height-A_B-to-D_C)))
(half
(/ new-thick 2))
;;;; The coordinates of the parallelogram
;(A (cons (- half) 0))
;(B (cons (+ (* height slope) (- half)) height))
;(C (cons (+ (* height slope) half) height))
;(D (cons half 0))
(x (* slope height))
(x-ext (ordered-cons 0 x))
(dot (ly:font-get-glyph (ly:grob-default-font grob) "dots.dot"))
(translated-dot-1
(ly:stencil-translate-axis dot (* 1.5 staff-space) Y))
(translated-dot-2
(ly:stencil-translate-axis dot (* 0.5 staff-space) Y))
(slash
(ly:make-stencil
`(polygon ',(list
(- half) 0
(+ (* height slope) (- half)) height
(+ (* height slope) half) height
half 0)
0 ;,blot
#t)
(cons (+ (- half) (car x-ext))
(+ half (cdr x-ext)))
(cons 0 height)))
(slash-count
(ly:prob-property (ly:grob-property grob 'cause) 'slash-count 1))
;; To get always one slash uncomment
;(slash-count 1)
(slashes
(make-list slash-count slash))
(slash-paddings
(make-list (1- slash-count) (- slash-negative-kern)))
(new-stencil
(stack-stencils-padding-list
;; axis
X
;; dir
LEFT ;RIGHT
;; paddings
`(,(- dot-negative-kern)
,@slash-paddings
,(- dot-negative-kern))
;; stencils
`(,translated-dot-1
,@slashes
,translated-dot-2))))
(ly:stencil-aligned-to new-stencil Y CENTER)
;; sometimes better spacing with (but sometimes not):
;(centered-stencil new-stencil)
))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXAMPLES
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Easier testing with an extern variable to set 'slope in 'RepeatSlash' and
%% 'PercentRepeat'
mySlope = 1
\layout {
\context {
\Voice
%% To distuingish between 'RepeatSlash' and 'PercentRepeat'
\override RepeatSlash.color = #red
\override PercentRepeat.color = #cyan
%% The new RepeatSlash.stencil can be customized by overrides for
%% slope, dot-negative-kern, slash-negative-kern
%%
%% Not sure why the dots do not respond for
%% \set Staff.fontSize = ...
%% Instead use
%% \override RepeatSlash.font-size = ...
\override RepeatSlash.slope = \mySlope
\override RepeatSlash.dot-negative-kern = 0.75
\override RepeatSlash.slash-negative-kern = 1.5
\override RepeatSlash.stencil = #my-repeat-slash-stencil
}
}
\score {
\relative c' {
\repeat percent 2 { c1 } %% NB grob is 'PercentRepeat'
\repeat percent 2 { cis2 }
\repeat percent 4 { d4 }
\repeat percent 4 { e8 e }
\repeat percent 4 { f16 f f f }
\repeat percent 4 { \repeat unfold 8 g32 }
\repeat percent 4 { \repeat unfold 16 g64 }
\repeat percent 2 { c4 d }
%\break
\repeat percent 4 { c128 d e f } r8 r4 r2
\override PercentRepeat.slope = \mySlope
\repeat percent 2 { c4 d e f }
}
\layout { ragged-right = ##t }
}
%% Also possible, from NR:
makePercent =
#(define-music-function (note) (ly:music?)
"Make a percent repeat the same length as NOTE."
(make-music 'PercentEvent
'length (ly:music-length note)))
\score {
\relative c' { c4 d \makePercent s2 }
\layout { ragged-right = ##t }
}
_______________________________________________
lilypond-user mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/lilypond-user