Re: Discern single note-event from one in a chord

2018-07-01 Thread David Kastrup
Urs Liska  writes:

> Well, the problem at hand is that I want to apply some styles, say a
> color, to the music passed into a music function. And depending on the
> type of music this should be done by wrapping the (sequential) music
> in \temporary \override .. \revert statements, by creating \tweaks or
> by issuing \once \overrides (which is necessary when the music is for
> example "\clef bass").
>
> I can discern between sequential and non-sequential music, and I can
> detect events that are not rhythmic-events. But I would like to be
> able to apply the wrapping to single music events too. For example
> when having a single note I'd like to override a number of grobs'
> color property while within a chord it's only the notehead, so \tweak
> is good.

>>> Is there maybe a way to get to a music's "parent" in order to check
>>> what type that is?
>> No.  A music function is a local transform.  It does not get to see
>> where its result is being used.  You can use its result in a variable
>> which you may use both as a single note and inside of a chord.
>>
>> If you want to work with music in context, you need to analyze stream
>> events in an engraver.
>>
>
> Hm, I don't think that's an option in my case. The problem is that in
> my \tagSpan function I *dispatch* the actual styling to another
> (user-provided) music function. And I think this has to be at the
> music-function stage because this function may not only override grob
> properties but may do anything a music function can do, like adding
> marks before or after the music or even apply some random procedure
> meddling with the content (I can imagine someone doing
>     \tagSpan randomize \with { strength = 0.9 seed = 0.49283567
> algorithm = original } { c c g' g a a g2 }
> )

So do both and use tags in-chord and not-in-chord (in a tag group of
their own) and add a scorification hook that removes all such tagged
music from where it does not belong.

> The problem is that
>     \tagSpan something c'
> often has to be treated differently from
>     
>
> Any ideas toward that use-case, independent from my original problem
> description?

Either do both but tagged, or just tweak the stuff and do a pass through
the finished music (scorification hook or not) that replaces recognized
tweaks outside of chords with corresponding overrides.

This will not work very favorably with people using parallel music
inside of one context for piecing stuff together but if you want to do
that, you really need to iterate.

-- 
David Kastrup

___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: Discern single note-event from one in a chord

2018-07-01 Thread Urs Liska



Am 01.07.2018 um 10:04 schrieb David Kastrup:

Urs Liska  writes:


Hi,

is there a way to discern whether the ly:music? passed into a music
function is a single note-event or a note within a chord?

\version "2.19.80"

testType =
#(define-music-function (music)(ly:music?)
(ly:message "Music type(s): ~a" (ly:music-property music 'types))
music)

{
   \clef bass
   \testType c
   
}

prints `Music type(s): (event note-event rhythmic-event
melodic-event)` in both cases.


Is there anything else besides the 'types music-property I can check
for in this context?

No.


Too bad.




I hope there is because there are many respects in which the two would
have to be treated differently.

Which ones?


Well, the problem at hand is that I want to apply some styles, say a 
color, to the music passed into a music function. And depending on the 
type of music this should be done by wrapping the (sequential) music in 
\temporary \override .. \revert statements, by creating \tweaks or by 
issuing \once \overrides (which is necessary when the music is for 
example "\clef bass").


I can discern between sequential and non-sequential music, and I can 
detect events that are not rhythmic-events. But I would like to be able 
to apply the wrapping to single music events too. For example when 
having a single note I'd like to override a number of grobs' color 
property while within a chord it's only the notehead, so \tweak is good.


So
    \testType c'
should be expanded to
    \temporary \override NoteHead.color = #red c' \revert NoteHead.color
while
    
should result in
    < \tweak color #red e>





Is there maybe a way to get to a music's "parent" in order to check
what type that is?

No.  A music function is a local transform.  It does not get to see
where its result is being used.  You can use its result in a variable
which you may use both as a single note and inside of a chord.

If you want to work with music in context, you need to analyze stream
events in an engraver.



Hm, I don't think that's an option in my case. The problem is that in my 
\tagSpan function I *dispatch* the actual styling to another 
(user-provided) music function. And I think this has to be at the 
music-function stage because this function may not only override grob 
properties but may do anything a music function can do, like adding 
marks before or after the music or even apply some random procedure 
meddling with the content (I can imagine someone doing
    \tagSpan randomize \with { strength = 0.9 seed = 0.49283567 
algorithm = original } { c c g' g a a g2 }

)

The problem is that
    \tagSpan something c'
often has to be treated differently from
    

Any ideas toward that use-case, independent from my original problem 
description?


Thanks
Urs

___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: Discern single note-event from one in a chord

2018-07-01 Thread Urs Liska



Am 01.07.2018 um 10:04 schrieb David Kastrup:

Urs Liska  writes:


Hi,

is there a way to discern whether the ly:music? passed into a music
function is a single note-event or a note within a chord?

\version "2.19.80"

testType =
#(define-music-function (music)(ly:music?)
(ly:message "Music type(s): ~a" (ly:music-property music 'types))
music)

{
   \clef bass
   \testType c
   
}

prints `Music type(s): (event note-event rhythmic-event
melodic-event)` in both cases.


Is there anything else besides the 'types music-property I can check
for in this context?

No.


Too bad.




I hope there is because there are many respects in which the two would
have to be treated differently.

Which ones?


Well, the problem at hand is that I want to apply some styles, say a 
color, to the music passed into a music function. And depending on the 
type of music this should be done by wrapping the (sequential) music in 
\temporary \override .. \revert statements, by creating \tweaks or by 
issuing \once \overrides (which is necessary when the music is for 
example "\clef bass").


I can discern between sequential and non-sequential music, and I can 
detect events that are not rhythmic-events. But I would like to be able 
to apply the wrapping to single music events too. For example when 
having a single note I'd like to override a number of grobs' color 
property while within a chord it's only the notehead, so \tweak is good.


So
    \testType c'
should be expanded to
    \temporary \override NoteHead.color = #red c' \revert NoteHead.color
while
    
should result in
    < \tweak color #red e>





Is there maybe a way to get to a music's "parent" in order to check
what type that is?

No.  A music function is a local transform.  It does not get to see
where its result is being used.  You can use its result in a variable
which you may use both as a single note and inside of a chord.

If you want to work with music in context, you need to analyze stream
events in an engraver.



Hm, I don't think that's an option in my case. The problem is that in my 
\tagSpan function I *dispatch* the actual styling to another music 
function. And I think this has to be at the music-function stage because 
this function may not only override grob properties but may do anything 
a music function can do, like adding marks before or after the music or 
even apply some random procedure meddling with the content (I can 
imagine someone doing
    \tagSpan randomize \with { strength = 0.9 seed = 0.49283567 
algorithm = original } { c c g' g a a g2 }

)

The problem is that
    \tagSpan something c'
often has to be treated differently from
    

Any ideas toward that use-case, independent from my original problem 
description?


Thanks
Urs

___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: Discern single note-event from one in a chord

2018-07-01 Thread David Kastrup
Urs Liska  writes:

> Hi,
>
> is there a way to discern whether the ly:music? passed into a music
> function is a single note-event or a note within a chord?
>
> \version "2.19.80"
>
> testType =
> #(define-music-function (music)(ly:music?)
>(ly:message "Music type(s): ~a" (ly:music-property music 'types))
>music)
>
> {
>   \clef bass
>   \testType c
>   
> }
>
> prints `Music type(s): (event note-event rhythmic-event
> melodic-event)` in both cases.
>
>
> Is there anything else besides the 'types music-property I can check
> for in this context?

No.

> I hope there is because there are many respects in which the two would
> have to be treated differently.

Which ones?

> Is there maybe a way to get to a music's "parent" in order to check
> what type that is?

No.  A music function is a local transform.  It does not get to see
where its result is being used.  You can use its result in a variable
which you may use both as a single note and inside of a chord.

If you want to work with music in context, you need to analyze stream
events in an engraver.

-- 
David Kastrup

___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user