The Dal Segno and Da Capo are two very commonly used musical terms. They mean "from the sign" (đť„‹) and "from the beginning" respectively.
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."
Description
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.
Input
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
a
,b
,c
,d
,e
,f
, org
, with an optional#
orb
appended (for the purposes of this challenge, there is no rhythm).A
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.An
S
(capital s) represents a signo marking. There will always be either zero or one signo marking(s).An
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 fine
s or multipleal coda
s in a piece.
Output
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.
Test cases
In: a# bb c b a
Out: a# bb c b a
In: a S b D.S. al fine c
Out: a b b c
In: a S b C c D.S. al coda d C e
Out: a b c b e
In: a b F c d D.C. al fine e f
Out: a b c d a b
In: a b D.C. al fine c d F e f
Out: a b a b c d
In: a b C c d D.C. al coda e f C g g#
Out: a b c d a b g g#
In: a b D.C. al coda c d C e f C g g#
Out: a b a b c d g g#
In: a b S c d C D.C. al coda C D.S. al fine e f F g
Out: a b c d a b c d c d e f
In: a S b C c D.S. al coda C d D.S. al fine e F f
Out: a b c b d b c d e
In: a b C c d D.C. al coda e f F g g# C gb a# D.C. al fine
Out: a b c d a b gb a# a b c d e f
In: a F b C D.C. al coda C D.C. al fine
Out: a b a b a
In: C a S b D.C. al coda C c D.S. al fine d
Out: a b c b c d
In: a S b D.S. al coda C C c D.C. al fine
Out: a b b c a b c
In: a F C b C D.C. al coda D.C. al fine
Out: a b a a
Rules
The markings will always appear in a logical order. That is, there will never be an
S
after aD.S.
and there will always be one before, etc.This is code-golf, so the shortest code in bytes will win.