Sha256: 2e6d7e4f328f2df08fcdc06c968864170e5a6c1e53372d15a3167fe0381a9ac8
Contents?: true
Size: 1.67 KB
Versions: 2
Compression:
Stored size: 1.67 KB
Contents
#!/usr/bin/env ruby exe_name = File.basename(__FILE__) doc = <<DOCOPT Loads a music-transcription score from YAML file, and converts to MIDI file. Usage: #{exe_name} <input> [PART PROGRAM] ... #{exe_name} <input> <output> [PART PROGRAM] ... #{exe_name} -h | --help #{exe_name} --version Arguments: input A music-transcription score file in YAML format output Midi filename PART name of a part in the score PROGRAM MIDI program (instrument) number for the given part Options: -h --help Show this screen. --version Show version. DOCOPT require 'docopt' begin require "pp" args = Docopt::docopt(doc) pp args rescue Docopt::Exit => e puts e.message exit end require 'yaml' require 'music-transcription' require 'music-performance' include Music fin_name = args["<input>"] File.open(fin_name) do |fin| print "Reading file '#{fin_name}'..." score = YAML.load(fin.read) if score.is_a? Hash score = Transcription::Score.unpack(score) end puts "complete" if score.valid? part_names = args["PART"] program_nums = args["PROGRAM"].map {|str| str.to_i } instr_map = Hash[[part_names,program_nums].transpose] print "Making MIDI sequence..." seq = Performance::ScoreSequencer.new(score).make_midi_seq(instr_map) puts "complete" fout_name = args["<output>"] if fout_name.nil? fout_name = "#{File.dirname(fin_name)}/#{File.basename(fin_name,File.extname(fin_name))}.mid" end print "Writing file '#{fout_name}'..." File.open(fout_name, 'wb'){ |fout| seq.write(fout) } puts "complete" else puts "Failed to load a valid score." puts "Errors:" puts score.errors.join("\n") end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
music-performance-0.4.2 | bin/midify |
music-performance-0.4.1 | bin/midify |