Repeat alternative count

classic Classic list List threaded Threaded
18 messages Options
Reply | Threaded
Open this post in threaded view
|

Repeat alternative count

Dan Eble
Is there a use case for specifying the number of times to reuse a repeat alternative in a way that \unfoldRepeats could honor?  Right now, it reuses the first alternative enough times to reach the repeat count.  If so, does anyone want to suggest a syntax?  Here's my entry.

    \repeat volta 40 {
      …
    } \alternative {
      { … }
      \repeat alternative 3 { … }
      { … }
    }

Good? Bad? Meh?

Dan


Reply | Threaded
Open this post in threaded view
|

Re: Repeat alternative count

Benkő Pál
\alternative volta 3 { ... } ?

Dan Eble <[hidden email]> ezt írta (időpont: 2020. aug. 29., Szo, 15:37):

>
> Is there a use case for specifying the number of times to reuse a repeat alternative in a way that \unfoldRepeats could honor?  Right now, it reuses the first alternative enough times to reach the repeat count.  If so, does anyone want to suggest a syntax?  Here's my entry.
>
>     \repeat volta 40 {
>       …
>     } \alternative {
>       { … }
>       \repeat alternative 3 { … }
>       { … }
>     }
>
> Good? Bad? Meh?
> —
> Dan
>
>

Reply | Threaded
Open this post in threaded view
|

Re: Repeat alternative count

Aaron Hill
In reply to this post by Dan Eble
On 2020-08-29 6:37 am, Dan Eble wrote:

> Is there a use case for specifying the number of times to reuse a
> repeat alternative in a way that \unfoldRepeats could honor?  Right
> now, it reuses the first alternative enough times to reach the repeat
> count.  If so, does anyone want to suggest a syntax?  Here's my entry.
>
>     \repeat volta 40 {
>       …
>     } \alternative {
>       { … }
>       \repeat alternative 3 { … }
>       { … }
>     }
>
> Good? Bad? Meh?

What would be nice is to have a way to semantically indicate precisely
when and how many times an alternative is used.

Consider a case when you have a first ending that would be labelled
"1.3." and a second ending that is labelled "2.4.5.".  Currently, this
can be done using custom repeat commands but \unfoldRepeats does not
know how to parse the volta text and produce the right expansion.

Perhaps:

%%%%
\repeat volta 5 {
   ...
}
\alternative 1,3 {
   ...
}
\alternative 2,4,5 {
   ...
}
%%%%


-- Aaron Hill

Reply | Threaded
Open this post in threaded view
|

Re: Repeat alternative count

Kieren MacMillan
Hi all,

> On Aug 29, 2020, at 10:00 AM, Aaron Hill <[hidden email]> wrote:
>
> %%%%
> \repeat volta 5 {
>  ...
> }
> \alternative 1,3 {
>  ...
> }
> \alternative 2,4,5 {
>  ...
> }
> %%%%

That's pretty nice.

K.
________________________________

Kieren MacMillan, composer (he/him/his)
‣ website: www.kierenmacmillan.info
‣ email: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: Repeat alternative count

Dan Eble
On Aug 29, 2020, at 10:06, Kieren MacMillan <[hidden email]> wrote:

>
> Hi all,
>
>> On Aug 29, 2020, at 10:00 AM, Aaron Hill <[hidden email]> wrote:
>>
>> %%%%
>> \repeat volta 5 {
>> ...
>> }
>> \alternative 1,3 {
>> ...
>> }
>> \alternative 2,4,5 {
>> ...
>> }
>> %%%%
>
> That's pretty nice.
>
> K.

Considering trying not to stray too far from the current syntax, what's your opinion of this?

    \repeat volta 5 {
      …
    } \alternative {
      \volta 1,3 { … }
      \volta 2,4,5 { … }
    }

Would you mind being limited to all-or-none use of \volta within a given \alternative{}?

Even with \volta on all elements, would you want to be able to leave some volta numbers implied, or would you prefer to have LilyPond draw your attention to the omission?  Example:

    \repeat volta 10 {
      …
    } \alternative {
      \volta 1,3,9 { … } % 1, 3-4, 9-10
      \volta 2,5 { … }   % 2, 5-8
    }

Regards,

Dan


Reply | Threaded
Open this post in threaded view
|

Re: Repeat alternative count

Aaron Hill
On 2020-08-29 9:02 am, Dan Eble wrote:

