lilypond-user
[Top][All Lists]
Advanced

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

Re: zigzag staffline


From: Thomas Morley
Subject: Re: zigzag staffline
Date: Thu, 20 Dec 2012 02:14:40 +0100

2012/12/18 Gagi Petrovic <address@hidden>:
> Hi David, yes indeed. A zigzag or a trillspan-kind-of line would also
> suffice.
>
> Thank you for your tip, seems like it's time for me to dive more deeply into
> this matter. When i look at the code i understand it only roughly, i will
> need some time for this. So if anyone has any tips for reading material /
> code about creating StaffSymbols, please share them.
>
> Thanks and all the best, Gagi
>
>
> On 18 December 2012 14:40, David Nalesnik <address@hidden> wrote:
>>
>> Gagi,
>>
>>
>> > On 15 December 2012 10:39, Gagi Petrovic <address@hidden> wrote:
>> >>
>> >> Dear Ponders, i'm working on a composition where i'm in need of a
>> >> custom
>> >> 3-lined-staff with a zigzagged (like the glissando style, see
>> >> attachment)
>> >> middle line. Is it possible to make a small adjustement to the code
>> >> below,
>> >> or should i start doing some serious tweaking?
>>
>> So the middle line of the 3-line staff will actually be replaced with
>> a zigzag line?  I'm not aware of doing something like that with a
>> simple override.  I would imagine that you'd have to build up a new
>> StaffSymbol from the ground up.  There's a snippet in the LSR which
>> colors individual lines, and that might be something to look at and
>> adapt to your needs.  Unfortunately, I don't have time right now to
>> work on it.
>>
>> http://lsr.dsi.unimi.it/LSR/Item?id=700
>>
>> HTH,
>> David

Hi Gagi,

the code below constructs a new StaffSymbol with zigzag-lines at to be
specified positions.
It is not widely tested, please shout if sth goes wrong.
Several explaining comments are added.

Use it like
                \zigzagStaffSymbolLines #'(#f #t #f)
#f will _not_ print a zigzag, but a normal line.
#t will print the zigzag

Or use it like
                \zigzagStaffSymbolLines #'(1 . -0.1) #'(#f #t #f)
#'(1 . -0.1) will alter the width/heigth of the squiggles.

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

\version "2.16.1"

zigzagStaffSymbolLines =
#(define-music-function (parser location width-height bool-list)
  ((number-pair? '(0 . 0)) list?)
"
 Replaces specified lines of a StaffSymbol with zigzag-lines.

 The lines to be changed should be given as a list containing booleans, with
 the meaning:
   #f - no zigzag, print a normal line
   #t - print a zigzag-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 fit a warning
 is printed.

 The width and height of the zigzags could be altered by adding a pair
 as first argument while calling the function:
 \\zigzagStaffSymbolLines #'(1 . 1) #'(#f #t #f)
"
#{
  \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))
             (staff-width
               (interval-length
                 (ly:stencil-extent staff-stencil X)))
             (staff-space (ly:staff-symbol-staff-space grob))
             (staff-line-thickness (ly:staff-symbol-line-thickness grob))
      ;; Partly hardcoded!!
      ;; x-width and y-width should not(!) be scaled with different fontSize.
             ;; width of the first half-squiggle
             (x-part (+ (car width-height) (/ 2 3)))
             ;; height of the squiggle
             (y-part (+ (cdr width-height) (/ 1 3)))
             ;; Construct the first squiggle
             (sample-path `((moveto 0 0)
                            (lineto ,x-part ,y-part)
                            (lineto ,(* 2 x-part) 0)))
             ;; Make a stencil of the first squiggle
             (zigzag-stencil
               (grob-interpret-markup
                 grob
                 (markup
                   #:path staff-line-thickness sample-path)))
             (zigzag-width
               (interval-length
                 (ly:stencil-extent zigzag-stencil X)))
             ;; Make a guess how many squiggles are needed.
             (count-zigzags
               (inexact->exact
                 (round
                   (/ staff-width
                      (- zigzag-width
                         staff-line-thickness)))))
             ;; Construct a stencil of squiggles with the guessed count
             (squiggle-stil
                 (ly:stencil-aligned-to
                   (apply ly:stencil-add
                     (map
                       (lambda (x)
                         (ly:stencil-translate-axis
                           zigzag-stencil
                           (* (- zigzag-width staff-line-thickness) x)
                           X))
                       (iota count-zigzags)))
                   Y
                   CENTER))
             ;; Get the the length of that squiggle-stencil
             (stil-x-length
               (interval-length
                 (ly:stencil-extent squiggle-stil  X)))
             ;; Construct a line-stencil to replace the staff-lines.
             (line-stil
               (make-line-stencil staff-line-thickness 0 0 staff-width 0))
             ;; Calculate the factor to scale the squiggle-stil to fit
             ;; the width of the original staff-symbol-stencil
             (corr-factor
               (/ staff-width (- stil-x-length staff-line-thickness)))
             ;; Construct the new staff-symbol
             (new-stil
               (apply
                 ly:stencil-add
                   (map
                     (lambda (x y)
                       (ly:stencil-translate
                           (if (eq? y #f)
                             line-stil
                             (ly:stencil-scale
                               squiggle-stil
                               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)
         (ly:warning
           "length of bool-list doesn't fit the line-positions - ignoring"))))
#})

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% TEST
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

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

mus =
\relative c' {
        \repeat unfold 5 {
                \autoBeamOff
                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)
  }
  \mus

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

  \new Staff
  \mus
>>

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

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

HTH,
  Harm

Attachment: zig-zag-middle-line-03.preview.png
Description: PNG image


reply via email to

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