alda-lang / alda

A music programming language for musicians. :notes:
https://alda.io
Eclipse Public License 2.0
5.59k stars 284 forks source link

Alternate play function for nested event sequences #207

Closed elydpg closed 7 years ago

elydpg commented 8 years ago

Often, when I need to repeat using event sequences, there's a phrase I want to play differently the second time around. Take this phrase:

V2: (quant 50) [o4 r4. e4. e8 r8]*2[o4 r4. a-4. a-8 r8]*2[o4 r4. a4. a8 r8]*2[o4 r4. a-4. a-8 r8]*2
V2: [o4 r4. e4. e8 r8]*2[o4 r4. a-4. a-8 r8]*2[o4 r4. a4. a8 r8]*2 r1 o4 r4. a-4. a-8 r8

It is almost identical except for a small section. This feature would allow it to be compressed to something like this:

V2: (quant 50) [[o4 r4. e4. e8 r8]*2[o4 r4. a-4. a-8 r8]*2[o4 r4. a4. a8 r8]*2[o4 r4. a-4. a-8 r8]*2'0[r1 o4 r4. a-4. a-8 r8]'2]*2

The 'n would indicate which time around the phrase would be played, with '0 indicating the default phrase to play.

I'm not sure if this would be too confusing but it would allow for interesting sequences. Thoughts?

daveyarwood commented 8 years ago

I like it. That would give us a way to do first/second endings in Alda scores.

We could be more flexible about it, though, like you could just have arbitrary notes/sequences within a sequence (and not necessarily at the end) that can be different depending on what time through you're playing.

elydpg commented 8 years ago

of course. You could do something like

[o4 c d [e f]'0[f e]'4 g [a b > c]'0[> c < b > c]'2]*4

Which would change the phrase depending on which iteration it's in. Each group would have a default and optional overriders. The above statement would be the equivalent of

o4 c d e f g a b > c
o4 c d e f g > c < b > c
o4 c d e f g a b > c
o4 c d f e g a b > c

One problem would arise if the alternate options were different lengths than the default. You might get some weird out-of-sync rhythm stuff, though it might be desirable for the alternates to be different lengths; albeit confusing.

daveyarwood commented 8 years ago

One problem would arise if the alternate options were different lengths than the default. You might get some weird out-of-sync rhythm stuff, though it might be desirable for the alternates to be different lengths; albeit confusing.

I think it would be in the "spirit of Alda" to leave it up to the composer to manage keeping each phrase the same length if desired. Markers could also be used to line things back up if needed.

The '0 syntax is convenient, but I find it slightly confusing. What if instead, the composer had to specify exactly which times each phrase would happen? I think making it more explicit would lead to more readable scores. Compare this with your example above:

[o4 c d [e f]'1-3 [f e]'4 g [a b > c]'1,3-4 [> c < b > c]'2]*4

It would be easier to implement this way, and less potential for parser bugs, but I also think it's nice from a readability standpoint. What do you think?

elydpg commented 8 years ago

I thought about something like that, but I wasn't really sure about a way to implement the whole x-y thing. firstly re-using - is not desirable (though we'd have to do it for negative ^ transpositions anyway). More importantly, it can get confusing with longer repetition cycles. Suppose, for example, a composer wanted to repeat the phrase 8 times, with an alternate part on times 2,3,5,and 7. With your syntax, they'd have to do this:

[c d [e f]'1[f e]'2-3[e f]'4[f e]'5[e f]'6[f e]'7[e f]'8 g a b > c]

But with my syntax, they could do this:

[c d [e f]'0[f e]'2[f e]'3[f e]'5[f e]'7 g a b > c]

Of course, there's no reason why we can't support both:

[c d [e f]'0[f e]'2-3[f e]'5[f e]'7 g a b > c]

Duplicate numbers might be a problem though.

[c d [e f]'0[f e]'2-5[e f]'4[f e]'7 g a b > c]
daveyarwood commented 8 years ago

I think reusing - should be fine from a parsing standpoint.

We can use commas to separate spaced-out iterations like in your example:

[c d [e f]'1,4,6,8 [f e]'2,3,5,7 g a b > c] *8

I find this the most readable, personally. It's the most similar to the kinds of "first/second ending" type repeats that you see in sheet music.

elydpg commented 8 years ago

Yeah. I think the problem here is for cases like this:

[c d e f g [a b > c]'1,2,3,4,5,6,7,8,9,10,11,12,13,14,15[> c < b > c]'16]*16

This is where a default would come in handy.

daveyarwood commented 8 years ago

For that, you could use -:

[c d e f g [a b > c]'1-15 [> c < b > c]'16]*16
elydpg commented 8 years ago

Yeah. Duplicate numbers would still be an issue, though the parser could always check for them by replacing them with the comma-ed list internally.

daveyarwood commented 7 years ago

Moved to https://github.com/alda-lang/alda-core/issues/17.