Eigenes Artikulationszeichen entwerfen

Aus Lilypond Wiki
Wechseln zu: Navigation, Suche

Aus einem Beitrag aus dem deutschen Lilypond-Forum, erstellt am 5.8.2016

Fragestellung

Wunsch: ein eigenes Artikulationszeichen definieren, Behelfslösung:


\version "2.19.54"

#(define-markup-command (softnote layout props) ()
   (interpret-markup layout props
     (markup #:stencil
       (ly:stencil-translate-axis
        (ly:stencil-add
         (make-circle-stencil 0.6 0.2 #f)
         (ly:stencil-in-color
          (make-filled-box-stencil '(-1 . 1) '(0 . 1.3))
          1 1 1 ))
        0.7 X))))

soft = \markup \softnote

{ c'' -\soft }

Lösung

Einfache Version

\version "2.19.54"

soft =
-\tweak stencil
#(lambda (grob)
   (grob-interpret-markup grob
     #{
       \markup
       \with-dimensions #'(-0.7 . 0.7) #'(-0.7 . 0)
       \postscript
       #"0.15 setlinewidth -0.7 0 moveto 0 0 0.7 180 0 arc stroke"
     #}))
\fermata

{ c''-\soft }

Berücksichtigung die Position des Zeichens (oberhalb oder unterhalb der Note)

Code

\version "2.19.54"

soft =
-\tweak stencil
#(lambda (grob)
   (grob-interpret-markup grob
     (if (eq? UP (ly:grob-property grob 'direction))
         #{
           \markup
           \with-dimensions #'(-0.7 . 0.7) #'(-0.7 . 0)
           \postscript
           #"0.15 setlinewidth -0.7 0 moveto 0 0 0.7 180 0 arc stroke"
         #}
         #{
           \markup
           \with-dimensions #'(-0.7 . 0.7) #'(0 . 0.7)
           \postscript
           #"0.15 setlinewidth 0.7 0 moveto 0 0 0.7 0 180 arc stroke"
         #})))
\fermata

{ c''\soft c''_\soft c''^\soft }

Output

LilyWiki Artikulation

Code der auch in Drums-Context funktioniert

#(define new-stil 
(lambda (grob)
  (let* ((sz (ly:grob-property grob 'font-size 0.0))
         (mult (magstep sz))
         (dir (ly:grob-property grob 'direction))
         (thick 0.15)
         (radius 0.7)
         (scaled-radius (* mult radius))
         (ps-command-string
           (format #f 
             " 
             0 ~a translate
             ~a setlinewidth 
             ~a 0 moveto 
             0 0 ~a 180 0 ~a
             stroke
             "
             ;mult
             (* thick dir)
             thick
             (- scaled-radius)
             scaled-radius
             (if (negative? dir) "arcn" "arc"))))
         
    (ly:make-stencil
      (list 'embedded-ps
            (format #f
              "
              gsave currentpoint translate
              ~a
              grestore
              "
             ps-command-string))
      (cons (- scaled-radius) scaled-radius)
      (cons 
        (if (negative? dir) 0 (- scaled-radius)) 
        (if (negative? dir) scaled-radius 0))))))

soft =
-\tweak stencil #new-stil
%% maybe add:
%-\tweak staff-padding #'()
\fermata

m = { c''\soft c''_\soft c''^\soft c''-> }

<<
  \new Staff \with { fontSize = -6 } \m
  \new Staff \with { fontSize = 0 } \m
  \new Staff \with { fontSize = 6 } \m
>>

\drums { 
  %% override takes no effect,because there _is_ no Script-grob!
  \override Script.stencil = #new-stil 
  bd8 bd  bd2. hh1 hh2 hh4 hh8 hh cb 
}

Ausführlicher Code mit script-stencils

Da die neuen script-stencils, die nicht auf feta-glyphs beruhen, nicht richtungsabhängig gemacht werden können, musste arc und uarc definiert werden. Da dass Skalieren nicht funktioniert, noch die Hilfsfunktion scaleCustomScripts zur Anwendung.


\version "2.19.54"

%% Working on a copy of `default-script-alist´ should warrant no bleed-over.
#(define my-script-alist (list-copy default-script-alist))

%% Some custom stencils
    
#(define ellipse-stil
  (ly:stencil-in-color
    (make-partial-ellipse-stencil 1 0.3 2 2 0.13 #t #f)
    1 0 0))
    
%% Code taken from 
%% http://www.lilypondforum.de/index.php?topic=1279.msg7040#msg7040
%% by Torsten and modified
#(define (n-agon-stil nmbr)
  (let* ((th 0.1)
         ;; Value @code{6} returns a hexagon.
         (alpha-step (/ (* 2 PI) nmbr)) 
         (alpha-start (/ alpha-step 2))
         (radius 0.7)
         (polypoints 
           (let loop ((alpha alpha-start))
             (if (> alpha (* 2 PI))
                 '()
                 (cons (* (abs radius) (sin alpha)) 
                       (cons (- 0 (* (abs radius) (cos alpha)))
                             (loop (+ alpha alpha-step))))))))
  (ly:make-stencil 
    `(polygon ',polypoints  ,th #f) 
    (cons (- radius) radius) 
    (cons (- radius) radius))))


#(define (bezier-arc-stil direction)
  (make-connected-path-stencil 
    `((0.15 ,direction  1.05 ,direction  1.2 0)) 0.2 1 1 #f #f))
  
%% Alists with the name of the new articulation and its settings.
#(define varsegno-settings
  `("varsegno"   
    . (
       (script-stencil . (feta . ("varsegno" . "varsegno")))
       (padding . 0.20)
       (avoid-slur . outside)
       (direction . ,UP))))
       
#(define ellipse-settings
  `("ellipse"   
    . (
       (avoid-slur . around)
       (padding . 0.20)
       (side-relative-direction . ,DOWN)
       (stencil . ,ellipse-stil))))
	      
#(define hexagon-settings
  `("hexagon"   
    . (
       (avoid-slur . around)
       (padding . 0.20)
       (stencil . ,(n-agon-stil 6))
       (side-relative-direction . ,DOWN))))
	      
#(define arc-settings
  `("arc"   
    . (
       (avoid-slur . around)
       (padding . 0.20)
       (stencil . ,(bezier-arc-stil -1))
       (side-relative-direction . ,DOWN))))
       
#(define up-arc-settings
  `("uarc"   
    . (
       (avoid-slur . around)
       (padding . 0.20)
       (stencil . ,(bezier-arc-stil 1))
       (side-relative-direction . ,DOWN))))
	      
%% A macro used to put the lists from above in `my-script-alist´
#(define-macro (set-my-script-alist! ls-1 ls-2)
"Creates a new key-value-pair, taken from ls-2, in ls-1"
 `(set! ,ls-1 
    (if (and (pair? ,ls-2) (pair? (cadr ,ls-2)))
        (assoc-set! ,ls-1 (car ,ls-2) (cdr ,ls-2))
        (begin
          (ly:warning (_"Unsuitable list\n\t~a \n\tdetected, ignoring. ") ,ls-2)
          ,ls-1))))

%% put the new articulations into `my-script-alist'
#(for-each
  (lambda (l)
     (set-my-script-alist! my-script-alist l))
  (list 
    varsegno-settings
    ellipse-settings 
    hexagon-settings 
    arc-settings 
    up-arc-settings))
    
%% `script-stencil' used for script-settings in script.scm looks for glyphs in
%% a font (feta), only explicit script-glyphs are accepted. The glyphs found are
%% scaled(?) to fit the current `fontSize'.  This seems to make it impossible to
%% put in there custom-stencils created by a procedure.  There are checks to 
%% ensure strings to be in there. Also, if script-stencil is empty one should 
%% fall back to stencil, which makes it impossible to get stencils with 
%% different appearance for UP/DOWN, instead one has to define different 
%% stencils for this purpose.
%% Anyway, here a workaround to get at least the scaling better.
scaleCustomScripts =
\override Script.before-line-breaking =
  #(lambda (grob)
    (let* ((script-stencil (ly:grob-property grob 'script-stencil)))
      (if (null? script-stencil)
          (let* ((sz (ly:grob-property grob 'font-size 0.0))
                 (mult (magstep sz)))
            (ly:grob-set-property! grob 'stencil
               (ly:stencil-scale
                 (ly:grob-property grob 'stencil)
                 mult 
                 mult))))))
                 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Examples
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\header {
  title = "New Scripts"
  subtitle = "for"
  subsubtitle = "\\drummode and \\notemode"
  meter = 
    \markup \fill-line { 
      "defined are ellipse, hexagon, varsegno, arc and uarc" 
    }
}

%% To use the new scripts call `my-script-alist' in \layout
%% Scale them accordingly
\layout {
  \context {
    \Score
    scriptDefinitions = #my-script-alist
    \scaleCustomScripts
  }
}

%%%%
%%%% default \notemode
%%%%

ellipse = #(make-articulation "ellipse")
hexagon = #(make-articulation "hexagon")
arc = #(make-articulation "arc")
uarc = #(make-articulation "uarc")
varsegno = #(make-articulation "varsegno")

%% Shortcuts.
%% TODO: How to create more shortcuts?
%% Below are redefined ones.
dashDash = "ellipse"
dashHat = "hexagon"

mus =
\relative c' {
	c1-\ellipse d^\ellipse
	e-\hexagon f^\hexagon
	c'1-- d_-
	e-^ f_^ 
	c-\arc
	c_\arc
	c^\arc
	c-\uarc
	c_\uarc
	c^\uarc
	c_\varsegno
}

<<
  \new Staff \with { fontSize = -6 } \mus
  \new Staff \with { fontSize = 0 } \mus
  \new Staff \with { fontSize = 6 } \mus
>>

%%%%
%%%% \drummode
%%%%

%% A new drum-table
#(define mydrums 
  '((bassdrum	laThin	"ellipse"	-1)
    (hihat 	laThin  "hexagon"      3)
    (closedhihat cross "stopped" 3)
    (cowbell triangle "arc" 5)))

\layout {
  \context {
    \DrumStaff
      \override StaffSymbol #'line-count = #2
      drumStyleTable = #(alist->hash-table mydrums)
  }
}

drum-mus = \drummode { bd8 bd  bd2. hh1 hh2 hh4 hh8 hh cb }

<<
  \new DrumStaff  \with { fontSize = #-6 } \drum-mus
  \new DrumStaff  \with { fontSize = #0 } \drum-mus
  \new DrumStaff  \with { fontSize = #6 } \drum-mus
>>

Links

Kategorien