lilypond-user
[Top][All Lists]
Advanced

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

Re: Get the positions of a beam (or other grob with positions)


From: David Nalesnik
Subject: Re: Get the positions of a beam (or other grob with positions)
Date: Thu, 17 May 2012 15:59:46 -0500

Hi Urs,

On Thu, May 17, 2012 at 5:08 AM, Urs Liska <address@hidden> wrote:
Hi,

I am very much enjoying now to tweak slurs and other curves using offsets instead of hardcoded control-points.

I wonder if it would be interesting to have a similar approach to grobs with a positions property (e.g. beams).
While it is comparably easy to find usable #'positions for a beam this is then of course hard-coded and won't work if either the system-system spacing changes for whatever reason, or the music is transposed.

Of course it must be quite straightforward to read out lilypond's decision and apply offsets to that in a music function?

One issue here is that 'positions of Slur are calculated differently from Beam.  You can find a function which offsets 'positions of Slur here:

http://lsr.dsi.unimi.it/LSR/Snippet?id=748

Basically, this function offsets the Y-coordinate of the first and last control-points.

For something like Beam, you can do something like this:
\version "2.15.38"

offsetBeamPositions =
  #(define-music-function (parser location offsets) (pair?)
    #{
       \once \override Beam #'positions = #(lambda (grob)
         (let* ((func (assoc-get 'positions (cdr (ly:grob-basic-properties grob))))
                (pos (func grob)))
                ; both of above assignments may be replaced by:
                ; (pos (beam::place-broken-parts-individually grob))
                
            (coord-translate pos offsets)))
    #})
      
\relative c'' {
  \offsetBeamPositions #'(-1 . -2)
  c8[ d e f]
}

I imagine that this could be generalized to cover other grobs using the 'positions property.  With that in mind, I've had it look up the callback which calculates 'positions (the commented-out lines give you a variant which uses that specific callback for Beam).  (Thank you Harm for showing me this method.)


And if that works one could even enhance the \shape function?
The wrapper function could check against a list of grob names and call the appropriate helper function (i.e. if its a Slur then call shape-curve).
Maybe it's even possible to make that still more generic. Is it possible to check if a given grob has a given property? (i.e. if the grob has a control-points property then call shape-curve, else if it has positions then call shape-positions [elseif used so that a slurs control-points take precedence over its positions]).

So it could be possible to write
shape Slur #'((1 . 0) (3 . -2) (0 . 0) (0 . 1))
or
shape Beam #'(2 . -1)
or
shape Arpeggio #'(-1 . 2)

Would be awesome I think.

Maybe one could even have more ideas to make this offset approach even more general/generic.

Instead of ready-made functions, I would also appreciate hints on how to achieve this (as said, I'm quite interested in getting used to write Scheme functions myself, without always having to ask here).

  
Though it is entirely too much fun to work out these puzzles, I'll leave it at that!  I hope what I've given you will give you a place to start with this.

Best,
David 


Best
Urs

_______________________________________________
lilypond-user mailing list
address@hidden
https://lists.gnu.org/mailman/listinfo/lilypond-user


reply via email to

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