From c02f0b8182b35df1a318418bbd0036c00be93b5c Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 19 May 2015 09:14:23 +0000 Subject: source/splitfx: allow watching extra external scripts Since writing nested shell commands inside YAML is subject to all sorts of strange quoting rules, encourage users to rely on external scripts which the YAML file refers to instead. These scripts can be written in any reasonable scripting language capable of executing other commands. This allows transparently monitoring things such as `my-script.rb' in the below example when playing my-splitfx.yml via dtas-player: --------------------- my-splitfx.yml ----------------------- infile: input.flac command: $INDIR/my-script.rb "$INFILE" ... --------------------- my-script.rb -------------------------- #!/usr/bin/ruby require 'shellwords' infile = ARGV.shift ch = %W(sox #{infile} -p).concat((ENV['TRIMFX'] || '').shellsplit) fx = %W(highpass 25 gain 9) l = ch.dup.concat(%W(remix 1v1)).concat(fx).concat(%w(contrast 30)) r = ch.dup.concat(%W(remix 2v1)).concat(fx).concat(%w(contrast 0)) cmd = %W(sox -M |#{l.shelljoin} |#{r.shelljoin}) cmd.concat((ENV['SOXFMT'] || '-p').shellsplit) cmd.concat(%w(- stats)) warn cmd.inspect exec *cmd --- lib/dtas/splitfx.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'lib/dtas/splitfx.rb') diff --git a/lib/dtas/splitfx.rb b/lib/dtas/splitfx.rb index 5a1431a..cc459ae 100644 --- a/lib/dtas/splitfx.rb +++ b/lib/dtas/splitfx.rb @@ -14,7 +14,7 @@ class DTAS::SplitFX # :nodoc: '$TRIMFX $FX $RATEFX $DITHERFX' include DTAS::Process include DTAS::XS - attr_reader :infile, :env + attr_reader :infile, :env, :command class UTrim attr_reader :env, :comments @@ -229,11 +229,11 @@ class DTAS::SplitFX # :nodoc: sub_env_s = sub_env.inject("") { |s,(k,v)| s << "#{k}=#{v} " } env['SOXFMT'] = '-tsox' sub_env['OUTFMT'] = env.delete('OUTFMT') - show_cmd = [ _expand_cmd(env, player_cmd), '|', '(', "#{sub_env_s};", - _expand_cmd(env.merge(sub_env), command), ')' ].flatten + show_cmd = [ expand_cmd(env, player_cmd), '|', '(', "#{sub_env_s};", + expand_cmd(env.merge(sub_env), command), ')' ].flatten command = "#{player_cmd} | (#{sub_env_s}; #{command})" else - show_cmd = _expand_cmd(env, command) + show_cmd = expand_cmd(env, command) end echo = "echo #{xs(show_cmd)}" @@ -397,7 +397,7 @@ class DTAS::SplitFX # :nodoc: env["INBASE"] = xs(base) end - def _expand_cmd(env, command) + def expand_cmd(env, command) Shellwords.split(command).map do |arg| qx(env, "printf %s \"#{arg}\"") end -- cgit v1.2.3-24-ge0c7