> On Aug 29, 2020, at 10:06, Kieren MacMillan
> <[hidden email]> wrote:
>>
>> Hi all,
>>
>>> On Aug 29, 2020, at 10:00 AM, Aaron Hill <[hidden email]>
>>> wrote:
>>>
>>> %%%%
>>> \repeat volta 5 {
>>> ...
>>> }
>>> \alternative 1,3 {
>>> ...
>>> }
>>> \alternative 2,4,5 {
>>> ...
>>> }
>>> %%%%
>>
>> That's pretty nice.
>>
>> K.
>
> Considering trying not to stray too far from the current syntax,
> what's your opinion of this?
>
>     \repeat volta 5 {
>       …
>     } \alternative {
>       \volta 1,3 { … }
>       \volta 2,4,5 { … }
>     }

Ah, of course.  I forget that \alternative only occurs once and has
nested music inside it.  If it were called \alternatives (plural), I'd
probably get it right for once.


> Would you mind being limited to all-or-none use of \volta within a
> given \alternative{}?

If the number list for the \volta command were optional, then perhaps
{...} could be treated as \volta {...}.  In that way, existing usage
maps to the new syntax without needing any conversion/translation.

Defining the semantics of an empty number list could be tricky, but the
goal is to mimic existing behavior for compatibility.


> Even with \volta on all elements, would you want to be able to leave
> some volta numbers implied, or would you prefer to have LilyPond draw
> your attention to the omission?  Example:
>
>     \repeat volta 10 {
>       …
>     } \alternative {
>       \volta 1,3,9 { … } % 1, 3-4, 9-10
>       \volta 2,5 { … }   % 2, 5-8
>     }

That usage makes sense to me.  And I think implied occurrences would be
desirable since a number list does not make it easy to specify ranges.


-- Aaron Hill

Reply | Threaded
Open this post in threaded view
|

Re: Repeat alternative count

David Kastrup
In reply to this post by Dan Eble
Dan Eble <[hidden email]> writes:

> Is there a use case for specifying the number of times to reuse a repeat alternative in a way that \unfoldRepeats could honor?  Right now, it reuses the first alternative enough times to reach the repeat count.  If so, does anyone want to suggest a syntax?  Here's my entry.
>
>     \repeat volta 40 {
>       …
>     } \alternative {
>       { … }
>       \repeat alternative 3 { … }
>       { … }
>     }
>
> Good? Bad? Meh?

My own take on it is that \alternative syntax is an abomination and it
should likely be more like

\repeat volta 40 {
  ...
  \alternative { ... }
  \alternative { ... }
  \alternative { ... }
}

since that would avoid several syntactical problems and would allow to
produce alternatives by music functions.

So if we are going to start phantasizing, that would be an approach I'd
prefer to start out from.

--
David Kastrup

Reply | Threaded
Open this post in threaded view
|

Re: Repeat alternative count

Dan Eble
On Aug 29, 2020, at 14:52, David Kastrup <[hidden email]> wrote:

>
> My own take on it is that \alternative syntax is an abomination and it
> should likely be more like
>
> \repeat volta 40 {
>  ...
>  \alternative { ... }
>  \alternative { ... }
>  \alternative { ... }
> }
>
> since that would avoid several syntactical problems and would allow to
> produce alternatives by music functions.

I agree, but that's a little too far into fantasy land for me to attempt right now.  The other stuff proposed so far seems more attainable.

I've been intending to ask you how difficult you think it would be to make the parser treat \alternative as a music function whenever it does not follow a \repeat {}?  I've gotten \alternative << >> working to my satisfaction, but I did it by requiring the << >> in the parser.  I think it would be nicer if something like

    \repeat volta 2 {
      ...notes...
      \alternative M
      ...notes...
    }

would call a music function with argument M.

Dan


Reply | Threaded
Open this post in threaded view
|

Re: Repeat alternative count

David Kastrup
Dan Eble <[hidden email]> writes:

> On Aug 29, 2020, at 14:52, David Kastrup <[hidden email]> wrote:
>>
>> My own take on it is that \alternative syntax is an abomination and it
>> should likely be more like
>>
>> \repeat volta 40 {
>>  ...
>>  \alternative { ... }
>>  \alternative { ... }
>>  \alternative { ... }
>> }
>>
>> since that would avoid several syntactical problems and would allow to
>> produce alternatives by music functions.
>
> I agree, but that's a little too far into fantasy land for me to attempt right now.  The other stuff proposed so far seems more attainable.
>
> I've been intending to ask you how difficult you think it would be to
> make the parser treat \alternative as a music function whenever it
> does not follow a \repeat {}?

I don't think that makes sense.  I'd just remove \alternative as a
reserved word from the parser altogether, give it a music type
representation, and then let some cleanup function put the bits
together (if equivalence in music expressions is wanted, but I am not
sure of that actually).

