Sha256: 6ba776cac43bc6d0b8bf57335ef2f87af33d0850cc7ddab7935181f0fd58261b

Contents?: true

Size: 1.36 KB

Versions: 6

Compression:

Stored size: 1.36 KB

Contents

require 'pathname'

module Scissor
  class Fragment
    attr_reader :filename, :start, :pitch

    def initialize(filename, start, duration, reverse = false, pitch = 100)
      @filename = Pathname.new(filename).realpath
      @start = start
      @duration = duration
      @reverse = reverse
      @pitch = pitch

      freeze
    end

    def duration
      @duration * (100 / pitch.to_f)
    end

    def true_duration
      @duration
    end

    def reversed?
      @reverse
    end

    def create(remaining_start, remaining_length)
      new_fragment = nil

      if remaining_start >= duration
        remaining_start -= duration
      else
        if remaining_start + remaining_length >= duration
          new_fragment = self.class.new(
            filename,
            start + remaining_start * pitch.to_f / 100,
            (duration - remaining_start) * pitch.to_f / 100,
            false,
            pitch)

          remaining_length -= duration - remaining_start
          remaining_start = 0
        else
          new_fragment = self.class.new(
            filename,
            start + remaining_start * pitch.to_f / 100,
            remaining_length * pitch.to_f / 100,
            false,
            pitch)

          remaining_start = 0
          remaining_length = 0
        end
      end

      return new_fragment, remaining_start, remaining_length
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
youpy-scissor-0.0.21 lib/scissor/fragment.rb
scissor-0.0.26 lib/scissor/fragment.rb
scissor-0.0.25 lib/scissor/fragment.rb
scissor-0.0.24 lib/scissor/fragment.rb
scissor-0.0.23 lib/scissor/fragment.rb
scissor-0.0.22 lib/scissor/fragment.rb