#!/usr/bin/env ruby
start_time = Time.now
$:.unshift File.dirname(__FILE__) + "/.."
require "optparse"
require "yaml"
require "lib/beats"
def parse_options
options = {:split => false, :pattern => nil}
optparse = OptionParser.new do |opts|
opts.on('-s', '--split', "Save each track to an individual wave file") do
options[:split] = true
end
opts.on('-p', '--pattern PATTERN_NAME', "Output a single pattern instead of the whole song" ) do |p|
options[:pattern] = p
end
opts.on('-v', '--version', "Display version number and exit") do
puts "BEATS v#{Beats::VERSION}"
exit
end
opts.on( '-h', '--help', "Display this screen and exit" ) do
puts opts
exit
end
end
optparse.parse!
return options
end
options = parse_options
input_file_name = ARGV[0]
output_file_name = ARGV[1]
beats = Beats.new(input_file_name, output_file_name, options)
begin
output = beats.run()
duration = output[:duration]
puts "#{duration[:minutes]}:#{duration[:seconds].to_s.rjust(2, '0')} of audio written in #{Time.now - start_time} seconds."
rescue Errno::ENOENT => detail
puts "\n"
puts "Song file '#{input_file_name}' not found.\n"
puts "\n"
rescue SongParseError => detail
puts "\n"
puts "Song file '#{input_file_name}' has an error:\n"
puts " #{detail}\n"
puts "\n"
rescue StandardError => detail
puts "\n"
puts "An error occured while generating sound for '#{input_file_name}':\n"
puts " #{detail}\n"
puts "\n"
end