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: Carl D. Sorensen
Subject: Re: Scheme function to print out active Voice context during interpretation?
Date: Mon, 15 Dec 2008 14:20:36 -0700



On 12/15/08 6:25 AM, "Trevor Bača" <address@hidden> wrote:

> On Sun, Dec 14, 2008 at 9:10 PM, Han-Wen Nienhuys <address@hidden> wrote:
>> On Mon, Dec 15, 2008 at 12:18 AM, Trevor Bača <address@hidden> wrote:

> 
> ... even though contexts do not literally nest! (Even though their iterators
> inherit from one another.)
> 
> So, to resume, this leads to the following situation:
> 
> EXPRESSIONS:
>   * exhibit syntactic nesting
>   * do not exhibit 'visual nesting' (or, maybe, 'properties nesting')
> 
> CONTEXTS:
>   * do not exhibit syntactic nesting
>   * do exhibit 'visual nesting' / 'properties nesting'
> 
> 
> Or maybe a better way of saying it:
> 
> EXPRESSIONS:
>   * exhibit syntactic nesting
>   * do not store grob properties
> 
> CONTEXTS:
>   * do not exhibit syntactic nesting
>   * do store grob properties
> 
> 
> 
> Hm. I think I get it now. Much thanks to everyone. If anyone sees more details
> missing from my working-out process, please correct.
> 
> 
> 
> Trevor.


I'd say it differently:

EXPRESSIONS:  
   Establish the timing of music-events relative to one another

So there is no difference between
{ {c4 d} {e f} {g a}}
and
{c4 d e f g a }


Similarly, there is no difference between

{ 
  {\override myObject #'prop = #value c4 d}
  {\override myObject #'prop = #new-value e f}
  {g a}
} 

and

{ 
  \override myObject #'prop = #value c4 d
  \override myObject #'prop = #new-value e f
  g a
} 

Both expressions cause the first override to apply to the current context
starting and the moment of the note c4 and the second override to apply
starting at the moment of the note e.

Note that those overrides will apply to ALL OBJECTS OF TYPE myObject IN THE
CURRENT CONTEXT, starting at those times.

So 

<<
   { c4 d \override myObject #'prop = #value e f}
   { g4 a b c}
>>

will have the overrides applied to the e, f, b, and c, but not g4 and a.
This is because it's the music moment, not the source file relative
location, that defines the applicability of the overrides.

CONTEXTS:
  Provide the evaluation environment (my words, not Han-Wen's) in which all
  music events will be evaluated when it's time to put them in the output
  stream (midi file or printed page).
  
  All properties that matter but are not tied to a particular grob reside in
  a context that contains the grob.  They may be tied to the immediate
  context containing the grob (e.g. Voice, for NoteHead) or may come from
  a context above the current context in the heierarchy (e.g. the Staff that
  contains the Voice that contains the notehead).

The confusion comes in because, if there is no appropriate context
available, when LilyPond sees a music expression it will automatically
create a context.  And there is nothing in the input syntax that tells you
when the context will be created.  So I continue to get surprised from time
to time if I don't explicitly instantiate all contexts.

I think your discussion about "naked" music expressions is illuminating, but
also potentially confusing.  It's not naked expressions that cause the
challenge, but expressions that occur at a point in the music stream (not
the input stream) where no appropriate context exists, therefore requiring
LilyPond to create one.

So if we look at your example 2:

%%% 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 %%%

Looking in music stream (not input stream) order:

1a instantiate Voice foo (this takes no musical time).  Oops, we don't have
   a Staff context to hold foo, so we'll need to create one.
1b Make an override to the notehead color (this also takes no musical time)
1c engrave g'8 (this is the first thing that takes musical time)
2 engrave a'8
3 engrave b'8
4 engrave c''8

Now we're done with the music expression explicitly created in voice "foo"

5 engrave d''8 -- and since we have a voice "foo", just keep on with it.
6 engrave e''8
7 engrave f''8
8 engrave g''8


In contrast, we have Example 2+1 Note:
%%% 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 %%%


Looking at this in music stream order we have

1.  engrave c'8.  Oops, we don't have a Voice context to engrave c'8.
Therefore we need to create a Voice context for c'8.  And since we don't
have a Staff to hold the Voice, we'll need to create a Staff context as
well.
2a. create a new Voice context called foo, and assign the next expression
   to voice foo. (no musical time)
2b. engrave g'8 in foo context
3.  engrave a'8 in foo context
4.  engrave b'8 in foo context
5.  engrave c''8 in foo context

Now I'm done with the music expression that was assigned to Voice foo.

6.  engrave d''8.  It goes in the Voice context that we were using
   before we created "foo" and assigned the music expression to "foo".
   The Voice context is an anonymous, automatically instantiated Voice.
7.  engrave e''8
8.  engrave f''8
9.  engrave g''8

Regarding the difference between \new Voice="foo" and \context Voice="foo":
\new Voice = "foo" instantiates Voice "foo".  \context Voice="foo" switches
to Voice "foo" and only instantiates if no Voice "foo" exists.

HTH,

Carl





reply via email to

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