RegEx/ANSI/Note.regex.txt

# Matches an ANSI VT520 Note
\e # An Escape
\[ # Followed by a bracket
(?>
  (?<Volume>(?<VolumeOff>0) # 0 is no volume
    |
    (?<VolumeLow>[1-3]) # 1-3 is low volume
    |
    (?<VolumeHigh>[4-7]) # 4-7 is high volume
))\; # A semicolon separated the volume from the duration
# Duration is measured in 1/32 of a second
(?<Duration>\d+)\; # A semicolon separates the duration from the note
# One or more notes will follow
(?<Notes>(?:(?>
  (?<C7>25) # 25 is C in the 7th octave (MIDI 96)
  |
  (?<B6>24) # 24 is B in the 6th octave (MIDI 95)
  |
  (?<ASharp6>23) # 23 is A Sharp in the 6th octave (MIDI 94)
  |
  (?<A6>22) # 22 is A in the 6th octave (MIDI 93)
  |
  (?<GSharp6>21) # 21 is G Sharp in the 6th octave (MIDI 92)
  |
  (?<G6>20) # 20 is G in the 6th octave (MIDI 91)
  |
  (?<FSharp6>19) # 19 is F Sharp in the 6th octave (MIDI 90)
  |
  (?<F6>18) # 18 is F in the 6th octave (MIDI 89)
  |
  (?<E6>17) # 17 is E in the 6th octave (MIDI 88)
  |
  (?<DSharp6>16) # 16 is D Sharp in the 6th octave (MIDI 87)
  |
  (?<D6>15) # 15 is D in the 6th octave (MIDI 86)
  |
  (?<CSharp6>14) # 14 is C Sharp in the 6th octave (MIDI 85)
  |
  (?<C6>13) # 13 is C in the 6th octave (MIDI 84)
  |
  (?<B5>12) # 12 is B in the 5th octave (MIDI 83)
  |
  (?<ASharp5>11) # 11 is A Sharp in the 5th octave (MIDI 82)
  |
  (?<A5>10) # 10 is A in the 5th octave (MIDI 81)
  |
  (?<GSharp5>9) # 9 is G Sharp in the 5th octave (MIDI 80)
  |
  (?<G5>8) # 8 is G in the 5th octave (MIDI 79)
  |
  (?<FSharp5>7) # 7 is F Sharp in the 5th octave (MIDI 78)
  |
  (?<F5>6) # 6 is F in the 5th octave (MIDI 77)
  |
  (?<E5>5) # 5 is E in the 5th octave (MIDI 76)
  |
  (?<DSharp5>4) # 4 is D Sharp in the 5th octave (MIDI 75)
  |
  (?<D5>3) # 3 is D in the 5th octave (MIDI 74)
  |
  (?<CSharp5>2) # 2 is C Sharp in the 5th octave (MIDI 73)
  |
  (?<C5>1) # 1 is C in the 5th octave (MIDI 72)
  |
  (?<Rest>0) # 0 is a rest
)\;?){0,}),~ # A command and a tilda end the sequence