class Rhythmmml::Command

Public Class Methods

new(arguments) click to toggle source
# File lib/rhythmmml/command.rb, line 11
def initialize(arguments)
  options = parse_options(arguments)
  mml = ARGF.readlines.join.split(/,/).first
  @game = Game.new(mml, options)
end
run(arguments) click to toggle source
# File lib/rhythmmml/command.rb, line 7
def self.run(arguments)
  new(arguments).run
end

Public Instance Methods

run() click to toggle source
# File lib/rhythmmml/command.rb, line 17
def run
  @game.show
end

Private Instance Methods

parse_options(arguments) click to toggle source
# File lib/rhythmmml/command.rb, line 22
def parse_options(arguments)
  options = {}

  parser = OptionParser.new("#{$0} INPUT_FILE")
  parser.version = VERSION

  parser.on("--sampling_rate=RATE",
            "Specify sampling rate", Integer) do |rate|
    options[:sampling_rate] = rate
  end
  parser.on("--bpm=BPM",
            "Specify BPM (beats per minute)", Integer) do |bpm|
    options[:bpm] = bpm
  end
  parser.on("--octave_reverse",
            "Reverse octave sign (><) effects") do |boolean|
    options[:octave_reverse] = boolean
  end
  # TODO: support stereo
  #parser.on("--channel_delimiter=DELIMITER",
  #          "Specify channel delimiter") do |delimiter|
  #  options[:channel_delimiter] = delimiter
  #end
  parser.parse!(arguments)

  unless File.pipe?('/dev/stdin') || IO.select([ARGF], nil, nil, 0)
    puts(parser.help)
    exit(true)
  end

  options
end