[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Dashed staff lines

From: Paul Morris
Subject: Dashed staff lines
Date: Thu, 20 Dec 2012 16:37:12 -0500

Hi all,  I was able to make some minor changes to the snippet Harm made for 
zig-zag staff lines[1] to create this snippet for dashed staff lines. 


You would use it like this:

    \dashedStaffSymbolLines #'(#f  #t #f)

or like this to customize the width of the dashes and the space between them:

    \dashedStaffSymbolLines #'(1 . 0.7) #'(#f  #t #f)

The 1 sets the width of the dashes, and the 0.7 sets the space between them.  
0.5 and 0.5 are defaults.


%%%% start snippet %%%%%%%%%%%%%%%%%%

\version "2.16.1"

dashedStaffSymbolLines =
#(define-music-function (parser location dash-space bool-list)
 ((number-pair? '(0.5 . 0.5)) list?)
Replaces specified lines of a StaffSymbol with dashed lines.

The lines to be changed should be given as a list containing booleans, with
the meaning:
  #f - no dashes, print a normal line
  #t - print a dashed line
The order of the bool-list corresponds with the order of the given list of
'line-positions or if not specified, with the default.
If the length of the bool-list and the 'line-positions doesn't match a warning
is printed.

The width of the dashes and the spacing between them can be altered by adding a 
as first argument while calling the function:
\\dashedStaffSymbolLines #'(1 . 1) #'(#f #t #f)
the first number of the pair is the width, the second the spacing
 \override Staff.StaffSymbol #'after-line-breaking =
   #(lambda (grob)
     (let* ((staff-stencil (ly:grob-property grob 'stencil))
            (staff-line-positions (ly:grob-property grob 'line-positions))
                (ly:stencil-extent staff-stencil X)))
            (staff-space (ly:staff-symbol-staff-space grob))
            (staff-line-thickness (ly:staff-symbol-line-thickness grob))
            ;; width of the dash
            (dash-width (car dash-space))
            ;; space between dashes
            (space-width (cdr dash-space))
            ;; Construct the first dash
            (sample-path `((moveto 0 0)
                           (lineto ,dash-width 0)
            ;; Make a stencil of the first dash
                  #:path staff-line-thickness sample-path)))
           ;; width of both dash and space
           (dash-space-width (+ dash-width space-width))
           ;; Or get width of dash from the stencil. Is this needed?
           ;;  (interval-length
           ;;    (ly:stencil-extent dash-stencil X)))
           ;;(dash-space-width (+ stil-width space-width))
            ;; Make a guess how many dashes are needed.
                  (/ staff-width
                     (- dash-space-width
            ;; Construct a stencil of dashes with the guessed count
                  (apply ly:stencil-add
                      (lambda (x)
                          (* (- dash-space-width staff-line-thickness) x)
                      (iota count-dashes)))
            ;; Get the the length of that dashed stencil
                (ly:stencil-extent dashed-stil  X)))
            ;; Construct a line-stencil to replace the staff-lines.
              (make-line-stencil staff-line-thickness 0 0 staff-width 0))
            ;; Calculate the factor to scale the dashed-stil to fit
            ;; the width of the original staff-symbol-stencil
              (/ staff-width (- stil-x-length staff-line-thickness)))
            ;; Construct the new staff-symbol
                    (lambda (x y)
                          (if (eq? y #f)
                              corr-factor 1))
                          (cons (/ staff-line-thickness 2)
                                (* (/ x 2) staff-space))))
                    staff-line-positions bool-list))))
      (if (= (length bool-list)(length staff-line-positions))
        (ly:grob-set-property! grob 'stencil new-stil)
          "length of bool-list doesn't fit the line-positions - ignoring"))))


\paper {
       indent = 10
       ragged-right = ##f
       line-width = 84.34

mus =
\relative c' {
       \repeat unfold 5 {
        d8 e f g  a b c16 d e f \break

 \new Staff \with {
           fontSize = #-6
           \override StaffSymbol #'staff-space = #(magstep -6)
           \override StaffSymbol #'thickness = #(magstep -6)

 \new Staff \with {
           fontSize = #-3
           \override StaffSymbol #'staff-space = #(magstep -3)
           \override StaffSymbol #'thickness = #(magstep -3)

 \new Staff

\layout {
       %% Construction-helper:
       % \context {
       %        \Score
       %        \override SystemStartBar #'transparent = ##t
       % }
       \context {
        %% Construction-helper:
        %\override BarLine #'transparent = ##t
        %\override BarLine #'layer = #-20
        %\override BarLine #'color = #green
        \override StaffSymbol #'line-positions = #'(-4  0  4)
        \dashedStaffSymbolLines #'(#f #t #f)
         %\dashedStaffSymbolLines #'(1 . 0.7) #'(#f #t #f)
         %\dashedStaffSymbolLines #'(0.05 . 0.3) #'(#f #t #f)

%%%% end snippet %%%%%%%%%%%%%%%%%%


reply via email to

[Prev in Thread] Current Thread [Next in Thread]