lilypond-user
[Top][All Lists]
Advanced

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

Re: Distance of a grob from its reference point


From: Thomas Morley
Subject: Re: Distance of a grob from its reference point
Date: Thu, 16 Jan 2020 23:35:00 +0100

Am Do., 16. Jan. 2020 um 23:12 Uhr schrieb David Nalesnik
<address@hidden>:
>
> On Thu, Jan 16, 2020 at 3:42 PM David Nalesnik <address@hidden> wrote:
> >
> > Hi Robin,
> >
> > On Thu, Jan 16, 2020 at 1:02 PM Robin Bannister <address@hidden> wrote:
> > >
> > > Paolo Prete wrote:
> > >
> > > > This is *precious* info. Please, can you tell/confirm  if
> > > >
> > > > 1) you are referring to \offset command ?
> > >
> > > No.  That would be premature in this case.
> > >
> > >
> > > > 2) is it applicable as a replacement for "\offset Y-offset" for *every*
> > > > grob that support Y-offset ?
> > >
> > > Well, I have trouble following your trains of thought.
> > > I won't try to understand that question.
> > >
> > > And I'm puzzled why you focus directly on the property Y-offset.
> > >
> > >
> > > As regards the \offset command:
> > > The section 'Properties which may be offset' at
> > > http://lilypond.org/doc/v2.19/Documentation/notation/the-offset-command
> > > says the property must have a default setting in define-grobs.scm.
> > >
> > > OttavaBracket has the property outside-staff-padding because it supports
> > > the outside-staff-interface.
> > > http://lilypond.org/doc/v2.19/Documentation/internals/outside_002dstaff_002dinterface
> > > but define-grobs.scm doesn't set it.
> > >
> > > So you can't use \offset in this case until that is amended.
> >
> > This is an argument for adding these hidden default values directly to
> > define-grobs.scm.
> >
>
> Actually, you can set a default value from which \offset will work.
> It relies on the combination \override and \once \offset:
> \version "2.19.80"
>
> {
>   \override Staff.OttavaBracket.outside-staff-padding = 0.46 % set me
> to default first!
>   \ottava #1
>   c''4 e'' d'' f''
>   \ottava #0
>   c''1
>   \once \offset outside-staff-padding #2 Staff.OttavaBracket
>   \ottava #1
>   c''4 e'' d'' f''
>   \ottava #0
> }
>
> Uh oh, now I've opened a can of worms :)
>
> David
>

And another one:
(To summarize;) It seems impossible to always get the actual used
values for properties with an unpure-pure-container. (Thus \offset has
problems in certain cases).
The actual used values are settled too late.

Though, (the other can of worms) we have the ┬┤page-post-process┬┤-hook.
See "Application Usage".

May lead to the code below.
Values are read after the _page_ is done, then used in a second run.
Thougn there's still some inaccuratesse, ~1/3-line-thickness, i.e.
~0.003, no idea where it comes from...

NB, It's nothing more then a proof-of-concept!
Tbh, I'd not try to make it really work ...

Anyway:

\version "2.19.83"

\paper { ragged-right = ##t }

test =
#(define-music-function (y) (number?)

   (define (proc grob)
     (let* ((orig (ly:grob-property grob 'stencil))
            (sten
              (grob-interpret-markup grob
                #{
                   \markup
                     \with-dimensions-from \stencil #orig
                     \overlay {
                       \stencil #orig
                       \with-color #red
                       \translate #(cons 0 (- y))
                       \path #0.1
                         #`((moveto -1 ,y)
                            (lineto 1 ,y)
                            (moveto 0 ,y)
                            (lineto 0 0)
                            (moveto -1 0)
                            (lineto 1 0)
                            (moveto -0.5 1)
                            (lineto 0 0)
                            (lineto 0.5 1))
                     }
                #})))

       (ly:grob-set-property! grob 'stencil sten)))

   #{ \override Staff.OttavaBracket.after-line-breaking = #proc #})


#(define (get-ottava-y-offs layout pages)
  (let* ((lines (map (lambda (page) (ly:prob-property page 'lines)) pages))
         (systems
           (append-map
             (lambda (line)
               (append-map
                 (lambda (l)
                   (let ((system-grob (ly:prob-property l 'system-grob)))
                     (if (not (null? system-grob))
                         (list system-grob)
                         system-grob)))
                 line))
             lines))
          (system-elts
            (map ly:grob-array->list
              (map (lambda (sys) (ly:grob-object sys 'all-elements)) systems)))
          (ottava-grobs
            (map
              (lambda (elt-list)
                 (filter
                   (lambda (elt)
                     (grob::has-interface elt 'ottava-bracket-interface))
                   elt-list))
              system-elts))
          (y-off-list
            (map
              (lambda (sub-list)
                (map
                  (lambda (ottava-grob)
                    (let* ((staff-symbol
                             (ly:grob-object ottava-grob 'staff-symbol))
                           (sys (ly:grob-system ottava-grob))
                           (centered-staff-symbol-y-ext
                             (interval-center
                               (ly:grob-robust-relative-extent
                                 staff-symbol sys Y)))
                           (centered-ottava-grob-y-ext
                             (interval-center
                               (ly:grob-robust-relative-extent
                                 ottava-grob sys Y)))
                           (y-off
                             (+
                                (abs centered-staff-symbol-y-ext)
                                centered-ottava-grob-y-ext)))
                      y-off))
                  sub-list))
             ottava-grobs)))

    (ly:output-def-set-variable!
      $defaultpaper
      'ottava-y-off-list
      (reverse (flatten-list y-off-list)))))

#(ly:output-def-set-variable!
   $defaultpaper
   'page-post-process
   (lambda (layout pages) (get-ottava-y-offs layout pages)))

#(ly:book-process
  #{
    \book {
           \score {
               {
          \ottava #1 c''''8 c'''' \ottava 0 c'''4
          \ottava #1 a'''8 a''' \ottava 0 a''4
          \ottava #1 a'''8( a''' \ottava 0 a''4)
          \bar "" \break
          \ottava #1 c''''8 c'''' \ottava 0 c'''4
          \ottava #1 a'''8 a''' \ottava 0 a''4
          \ottava #1 a'''8( a''' \ottava 0 a''4)
         }
        }
    }
  #}
   $defaultpaper
   $defaultlayout
   (ly:parser-output-name))


#(let ((ottava-y-off-list
         (ly:output-def-lookup $defaultpaper 'ottava-y-off-list)))
 (ly:book-process
  #{
    \book {
      \markup \wordwrap-string #"This is a proof of concept. Don't use it for
serious type-setting work before it is much more mature."
      \score {
        {
          \test #(first ottava-y-off-list)
          \ottava #1 c''''8 c'''' \ottava 0 c'''4
          \test #(second ottava-y-off-list)
          \ottava #1 a'''8 a''' \ottava 0 a''4
          \test #(third ottava-y-off-list)
          \ottava #1 a'''8( a''' \ottava 0 a''4)

          \bar "" \break

          \test #(fourth ottava-y-off-list)
          \ottava #1 c''''8 c'''' \ottava 0 c'''4
          \test #(fifth ottava-y-off-list)
          \ottava #1 a'''8 a''' \ottava 0 a''4
          \test #(sixth ottava-y-off-list)
          \ottava #1 a'''8( a''' \ottava 0 a''4)
        }
      }
    }
  #}
   $defaultpaper
   $defaultlayout
   (ly:parser-output-name)))


Cheers,
  Harm



reply via email to

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