From 37eae22446feb5a805d9cd59f6ad54362829189f Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 28 Jan 2015 07:44:05 +0000 Subject: player: support the "trim" parameter 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"). --- lib/dtas/source/file.rb | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'lib/dtas/source/file.rb') diff --git a/lib/dtas/source/file.rb b/lib/dtas/source/file.rb index 8a9fa34..75b4a43 100644 --- a/lib/dtas/source/file.rb +++ b/lib/dtas/source/file.rb @@ -21,17 +21,18 @@ module DTAS::Source::File # :nodoc: FILE_SIVS = %w(infile comments command env) # for the "current" command SRC_SIVS = %w(command env tryorder) - def source_file_dup(infile, offset) + def source_file_dup(infile, offset, trim) rv = dup - rv.__file_init(infile, offset) + rv.__file_init(infile, offset, trim) rv end - def __file_init(infile, offset) + def __file_init(infile, offset, trim) @env = @env.dup @format = nil @infile = infile @offset = offset + @trim = trim @comments = nil @samples = nil @cuebp = nil @@ -47,6 +48,13 @@ module DTAS::Source::File # :nodoc: # returns any offset in samples (relative to the original source file), # likely zero unless seek was used def offset_samples + off = __offset_samples + return off unless @trim + tbeg = @trim[0] * format.rate + tbeg < off ? off : tbeg + end + + def __offset_samples return 0 unless @offset case @offset when /\A\d+s\z/ @@ -56,6 +64,16 @@ module DTAS::Source::File # :nodoc: end end + # creates the effect to fill the TRIMFX env + def trimfx + return unless @offset || @trim + fx = "trim #{offset_samples}s" + if @trim && @trim[1] + fx << sprintf(' =%0.9gs', (@trim[0] + @trim[1]) * format.rate) + end + fx + end + # A user may be downloading the file and start playing # it before the download completes, this refreshes def samples! -- cgit v1.2.3-24-ge0c7