> I've gotten \alternative << >> working to my satisfaction, but I did
> it by requiring the << >> in the parser.  I think it would be nicer if
> something like
>
>     \repeat volta 2 {
>       ...notes...
>       \alternative M
>       ...notes...
>     }
>
> would call a music function with argument M.

Sure, that should be feasible with an optional argument of type
index-list? or similar.

--
David Kastrup

Reply | Threaded
Open this post in threaded view
|

Re: Repeat alternative count

Christopher Heckman
In reply to this post by Dan Eble
On Sat, Aug 29, 2020 at 9:00 AM <[hidden email]> wrote:

>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Sat, 29 Aug 2020 07:00:17 -0700
> From: Aaron Hill <[hidden email]>
> To: [hidden email]
> Subject: Re: Repeat alternative count
> Message-ID: <[hidden email]>
> Content-Type: text/plain; charset=UTF-8; format=flowed
>
> On 2020-08-29 6:37 am, Dan Eble wrote:
> > Is there a use case for specifying the number of times to reuse a
> > repeat alternative in a way that \unfoldRepeats could honor?  Right
> > now, it reuses the first alternative enough times to reach the repeat
> > count.  If so, does anyone want to suggest a syntax?  Here's my entry.
> >
> >     \repeat volta 40 {
> >       …
> >     } \alternative {
> >       { … }
> >       \repeat alternative 3 { … }
> >       { … }
> >     }
> >
> > Good? Bad? Meh?
>
> What would be nice is to have a way to semantically indicate precisely
> when and how many times an alternative is used.
>
> Consider a case when you have a first ending that would be labelled
> "1.3." and a second ending that is labelled "2.4.5.".  Currently, this
> can be done using custom repeat commands but \unfoldRepeats does not
> know how to parse the volta text and produce the right expansion.
>
> Perhaps:
>
> %%%%
> \repeat volta 5 {
>    ...
> }
> \alternative 1,3 {
>    ...
> }
> \alternative 2,4,5 {
>    ...
> }
> %%%%
>
>
> -- Aaron Hill

That would break too many things, since \alternative takes a sequence
of SequentialMusic's as an argument.

How about allowing modifying the syntax of \alternative to include the
possibility of a number, which means to repeat that ending? This would
look like

\alternative {
  { c1 }
  1
  { d1 }
  1
   }

Which would be interpretted as: the 1st, 2nd, and 4th endings are c,
and the 3nd  ending is d.

Obviously, something like \alternative { 1 ... } would be illegal, although
\alternative { 2 { ... } } might be acceptable.

As a bonus, maybe Lilypond could automatically typeset the repeat
numbers based on the \alternative structure? In the example above, we
would have something that looks like

_||__1, 2, 4.___:||__3.___:||__

((A few minutes later)) Those repeat signs might make things a bit
difficult. Perhaps we could include \start-repeat to print a ||: and
\end-repeat to print a :|| ... so that the example above would look
more like

\alternative {
  { c1 \end-repeat }
  1
  { d1 }
  1
   }

to get the following instead:

_||__1, 2, 4.___:||__3.___||__

--- Christopher Heckman

Reply | Threaded
Open this post in threaded view
|

Re: Repeat alternative count

Dan Eble
In reply to this post by Dan Eble
On Aug 29, 2020, at 15:50, Dan Eble <[hidden email]> wrote:

>
> On Aug 29, 2020, at 14:52, David Kastrup <[hidden email]> wrote:
>>
>> \repeat volta 40 {
>> ...
>> \alternative { ... }
>> \alternative { ... }
>> \alternative { ... }
>> }
>>
>> since that would avoid several syntactical problems and would allow to
>> produce alternatives by music functions.
>
> I agree, but that's a little too far into fantasy land for me to attempt right now.

After further thought, I believe we can do this, but using \volta where you have \alternative.  These are my current thoughts (some informed by experiment).

\volta i,j,k can be used anywhere and is semantically similar to tags.  During unfolding, music is kept which is either marked for the current volta or is unmarked.  An important difference from tags is that unfolding will avoid processing nested repeats before their time.

If you write { \volta 6,12 {…} … \volta 12,13,5 {…} }, LilyPond will give you what you seem to be asking for, in repeat layout, unfolded layout, and in midi, and not try to make more sense of it than is necessary.

\alternative remains (but at some point is renamed \alternatives) for these reasons at least:

a. backward compatibility: the legacy syntax produces the same data structures as if \volta had been used

