Skip to content
Browse files

add Scissor::Tape#pan

  • Loading branch information...
1 parent 92877ca commit 4cf15d062eca65a23e1ea5233dadbf38b735cc03 @youpy committed Nov 20, 2012
Showing with 43 additions and 5 deletions.
  1. +5 −3 lib/scissor/fragment.rb
  2. +21 −2 lib/scissor/tape.rb
  3. +4 −0 lib/scissor/writer.rb
  4. +6 −0 spec/fragment_spec.rb
  5. +7 −0 spec/scissor_spec.rb
View
8 lib/scissor/fragment.rb
@@ -2,15 +2,16 @@
module Scissor
class Fragment
- attr_reader :filename, :start, :pitch
+ attr_reader :filename, :start, :pitch, :pan
- def initialize(filename, start, duration, reverse = false, pitch = 100, stretch = false)
+ 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
@@ -52,7 +53,8 @@ def create(remaining_start, remaining_length)
new_length * pitch.to_f / 100,
false,
pitch,
- stretched?)
+ stretched?,
+ pan)
return [new_fragment, 0, remaining_length]
end
View
23 lib/scissor/tape.rb
@@ -176,7 +176,8 @@ def reverse
fragment.original_duration,
!fragment.reversed?,
fragment.pitch,
- fragment.stretched?))
+ fragment.stretched?,
+ fragment.pan))
end
new_instance
@@ -192,7 +193,8 @@ def pitch(pitch, stretch = false)
fragment.original_duration,
fragment.reversed?,
fragment.pitch * (pitch.to_f / 100),
- stretch))
+ stretch,
+ fragment.pan))
end
new_instance
@@ -203,6 +205,23 @@ def stretch(factor)
pitch(factor_for_pitch, true)
end
+ 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))
+ end
+
+ new_instance
+ end
+
def to_file(filename, options = {})
Scissor.mix([self], filename, options)
end
View
4 lib/scissor/writer.rb
@@ -49,6 +49,10 @@ def join_fragments(fragments, outfile, tmpdir)
cmd << "-a:#{index} -o:#{outfile} -y:#{position}#{is_mono[fragment_filename] ? ' -chcopy:1,2' : ''}"
+ if fragment.pan != 50
+ cmd << "-epp:%i" % fragment.pan
+ end
+
if fragment.stretched? && fragment.pitch.to_f != 100.0
rubberband_out = tmpdir + (Digest::MD5.hexdigest(fragment_filename.to_s) + "rubberband_#{index}.wav")
rubberband_temp = tmpdir + "_rubberband.wav"
View
6 spec/fragment_spec.rb
@@ -37,6 +37,12 @@
fragment.duration.should eql(21.0)
end
+ it "should have a pan" do
+ fragment = Scissor::Fragment.new(fixture('sample.mp3'), 5, 10.5, false, 50, false, 10)
+
+ fragment.pan.should eql(10)
+ end
+
it "should return new fragment and remaining start point and length" do
new_fragment, remaining_start, remaining_length = @fragment.create(0.5, 1.0)
new_fragment.filename.should eql(fixture('sample.mp3'))
View
7 spec/scissor_spec.rb
@@ -212,6 +212,13 @@
scissor.fragments.first.should be_stretched
end
+ it "should pan" do
+ scissor = @mp3.slice(0, 10) + @mp3.slice(0, 5)
+
+ scissor.pan(10).fragments[0].pan.should eql(10)
+ scissor.pan(10).pan(10).fragments[0].pan.should eql(10)
+ end
+
it "should join instances of scissor" do
a = @mp3.slice(0, 120)
b = @mp3.slice(150, 20)

0 comments on commit 4cf15d0

Please sign in to comment.
Something went wrong with that request. Please try again.