lilypond-devel
[Top][All Lists]
Advanced

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

Re: Scheme function to print out active Voice context during interpretat


From: Trevor Bača
Subject: Re: Scheme function to print out active Voice context during interpretation?
Date: Sun, 14 Dec 2008 17:34:14 -0600

On Sun, Dec 14, 2008 at 3:52 PM, John Mandereau <address@hidden> wrote:
Hi Trevor!

Hey John :-)

 

Le dimanche 14 décembre 2008 à 12:42 -0600, Trevor Bača a écrit :
> Is there a way to print out the name (or other identity) of the
> currently active voice just before any given note or rest in an input
> file?

> Does something like this exist?

I haven't found such a function in Lily sources and docs, try these two
music functions (freely inspired from barNumberCheck definition):

whichContext = #(define-music-function (parser location) ()
                (make-music 'ApplyContext
                 'origin location
                 'procedure (
                   lambda (c)
                   (display
                    (string-append
                     "\nCurrent voice is "
                     (ly:context-id c)
                     "\n")))))

locationWhichContext = #(define-music-function (parser location) ()
                (make-music 'ApplyContext
                 'origin location
                 'procedure (
                   lambda (c)
                   (display
                    (ly:input-message location
                     "current voice is ~a"
                     (ly:context-id c))))))

Oh wow: these are *super* helpful! Exactly what I was looking for.

Thanks, John!


 


It's also possible to make Scheme avatars of these functions, but then
they would need to take the location as an argument.

This should be added to the docs IMHO; should this be added in LSR, the
manual or the (yet to be written) docstring of applyContext?


> [The motivation is that I'm researching the way that LilyPond
> determines which voice music events are assigned to ... from a user's
> perspective based solely on looking at input files. Voice-resolution
> in the example above is of course quite clear; voice-resolution when
> there are multiple anonymous voices, possibly in parallel, has become
> extremely tricky as I've written more and more test files, all of
> which I'll be happy to post if anyone else is interested in that sort
> of thing.]

Please do :-) I guess some of these tests may be added to LSR.


I have a pretty big stockpile of tests and sometime in the next couple of days I'll find a way to organize them and send them over. But I'd like to start with the pair of examples that just seems absolutely pathological to me. Here it is:


%%% VOICE-RESOLUTION EXAMPLE 1 %%%

\version "2.11.57"

   {
      \override Voice.NoteHead #'color = #red
      c'8
      d'8
      e'8
      f'8
      \new Voice = "foo" {
         g'8
         a'8
         b'8
         c''8
      }
      d''8
      e''8
      f''8
      g''8
   }

%%% END EXAMPLE 1 %%%

So far, so good. In example 1, LilyPond creates two voices with one nested inside the other. We see this because the outer eight notes are red while the inner four notes are black.

But now look at this:

%%% VOICE-RESOLUTION EXAMPLE 2 %%%

\version "2.11.57"

   {
      \new Voice = "foo" {
      \override Voice.NoteHead #'color = #red
         g'8
         a'8
         b'8
         c''8
      }
      d''8
      e''8
      f''8
      g''8
   }


%%% END EX 2 %%%

(Stop and think what you'd expect here before looking at the output.)

Here LilyPond renders a single voice! We see this because all eight notes are red.

Sprinkling the new \whichContext function before the first, fourth (and eighth) notes in each example (where possible) makes it clear that the "foo" context governs only the middle four notes in the first example while governing *all* eight notes in the second example.

What on earth is going on here?

What's so odd is that if you look at example 2 and think "OK, this is all just a single voice because the explicitly instantiated voice 'leaks' over into the following four notes" ... then you're in for a big surprise when you add just a single note to the beginning of the example:

%%% EX 2 + 1 NOTE %%%

   {
   c'8
      \new Voice = "foo" {
      \override Voice.NoteHead #'color = #red
         g'8
         a'8
         b'8
         c''8
      }
      d''8
      e''8
      f''8
      g''8
   }

%%% END EX 2 MOD %%%

That single note at the beginning now breaks the example into two voices just like example 1!

Can anyone explain what's going on here?


Trevor.


--
Trevor Bača
address@hidden

Attachment: example-1.png
Description: PNG image

Attachment: example-2.png
Description: PNG image

Attachment: example-2-mod.png
Description: PNG image


reply via email to

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