b. it provides a scope in which LilyPond can derive implied volta numbers as previously discussed in this thread

c. like (b), it might be helpful for producing brackets (but I haven't thought much about it yet)

Dan


Reply | Threaded
Open this post in threaded view
|

Re: Repeat alternative count

David Kastrup
Dan Eble <[hidden email]> writes:

> After further thought, I believe we can do this, but using \volta
> where you have \alternative.  These are my current thoughts (some
> informed by experiment).
>
> \volta i,j,k can be used anywhere and is semantically similar to tags.
> During unfolding, music is kept which is either marked for the current
> volta or is unmarked.  An important difference from tags is that
> unfolding will avoid processing nested repeats before their time.
>
> If you write { \volta 6,12 {…} … \volta 12,13,5 {…} }, LilyPond will
> give you what you seem to be asking for, in repeat layout, unfolded
> layout, and in midi, and not try to make more sense of it than is
> necessary.
>
> \alternative remains (but at some point is renamed \alternatives) for
> these reasons at least:
>
> a. backward compatibility: the legacy syntax produces the same data
> structures as if \volta had been used
>
> b. it provides a scope in which LilyPond can derive implied volta
> numbers as previously discussed in this thread
>
> c. like (b), it might be helpful for producing brackets (but I haven't
> thought much about it yet)

The reason I want to lose it is that most constructs of the form

\prefix ... { ... }

do not require further lookahead to resolve.  That's important in
several respect, such like writing

music = \prefix ... { ... }

\music

\alternative is one ugly wart in that respect.  \addlyrics is another.
Either cause a fair share of headaches whenever there is a change in the
parser.

Also, \alternative is basically the only construct I know that has
{ sequence of music expressions } mean something different from, well, a
sequential music expression.  There have been several cases of people
getting tripped up when forgetting to add inner braces.

Also when the included expressions become longer, the readability for
humans goes down the drain since the individual alternatives are not
separated by anything other than } { or similar.

\volta (?) would be able to take an _optional_ number list if we are
reasonably sure that this is all we need.

Usually prettier alternatives can come with a backward compatibility
hook (though their lifetime tends to be semi-eternal).  But in this case
the ugliness does not just extend to the input, but also to the input
processing.

--
David Kastrup

Reply | Threaded
Open this post in threaded view
|

Re: Repeat alternative count

David Kastrup
In reply to this post by Christopher Heckman
Christopher Heckman <[hidden email]> writes:

> How about allowing modifying the syntax of \alternative to include the
> possibility of a number, which means to repeat that ending? This would
> look like
>
> \alternative {
>   { c1 }
>   1
>   { d1 }
>   1
>    }
>
> Which would be interpretted as: the 1st, 2nd, and 4th endings are c,
> and the 3nd  ending is d.

That is already valid syntax and makes the first and second alternative
c1 and the third and fourth alternative d1 .

Extending LilyPond syntax is not really a matter of arbitrarily
inventing something: a lot of stuff is already taken.

--
David Kastrup

Reply | Threaded
Open this post in threaded view
|

Re: Repeat alternative count

Christopher Heckman
On Sun, Aug 30, 2020 at 11:59 AM David Kastrup <[hidden email]> wrote:

>
> Christopher Heckman <[hidden email]> writes:
>
> > How about allowing modifying the syntax of \alternative to include the
> > possibility of a number, which means to repeat that ending? This would
> > look like
> >
> > \alternative {
> >   { c1 }
> >   1
> >   { d1 }
> >   1
> >    }
> >
> > Which would be interpretted as: the 1st, 2nd, and 4th endings are c,
> > and the 3nd  ending is d.
>
> That is already valid syntax and makes the first and second alternative
> c1 and the third and fourth alternative d1 .
>
> Extending LilyPond syntax is not really a matter of arbitrarily
> inventing something: a lot of stuff is already taken.
>
> --
> David Kastrup

If Lilypond already does this, it ought to be documented. (It isn't,
not on the website anyway.)

--- Christopher Heckman

Reply | Threaded
Open this post in threaded view
|

Re: Repeat alternative count

Werner LEMBERG

>> > \alternative {
>> >   { c1 }
>> >   1
>> >   { d1 }
>> >   1
>> >    }
>> >
>> > Which would be interpretted as: the 1st, 2nd, and 4th endings are c,
>> > and the 3nd  ending is d.
>>
>> That is already valid syntax and makes the first and second
>> alternative c1 and the third and fourth alternative d1 .
>
> If Lilypond already does this, it ought to be documented. (It isn't,
> not on the website anyway.)

Nothing to be documented IMHO: Since 2.20 you can use '1' to
repeat the same pitch with the given rythm.


    Werner

Reply | Threaded
Open this post in threaded view
|

Re: Repeat alternative count

Christopher Heckman
On Sun, Aug 30, 2020 at 10:34 PM Werner LEMBERG <[hidden email]> wrote:

>
>
> >> > \alternative {
> >> >   { c1 }
> >> >   1
> >> >   { d1 }
> >> >   1
> >> >    }
> >> >
> >> > Which would be interpretted as: the 1st, 2nd, and 4th endings are c,
> >> > and the 3nd  ending is d.
> >>
> >> That is already valid syntax and makes the first and second
> >> alternative c1 and the third and fourth alternative d1 .
> >
> > If Lilypond already does this, it ought to be documented. (It isn't,
> > not on the website anyway.)
>
> Nothing to be documented IMHO: Since 2.20 you can use '1' to
> repeat the same pitch with the given rhythm.
>
>     Werner

Ah. I heard about this feature, but didn't know whether it got added
officially yet.

So maybe what we need is something like a new macro like "\redo"

\alternative {
   { c1 }
   \redo 1
   { d1 }
   \redo 1
   \redo 3
    }

... although I'm starting to wonder whether the number should refer to
the index of the music sequence, and not the iteration at which it
appears.  (You'd have "\redo 2" instead of "\redo 3" in the example
above.) Otherwise you could conceivably have constructions like

\alternative { { c1 } \redo 1 \redo 1 ... \redo 1 { d1 } \redo 1 \redo x }

and you have to count the \redo's to figure out what x is. Whereas, if
the items in \alternatiave's argument that are \redo's are removed,
you get the list

{ { c1 }  { d1 } }

and you would know that x = 2 (instead of something like x = 8).

--- Christopher Heckman

Reply | Threaded
Open this post in threaded view
|

Re: Repeat alternative count

David Kastrup
In reply to this post by Christopher Heckman
Christopher Heckman <[hidden email]> writes:

> On Sun, Aug 30, 2020 at 11:59 AM David Kastrup <[hidden email]> wrote:
>>
>> Christopher Heckman <[hidden email]> writes:
>>
>> > How about allowing modifying the syntax of \alternative to include the
>> > possibility of a number, which means to repeat that ending? This would
>> > look like
>> >
>> > \alternative {
>> >   { c1 }
>> >   1
>> >   { d1 }
>> >   1
>> >    }
>> >
>> > Which would be interpretted as: the 1st, 2nd, and 4th endings are c,
>> > and the 3nd  ending is d.
>>
>> That is already valid syntax and makes the first and second alternative
>> c1 and the third and fourth alternative d1 .
>>
>> Extending LilyPond syntax is not really a matter of arbitrarily
>> inventing something: a lot of stuff is already taken.
>>
>> --
>> David Kastrup
>
> If Lilypond already does this, it ought to be documented. (It isn't,
> not on the website anyway.)

It does something entirely different.  If it sees an isolated duration
in a sequential music expression, it creates a note event taking the
pitch from the previous note.

That is documented.

--
David Kastrup

Reply | Threaded
Open this post in threaded view
|

Re: Repeat alternative count

Dan Eble
In reply to this post by Aaron Hill
On Aug 29, 2020, at 13:34, Aaron Hill <[hidden email]> wrote:

>
> On 2020-08-29 9:02 am, Dan Eble wrote:
>> On Aug 29, 2020, at 10:06, Kieren MacMillan
>> <[hidden email]> wrote:
>>> Hi all,
>>>> On Aug 29, 2020, at 10:00 AM, Aaron Hill <[hidden email]> wrote:
>>>> %%%%
>>>> \repeat volta 5 {
>>>> ...
>>>> }
>>>> \alternative 1,3 {
>>>> ...
>>>> }
>>>> \alternative 2,4,5 {
>>>> ...
>>>> }
>>>> %%%%
>>> That's pretty nice.
>>> K.
>> Considering trying not to stray too far from the current syntax,
>> what's your opinion of this?
>>    \repeat volta 5 {
>>      …
>>    } \alternative {
>>      \volta 1,3 { … }
>>      \volta 2,4,5 { … }
>>    }
>
> Ah, of course.  I forget that \alternative only occurs once and has nested music inside it.  If it were called \alternatives (plural), I'd probably get it right for once.

You might be interested in the proposed \volta regression tests at https://gitlab.com/lilypond/lilypond/-/merge_requests/386#note_408536934 .  Use within \alternative{} seems to work fine, but there are some rough edges in other cases.

Dan