Sha256: 00fb1367614c2bc483dca664ae2b827cad8b370ee72beb15ca1b8bcda156bf4b

Contents?: true

Size: 1.05 KB

Versions: 2

Compression:

Stored size: 1.05 KB

Contents

require "optparse"
require "mml2wav/version"
require "mml2wav/wave"

module Mml2wav
  class Command
    def self.run(arguments)
      new(arguments).run
    end

    def initialize(arguments)
      @options = parse_options(arguments)
      @sounds = ARGF.readlines.join(" ")
    end

    def run
      Wave.write(@sounds, @options)
    end

    private
    def parse_options(arguments)
      options = {}

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

      parser.on("--output=FILE", "Specify output file path") do |path|
        options[:output] = path
      end
      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.parse!(arguments)

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

      options
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mml2wav-0.0.3 lib/mml2wav/command.rb
mml2wav-0.0.2 lib/mml2wav/command.rb