module Transcore::Command::Transpose

Constants

NEXT_TONE

Public Class Methods

parse_opts(_argv) click to toggle source
# File lib/transcore/command/transpose.rb, line 19
def self.parse_opts(_argv)
  {}
end
run(argv, input_stream = $stdin, output_stream = $stdout) click to toggle source
# 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