about summary refs log tree commit homepage
path: root/lib/dtas/source/av_ff_common.rb
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2015-01-28 07:44:05 +0000
committerEric Wong <e@80x24.org>2015-01-28 07:47:57 +0000
commit37eae22446feb5a805d9cd59f6ad54362829189f (patch)
tree50172ce0b549fb9a0eae1e2e0b4d6bc47bc3a8d6 /lib/dtas/source/av_ff_common.rb
parentead7725fa693c7dd832b22f77b32847c81a70d72 (diff)
downloaddtas-37eae22446feb5a805d9cd59f6ad54362829189f.tar.gz
This feature is intended to allow users to "zoom-in" on a
particular portion of a track to tweak parameters (either
with dtas-sourceedit(1) or via playback of splitfx YAML files).
This may be combined with looping the tracklist
(via "tl repeat").
Diffstat (limited to 'lib/dtas/source/av_ff_common.rb')
-rw-r--r--lib/dtas/source/av_ff_common.rb25
1 files changed, 18 insertions, 7 deletions
diff --git a/lib/dtas/source/av_ff_common.rb b/lib/dtas/source/av_ff_common.rb
index 03526d2..189e135 100644
--- a/lib/dtas/source/av_ff_common.rb
+++ b/lib/dtas/source/av_ff_common.rb
@@ -19,8 +19,8 @@ module DTAS::Source::AvFfCommon # :nodoc:
   attr_reader :precision # always 32
   attr_reader :format
 
-  def try(infile, offset = nil)
-    rv = source_file_dup(infile, offset)
+  def try(infile, offset = nil, trim = nil)
+    rv = source_file_dup(infile, offset, trim)
     rv.av_ff_ok? or return
     rv
   end
@@ -101,10 +101,20 @@ module DTAS::Source::AvFfCommon # :nodoc:
     ! @astreams.compact.empty?
   end
 
-  def sspos(offset)
-    offset =~ /\A(\d+)s\z/ or return "-ss #{offset}"
-    samples = $1.to_f
-    sprintf("-ss %0.9g", samples / @format.rate)
+  def sspos
+    return unless @offset || @trim
+    off = offset_samples / @format.rate.to_f
+    sprintf('-ss %0.9g', off)
+  end
+
+  def av_ff_trimfx # for sox
+    return unless @trim
+    tbeg, tlen = @trim # Floats
+    tend = tbeg + tlen
+    off = offset_samples / @format.rate.to_f
+    tlen = tend - off
+    tlen = 0 if tlen < 0
+    sprintf('trim 0 %0.9g', tlen)
   end
 
   def select_astream(as)
@@ -150,8 +160,9 @@ module DTAS::Source::AvFfCommon # :nodoc:
     # make sure these are visible to the source command...
     e["INFILE"] = @infile
     e["AMAP"] = amap
-    e["SSPOS"] = @offset ? sspos(@offset) : nil
+    e["SSPOS"] = sspos
     e["RGFX"] = rg_state.effect(self) || nil
+    e["TRIMFX"] = av_ff_trimfx
     e.merge!(@rg.to_env) if @rg
 
     @pid = dtas_spawn(e, command_string, opts)