lib/mml2wav/wave.rb in mml2wav-0.0.2 vs lib/mml2wav/wave.rb in mml2wav-0.0.3

- old
+ new

@@ -7,33 +7,31 @@ include WaveFile def write(sounds, options={}) output_path = options[:output] || "doremi.wav" sampling_rate = options[:sampling_rate] || 22050 - bpm = options[:bpm] || 60 + bpm = options[:bpm] || 120 velocity = 5 octave = 4 default_length = 4.0 format = Format.new(:mono, :pcm_8, sampling_rate) Writer.new(output_path, format) do |writer| buffer_format = Format.new(:mono, :float, sampling_rate) - sounds.scan(/T\d+|V\d+|L\d+|[A-G][#+]?(?:\d+|\.)?|O\d+|[><]|./i).each do |sound| - base_sec = 60.0 + sounds.scan(/T\d+|V\d+|L\d+|[A-G][#+-]?\d*\.?|O\d+|[><]|./i).each do |sound| + base_sec = 60.0 * 4 length = default_length case sound when /\AT(\d+)/i bpm = $1.to_i when /\AV(\d+)/i velocity = $1.to_i when /\AL(\d+)/i default_length = $1.to_f - when /\A([A-G][#+]?)(\d+)/i + when /\A([A-G][#+-]?)(\d+)(\.)?/i length = $2.to_f sound = $1 - when /\A([A-G][#+]?)(\.)/i - length = default_length / 1.5 - sound = $1 + length = default_length / 1.5 if $3 when /\AO(\d+)/i octave = $1.to_i when "<" octave += 1 when ">"