Better slashed graces

classic Classic list List threaded Threaded
21 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Better slashed graces

Gilberto Agostinho
Hi all,

I am trying to improve the slashed grace function because currently it does work only for a limited amount of examples. I am trying to make the slash always at the same position relative to the highest beam (which was one of the most annoying things about the other function) and then take into account the beam angle to compensate for the slash angle. My solution is surely very inelegant (regarding programming) so I'd welcome anyone who wants to improve it, but it does a much better job in practise. Compare it below.

BEFORE:


AFTER:


Here is the function: slashed-notes-function.ly

Cheers,
Gilberto
Reply | Threaded
Open this post in threaded view
|

Re: Better slashed graces

David Nalesnik
Hi Gilberto,

On Mon, Nov 30, 2015 at 10:16 AM, Gilberto Agostinho <[hidden email]> wrote:
Hi all,

I am trying to improve the slashed grace function because currently it does
work only for a limited amount of examples. I am trying to make the slash
always at the same position relative to the highest beam (which was one of
the most annoying things about the other function) and then take into
account the beam angle to compensate for the slash angle. My solution is
surely very inelegant (regarding programming) so I'd welcome anyone who
wants to improve it, but it does a much better job in practise. Compare it
below.

BEFORE:
<http://lilypond.1069038.n5.nabble.com/file/n184292/04.png>

AFTER:
<http://lilypond.1069038.n5.nabble.com/file/n184292/19.png>

Here is the function:  slashed-notes-function.ly
<http://lilypond.1069038.n5.nabble.com/file/n184292/slashed-notes-function.ly>

Cheers,
Gilberto


Could you provide a link to the function you're trying to improve?  It isn't part of the regular distribution.

Thanks,
David 

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Better slashed graces

tisimst
David,

On Mon, Nov 30, 2015 at 9:45 AM, David Nalesnik-2 [via Lilypond] <[hidden email]> wrote:
Hi Gilberto,

On Mon, Nov 30, 2015 at 10:16 AM, Gilberto Agostinho <[hidden email]> wrote:
Hi all,

I am trying to improve the slashed grace function because currently it does
work only for a limited amount of examples. I am trying to make the slash
always at the same position relative to the highest beam (which was one of
the most annoying things about the other function) and then take into
account the beam angle to compensate for the slash angle. My solution is
surely very inelegant (regarding programming) so I'd welcome anyone who
wants to improve it, but it does a much better job in practise. Compare it
below.

BEFORE:
<http://lilypond.1069038.n5.nabble.com/file/n184292/04.png>

AFTER:
<http://lilypond.1069038.n5.nabble.com/file/n184292/19.png>

Here is the function:  slashed-notes-function.ly
<http://lilypond.1069038.n5.nabble.com/file/n184292/slashed-notes-function.ly>

Cheers,
Gilberto


Could you provide a link to the function you're trying to improve?  It isn't part of the regular distribution.

I believe it's in response to this snippet in the LSR: http://lsr.di.unimi.it/LSR/Item?id=721 (Slashed beamed grace notes)

Gilberto,

I think this is a VERY nice improvement! Great work!

Devs,

Any reason this can't be incorporated into the regular distribution? I know that beamed grace notes don't need a slash, so maybe there could be a hook to turn it on or off?

Best,
Abraham
Reply | Threaded
Open this post in threaded view
|

Re: Better slashed graces

David Nalesnik
In reply to this post by David Nalesnik
Hi again,

On Mon, Nov 30, 2015 at 10:44 AM, David Nalesnik <[hidden email]> wrote:
Hi Gilberto,

On Mon, Nov 30, 2015 at 10:16 AM, Gilberto Agostinho <[hidden email]> wrote:
Hi all,

I am trying to improve the slashed grace function because currently it does
work only for a limited amount of examples. I am trying to make the slash
always at the same position relative to the highest beam (which was one of
the most annoying things about the other function) and then take into
account the beam angle to compensate for the slash angle. My solution is
surely very inelegant (regarding programming) so I'd welcome anyone who
wants to improve it, but it does a much better job in practise. Compare it
below.

BEFORE:
<http://lilypond.1069038.n5.nabble.com/file/n184292/04.png>

AFTER:
<http://lilypond.1069038.n5.nabble.com/file/n184292/19.png>

Here is the function:  slashed-notes-function.ly
<http://lilypond.1069038.n5.nabble.com/file/n184292/slashed-notes-function.ly>

