lilypond-user
[Top][All Lists]
Advanced

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

Re: Sponsorhip offer: slash on beamed grace notes


From: Maximilian Albert
Subject: Re: Sponsorhip offer: slash on beamed grace notes
Date: Sun, 29 Apr 2007 11:49:17 +0200
User-agent: IceDove 1.5.0.10 (X11/20070329)

Hi Jamie, hi everyone,

I didn't have the time to work out how this could be implemented in lily
itself. But given the combined power of lilypond and scheme, I thought
it must be possible to write a music function which implements this.
After some trial and error, I have come up with the attached one, which
should work pretty generically and is maybe also useful for other purposes.

In the attached file, a "generic" function 'MakeSlash' is defined. It
uses some postscript commands to draw a slash that looks like a (very
oblonged) rectangle with rounded ends and overrides the stem's stencil.
Pretty much everything about the shape is parametrized so that it can be
adapted to your needs. The function takes the following arguments:

#1: the angle of the slash (in degrees)
#2: the length of the left half of the slash (measured from the
    attachment point)
#3: the length of the right half of the slash
#4: its thickness
#5: a factor that determines where the slash is attached to the stem of
    the current note: +1 means top, -1 means bottom; other values are
    interpolated (e.g., the value 0.5 means the middle of the stem)
#6: an additional offset for the attachment point (given as an xy-pair),
    just in case you want to move the slash around

(the length unit for all values is the distance between two stafflines).

To use the function in practice, simply place it in front of the note
you want to attach a slash to. Since I presume that you will mostly be
using slashes having a fixed appearance, it is maybe best to define a
variable like 'slash' in the example file with a fixed set of parameters
(or to define a new function that takes as arguments only the parameters
you regularly change).

I hope this helps and suits your needs. Comments and further suggestions
are welcome. BTW, I don't claim that this is a pretty function, so
people are invited to modify it :))

Cheers,
Max


\version "2.11.22"

\layout {
   ragged-right = ##f
   point-and-click = ##f
}

%% Arguments to Makeslash (all numbers are in staff units):
%%
%% #1: angle
%% #2: length of the left  half of the slash
%% #3: length of the right half of the slash
%% #4: thickness
%% #5: factor to shift the slash relative to the stem (+1/-1 = attached to 
top/bottom)
%% #6: offset as a pair (x-offset, y-offset)
%%
%% Values other than +/-1 in arguments #5 and #6 are interpolated.

MakeSlash = #(define-music-function (parser location angle len-left len-right 
thick y-factor offset)
                                    (number? number? number? number? number? 
pair?)
#{
\once \override Voice.Stem #'text = \markup {
    \postscript #(let ((x-off (car $offset))
                       (y-off (cdr $offset)))
    (string-append
    (ly:number->string (car $offset)) " " (ly:number->string (cdr $offset)) " 
translate "
    (ly:number->string $angle) " rotate "
    (ly:number->string (- x-off)) " " 
    (ly:number->string (- y-off)) " translate 0 setlinewidth "
    (ly:number->string (- x-off $len-left))  " " (ly:number->string (+ y-off 
$thick)) " moveto " 
    (ly:number->string (- x-off $len-left))  " " (ly:number->string y-off)
                                             " " (ly:number->string $thick) " 
90 270 arc "
    (ly:number->string (+ x-off $len-right)) " " (ly:number->string y-off)
                                             " " (ly:number->string $thick) " 
270 90 arc "
                                             " gsave fill grestore stroke")) }

\once \override Voice.Stem #'stencil = #(lambda (grob)
    (let* ((sten1 (ly:stem::print grob))
           (sten2 (ly:text-interface::print grob))
           (extent1 (ly:stencil-extent sten1 Y))
           (extent2 (ly:stencil-extent sten2 Y)))
    (ly:stencil-add
        sten1
        (ly:stencil-translate sten2
                              (cons 0 (+ (* $y-factor (cdr extent1)) 
                                         (* (- 1 $y-factor) (car extent1))))))))
#})



slash = { \MakeSlash #40 #1.5 #3.0 #0.15 #1.0 #'(0 . 0) }

\relative c'
{
    \slash c16[
    \slash b']

    \MakeSlash #-20 #2.0 #1.0 #0.05 #0.75 #'(0 . 0)
    f2
    r8
    r4
}

Attachment: slash.pdf
Description: Adobe PDF document


reply via email to

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