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, stretch = false, pan = 50) ⇒ Fragment

Returns a new instance of Fragment.



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

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

  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

#panObject (readonly)

Returns the value of attribute pan.



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

def pan
  @pan
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

#clone(&block) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/scissor/fragment.rb', line 61

def clone(&block)
  attributes = {
    :filename => filename,
    :start    => start,
    :duration => original_duration,
    :reverse  => reversed?,
    :pitch    => pitch,
    :stretch  => stretched?,
    :pan      => pan
  }

  if block_given?
    block.call(attributes)
  end

  self.class.new(
    attributes[:filename],
    attributes[:start],
    attributes[:duration],
    attributes[:reverse],
    attributes[:pitch],
    attributes[:stretch],
    attributes[:pan]
  )
end

#create(remaining_start, remaining_length) ⇒ Object



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 35

def create(remaining_start, remaining_length)
  if remaining_start >= duration
    return [nil, remaining_start - duration, remaining_length]
  end

  have_remain_to_return = (remaining_start + remaining_length) >= duration

  if have_remain_to_return
    new_length = duration - remaining_start
    remaining_length -= new_length
  else
    new_length = remaining_length
    remaining_length = 0
  end

  new_fragment = clone do |attributes|
    attributes.update(
      :start    =>  start + remaining_start * pitch.to_f / 100,
      :duration =>  new_length * pitch.to_f / 100,
      :reverse  => false
      )
  end

  return [new_fragment, 0, remaining_length]
end

#durationObject



19
20
21
# File 'lib/scissor/fragment.rb', line 19

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

#original_durationObject



23
24
25
# File 'lib/scissor/fragment.rb', line 23

def original_duration
  @duration
end

#reversed?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/scissor/fragment.rb', line 27

def reversed?
  @reverse
end

#stretched?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/scissor/fragment.rb', line 31

def stretched?
  @is_stretched
end