youpy-scissor 0.0.15 → 0.0.16

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -37,13 +37,13 @@ supported file format:
37
37
  foo + bar > 'foobar.mp3'
38
38
 
39
39
  # slice + concat
40
- (foo.slice(10, 1) + bar.slice(2, 3)).to_file('slicefoobar.mp3')
40
+ foo[10, 1] + bar.slice[2, 3] > 'slicefoobar.mp3'
41
41
 
42
42
  # slice + concat + loop
43
- ((foo.slice(10, 1) + bar.slice(2, 3)) * 4).to_file('slicefoobarloop.mp3')
43
+ foo[10, 1] + bar[2, 3] * 4 > 'slicefoobarloop.mp3'
44
44
 
45
45
  # split
46
- (Scissor.new('sequence.mp3') / 16).first.to_file('split.mp3')
46
+ (Scissor('sequence.mp3') / 16).first.to_file('split.mp3')
47
47
 
48
48
  # replace first 10 seconds with 30 seconds of silence
49
49
  foo.replace(0, 10, Scissor.silence(30)).to_file('replace.mp3')
data/Rakefile CHANGED
@@ -17,7 +17,7 @@ DESCRIPTION = "utility to chop sound files"
17
17
  RUBYFORGE_PROJECT = "scissor"
18
18
  HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
19
19
  BIN_FILES = %w( )
20
- VERS = "0.0.15"
20
+ VERS = "0.0.16"
21
21
 
22
22
  REV = File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
23
23
  CLEAN.include ['**/.*.sw?', '*.gem', '.config']
data/lib/scissor/chunk.rb CHANGED
@@ -21,7 +21,7 @@ module Scissor
21
21
 
22
22
  if filename
23
23
  @fragments << Fragment.new(
24
- Pathname.new(filename),
24
+ filename,
25
25
  0,
26
26
  SoundFile.new(filename).length)
27
27
  end
@@ -43,38 +43,27 @@ module Scissor
43
43
  end
44
44
 
45
45
  new_instance = self.class.new
46
- remain = length
46
+ remaining_start = start.to_f
47
+ remaining_length = length.to_f
47
48
 
48
49
  @fragments.each do |fragment|
49
- if start >= fragment.duration
50
- start -= fragment.duration
50
+ new_fragment, remaining_start, remaining_length =
51
+ fragment.create(remaining_start, remaining_length)
51
52
 
52
- next
53
+ if new_fragment
54
+ new_instance.add_fragment(new_fragment)
53
55
  end
54
56
 
55
- if (start + remain) <= fragment.duration
56
- new_instance.add_fragment(Fragment.new(
57
- fragment.filename,
58
- fragment.start + start,
59
- remain,
60
- fragment.reversed?))
61
-
57
+ if remaining_length == 0
62
58
  break
63
- else
64
- remain = remain - (fragment.duration - start)
65
- new_instance.add_fragment(Fragment.new(
66
- fragment.filename,
67
- fragment.start + start,
68
- fragment.duration - start,
69
- fragment.reversed?))
70
-
71
- start = 0
72
59
  end
73
60
  end
74
61
 
75
62
  new_instance
76
63
  end
77
64
 
65
+ alias [] slice
66
+
78
67
  def concat(other)
79
68
  other.fragments.each do |fragment|
80
69
  add_fragment(fragment)
@@ -83,7 +72,17 @@ module Scissor
83
72
  self
84
73
  end
85
74
 
86
- alias + concat
75
+ alias << concat
76
+
77
+ def +(other)
78
+ new_instance = Scissor()
79
+
80
+ (@fragments + other.fragments).each do |fragment|
81
+ new_instance.add_fragment(fragment)
82
+ end
83
+
84
+ new_instance
85
+ end
87
86
 
88
87
  def loop(count)
89
88
  orig_fragments = @fragments.clone
@@ -1,9 +1,11 @@
1
+ require 'pathname'
2
+
1
3
  module Scissor
2
4
  class Fragment
3
5
  attr_reader :filename, :start, :duration
4
6
 
5
7
  def initialize(filename, start, duration, reverse = false)
6
- @filename = filename
8
+ @filename = Pathname.new(filename)
7
9
  @start = start
8
10
  @duration = duration
9
11
  @reverse = reverse
@@ -14,5 +16,33 @@ module Scissor
14
16
  def reversed?
15
17
  @reverse
16
18
  end
19
+
20
+ def create(remaining_start, remaining_length)
21
+ new_fragment = nil
22
+
23
+ if remaining_start >= duration
24
+ remaining_start -= duration
25
+ else
26
+ if remaining_start + remaining_length >= duration
27
+ new_fragment = self.class.new(
28
+ filename,
29
+ start + remaining_start,
30
+ duration - remaining_start)
31
+
32
+ remaining_length -= (duration - remaining_start)
33
+ remaining_start = 0
34
+ else
35
+ new_fragment = self.class.new(
36
+ filename,
37
+ start + remaining_start,
38
+ remaining_length)
39
+
40
+ remaining_start = 0
41
+ remaining_length = 0
42
+ end
43
+ end
44
+
45
+ return new_fragment, remaining_start, remaining_length
46
+ end
17
47
  end
18
48
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: youpy-scissor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.15
4
+ version: 0.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - youpy
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-06 00:00:00 -07:00
12
+ date: 2009-04-08 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency