Browse files

add Scissor::Fragment#clone

  • Loading branch information...
1 parent 4cf15d0 commit 0561f83eeb88e372d6b6140dff94b383bb47b606 @youpy committed Nov 20, 2012
Showing with 43 additions and 32 deletions.
  1. +33 −8 lib/scissor/fragment.rb
  2. +10 −24 lib/scissor/tape.rb
View
41 lib/scissor/fragment.rb
@@ -47,16 +47,41 @@ def create(remaining_start, remaining_length)
remaining_length = 0
end
- new_fragment = self.class.new(
- filename,
- start + remaining_start * pitch.to_f / 100,
- new_length * pitch.to_f / 100,
- false,
- pitch,
- stretched?,
- pan)
+ 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
+
+ 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
end
end
View
34 lib/scissor/tape.rb
@@ -170,14 +170,9 @@ def reverse
new_instance = self.class.new
@fragments.reverse.each do |fragment|
- new_instance.add_fragment(Fragment.new(
- fragment.filename,
- fragment.start,
- fragment.original_duration,
- !fragment.reversed?,
- fragment.pitch,
- fragment.stretched?,
- fragment.pan))
+ new_instance.add_fragment(fragment.clone do |attributes|
+ attributes[:reverse] = !fragment.reversed?
+ end)
end
new_instance
@@ -187,14 +182,10 @@ def pitch(pitch, stretch = false)
new_instance = self.class.new
@fragments.each do |fragment|
- new_instance.add_fragment(Fragment.new(
- fragment.filename,
- fragment.start,
- fragment.original_duration,
- fragment.reversed?,
- fragment.pitch * (pitch.to_f / 100),
- stretch,
- fragment.pan))
+ new_instance.add_fragment(fragment.clone do |attributes|
+ attributes[:pitch] = fragment.pitch * (pitch.to_f / 100)
+ attributes[:stretch] = stretch
+ end)
end
new_instance
@@ -209,14 +200,9 @@ def pan(right_percent)
new_instance = self.class.new
@fragments.each do |fragment|
- new_instance.add_fragment(Fragment.new(
- fragment.filename,
- fragment.start,
- fragment.original_duration,
- fragment.reversed?,
- fragment.pitch,
- fragment.stretched?,
- right_percent))
+ new_instance.add_fragment(fragment.clone do |attributes|
+ attributes[:pan] = right_percent
+ end)
end
new_instance

0 comments on commit 0561f83

Please sign in to comment.