lib/scissor/chunk.rb in youpy-scissor-0.0.15 vs lib/scissor/chunk.rb in youpy-scissor-0.0.16

- old
+ new

@@ -19,11 +19,11 @@ @logger = Logger.new(STDOUT) @logger.level = Logger::INFO if filename @fragments << Fragment.new( - Pathname.new(filename), + filename, 0, SoundFile.new(filename).length) end end @@ -41,50 +41,49 @@ if start + length > duration raise OutOfDuration end new_instance = self.class.new - remain = length + remaining_start = start.to_f + remaining_length = length.to_f @fragments.each do |fragment| - if start >= fragment.duration - start -= fragment.duration + new_fragment, remaining_start, remaining_length = + fragment.create(remaining_start, remaining_length) - next + if new_fragment + new_instance.add_fragment(new_fragment) end - if (start + remain) <= fragment.duration - new_instance.add_fragment(Fragment.new( - fragment.filename, - fragment.start + start, - remain, - fragment.reversed?)) - + if remaining_length == 0 break - else - remain = remain - (fragment.duration - start) - new_instance.add_fragment(Fragment.new( - fragment.filename, - fragment.start + start, - fragment.duration - start, - fragment.reversed?)) - - start = 0 end end new_instance end + alias [] slice + def concat(other) other.fragments.each do |fragment| add_fragment(fragment) end self end - alias + concat + alias << concat + + def +(other) + new_instance = Scissor() + + (@fragments + other.fragments).each do |fragment| + new_instance.add_fragment(fragment) + end + + new_instance + end def loop(count) orig_fragments = @fragments.clone (count - 1).times do