Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add Scissor.mix Fixes gh-1

  • Loading branch information...
commit 4cf0f624184a5b8e1e36afa3ad72dbe365619e9e 1 parent c35de61
youpy authored
3  README.rdoc
View
@@ -53,6 +53,9 @@ supported file format:
seq = Scissor.sequence('x y xyz', 0.2)
seq.apply(:x => foo, :y => Proc.new { bar }, :z => foo.reverse) * 4 > 'sequence.wav'
+ # mix
+ Scissor.mix([foo, bar], 'mix.mp3')
+
== Copyright
Author:: youpy <youpy@buycheapviagraonlinenow.com>
12 lib/scissor.rb
View
@@ -39,5 +39,17 @@ def join(scissor_array)
m + scissor
end
end
+
+ def mix(scissor_array, filename, options = {})
+ writer = Scissor::Writer.new
+
+ scissor_array.each do |scissor|
+ writer.add_fragments(scissor.fragments)
+ end
+
+ writer.to_file(filename, options)
+
+ Scissor(filename)
+ end
end
end
4 lib/scissor/writer.rb
View
@@ -46,11 +46,12 @@ def to_file(filename, options)
tmpdir = Pathname.new(dir)
tmpfile = tmpdir + 'tmp.wav'
cmd = %w/ecasound/
+ index = 0
@tracks.each do |fragments|
position = 0.0
- fragments.each_with_index do |fragment, index|
+ fragments.each do |fragment|
fragment_filename = fragment.filename
fragment_duration = fragment.duration
@@ -75,6 +76,7 @@ def to_file(filename, options)
"-o:#{tmpfile} " +
"-y:#{position}"
+ index += 1
position += fragment_duration
end
end
9 spec/scissor_spec.rb
View
@@ -165,6 +165,15 @@
scissor.fragments[0].duration.should eql(120.0)
end
+ it "should mix instances of scissor" do
+ a = @mp3.slice(0, 120)
+ b = @mp3.slice(150, 20)
+
+ scissor = Scissor.mix([a, b], '/tmp/scissor-test/out.mp3')
+ scissor.should be_an_instance_of(Scissor::Chunk)
+ scissor.duration.should eql(120.05875)
+ scissor.fragments.size.should eql(1)
+ end
it "should raise error if replaced range is out of duration" do
lambda {
Please sign in to comment.
Something went wrong with that request. Please try again.