Cheers,
Gilberto


Could you provide a link to the function you're trying to improve?  It isn't part of the regular distribution.



What confuses me a little here is your usage of the stem-fraction parameter.  This is designed in the original to represent where the slash crosses the initial stem as a fraction of the stem's length.  From visual inspection, it appears that you have it set to halfway along the stem in the original in every case.  The idea--surely not ideal--is that it would need to be adjusted on a case-by-case basis.

It appears to have a different function in your example.

--David




_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Better slashed graces

Gilberto Agostinho
In reply to this post by tisimst
Hi all, thanks for the comments,

tisimst wrote
I believe it's in response to this snippet in the LSR:
http://lsr.di.unimi.it/LSR/Item?id=721 (Slashed beamed grace notes)
Yes, that's the function, sorry for being unclear. My improvements above work well on most cases, but I modified that function using only trial and error methods, so it's surely not very elegant. If we could come up with a consistent and good looking slash function, it would be a great addition to LilyPond, as slashed graces are a fundamental part of contemporary music (just open any score by Boulez, Stockhausen, Ferneyhough, Cage and others).

Cheers,
Gilberto
Reply | Threaded
Open this post in threaded view
|

Re: Better slashed graces

David Nalesnik
In reply to this post by tisimst


On Mon, Nov 30, 2015 at 11:01 AM, tisimst <[hidden email]> wrote:
Devs,

Any reason this can't be incorporated into the regular distribution? I know that beamed grace notes don't need a slash, so maybe there could be a hook to turn it on or off?


I remember an email--I believe it was from Neil Puttock to Valentin about the original version of the function (of which the LSR snippet is a rewrite)--that such a thing ought to have its own grob to
allow for all manner of user customization.  Sorry--can't seem to locate the mail!!

DN


_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Better slashed graces

Gilberto Agostinho
Hi David,

As I wrote, I simply tried using some basic programming skills and trial and error in order to get a better looking results, and I would need some help to make this function look decently (I am not very familiar with Scheme at all, nor with programming functions in LilyPond). The main thing I tried to achieve is the following:

- make the slash to always cross the first stem at a constant distance from beam (the previous function wasn't consistent with this at all, and the results were all over the place even for beams with similar angles)
- compensate the angle of the slash with the angle of the beam, so that all of these slashes look more uniform
Reply | Threaded
Open this post in threaded view
|

Re: Better slashed graces

David Nalesnik


On Mon, Nov 30, 2015 at 11:17 AM, Gilberto Agostinho <[hidden email]> wrote:
Hi David,

As I wrote, I simply tried using some basic programming skills and trial and
error in order to get a better looking results, and I would need some help
to make this function look decently (I am not very familiar with Scheme at
all, nor with programming functions in LilyPond). The main thing I tried to
achieve is the following:

- make the slash to always cross the first stem at a constant distance from
beam (the previous function wasn't consistent with this at all, and the
results were all over the place even for beams with similar angles)

The reason it isn't consistent with regard to the beam is that the crossing is determined solely by the quantity stem-fraction which is based on stem length. The beam is not taken into account for the crossing.  It is, however, considered with protrusion, how much the line sticks out at either end, since a sloping beam must be reckoned with.

(Note that the improved examples in your rewrite are doable with the original function -- you just have to mess with stem-fraction. You can't leave it at the same setting.  It's the lack of complete automation that makes the LSR snippet a hassle.)

I like the idea of consulting the beam for the crossing.  After all, changing the stem-fraction when using the original is probably mostly done to get a good position relative to the beam!  Should've thought of that :)

My question would be: what is 'stem-fraction' now?  What does it now measure? 

Best,
David

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Better slashed graces

Gilberto Agostinho
David Nalesnik-2 wrote
My question would be: what is 'stem-fraction' now?  What does it now
measure?
I have absolutely no idea, I just messed around with the variables and expressions until I got a result that looked right in the situations I was testing :) As you say, ideally this all could be automatized, so that those three arguments can actually become three parameters in the function.
Reply | Threaded
Open this post in threaded view
|

Re: Better slashed graces

David Nalesnik


On Mon, Nov 30, 2015 at 11:48 AM, Gilberto Agostinho <[hidden email]> wrote:
David Nalesnik-2 wrote
> My question would be: what is 'stem-fraction' now?  What does it now
> measure?

