From 2907cc6dd0b0d2d80d44ae292a157651d6e05ee7 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 26 Aug 2013 05:25:22 +0000 Subject: player: flesh out multi-source in protocol/sourceedit We should be fully-capable of managing any number of options to try sources in. --- lib/dtas/source/av.rb | 8 ++++++-- lib/dtas/source/file.rb | 27 +++++++++++++++++++++++++-- lib/dtas/source/sox.rb | 9 ++++++--- 3 files changed, 37 insertions(+), 7 deletions(-) (limited to 'lib/dtas/source') diff --git a/lib/dtas/source/av.rb b/lib/dtas/source/av.rb index a6a0e3a..61d88b2 100644 --- a/lib/dtas/source/av.rb +++ b/lib/dtas/source/av.rb @@ -17,6 +17,7 @@ class DTAS::Source::Av # :nodoc: "command" => 'avconv -v error $SSPOS -i "$INFILE" $AMAP -f sox - |' \ 'sox -p $SOXFMT - $RGFX', + "tryorder" => 1, ) attr_reader :precision # always 32 @@ -28,8 +29,7 @@ class DTAS::Source::Av # :nodoc: end def try(infile, offset = nil) - rv = dup - rv.source_file_init(infile, offset) + rv = source_file_dup(infile, offset) rv.av_ok? or return rv end @@ -133,4 +133,8 @@ class DTAS::Source::Av # :nodoc: def to_hsh to_hash.delete_if { |k,v| v == AV_DEFAULTS[k] } end + + def source_defaults + AV_DEFAULTS + end end diff --git a/lib/dtas/source/file.rb b/lib/dtas/source/file.rb index a66308b..3663d8d 100644 --- a/lib/dtas/source/file.rb +++ b/lib/dtas/source/file.rb @@ -10,6 +10,7 @@ require_relative '../process' module DTAS::Source::File # :nodoc: attr_reader :infile attr_reader :offset + attr_accessor :tryorder require_relative 'common' # dtas/source/common require_relative 'mp3gain' include DTAS::Command @@ -17,9 +18,17 @@ module DTAS::Source::File # :nodoc: include DTAS::Source::Common include DTAS::Source::Mp3gain - FILE_SIVS = %w(infile comments command env) + FILE_SIVS = %w(infile comments command env) # for the "current" command + SRC_SIVS = %w(command env tryorder) - def source_file_init(infile, offset) + def source_file_dup(infile, offset) + rv = dup + rv.__file_init(infile, offset) + rv + end + + def __file_init(infile, offset) + @env = @env.dup @format = nil @infile = infile @offset = offset @@ -68,4 +77,18 @@ module DTAS::Source::File # :nodoc: DTAS::ReplayGain.new(mp3gain_comments) end + def to_source_cat + ivars_to_hash(SRC_SIVS) + end + + def load!(src_hsh) + SRC_SIVS.each do |field| + val = src_hsh[field] and instance_variable_set("@#{field}", val) + end + end + + def to_state_hash + defaults = source_defaults # see dtas/source/{av,sox}.rb + to_source_cat.delete_if { |k,v| v == defaults[k] } + end end diff --git a/lib/dtas/source/sox.rb b/lib/dtas/source/sox.rb index fa6192d..e1baee9 100644 --- a/lib/dtas/source/sox.rb +++ b/lib/dtas/source/sox.rb @@ -13,6 +13,7 @@ class DTAS::Source::Sox # :nodoc: SOX_DEFAULTS = COMMAND_DEFAULTS.merge( "command" => 'exec sox "$INFILE" $SOXFMT - $TRIMFX $RGFX', + "tryorder" => 0, ) def initialize @@ -23,9 +24,7 @@ class DTAS::Source::Sox # :nodoc: err = "" qx(@env, %W(soxi #{infile}), err_str: err, no_raise: true) return if err =~ /soxi FAIL formats:/ - rv = dup - rv.source_file_init(infile, offset) - rv + source_file_dup(infile, offset) end def precision @@ -100,4 +99,8 @@ class DTAS::Source::Sox # :nodoc: def to_hsh to_hash.delete_if { |k,v| v == SOX_DEFAULTS[k] } end + + def source_defaults + SOX_DEFAULTS + end end -- cgit v1.2.3-24-ge0c7