23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/transcore/command/transpose.rb', line 23
def self.run(argv, input_stream = $stdin, output_stream = $stdout)
step = (argv.shift || 1).to_i
input = input_stream.read
input.gsub!(/ /, ' ')
input.gsub!(/ +$/, '')
input.gsub!(/(^|\s|\/|on)([ACDFG])#/, '\\1\\2#')
input.gsub!(/(^|\s|\/|on)A♭/, '\\1G#')
input.gsub!(/(^|\s|\/|on)B♭/, '\\1A#')
input.gsub!(/(^|\s|\/|on)D♭/, '\\1C#')
input.gsub!(/(^|\s|\/|on)E♭/, '\\1D#')
input.gsub!(/(^|\s|\/|on)G♭/, '\\1F#')
step %= 12
rest = input
step.times do |_i|
next_str = ''
while /(^|\s|\/|on)(A#|A|B|C#|C|D#|D|E|F#|F|G#|G)/ =~ rest
next_str += $` + Regexp.last_match[1]
match_str = Regexp.last_match[2]
rest = $'
next_str += NEXT_TONE[match_str]
end
rest = next_str + rest
end
result = rest
output_stream.puts result
0
end
|