I have absolutely no idea, I just messed around with the variables and
expressions until I got a result that looked right in the situations I was
testing :)

Seems to now be a simple offset of the line along the stem -- 1 is move the line down 1 ss, rather than put the line at 100% of the stem's length.  Much better, I would say.

You could have the idea of proportionality, but relative to the width of the beam, so the line would always cross dead-center or a fixed distance below the beams, whether you have 1, 2, 3, .... That's doable, but a little annoying: get the number of beams, the space between beams, do some math.

David

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Better slashed graces

David Nalesnik


On Mon, Nov 30, 2015 at 12:08 PM, David Nalesnik <[hidden email]> wrote:


You could have the idea of proportionality, but relative to the width of the beam, so the line would always cross dead-center or a fixed distance 

Well, not "fixed" if proportional... 


_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Better slashed graces

Gilberto Agostinho
In reply to this post by David Nalesnik
David Nalesnik-2 wrote
You could have the idea of proportionality, but relative to the width of
the beam, so the line would always cross dead-center or a fixed distance
below the beams, whether you have 1, 2, 3, .... That's doable, but a little
annoying: get the number of beams, the space between beams, do some math.
I don't think that's really necessary, I think very often the slash is already crossing the beams when it intercepts the stem (when there are too many beams). Also, if the slash is set against a fixed point (connection point of top beam and stem) then it's much easier to ensure it will always look a certain way regardless of the angle of the beams, number of beams, position of notes, etc. That's for instance how Sibelius handles slashed graces if my memory serves well (it has been ages since I migrated to LilyPond...): the slash crosses only the very corner of the beams, so it's easy for it to look consistent regardless of other variables. See:

Reply | Threaded
Open this post in threaded view
|

Re: Better slashed graces

Peter Bjuhr
In reply to this post by tisimst


On 2015-11-30 18:01, tisimst wrote:
I know that beamed grace notes don't need a slash, so maybe there could be a hook to turn it on or off?


There already is \slashedGrace. But it doesn't work for multiple notes.

Best
Peter


_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Better slashed graces

Gilberto Agostinho
Hi all,

I just discovered a bug with my function above. It turns out the function works well when there are two of more notes inside the \slashedGrace{}, but when a single note is there the file does not compile. I believe I need a conditional somewhere to take care of this but I don't really know how to implement it, would anyone be able to give me a hand? Example of a problematic case: slash-bug.ly

Thanks a lot,
Gilberto
Reply | Threaded
Open this post in threaded view
|

Re: Better slashed graces

David Nalesnik
Hi Gilberto,

On Mon, Dec 19, 2016 at 6:43 AM, Gilberto Agostinho
<[hidden email]> wrote:
> Hi all,
>
> I just discovered a bug with my function above. It turns out the function
> works well when there are two of more notes inside the \slashedGrace{}, but
> when a single note is there the file does not compile. I believe I need a
> conditional somewhere to take care of this but I don't really know how to
> implement it, would anyone be able to give me a hand? Example of a
> problematic case:  slash-bug.ly
> <http://lilypond.1069038.n5.nabble.com/file/n198182/slash-bug.ly>

The problem is that there is no Beam grob, so an error is raised when
you query its properties.

Following is a simple way to use substitute values when there is no Beam object.

