Re: replace-stencil and overlay-stencil (was: Re: time signature 4 / \breve ?)
Thank you for this Aaron! Cheers, Pierre Le jeu. 17 oct. 2019 à 06:42, Aaron Hill a écrit : > On 2019-10-16 7:00 pm, Graham King wrote: > > \version "2.19.82" > > { > > \once \override Staff.TimeSignature #'stencil = > > #(lambda (grob) > > (grob-interpret-markup > >grob > >#{ \markup > > \override #'(baseline-skip . 1) > > \center-column { > > \musicglyph "four" > > \musicglyph "noteheads.sM1" } #})) > > \time 8/1 > > c'\breve c' c' c' > > } > > If you find yourself doing this type of stencil \override on a regular > basis, you could wrap it up in a more general-purpose helper similar to > the following: > > > \version "2.19.83" > > replace-stencil = #(define-music-function (grob text) (grob-list? > markup?) >(define (stencil grob) (grob-interpret-markup grob text)) >#{ \override $grob . stencil = $stencil #}) > > { >\once \replace-stencil Staff.TimeSignature > \markup \override #'(baseline-skip . 1) >\center-column { \musicglyph "four" \musicglyph "noteheads.sM1" } >\time 8/1 c'\breve c' c' c' > } > > > Putting together the function above got me thinking about and working on > a version that overlays \markup on an existing stencil instead of > replacing it: > > > \version "2.19.83" > > overlay-stencil = #(define-music-function (grob align text) >(grob-list? (number-pair? '(0 . 0)) markup?) >(define stencil (grob-transformer 'stencil (lambda (grob orig) > (let ((x (interval-index (ly:stencil-extent orig X) (car align))) >(y (interval-index (ly:stencil-extent orig Y) (cdr align))) >(new (grob-interpret-markup grob text))) >(ly:stencil-add orig (ly:stencil-translate new (cons x y))) >#{ \override $grob . stencil = $stencil #}) > > red-x = \markup \with-dimensions-from \null >\vcenter \center-align \with-color #red "X" > > { >\overlay-stencil Staff.Clef #'(-1 . 1) "Clef" >b'8 c'' >\temporary \overlay-stencil NoteHead \red-x >g' a' >\revert NoteHead.stencil >b'2 > } > > > Not sure how useful these would be in practice, but the resulting syntax > might be preferable for some folks. > > > -- Aaron Hill___ > lilypond-user mailing list > lilypond-user@gnu.org > https://lists.gnu.org/mailman/listinfo/lilypond-user > ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: time signature 4 / \breve ?
Graham, Thank you very much for both your solutions! Paul On Oct 16, 2019, at 7:00 PM, Graham King wrote: > Another way (slightly different result): > > \version "2.19.82" > > { > \once \override Staff.TimeSignature #'stencil = >#(lambda (grob) > (grob-interpret-markup > grob > #{ \markup > \override #'(baseline-skip . 1) > \center-column { >\musicglyph "four" >\musicglyph "noteheads.sM1" } #})) > \time 8/1 > c'\breve c' c' c' > } > > ___ > lilypond-user mailing list > lilypond-user@gnu.org > https://lists.gnu.org/mailman/listinfo/lilypond-user ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: time signature 4 / \breve ?
On Oct 16, 2019, at 6:14 PM, Ben wrote: Ben, Thank you very much! Paul > On 10/16/2019 8:59 PM, Paul Scott wrote: >> Is it possible to write a time signature 4 / \breve ? >> >> This occurs in Carmina Burana. >> >> Thank you for any ideas, >> >> Paul >> > Hi Paul, > > Does this help get you close to what you're looking for? > ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
replace-stencil and overlay-stencil (was: Re: time signature 4 / \breve ?)
On 2019-10-16 7:00 pm, Graham King wrote: \version "2.19.82" { \once \override Staff.TimeSignature #'stencil = #(lambda (grob) (grob-interpret-markup grob #{ \markup \override #'(baseline-skip . 1) \center-column { \musicglyph "four" \musicglyph "noteheads.sM1" } #})) \time 8/1 c'\breve c' c' c' } If you find yourself doing this type of stencil \override on a regular basis, you could wrap it up in a more general-purpose helper similar to the following: \version "2.19.83" replace-stencil = #(define-music-function (grob text) (grob-list? markup?) (define (stencil grob) (grob-interpret-markup grob text)) #{ \override $grob . stencil = $stencil #}) { \once \replace-stencil Staff.TimeSignature \markup \override #'(baseline-skip . 1) \center-column { \musicglyph "four" \musicglyph "noteheads.sM1" } \time 8/1 c'\breve c' c' c' } Putting together the function above got me thinking about and working on a version that overlays \markup on an existing stencil instead of replacing it: \version "2.19.83" overlay-stencil = #(define-music-function (grob align text) (grob-list? (number-pair? '(0 . 0)) markup?) (define stencil (grob-transformer 'stencil (lambda (grob orig) (let ((x (interval-index (ly:stencil-extent orig X) (car align))) (y (interval-index (ly:stencil-extent orig Y) (cdr align))) (new (grob-interpret-markup grob text))) (ly:stencil-add orig (ly:stencil-translate new (cons x y))) #{ \override $grob . stencil = $stencil #}) red-x = \markup \with-dimensions-from \null \vcenter \center-align \with-color #red "X" { \overlay-stencil Staff.Clef #'(-1 . 1) "Clef" b'8 c'' \temporary \overlay-stencil NoteHead \red-x g' a' \revert NoteHead.stencil b'2 } Not sure how useful these would be in practice, but the resulting syntax might be preferable for some folks. -- Aaron Hill___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: time signature 4 / \breve ?
Another way (slightly different result): \version "2.19.82" { \once \override Staff.TimeSignature #'stencil = #(lambda (grob) (grob-interpret-markup grob #{ \markup \override #'(baseline-skip . 1) \center-column { \musicglyph "four" \musicglyph "noteheads.sM1" } #})) \time 8/1 c'\breve c' c' c' } ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: time signature 4 / \breve ?
\version "2.19.82" tsMarkup = \markup { \override #'(baseline-skip . 0.5) \column { \number 4 \note #"breve" #0 } } { \override Staff.TimeSignature.style = #'default \override Staff.TimeSignature.stencil = #(lambda (grob) (grob-interpret-markup grob tsMarkup)) \time 8/1 c'\breve c' c' c' } HTH -- Graham ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user
Re: time signature 4 / \breve ?
On 10/16/2019 8:59 PM, Paul Scott wrote: Is it possible to write a time signature 4 / \breve ? This occurs in Carmina Burana. Thank you for any ideas, Paul Hi Paul, Does this help get you close to what you're looking for? (see attached) %%% \version "2.19.83" #(use-modules (ice-9 regex)) my-format-procedure = #(define-scheme-function (parser location args)(pair?) #{ \markup \concat { \number $(car args) \raise #-0.9 \huge "/" \small \override #'(style . default) \note $(cdr args) #DOWN } #}) %% alternative: %{ my-format-procedure = #(define-scheme-function (parser location args)(pair?) #{ \markup \override #'(baseline-skip . 0.5) \column { \number $(car args) \override #'(style . default) \note $(cdr args) #DOWN } #}) %} #(define ((format-time-sig-with-note frac trim?) grob) (let* ((num (if (pair? frac) (car frac) 4)) (den (if (pair? frac) (cdr frac) 4)) (args (cond ((string? den) (cons (number->string num) den)) ((and (integer? (/ num 3)) (integer? (/ den 2))) (cons (number->string (if trim? (/ num 3) num)) (if trim? (string-append (number->string (/ den 2)) ".") (number->string den ((and (integer? (/ num 2)) (integer? (/ den 2))) (cons (number->string (if trim? (/ num 2) num)) (number->string (if trim? (/ den 2) den (else (cons (number->string num) (number->string den)) (grob-interpret-markup grob #{ \my-format-procedure $args #}))) time = #(define-music-function (parser location trm vals)((boolean? #t) pair?) ;; c/p from define-makups.scm (define log2 (let ((divisor (log 2))) (lambda (z) (inexact->exact (/ (log z) divisor) ;; c/p from define-makups.scm (define (parse-simple-duration duration-string) "Parse the `duration-string', eg ''4..'' or ''breve.'', and return a (log dots) list." (let ((match (regexp-exec (make-regexp "(breve|longa|maxima|[0-9]+)(\\.*)") duration-string))) (if (and match (string=? duration-string (match:substring match 0))) (let ((len (match:substring match 1)) (dots (match:substring match 2))) (list (cond ((string=? len "breve") -1) ((string=? len "longa") -2) ((string=? len "maxima") -3) (else (log2 (string->number len (if dots (string-length dots) 0))) (ly:error (_ "not a valid duration string: ~a") duration-string (let* ((den (cdr vals)) (num (car vals))) (if (string? den) (let* ((parsed (parse-simple-duration den))) ;; TODO lazy bump ... (cond ((and (= -1 (car parsed)) (zero? (cadr parsed))) (set! den 1) (set! num (* 2 num))) ((and (= -1 (car parsed)) (= 1 (cadr parsed))) (set! den 1) (set! num (* 3 num))) ((and (= -2 (car parsed)) (zero? (cadr parsed))) (set! den 1) (set! num (* 4 num))) ((and (= -2 (car parsed)) (= 1 (cadr parsed))) (set! den 1) (set! num (* 6 num))) (else (ly:error "not smart enough to handle ~a" den) #{ \temporary \override Staff.TimeSignature.stencil = #(format-time-sig-with-note vals trm) $(make-music 'TimeSignatureMusic 'beat-structure '() 'denominator den 'numerator num) #})) \relative c' { \override Staff.TimeSignature.Y-offset = 5 \time 9/4 \repeat unfold 9 c4 \time 3/4 \repeat unfold 3 c4 \time ##f 3/4 \repeat unfold 3 c4 \time 7/4 \repeat unfold 7 c4 \time 12/2 \repeat unfold 4 c1. \time #'(3 . "breve.") \repeat unfold 3 c\breve. \time #'(3 . "longa") \repeat unfold 3 c\longa \time #'(4 . "longa.") \repeat unfold 4 c\longa. \time #(cons 4 "breve") \clef bass f\breve-> c-> d-> c-> \bar"|." } ___ lilypond-user mailing list lilypond-user@gnu.org https://lists.gnu.org/mailman/listinfo/lilypond-user