lilypond-user
[Top][All Lists]
Advanced

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

Re: Accessing Context Properties


From: David Kastrup
Subject: Re: Accessing Context Properties
Date: Thu, 25 Feb 2016 19:02:53 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1.50 (gnu/linux)

tisimst <address@hidden> writes:

> David,
>
>> All of that cannot be done from within a music function.  I repeat:
>> All they can do is create music expressions (typically overrides or
>> applyContext calls, possibly as context modifications) that contain
>> callbacks of some form that, when ultimately called during iteration
>> of the music expression, will be able to access actual properties.
>>
>> That has nothing to do with music functions at all but rather with
>> the kind of music expressions you'd want the music function to
>> create.
>
> I got that from your first message. I promise. I just am not sure what
> this means. Can you point me to a snippet (in the LSR?) that shows
> this?

Shows _what_?

> That would help a lot.
>
>> > These are just examples and I'm not even asking for specifics on
>> > how to do these (as they've partially been discussed in other
>> > threads). What approach would I want to follow in order to access
>> > the properties so I could make a change elsewhere?
>>
>> Have you read what I wrote?  Music functions are not able to access
>> properties.  Various music expressions (possibly created by music
>> functions) may contain callbacks that might be used for such
>> purposes.
>>
>
> Thanks you for your reply. Yes, I definitely read what you wrote. I
> realize that music functions aren't the way to go and you've made that
> perfectly clear. I didn't even mean to imply in my previous response
> that I wanted to do those things with music functions. I don't care
> what the mechanism is. I just want to know what it is!

So do you or don't you care to know?

At any rate, there are a number of different mechanisms where accessing
context properties make sense.

Basically all of the _user_-accessible mechanisms occur in the context
of engravers, as event listeners, acknowledgers, end acknowledgers.
Iterators are not user-definable, so there is little opportunity to
access context properties from within them, but they may call callbacks
like the elements-callback of sequential expressions.  There is also
\applyContext.

> That is exactly why I asked "what approach would I follow in order to
> access the properties so I could make a change elsewhere?".

It depends on what you want to do.  There is no general answer.

> I have no idea where your statements are supposed to be leading me.
> I'd really like to know, though.

Shrug.  Without a specific question, there will be no specific answer.

> Would you be kind enough to show how YOU would access a context
> property and use its value in an grob override?

Actually, one usually wouldn't (sorry for having mentioned them in that
context).  Grob callbacks are usually called on-demand, at a time where
iteration has already completed and contexts are no longer available.

> Perhaps it's too dependent on what I'd actually like to do.

It very much depends on what you want to do.

> I'm asking this because I know that if I can get my hands on a grob,

But you can't.  Not in a music expression.  Only in various other
contexts.

> I know how to access its properties (with ly:grob-property) and use
> that property's value to make a change if I want (e.g., with
> ly:grob-set-property!). I just don't know the equivalent process for
> getting my hands on a context to access its properties.

The equivalent process to _what_?  You did not specify _how_ you are
getting your hands on a grob, so how can one answer with an "equivalent"
process for getting your hands on a context?

> Now, when you say a music expression that contains callbacks might be used,
> do you mean like this (Warning: made-up, non-functional pseudo-code ahead):
>
> %%%%%%%
>
> test = { \applyContext ... (get currentBarNumber, change MMR stencil using
> currentBarNumber set bar number visibility, etc.) ... }
>
> { c1 \test R1*2 d2 e }

That's probably the most straightforward mechanism through which a music
expression can trigger accesses to context properties.  It's actually
not used all that often, but it's there too.  Yes.

-- 
David Kastrup



reply via email to

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