Mark Polesky wrote:
> here's one solution. 

same function with leaner code.
Got rid of about 15 lines.

- Mark



      
\version "2.13.0"

halfAndHalfSlur =
#(define-music-function
   (parser location switch-point start-dashed?)
   (number? boolean?)
#{
  % set 'layer to -2 if you're also using my \hideCurvesFrom macro:
  \override Slur #'layer = #-1
  \override Slur #'stencil =
  #(lambda (grob)
    (let* ((grob-copy grob)
           (switch-point $switch-point)
           (this-stil (ly:slur::print grob))
           (orig-stil-x-ext (ly:stencil-extent this-stil 0))
           (orig-stil-y-ext (ly:stencil-extent this-stil 1))

           ; kludge: extents don't completely cover the slur.
           (stil-x-ext (cons (- (car orig-stil-x-ext) 0.25)
                             (+ (cdr orig-stil-x-ext) 0.25)))
           (stil-y-ext (cons (- (car orig-stil-y-ext) 0.25)
                             (+ (cdr orig-stil-y-ext) 0.25)))

           (orig-stil-w (- (cdr orig-stil-x-ext) (car orig-stil-x-ext)))
           (box-x-ext (if $start-dashed?
                          (cons (car stil-x-ext)
                                (+ (car orig-stil-x-ext)
                                   (* orig-stil-w switch-point)))
                          (cons (- (cdr orig-stil-x-ext)
                                   (* orig-stil-w (- 1 switch-point)))
                                (cdr stil-x-ext)))))

      ;; values come from slurDashed definition in property-init.ly:
      (ly:grob-set-property! grob-copy 'dash-period 0.75)
      (ly:grob-set-property! grob-copy 'dash-fraction 0.4)

      (ly:stencil-add

       ;; first the solid slur:
       this-stil

       ;; then the white box covering part of the solid slur:
       (stencil-with-color
        (ly:round-filled-box box-x-ext stil-y-ext 0.0)
        white)

       ;; then the dashed slur:
       (ly:slur::print grob-copy)
       )))
#})

slurDashedSolid = {
  \halfAndHalfSlur #0.5 ##t
}

slurSolidDashed = {
  \halfAndHalfSlur #0.5 ##f
}

slurSolid = {
  % commenting this line out keeps slurs in a lower layer:
  \revert Slur #'layer
  \revert Slur #'stencil
  \slurSolid
}

slurDashed = {
  % commenting this line out keeps slurs in a lower layer:
  \revert Slur #'layer
  \revert Slur #'stencil
  \slurDashed
}

slurDotted = {
  % commenting this line out keeps slurs in a lower layer:
  \revert Slur #'layer
  \revert Slur #'stencil
  \slurDashed
}


%%%%%% EXAMPLE %%%%%%

%{
\relative {
  \slurDashedSolid f4( d e f)
  \slurSolidDashed f4( d e f)
  \slurSolid f4( d e f)
}
%}
_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
http://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to