lilypond-user
[Top][All Lists]
Advanced

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

Changing staff size with custom note head stencils


From: Paul Morris
Subject: Changing staff size with custom note head stencils
Date: Wed, 31 Oct 2012 15:27:23 -0400

Hello,  I'm trying to increase the overall size of a given staff, as described in the docs[1] using:

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

    \override NoteHead #'before-line-breaking = \TwinNoteNoteHeads
  }

But I'm also using custom note head shapes, with an override that references a scheme function  that alters the NoteHead stencil and stem-attachment properties.  

That is preventing the resizing of the note heads.  They just stay the same as the rest of the staff, stems, clefs, etc, become larger.  (This may be related to using "before-line-breaking", but I need to use that to get the horizontal spacing to work properly.[2] )

I have tried various things (including putting the size adjustments in the \layout block [3]) and the only thing I've found that will change the size of the noteheads is using set-global-staff-size [3].  But that also increases the size of all the text (lyrics, chord names, titles, etc), when I just want to increase the size of the staff, not the text.  

Anyone know how to get this to work?  Any advice or pointers would be greatly appreciated.  I realize that this is non-standard stuff, but LilyPond has been amazing at handling whatever I've thrown at it, making it possible to experiment.  A simplified version of my code is below.

Thanks!
-Paul

[2] http://lists.gnu.org/archive/html/lilypond-user/2012-04/msg00145.html
[3] http://lilypond.org/doc/v2.12/Documentation/user/lilypond/Setting-the-staff-size


\version "2.16.0"  

%%%% Begin TwinNote scripts 

%%%% Customize note head stencils based on pitch

upTriangle =
#(ly:make-stencil
    (list 'embedded-ps
    "gsave
      currentpoint translate
      newpath
      -.1875 -.5 moveto
      .65625 .5 lineto
      1.5 -.5 lineto
      closepath
      fill
      grestore" )
    (cons -.1875 1.5)
    (cons -.5 .5)
)

downTriangle =
#(ly:make-stencil
    (list 'embedded-ps
    "gsave
      currentpoint translate

      newpath
      .08 .34 moveto
      .65625 -.4 lineto
      1.2325 .34 lineto
      closepath
      0.12 setlinewidth
      stroke     

      newpath
      -.0775 .43 moveto
      .65625 -.43 lineto
      1.39 .43 lineto
      closepath
      0.1 setlinewidth
      stroke     
     
      newpath
      -.1675 .48 moveto
      .65625 -.48 lineto
      1.48 .48 lineto
      closepath
      0.04 setlinewidth
      stroke

      grestore" )
    (cons -.1875 1.5)
    (cons -.5 .5)
)

%Based on the semitone, assign correct note head
#(define (semitone-to-stencil semitone)
        (if (= (remainder semitone 2) 0) downTriangle upTriangle)
)

%Get the pitch in semitones from the note head grob
#(define (stencil-notehead grob)
   (semitone-to-stencil
     (ly:pitch-semitones (ly:event-property (event-cause grob) 'pitch))
   )
)


%%%% Attach stems to note heads correctly

%Stem attachment values as variables
upTriUpStem = #'(1 . -1)
upTridownStem = #'(1 . .9)
downTriUpStem = #'(1 . .9)
downTriDownStem = #'(1 . -1)

%Based on pitch (odd or even), is the note head an up or down triangle, 
%Then based on stem direction, assign stem attachment values
#(define (pitch-to-stem pitch stemdir)
(if (= (remainder (absolute-value (ly:pitch-semitones pitch) ) 2) 1) 
(if (= UP stemdir) upTriUpStem upTridownStem) (if (= DOWN stemdir) downTriDownStem downTriUpStem)
)
)

%Get absolute value
#(define (absolute-value x) (if (> x 0) x (- 0 x)))

%Get the stem from notehead grob
#(define (notehead-get-notecolumn nhgrob)
   (ly:grob-parent nhgrob X))

#(define (notehead-get-stem nhgrob)
   (let ((notecolumn (notehead-get-notecolumn nhgrob)))
     (ly:grob-object notecolumn 'stem)))

%Get the pitch and stem direction from the grob
#(define (stem-adjuster nhgrob)
(pitch-to-stem
   (ly:event-property (event-cause nhgrob) 'pitch) 
(ly:grob-property (notehead-get-stem nhgrob) 'direction) ))


%%%% Begin notehead shape and stem attachment tweaks

TwinNoteNoteHeads = 
#(lambda (grob) 
      (set! (ly:grob-property grob 'stencil) (stencil-notehead grob))
      (set! (ly:grob-property grob 'stem-attachment) (stem-adjuster grob))
)

%%%% Place pitches on the staff

TwinNotePitchLayout = 
#(lambda (p) (floor (/ (+ (ly:pitch-semitones p) 1) 2)))

%%%%% End TwinNote scripts


melody = \relative c' {
  a4 b c d e f g a
}

\score {
  <<

    \new Staff = "usual size staff"  \with { 
        \override NoteHead #'before-line-breaking = \TwinNoteNoteHeads    
        staffLineLayoutFunction = \TwinNotePitchLayout
      }
      {  \melody }

    \new Staff = "larger size staff"  \with { 
        \override NoteHead #'before-line-breaking = \TwinNoteNoteHeads    
        staffLineLayoutFunction = \TwinNotePitchLayout

        fontSize = #3
        \override StaffSymbol #'staff-space = #(magstep 3)
      }
      {  \melody }

  >>
  \layout { }
}


reply via email to

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