lilypond-user
[Top][All Lists]
Advanced

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

Re: Overriding NoteHead stencil in a chord produces unwanted X offset


From: Mark Polesky
Subject: Re: Overriding NoteHead stencil in a chord produces unwanted X offset
Date: Tue, 7 Jul 2009 11:30:21 -0700 (PDT)

Neil Puttock wrote:
> Why not use an artificial harmonic instead?  They're
> automatically centred on semibreves...

Neil,

this is what I ended up doing; what do you think? As you probably
know, I'm a stickler for semantics, and strictly speaking, these
notes are not harmonics.

Also, why does (drop-right ...) work without having to add
#(use-modules (srfi srfi-1))?

- Mark


\version "2.13.0"

#(define (EventChord? music)
  (eq? (ly:music-property music 'name) 'EventChord))

#(define (centered-s2-head grob)
   (let* ((this-stil   (ly:note-head::print grob))
          (X-ext       (ly:stencil-extent this-stil 0))
          (Y-ext       (ly:stencil-extent this-stil 1))
          (font        (ly:grob-default-font grob))
          (s2-stil     (ly:font-get-glyph font "noteheads.s2"))
          (s2-expr     (ly:stencil-expr s2-stil))
          (s2-X-ext    (ly:stencil-extent s2-stil 0))
          (X-diff      (- (cdr X-ext) (cdr s2-X-ext)))
          (half-X-diff (/ X-diff 2))
          (new-X-ext   (cons (- (car s2-X-ext) half-X-diff)
                             (+ (cdr s2-X-ext) half-X-diff)))
          (new-stil    (ly:make-stencil s2-expr new-X-ext Y-ext)))
    new-stil))

multiphonics =
#(define-music-function (parser location music) (ly:music?)
  (music-map
   (lambda (x)
    (if (EventChord? x)
     (let* ((all-notes   (event-chord-notes x))
            (inner-notes (cdr (drop-right all-notes 1))))
       (map (lambda (note)
             (let ((tweaks (ly:music-property note 'tweaks)))
               (ly:music-set-property! note 'tweaks
                 (append tweaks `((stencil . ,centered-s2-head))))))
            inner-notes)
       x))
    x)
#{
  $music
#}))

% chords must be spelled from bottom to top in the ly file!
\relative  c' {
  % one at a time
  \multiphonics <c cis' g'>2

  % several in a row
  \multiphonics {
    <f fis' c'>2
    <c ais' cis g'>1
    <f dis' fis c'>1
  }
}


      

Attachment: centered-s2-head.png
Description: PNG image


reply via email to

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