everything related to duct tape audio suite (dtas)
 help / color / mirror / Atom feed
From: Eric Wong <e@80x24.org>
To: <dtas-all@nongnu.org>
Cc: Eric Wong <e@80x24.org>
Subject: [PATCH] splitfx: support -O/--outdir switch to control output dir
Date: Sun, 10 May 2015 11:22:56 +0000
Message-ID: <1431256976-18583-1-git-send-email-e@80x24.org> (raw)

It is useful to force output to a writable directory if the YAML
file is on a read-only mount point or to force the output to a
large tmpfs mount point to avoid SSD/HDD wear.
---
 Documentation/dtas-splitfx.txt | 12 +++++++++---
 bin/dtas-splitfx               |  1 +
 lib/dtas/splitfx.rb            | 11 +++++++++--
 3 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/Documentation/dtas-splitfx.txt b/Documentation/dtas-splitfx.txt
index 8e37523..a6a1f7d 100644
--- a/Documentation/dtas-splitfx.txt
+++ b/Documentation/dtas-splitfx.txt
@@ -35,6 +35,12 @@ to use ecasound(1), too.
 :    Disable automatic setting of the DITHERFX env.  This also passes
     the option to sox(1) via SOX_OPTS.
 
+-O, \--outdir OUTDIR
+:    Set output directory instead of current directory.
+    User-created targets must allow a placeholder for the
+    (by default, an empty string) $OUTDIR environment variable
+    in the output command.
+
 # FILE FORMAT
 
 * infile - string, the pathname of the original audio file
@@ -106,7 +112,7 @@ use in targets:
 * TRIMFX - essential, this supplys the necessary sox(1) trim effect to
   each track. In other words, this is: "trim ${TBEG}s ${TLEN}s"
 * COMMENTS - expands to --comment-file=PATH for sox(1)
-* OUTFMT - sox(1) arguments for the output format (e.g. "-ts32 -c2 * -r44100")
+* OUTDIR - placeholder for --outdir, defaults to an empty string
 * SUFFIX - the suffix of the output format without "." (e.g. "flac", "ogg")
 * TRACKNUMBER - the track number, useful for comments and filenames
 * RATEFX - rate effect and arguments for sox(1) resampling
@@ -147,7 +153,7 @@ imbalance in a live concert recording from the audience:
           "|sox $INFILE -c1 -p $TRIMFX remix 1v1 vol +9.5dB"
           "|sox $INFILE -c1 -p $TRIMFX remix 2v1 vol +8.5dB"
           $COMMENTS $OUTFMT
-          bandYYYY-MM-DD.FOO.t0"$TRACKNUMBER.$SUFFIX"
+          ${OUTDIR}bandYYYY-MM-DD.FOO.t0"$TRACKNUMBER.$SUFFIX"
           $RATEFX $DITHERFX stats
         format:
           type: flac
@@ -163,7 +169,7 @@ For reference, the "opusenc" default target is implemented as follows:
            --raw-bits $BITS_PER_SAMPLE
            $OPUSENC_BITRATE --raw-rate $RATE --raw-chan $CHANNELS
            --raw-endianness $ENDIAN_OPUSENC
-           $OPUSENC_COMMENTS - $TRACKNUMBER.opus
+           $OPUSENC_COMMENTS - $OUTDIR$TRACKNUMBER.opus
         format:
           bits: 16
           rate: 48000
diff --git a/bin/dtas-splitfx b/bin/dtas-splitfx
index be12910..b8fc6c8 100755
--- a/bin/dtas-splitfx
+++ b/bin/dtas-splitfx
@@ -14,6 +14,7 @@ OptionParser.new('', 24, '  ') do |op|
   op.on('-j', '--jobs [JOBS]', Integer) { |val| opts[:jobs] = val }
   op.on('-s', '--quiet', '--silent') { |val| opts[:silent] = true }
   op.on('-D', '--no-dither') { |val| opts[:no_dither] = true }
+  op.on('-O', '--outdir OUTDIR') { |val| opts[:outdir] = val }
   op.parse!(ARGV)
 end
 
diff --git a/lib/dtas/splitfx.rb b/lib/dtas/splitfx.rb
index 208ff67..3f673ee 100644
--- a/lib/dtas/splitfx.rb
+++ b/lib/dtas/splitfx.rb
@@ -10,7 +10,7 @@ require 'tempfile'
 # Unlike the stuff for dtas-player, dtas-splitfx is fairly tied to sox
 # (but we may still pipe to ecasound or anything else)
 class DTAS::SplitFX # :nodoc:
-  CMD = 'sox "$INFILE" $COMMENTS $OUTFMT "$TRACKNUMBER.$SUFFIX" '\
+  CMD = 'sox "$INFILE" $COMMENTS $OUTFMT "$OUTDIR$TRACKNUMBER.$SUFFIX" '\
         '$TRIMFX $FX $RATEFX $DITHERFX'
   include DTAS::Process
   include DTAS::XS
@@ -55,6 +55,7 @@ class DTAS::SplitFX # :nodoc:
     @track_zpad = true
     @t2s = method(:t2s)
     @infile = nil
+    @outdir = nil
     @targets = {
       "flac-cdda" => {
         "command" => CMD,
@@ -72,7 +73,7 @@ class DTAS::SplitFX # :nodoc:
            '$OPUSENC_BITRATE --raw-rate $RATE --raw-chan $CHANNELS ' \
            '--raw-endianness $ENDIAN_OPUSENC ' \
            '$OPUSENC_COMMENTS ' \
-           '- $TRACKNUMBER.opus',
+           '- $OUTDIR$TRACKNUMBER.opus',
         "format" => {
           "bits" => 16,
           "rate" => 48000,
@@ -197,6 +198,7 @@ class DTAS::SplitFX # :nodoc:
     infile_env(env, @infile)
     env["OUTFMT"] = xs(outfmt.to_sox_arg)
     env["SUFFIX"] = outfmt.type
+    env["OUTDIR"] = @outdir ? "#@outdir/".squeeze('/') : ''
     env.merge!(t.env)
 
     command = target["command"]
@@ -323,6 +325,11 @@ class DTAS::SplitFX # :nodoc:
   end
 
   def run(target, opts = {})
+    if @outdir = opts[:outdir]
+      require 'fileutils'
+      FileUtils.mkpath(@outdir)
+    end
+
     fails = []
     tracks = @tracks.dup
     pids = {}
-- 
EW



                 reply	other threads:[~2015-05-10 11:23 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://80x24.org/dtas/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1431256976-18583-1-git-send-email-e@80x24.org \
    --to=e@80x24.org \
    --cc=dtas-all@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

everything related to duct tape audio suite (dtas)

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://80x24.org/dtas-all
	git clone --mirror http://ou63pmih66umazou.onion/dtas-all

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 dtas-all dtas-all/ https://80x24.org/dtas-all \
		dtas-all@nongnu.org
	public-inbox-index dtas-all

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.audio.dtas
	nntp://ou63pmih66umazou.onion/inbox.comp.audio.dtas
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for the project(s) associated with this inbox:

	dtas.git

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git