Class: Scissor::Fragment

Inherits:
Object
  • Object
show all
Defined in:
lib/scissor/fragment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, start, duration, reverse = false, pitch = 100) ⇒ Fragment

Returns a new instance of Fragment.



7
8
9
10
11
12
13
14
15
# File 'lib/scissor/fragment.rb', line 7

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

  freeze
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



5
6
7
# File 'lib/scissor/fragment.rb', line 5

def filename
  @filename
end

#pitchObject (readonly)

Returns the value of attribute pitch.



5
6
7
# File 'lib/scissor/fragment.rb', line 5

def pitch
  @pitch
end

#startObject (readonly)

Returns the value of attribute start.



5
6
7
# File 'lib/scissor/fragment.rb', line 5

def start
  @start
end

Instance Method Details

#create(remaining_start, remaining_length) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/scissor/fragment.rb', line 29

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

#durationObject



17
18
19
# File 'lib/scissor/fragment.rb', line 17

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

#reversed?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/scissor/fragment.rb', line 25

def reversed?
  @reverse
end

#true_durationObject



21
22
23
# File 'lib/scissor/fragment.rb', line 21

def true_duration
  @duration
end