Class: Scissor::Fragment
- Inherits:
-
Object
- Object
- Scissor::Fragment
- Defined in:
- lib/scissor/fragment.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#pan ⇒ Object
readonly
Returns the value of attribute pan.
-
#pitch ⇒ Object
readonly
Returns the value of attribute pitch.
-
#start ⇒ Object
readonly
Returns the value of attribute start.
Instance Method Summary collapse
- #clone(&block) ⇒ Object
- #create(remaining_start, remaining_length) ⇒ Object
- #duration ⇒ Object
-
#initialize(filename, start, duration, reverse = false, pitch = 100, stretch = false, pan = 50) ⇒ Fragment
constructor
A new instance of Fragment.
- #original_duration ⇒ Object
- #reversed? ⇒ Boolean
- #stretched? ⇒ Boolean
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
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
5 6 7 |
# File 'lib/scissor/fragment.rb', line 5 def filename @filename end |
#pan ⇒ Object (readonly)
Returns the value of attribute pan.
5 6 7 |
# File 'lib/scissor/fragment.rb', line 5 def pan @pan end |
#pitch ⇒ Object (readonly)
Returns the value of attribute pitch.
5 6 7 |
# File 'lib/scissor/fragment.rb', line 5 def pitch @pitch end |
#start ⇒ Object (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 |
#duration ⇒ Object
19 20 21 |
# File 'lib/scissor/fragment.rb', line 19 def duration @duration * (100 / pitch.to_f) end |
#original_duration ⇒ Object
23 24 25 |
# File 'lib/scissor/fragment.rb', line 23 def original_duration @duration end |
#reversed? ⇒ Boolean
27 28 29 |
# File 'lib/scissor/fragment.rb', line 27 def reversed? @reverse end |
#stretched? ⇒ Boolean
31 32 33 |
# File 'lib/scissor/fragment.rb', line 31 def stretched? @is_stretched end |