[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 20:36:33 +0100 |
Am So., 18. Nov. 2018 um 19:19 Uhr schrieb David Kastrup <address@hidden>:
>
> Thomas Morley <address@hidden> writes:
>
> > Hi,
> >
> > consider the code below. I'd like to restrict usage to Staff-like
> > contexts, i.e. Staff, Tab- and DrumStaff, etc would be ok, but
> > container-contexts like StaffGroup, etc should lead to return '().
> >
> > Pseudo-code:
> >
> > \new Staff(Group)
> > \with {
> > \applyContext
> > #(lambda (context)
> > (if <condition>
> > ;; Do something, if we are in a Staff-like context
> > ;; Multiple Bottom-contexts may happen
> > (lambda (x) ...)
> > ;; Do nothing if we are are in container-contexts like
> > ChoirStaff,
> > ;; StaffGroup, etc
> > '()
> > )
> > }
> > { c''1 }
> >
> > I thought the <condition> could be "Do I have the Staff_symbol_engraver?"
> > Though, how to code?
> > \applyContext
> > #(lambda (context)
> > (ly:context-def-lookup context 'consists))
> > does not work, because 'context' is not a context-definition.
> >
> > Any hint how to proceed would be great.
>
> Why don't you check whether they have a Staff alias? Basically if
> looking up 'Staff returns the context itself.
>
> --
> David Kastrup
You mean like below?
foo =
\applyContext
#(lambda (ctx)
(let* ((ctx-name (ly:context-name ctx))
(staff-ctx-def (ly:output-find-context-def $defaultlayout 'Staff))
(staff-like? (assoc-get ctx-name staff-ctx-def #f)))
(if staff-like?
(format #t "\n\tI'm in a staff-like context: ~a" ctx-name)
(format #t "\n\tWrong here in: ~a" ctx-name))))
\score {
<<
\new StaffGroup R1
\new Staff R1
\new TabStaff R1
\new DrumStaff R1
\new ChoirStaff R1
>>
\layout {
\context Staff \foo
\context {
\StaffGroup
\foo
}
\context {
\ChoirStaff
\foo
}
}
}
Thanks,
Harm
- Getting context-definiton, while being in applyContext, Thomas Morley, 2018/11/18
- Re: Getting context-definiton, while being in applyContext, Thomas Morley, 2018/11/18
- Re: Getting context-definiton, while being in applyContext, David Kastrup, 2018/11/18
- Re: Getting context-definiton, while being in applyContext,
Thomas Morley <=
- Re: Getting context-definiton, while being in applyContext, David Kastrup, 2018/11/18
- Re: Getting context-definiton, while being in applyContext, Thomas Morley, 2018/11/18
- Re: Getting context-definiton, while being in applyContext, David Kastrup, 2018/11/18
- Re: Getting context-definiton, while being in applyContext, Thomas Morley, 2018/11/18
- Re: Getting context-definiton, while being in applyContext, David Kastrup, 2018/11/18
- Re: Getting context-definiton, while being in applyContext, Thomas Morley, 2018/11/18
- Re: Getting context-definiton, while being in applyContext, David Kastrup, 2018/11/18