MonAmiPierrot wrote:
> Is there any way to have a half-dashed-half-solid Slur, i.e. a slur that
> begins dashed and at a certain point turns solid (or viceversa?)

Piero,

here's one solution. Personally, I don't think it
looks quite as good as it should, but maybe you're
not as picky as I am. Print it out with your highest
quality printer settings and let me know if it is 
good enough for you. Do you need PhrasingSlur done
this way too?

Happy to help.
- 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))
           (stil-x-ext (ly:stencil-extent this-stil 0))
           (stil-y-ext (ly:stencil-extent this-stil 1))
           
           ; kludge: extents don't completely cover the slur!
           (stil-x-ext (cons (- (car stil-x-ext) 1)
                             (+ (cdr stil-x-ext) 1)))
           (stil-y-ext (cons (- (car stil-y-ext) 1)
                             (+ (cdr stil-y-ext) 1)))
                             
           (stil-w (- (cdr stil-x-ext) (car stil-x-ext)))
           (stil-h (- (cdr stil-y-ext) (car stil-y-ext)))
                       
           (box-w (if $start-dashed?
                      (* stil-w switch-point)
                      (* stil-w (- 1 switch-point))))
           (box-x0 (if $start-dashed?
                       (car stil-x-ext)
                       (- (cdr stil-x-ext)
                          box-w)))
           (box-y0 (car stil-y-ext))
           (box-h stil-h))
           
      ;; 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:
       (ly:make-stencil
        (list 'embedded-ps
         (ly:format
          (string-append "gsave\n"
                         "currentpoint translate\n"
                         "1 setgray\n"
                         "~a ~a ~a ~a rectfill\n"
                         "grestore\n")
          box-x0
          box-y0
          box-w
          box-h))
        stil-x-ext
        stil-y-ext)
        
       ;; 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)
}
%}

<<attachment: half-and-half-slur.png>>

_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
http://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to