about summary refs log tree commit homepage
path: root/lib/dtas/splitfx.rb
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2024-04-26 07:04:15 +0000
committerEric Wong <e@80x24.org>2024-05-07 08:53:00 +0000
commit196a1f23690ee6d2eecc4ebdc246d7228f202bb6 (patch)
tree328a944ff6d5eab1ff4417e814310447fd8c79df /lib/dtas/splitfx.rb
parentb7e6406f79a1b27e50997e02ef6985ae0a33b14b (diff)
downloaddtas-master.tar.gz
This directive is useful for cutting sections of audio out in
addition to making it easier to share track offsets between
different recordings of the same source.
Diffstat (limited to 'lib/dtas/splitfx.rb')
-rw-r--r--lib/dtas/splitfx.rb20
1 files changed, 17 insertions, 3 deletions
diff --git a/lib/dtas/splitfx.rb b/lib/dtas/splitfx.rb
index 1150ee0..b94f54b 100644
--- a/lib/dtas/splitfx.rb
+++ b/lib/dtas/splitfx.rb
@@ -66,6 +66,7 @@ class DTAS::SplitFX # :nodoc:
   # $CHANNELS (input)
   # $BITS_PER_SAMPLE (input)
   def initialize
+    @tshift = 0
     @env = {}
     @comments = {}
     @track_start = 1
@@ -290,7 +291,7 @@ class DTAS::SplitFX # :nodoc:
       start_time = argv.shift
       title = argv.shift
       t = T.new
-      t.tbeg = @t2s.call(start_time)
+      t.tbeg = @t2s.call(start_time) + @tshift
       t.comments = @comments.dup
       title.valid_encoding? or warn "#{title.inspect} encoding invalid"
       t.comments["TITLE"] = title
@@ -311,11 +312,24 @@ class DTAS::SplitFX # :nodoc:
 
       prev = @tracks.last and prev.commit(t.tbeg)
       @tracks << t
+    when 'tshift'
+      tshift = argv.shift
+      argv.empty? or raise ArgumentError, 'tshift does not take extra args'
+      if tshift.sub!(/\A-=/, '')
+        @tshift = @tshift - @t2s.call(tshift)
+      elsif tshift.sub!(/\A\+=/, '')
+        @tshift = @tshift + @t2s.call(tshift)
+      elsif tshift.sub!(/\A-/, '')
+        @tshift = -@t2s.call(tshift)
+      else
+        tshift.sub!(/\A\+/, '')
+        @tshift = @t2s.call(tshift)
+      end
     when "skip"
       stop_time = argv.shift
       argv.empty? or raise ArgumentError, "skip does not take extra args"
       s = Skip.new
-      s.tbeg = @t2s.call(stop_time)
+      s.tbeg = @t2s.call(stop_time) + @tshift
       # s.comments = {}
       # s.env = {}
       prev = @tracks.last or raise ArgumentError, "no tracks to skip"
@@ -324,7 +338,7 @@ class DTAS::SplitFX # :nodoc:
     when "stop"
       stop_time = argv.shift
       argv.empty? or raise ArgumentError, "stop does not take extra args"
-      samples = @t2s.call(stop_time)
+      samples = @t2s.call(stop_time) + @tshift
       prev = @tracks.last and prev.commit(samples)
     else
       raise ArgumentError, "unknown command: #{xs(cmd)}"