Jump to content

Generate special note head shapes: Difference between revisions

From LilyPond wiki
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
When a note head with a special shape cannot easily be generated with graphic markup, PostScript code can be used to generate the shape. This example shows how a parallelogram-shaped note head is generated.
When a note head with a special shape cannot easily be generated with graphic markup, a drawing specification for <code>ly:make-stencil</code> can be used to generate the shape. This example gives an example for a parallelogram-shaped note head.
 
Unfortunately, the available commands in a drawing specification are [https://gitlab.com/lilypond/lilypond/-/issues/6874 currently not documented]; in any case, the used <code>path</code> sub-command has the following signature, quite similar to the <code>make-path-stencil</code> Scheme function.
 
(path <var>thickness</var> <var>command-list</var> <var>line-cap-style</var> <var>line-join-style</var> <var>fill</var>)
 
The commands in <var>command-list</var> resemble PostScript drawing commands but with arguments after the command name.


<lilypond version="2.24">
<lilypond version="2.24">
%% Updaters remark:
%% For unkown reasons this snippet returns a gs-error, but only, if compiled
%% with multiple others like: lilypond *.ly
%% Thus changing to a path-stencil.
%% TODO description needs to get adjusted  --harm
   
parallelogram =
parallelogram =
   #(ly:make-stencil
   #(ly:make-stencil
     '(path 0.1
     '(path 0.1
        (rmoveto 0 0.25
          (rmoveto 0 0.25
        lineto 1.3125 0.75  
            lineto 1.2 0.75
        lineto 1.3125 -0.25  
            lineto 1.2 -0.25
        lineto 0 -0.75)
            lineto 0 -0.75
        round
            lineto 0 0.25)
        round
          round
        #t)
          round
     (cons 0 1.3125)
          #t)
     (cons -0.05 1.25)
     (cons -.75 .75))
     (cons -.75 .75))


Line 32: Line 33:
</lilypond>
</lilypond>


[[Category:Editorial annotations]]
[[Category:Scheme]]
[[Category:Tweaks and overrides]]
[[Category:Tweaks and overrides]]
[[Category:Scheme]]
[[Category:Editorial annotations]]
[[Category:Included in the official documentation]]
[[Category:Included in the official documentation]]
[[Category:Really cool]][[Category:Snippet]]
[[Category:Snippet]]

Latest revision as of 14:05, 12 December 2025

When a note head with a special shape cannot easily be generated with graphic markup, a drawing specification for ly:make-stencil can be used to generate the shape. This example gives an example for a parallelogram-shaped note head.

Unfortunately, the available commands in a drawing specification are currently not documented; in any case, the used path sub-command has the following signature, quite similar to the make-path-stencil Scheme function.

(path thickness command-list line-cap-style line-join-style fill)

The commands in command-list resemble PostScript drawing commands but with arguments after the command name.

\version "2.24"

parallelogram =
  #(ly:make-stencil
    '(path 0.1
           (rmoveto 0 0.25
            lineto 1.2 0.75
            lineto 1.2 -0.25
            lineto 0 -0.75
            lineto 0 0.25)
           round
           round
           #t)
    (cons -0.05 1.25)
    (cons -.75 .75))

myNoteHeads = \override NoteHead.stencil = \parallelogram
normalNoteHeads = \revert NoteHead.stencil

\relative c'' {
  \myNoteHeads
  g4 d'
  \normalNoteHeads
  <f, \tweak stencil \parallelogram b e>4 d
}