lilypond-user
[Top][All Lists]
Advanced

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

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


From: Urs Liska
Subject: Re: Discern single note-event from one in a chord
Date: Sun, 1 Jul 2018 11:29:43 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0



Am 01.07.2018 um 10:04 schrieb David Kastrup:
Urs Liska <address@hidden> 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
   <c \testType e g>
}

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
    <c \testType e>
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
    <c' \tagSpan something e'>

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

Thanks
Urs



reply via email to

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