From 22d62a37c510737f5c46bd507c1e09cbbe52eb36 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 3 Jan 2015 01:33:52 +0000 Subject: dtas-splitfx: use the top-level command used by -player If somebody is using dtas-player to help edit a file for dtas-splitfx, it is likely they will want to use it when generating the final files (regardless of "target" format). --- lib/dtas/splitfx.rb | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/lib/dtas/splitfx.rb b/lib/dtas/splitfx.rb index e31972a..dac2a97 100644 --- a/lib/dtas/splitfx.rb +++ b/lib/dtas/splitfx.rb @@ -78,6 +78,7 @@ class DTAS::SplitFX # :nodoc: @tracks = [] @infmt = nil # wait until input is assigned @cuebp = nil # for playback + @command = nil # top-level, for playback end def _bool(hash, key) @@ -134,6 +135,7 @@ class DTAS::SplitFX # :nodoc: load_input!(hash) load_tracks!(hash) + @command = hash["command"] # nil by default end def load_input!(hash) @@ -193,10 +195,23 @@ class DTAS::SplitFX # :nodoc: env.merge!(t.env) command = target["command"] - tmp = Shellwords.split(command).map do |arg| - qx(env, "printf %s \"#{arg}\"") + + # if a default dtas-player command is set, use that. + # we'll clobber our default environment since we assume play_cmd + # already takes those into account. In other words, use our + # target-specific commands like a dtas-player sink: + # @command | (INFILE= FX= TRIMFX=; target['command']) + if player_cmd = @command + sub_env = { 'INFILE' => '-', 'FX' => '', 'TRIMFX' => '' } + sub_env_s = sub_env.inject("") { |s,(k,v)| s << "#{k}=#{v} " } + command = "#{player_cmd} | (#{sub_env_s}; #{command})" + show_cmd = [ _expand_cmd(env, player_cmd), '|', '(', "#{sub_env_s};", + _expand_cmd(env.merge(sub_env), command), ')' ].flatten + else + show_cmd = _expand_cmd(env, command) end - echo = "echo #{xs(tmp)}" + + echo = "echo #{xs(show_cmd)}" if opts[:dryrun] command = echo else @@ -347,4 +362,10 @@ class DTAS::SplitFX # :nodoc: env["INFILE"] = infile env["INDIR"], env["INBASE"] = File.split(File.expand_path(infile)) end + + def _expand_cmd(env, command) + Shellwords.split(command).map do |arg| + qx(env, "printf %s \"#{arg}\"") + end + end end -- cgit v1.2.3-24-ge0c7