alda-lang / alda

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

Repetition variations don't behave well in a sequence containing repeats #401

Open daveyarwood opened 3 years ago

daveyarwood commented 3 years ago

🐞 Bug report 🐞

Description

We are storing a single currentRepetition value (see repeat.go and repetitions.go) and using it to track the current repetition number that we are going through a repeated sequence of events.

However, a repeated sequence can itself contain repeated events, and the nesting can be arbitrarily deep.

I think it would probably make sense to refactor so that instead of a single "current repetition" value, we are working with a stack of "current repetition" values, where we use the topmost one and discard it when we exit the loop.

Steps to Reproduce

Repro case, adapted from the one @wesen provided on Slack:

period = r16
motif = a b c

(tempo! 100)

piano:
  V1: o4 [{motif}8 period period <'2 ]*4

This behaves as expected. The motif is played twice in octave 4, then twice in octave 3, because on the second repetition, the "octave down" event is applied.

period = r16
motif = a b c

(tempo! 100)

piano:
  V1: o4 [{motif}8 period*2 <'2 ]*4

This should behave the same, however the "octave down" event ends up getting applied on every repetition, so we play the motif in octave 4, then 3, then 2, then 1.

Environment

Alda version:

$ alda version
alda 2.0.5
$ alda-player info
alda-player 2.0.5
log path: /home/dave/.cache/alda/logs