There is also the idea of the coda (𝄌), which is the very end of a piece of music. It's what's played after the "main section" of the piece.
A D.S. al coda (Dal Segno al coda), for example, means "go to the segno, play until you're told to go to the coda, and then jump there."
Your job in this challenge is to take input composed of any number of notes which may or may not contain Dal Segnos and Da Capos and output the same music with the aforementioned jumps "unfolded" so that the repetitions are expanded out verbatim.
Your code should take as input a sequence of either notes or signals (here defined as anything but a note), separated by spaces in one string.
Notes are any of
g, with an optional
bappended (for the purposes of this challenge, there is no rhythm).
C(capital c) represents a coda marking. There will always be either zero or two coda markings; the first coda marking represents where to jump from, and the second represents where to jump to.
S(capital s) represents a signo marking. There will always be either zero or one signo marking(s).
F(capital f) represents a fine marking. This "overrides" the end of the piece—more on that below. There will always be either zero or one fine marking(s).
Any of the following exact strings of text represent:
D.S. al fine: go to the signo and play until either the end of the piece or the fine marking (if it exists).
D.S. al coda: go to the signo, play until the coda, then jump to the second coda marking and play until the end of the piece.
D.C. al fine: go to the beginning, play until the end or the fine marking.
D.C. al coda: go to the beginning, play until the coda, then jump to the second coda marking and play until the end of the piece.
There will always be a minimum of zero and a maximum of one of each string per piece. There will never be multiple
al fines or multiple
al codas in a piece.
Your code should output in a similar string format: a list of notes, separated by spaces.
You may always assume that the output will end up being one or more characters long.
a# bb c b a
a# bb c b a
a S b D.S. al fine c
a b b c
a S b C c D.S. al coda d C e
a b c b e
a b F c d D.C. al fine e f
a b c d a b
a b D.C. al fine c d F e f
a b a b c d
a b C c d D.C. al coda e f C g g#
a b c d a b g g#
a b D.C. al coda c d C e f C g g#
a b a b c d g g#
a b S c d C D.C. al coda C D.S. al fine e f F g
a b c d a b c d c d e f
a S b C c D.S. al coda C d D.S. al fine e F f
a b c b d b c d e
a b C c d D.C. al coda e f F g g# C gb a# D.C. al fine
a b c d a b gb a# a b c d e f
a F b C D.C. al coda C D.C. al fine
a b a b a
C a S b D.C. al coda C c D.S. al fine d
a b c b c d
a S b D.S. al coda C C c D.C. al fine
a b b c a b c
a F C b C D.C. al coda D.C. al fine
a b a a
The markings will always appear in a logical order. That is, there will never be an
D.S.and there will always be one before, etc.
This is code-golf, so the shortest code in bytes will win.