[Top][All Lists]

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

Re: Getting context-definiton, while being in applyContext

From: Thomas Morley
Subject: Re: Getting context-definiton, while being in applyContext
Date: Sun, 18 Nov 2018 21:57:45 +0100

Am So., 18. Nov. 2018 um 21:15 Uhr schrieb David Kastrup <address@hidden>:
> Thomas Morley <address@hidden> writes:
> > Am So., 18. Nov. 2018 um 20:40 Uhr schrieb David Kastrup <address@hidden>:
> >
> >> Just do
> >>
> >> (eq? ctx (ly:context-find ctx 'Staff))
> >>
> >> --
> >> David Kastrup
> >
> > I did not even consider to use ly:context-find. The description says:
> > Find a _parent_ of context that has name or alias name. Return #f if not 
> > found.
> > So I expected it could return
> > Staff as parent of Voice
> > StaffGroup as parent of Staff
> > Score as parent of StaffGroup
> >
> > Similar to
> > Function: ly:context-parent context
> >     Return the parent of context, #f if none.
> > Although this one returns a tree of contexts not even a single parent.
> > At least for me this was a surprise.
> >
> > Is my understanding of parents with contexts entirely wrong ...?
> Probably not.  I remembered that the function was there.  I read the doc
> string and said "huh?".  I read the C++ code and said "WTF?".  And then
> I pretended that this was totally obvious to make me look smart.


> In my
> defense, I did not write that doc string (at least I hope so).
> "Find a parent" does not make a lot of sense considering that each
> context has at most one parent.
> It's more like "Find among the chain of successive direct parents
> starting with the context itself".


> Some of our doc strings are not particularly helpful.

Very true.

> At least the
> function itself is.


Some background:
Today I was beaten by
"fingeringOrientations affects cross-voices arpeggio"
which is still present with 2.21.0
and tried to find a workaround.

As a side-effect of this thread I learned that doing
    whatever = \context Staff \applyContext #(lambda (ctx) ...)
will affect Staff _and_ all it's alias. Furthermore it can be put as
is into \with or \layout or directly into music.
So I don't need to restrict it to Staff-like contexts anymore, this is
now built-in. :)

But here the code:

correctConnectedArpeggio =
  \context Staff
    #(lambda (ctx)
       (let* ((x-offs '())
              (mom '()))
         (ly:context-pushpop-property ctx 'Arpeggio 'before-line-breaking
           (lambda (grob)
             (if (negative? (ly:grob-property grob 'direction))
                 (let ((grob-mom (grob::when grob))
                       (x-off-proc (ly:grob-property-data grob 'X-offset)))
                   (set! x-offs
                         (if (equal? grob-mom mom)
                             (cons (x-off-proc grob) x-offs)
                   (set! mom (grob::when grob))
                   (if (pair? x-offs)
                         ;; Mmmh, is using the arbitrary 10 sufficient?
                         (apply min 10 (drop x-offs 1))))))))))

melody = \relative c'' {
  \set fingeringOrientations = #'(left)
  <g-0 c-1>2\arpeggio
  \set fingeringOrientations = #'(right)
  <g-0 c-1>\arpeggio
  \set fingeringOrientations = #'(up)
  <g-0 c-1>1\arpeggio

bass = \relative c' {
  \set fingeringOrientations = #'(left)
  \set fingeringOrientations = #'(right)
  \set fingeringOrientations = #'(down)

\score {
  \context Staff \with {
    \consists "Span_arpeggio_engraver"
    \set Staff.connectArpeggios = ##t
    \context Voice = "melody" { \melody }
    \context Voice = "bass"   { \bass   }


  You _are_ smart :))

reply via email to

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