lilypond-user
[Top][All Lists]
Advanced

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

Re: triangle noteheads


From: Thomas Morley
Subject: Re: triangle noteheads
Date: Tue, 10 Jun 2014 13:51:08 +0200

2014-06-10 9:50 GMT+02:00 Pierre Perol-Schneider
<address@hidden>:
> 2014-06-09 22:42 GMT+02:00 Thomas Morley <address@hidden>:
>
>
>>
>> myHead =
>> #(define-music-function (parser location music)(ly:music?)
>>   (if (music-is-of-type? music 'event-chord)
>>       #{
>>         \override NoteHead.stencil = #(new-head "doThin")
>>         #music
>>       #}
>>       #{
>>         \tweak NoteHead.stencil #(new-head "doThin")
>>         #music
>>       #}))
>
>
> Hi Harm,
>
> I suspect you wanted to write : \once\override NoteHead.stencil = #(new-head
> "doThin")
> in myHead definition, didn't you ?

Yep, an oversight.

Here the next version.
Adding functionality for 'stem-attachment, extending general
functionality, making it more robust, adding comments:

\version "2.18.0"

#(define (new-head type)
;; Returns a new stencil for NoteHead, specified via `type'
;; `type' is supposed to be a string containing two things:
;; the first letter after the dot and the actual type from the note-heads
;; listed in NR A.8 The Feta font
;; example: "noteheads.d1faThin" should be transformed to "dfaThin" as value for
;; `type'
  (lambda (grob)
    (if (or (not (string? type)) (string-null? type))
        (ly:note-head::print grob)
        (let* (;; not every note-head has a glyph for whole or even longer notes
               ;; as a fall-back, use half note glyph
               (duration (max 1 (ly:grob-property grob 'duration-log)))
               (head (format #f "noteheads.~a~a~a"
                                  (string-take type 1)
                                  duration
                                  (string-drop type 1)))
               (stil (ly:font-get-glyph
                       (ly:grob-default-font grob)
                       head)))
          (if (ly:stencil-empty? stil)
              (begin
                (ly:warning "Unknown NoteHead: ~a, ignoring." head)
                (ly:note-head::print grob))
              stil)))))

%% adjusts stem-adjustment for note-heads of type doThin
%% other note-head-glyphs may need different settings
adjustStemAttachment =
  \once \override NoteHead.stem-attachment =
  #(lambda (grob)
    (let* ((stem (ly:grob-object grob 'stem))
           (stem-dir (ly:grob-property stem 'direction)))
      (cons 1 (if (>= stem-dir 0) -1 0.75))))

my-head =
  #(define-scheme-function (parser location strg) (string?)
     (define-music-function (parser location music)(ly:music?)
       (if (music-is-of-type? music 'event-chord)
           #{
             \once \override NoteHead.stencil = #(new-head strg)
             #music
           #}
           #{
             \tweak NoteHead.stencil #(new-head strg)
             #music
           #})))

%% See comment in (new-head type) how to specify the type
doThinHead = \my-head "ddoThin"
faThinHead = \my-head "dfaThin"

\relative c' {
  \adjustStemAttachment
  \doThinHead
  c'2

  \adjustStemAttachment
  \doThinHead
  c,2

  \adjustStemAttachment
  \doThinHead
  <c e g>4

  <
   c
   \doThinHead
   e
   \doThinHead
   \tweak duration-log #1
   g
  >4

  \adjustStemAttachment
  <
   \faThinHead
   c
   e
   g
  >4
}


Cheers,
   Harm



reply via email to

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