lib/midi_lyrics.rb in midi_lyrics-0.0.7 vs lib/midi_lyrics.rb in midi_lyrics-0.0.8

- old
+ new

@@ -27,11 +27,11 @@ def duration format_time(duration_in_pulses) end def blank? - text.strip == "" + text.gsub('-', '').strip == "" end def similar_to?(another) self.duration_in_pulses == another.duration_in_pulses && self.text == another.text end @@ -107,16 +107,16 @@ def load_lyrics @lyrics = [] @lyrics_track.each do |event| event_text = event.data.collect{|x| x.chr(Encoding::UTF_8)}.join - letters = event_text.gsub(/^\s+|\s+$/, '') + letters = event_text.gsub(/^[\s-]+|[\s-]+$/, '') - heading_space = event_text.match(/^(\s+)[^\s]/) + heading_space = event_text.match(/^([\s-]+)[^[\s-]]/) heading_space = heading_space[1] unless heading_space.nil? - trailing_space = event_text.match(/(\s+)$/) + trailing_space = event_text.match(/([\s-]+)$/) trailing_space = trailing_space[1] unless trailing_space.nil? [heading_space, letters, trailing_space].each do |text| unless text.nil? @lyrics << LyricSyllable.new( @@ -129,35 +129,40 @@ end end end def remove_heading_blank_lines - while @lyrics.first.text.strip == "" + while @lyrics.first.blank? @lyrics.shift end end def consolidate_empty_syllables new_lyrics = [] @lyrics.each do |l| if l.blank? - if new_lyrics.last.blank? - new_lyrics.last.text += l.text - else - l.start_in_pulses = new_lyrics.last.start_in_pulses + new_lyrics.last.duration_in_pulses - l.duration_in_pulses = 0.0 - new_lyrics << l - end + # if new_lyrics.last + if new_lyrics.last.blank? + new_lyrics.last.text += l.text + else + l.start_in_pulses = new_lyrics.last.start_in_pulses + new_lyrics.last.duration_in_pulses + l.duration_in_pulses = 0.0 + new_lyrics << l + end + # else + # l.duration_in_pulses = 0.0 + # new_lyrics << l + # end else new_lyrics << l end end @lyrics = new_lyrics end def remove_lines_trailing_spaces @lyrics.each do |l| - l.text.gsub!(/^ ([\r\n])/, '\1') + l.text.gsub!(/^[ -]*([\r\n])/, '\1') end end def half_is_equal half = @lyrics.count / 2