Notice that there is an additional complication.  The grob extent for
the stem in the absence of a beam is (+inf.0 . -inf.0).  I don't know
why.  I hacked a simple fix for this: use the stencil's extent when
grob-extent returns something unusable.  (I didn't give it much
thought -- there's certainly a prettier way.)

Anyway, hope this helps.

David

P. S.  You need { } around your music expression.

%%%%%

slash =
#(define-music-function (parser location ang stem-fraction protrusion)
   (number? number? number?)
   (remove-grace-property 'Voice 'Stem 'direction)
   #{
     \once \override Stem #'stencil =
     #(lambda (grob)
        (let* ((x-parent (ly:grob-parent grob X))
               (is-rest? (ly:grob? (ly:grob-object x-parent 'rest))))
          (if is-rest?
              empty-stencil
              (let* ((refp (ly:grob-system grob))
                     (stil (ly:stem::print grob))
                     (stem-y-ext (ly:grob-extent grob grob Y))
                     (stem-y-ext (if (interval-sane? stem-y-ext)
                                     stem-y-ext
                                     (ly:stencil-extent stil Y)))
                     (stem-length (- (cdr stem-y-ext) (car stem-y-ext)))
                     (beam (ly:grob-object grob 'beam))
                     (beam? (ly:grob? beam))
                     (beam-X-pos (if beam?
                                     (ly:grob-property beam 'X-positions)
                                     #f))
                     (beam-Y-pos (if beam?
                                     (ly:grob-property beam 'positions)
                                     #f))
                     (beam-slope (if beam?
                                     (/ (- (cdr beam-Y-pos) (car beam-Y-pos))
                                       (- (cdr beam-X-pos) (car beam-X-pos)))
                                     0.0))
                     (beam-angle (atan beam-slope))
                     (dir (ly:grob-property grob 'direction))
                     (line-dy (* stem-length stem-fraction))
                     (line-dy-with-protrusions (if (= dir 1)
                                                   (+ (* 4 protrusion)
beam-angle)
                                                   (- (* 4 protrusion)
beam-angle)))
                     (ang (if (> beam-slope 0)
                              (if (= dir 1)
                                  (+ (degrees->radians ang) (* beam-angle 0.7))
                                  (degrees->radians ang))
                              (if (= dir 1)
                                  (degrees->radians ang)
                                  (- (degrees->radians ang) (*
beam-angle 0.7)))))
                     (line-dx (/ line-dy-with-protrusions (tan ang)))
                     (protrusion-dx (/ protrusion (tan ang)))
                     (corr (if (= dir 1) (car stem-y-ext) (cdr stem-y-ext)))
                     (stil (ly:stem::print grob)))

                (ly:stencil-add
                 stil
                 (grob-interpret-markup grob
                   (markup
                    ;#:with-color red
                    #:translate
                    (cons (- protrusion-dx)
                      (+ corr
                        (* dir
                          (- stem-length (+ stem-fraction protrusion)))))
                    #:draw-line
                    (cons line-dx
                      (* dir line-dy-with-protrusions)))))))))
   #})

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Better slashed graces

Gilberto Agostinho
Hi David,

First of all, thanks for your reply and for your help!

David Nalesnik wrote
The problem is that there is no Beam grob, so an error is raised when
you query its properties.
I see!

Following is a simple way to use substitute values when there is no Beam object.
This modified function does compile, but actually it's not doing what it's supposed to do in the case of single notes: for that, LilyPond already slashes them, so now the function is attempting to add a second slash, see:



That's what I said about the conditional, I think the function needs something like "if there is a beam, then add a slash, else if no beam then no slash". Do you think you could give me a hand with that?

Thanks a lot once again, I really appreciate your help!

Cheers,
Gilberto
Reply | Threaded
Open this post in threaded view
|

Re: Better slashed graces

David Nalesnik
On Mon, Dec 19, 2016 at 1:32 PM, Gilberto Agostinho
<[hidden email]> wrote:

> Hi David,
>
> First of all, thanks for your reply and for your help!
>
>
> David Nalesnik wrote
>> The problem is that there is no Beam grob, so an error is raised when
>> you query its properties.
>
> I see!
>
>
>> Following is a simple way to use substitute values when there is no Beam
>> object.
>
> This modified function does compile, but actually it's not doing what it's
> supposed to do in the case of single notes: for that, LilyPond already
> slashes them, so now the function is attempting to add a second slash, see:
>
> <http://lilypond.1069038.n5.nabble.com/file/n198193/33.png>
>
> That's what I said about the conditional,

You simply wrote that the file wouldn't compile.  Unfortunately, my
eyesight seems to be worse than I thought, and I missed the second
slash.

 I think the function needs
> something like "if there is a beam, then add a slash, else if no beam then
> no slash". Do you think you could give me a hand with that?

Sure, that's no problem.  And it looks a bit cleaner than what I went
in the last reply:

slash =
#(define-music-function (parser location ang stem-fraction protrusion)
   (number? number? number?)
   (remove-grace-property 'Voice 'Stem 'direction)
   #{
     \once \override Stem #'stencil =
     #(lambda (grob)
        (let* ((x-parent (ly:grob-parent grob X))
               (is-rest? (ly:grob? (ly:grob-object x-parent 'rest)))
               (beam (ly:grob-object grob 'beam))
               (stil (ly:stem::print grob)))
          (cond
           (is-rest? empty-stencil)
           ((ly:grob? beam)
            (let* ((refp (ly:grob-system grob))
                   (stem-y-ext (ly:grob-extent grob grob Y))
                   (stem-length (- (cdr stem-y-ext) (car stem-y-ext)))
                   (beam-X-pos (ly:grob-property beam 'X-positions))
                   (beam-Y-pos (ly:grob-property beam 'positions))
                   (beam-slope (/ (- (cdr beam-Y-pos) (car beam-Y-pos))
                                 (- (cdr beam-X-pos) (car beam-X-pos))))
                   (beam-angle (atan beam-slope))
                   (dir (ly:grob-property grob 'direction))
                   (line-dy (* stem-length stem-fraction))
                   (line-dy-with-protrusions (if (= dir 1)
                                                 (+ (* 4 protrusion) beam-angle)
                                                 (- (* 4 protrusion)
beam-angle)))
                   (ang (if (> beam-slope 0)
                            (if (= dir 1)
                                (+ (degrees->radians ang) (* beam-angle 0.7))
                                (degrees->radians ang))
                            (if (= dir 1)
                                (degrees->radians ang)
                                (- (degrees->radians ang) (* beam-angle 0.7)))))
                   (line-dx (/ line-dy-with-protrusions (tan ang)))
                   (protrusion-dx (/ protrusion (tan ang)))
                   (corr (if (= dir 1) (car stem-y-ext) (cdr stem-y-ext))))
              (ly:stencil-add
               stil
               (grob-interpret-markup grob
                 (markup
                  ;#:with-color red
                  #:translate
                  (cons (- protrusion-dx)
                    (+ corr
                      (* dir
                        (- stem-length (+ stem-fraction protrusion)))))
                  #:draw-line
                  (cons line-dx
                    (* dir line-dy-with-protrusions)))))))
           (else stil))))
   #})

>
> Thanks a lot once again, I really appreciate your help!
>

You're welcome!

David

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Better slashed graces

Gilberto Agostinho
Hi David,

David Nalesnik wrote
> I think the function needs
> something like "if there is a beam, then add a slash, else if no beam then
> no slash". Do you think you could give me a hand with that?

Sure, that's no problem.  And it looks a bit cleaner than what I went
in the last reply
Fantastic, thanks a lot for the help!!

I made one small improvement to the functions, now the slashes the same thickness as in the default single note \slashedGrace, and it looks better now. For anyone interested, here is the link for the function: acciaccaturas_and_slashed_notes.ly

Take care!
Gilberto
Reply | Threaded
Open this post in threaded view
|

Re: Better slashed graces

David Nalesnik
On Mon, Dec 19, 2016 at 3:44 PM, Gilberto Agostinho
<[hidden email]> wrote:

> Hi David,
>
>
> David Nalesnik wrote
>>> I think the function needs
>>> something like "if there is a beam, then add a slash, else if no beam
>>> then
>>> no slash". Do you think you could give me a hand with that?
>>
>> Sure, that's no problem.  And it looks a bit cleaner than what I went
>> in the last reply
>
> Fantastic, thanks a lot for the help!!
>
> I made one small improvement to the functions, now the slashes the same
> thickness as in the default single note \slashedGrace, and it looks better
> now. For anyone interested, here is the link for the function:
> acciaccaturas_and_slashed_notes.ly
> <http://lilypond.1069038.n5.nabble.com/file/n198198/acciaccaturas_and_slashed_notes.ly>
>

Looks great!

-David

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: Better slashed graces

Andrew Bernard
In reply to this post by Gilberto Agostinho
Hi Gilberto,


You may not be aware of my detailed work on slashed beams and slashed stems that I recently contributed to openlilylib. Theres a function that provides fine control over the parameters of beam slashes, and which works on the left as well as the right (needed for many contemporary scores). Also, another library function for individual stem slashes, motivated by a need to have horizontal slashes, but I generalised it to do any angle, again with fine control over many of the parameters such as thickness and fractional position.

You can find the code under the /slash-beam and /slash-stem directories under /notation-snippets in the openlilylib/snippets repository, complete with examples.

I think you have somewhat different use case to me - I needed individual control finely tuned, but is it that you want the function to automatically compute a variable angle but based on some beam criteria? I am sure something like that could be added to my code. The code I have submitted has been pretty heavily tested, and apart from anything else, has some lovely trigonometry!

Hope this may be helpful.

Andrew



_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
12