everything related to duct tape audio suite (dtas)
 help / color / mirror / code / Atom feed
* [PATCH 0/5] misc updates, major sourceedit feature!
@ 2015-01-17 11:49 Eric Wong
  2015-01-17 11:49 ` [PATCH 1/5] partstats: use Etc.nprocessors on Ruby 2.2+ Eric Wong
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Eric Wong @ 2015-01-17 11:49 UTC (permalink / raw)
  To: dtas-all; +Cc: e

The last sourceedit change is _really_ exciting to me!
(as is the splitfx playback support pushed out earlier).

The editing/post-production-oriented features of dtas are
really coming together and I think 0.10.0 will be a big
milestone for this project.

Eric Wong (5):
      partstats: use Etc.nprocessors on Ruby 2.2+
      splitfx: remove unnecessary assignment
      player: enqueued commands cannot use bypass
      dtas-console: avoid crashing on failed cue seeks
      dtas-sourceedit: update player as user saves in the editor



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/5] partstats: use Etc.nprocessors on Ruby 2.2+
  2015-01-17 11:49 [PATCH 0/5] misc updates, major sourceedit feature! Eric Wong
@ 2015-01-17 11:49 ` Eric Wong
  2015-01-17 11:49 ` [PATCH 2/5] splitfx: remove unnecessary assignment Eric Wong
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Eric Wong @ 2015-01-17 11:49 UTC (permalink / raw)
  To: dtas-all; +Cc: e

This will likely become more available and faster than GNU nproc(1)
over time.
---
 bin/dtas-partstats | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/bin/dtas-partstats b/bin/dtas-partstats
index 7026b2e..fd9bb0b 100755
--- a/bin/dtas-partstats
+++ b/bin/dtas-partstats
@@ -9,9 +9,15 @@
 require 'dtas/partstats'
 infile = ARGV[0] or abort "usage: #$0 INFILE"
 ps = DTAS::PartStats.new(infile)
-opts = {
-  jobs: `nproc 2>/dev/null || echo 2`.to_i
-}
+
+def nproc
+  require 'etc'
+  Etc.nprocessors
+rescue NoMethodError
+  `nproc 2>/dev/null || echo 2`.to_i
+end
+
+opts = { jobs: nproc }
 stats = ps.run(opts)
 
 headers = ps.key_idx.to_a
-- 
EW



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/5] splitfx: remove unnecessary assignment
  2015-01-17 11:49 [PATCH 0/5] misc updates, major sourceedit feature! Eric Wong
  2015-01-17 11:49 ` [PATCH 1/5] partstats: use Etc.nprocessors on Ruby 2.2+ Eric Wong
@ 2015-01-17 11:49 ` Eric Wong
  2015-01-17 11:49 ` [PATCH 3/5] player: enqueued commands cannot use bypass Eric Wong
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Eric Wong @ 2015-01-17 11:49 UTC (permalink / raw)
  To: dtas-all; +Cc: e

We already assigned fmt before entering the case statement,
so make the case statement smaller.
---
 lib/dtas/splitfx.rb | 2 --
 1 file changed, 2 deletions(-)

diff --git a/lib/dtas/splitfx.rb b/lib/dtas/splitfx.rb
index 8aa37e7..2335636 100644
--- a/lib/dtas/splitfx.rb
+++ b/lib/dtas/splitfx.rb
@@ -232,8 +232,6 @@ class DTAS::SplitFX # :nodoc:
       fmt = "%0#{max.to_s.size}d"
     when Integer
       fmt = "%0#{@track_zpad}d"
-    else
-      fmt = "%d"
     end
     nr = @track_start
     @tracks.delete_if do |t|
-- 
EW



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/5] player: enqueued commands cannot use bypass
  2015-01-17 11:49 [PATCH 0/5] misc updates, major sourceedit feature! Eric Wong
  2015-01-17 11:49 ` [PATCH 1/5] partstats: use Etc.nprocessors on Ruby 2.2+ Eric Wong
  2015-01-17 11:49 ` [PATCH 2/5] splitfx: remove unnecessary assignment Eric Wong
@ 2015-01-17 11:49 ` Eric Wong
  2015-01-17 11:49 ` [PATCH 4/5] dtas-console: avoid crashing on failed cue seeks Eric Wong
  2015-01-17 11:49 ` [PATCH 5/5] dtas-sourceedit: update player as user saves in the editor Eric Wong
  4 siblings, 0 replies; 6+ messages in thread
From: Eric Wong @ 2015-01-17 11:49 UTC (permalink / raw)
  To: dtas-all; +Cc: e

We cannot specify an audio format for bypass mode,
so inherit the last one we used and hope it works.
---
 lib/dtas/player.rb | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/dtas/player.rb b/lib/dtas/player.rb
index ea48926..002decf 100644
--- a/lib/dtas/player.rb
+++ b/lib/dtas/player.rb
@@ -400,7 +400,7 @@ class DTAS::Player # :nodoc:
         msg = %W(command #{pending.command_string})
       end
 
-      unless @bypass.empty?
+      if ! @bypass.empty? && pending.respond_to?(:format)
         new_fmt = bypass_match!(@format.dup, pending.format)
         if new_fmt != @format
           stop_sinks # we may fail to start below
-- 
EW



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 4/5] dtas-console: avoid crashing on failed cue seeks
  2015-01-17 11:49 [PATCH 0/5] misc updates, major sourceedit feature! Eric Wong
                   ` (2 preceding siblings ...)
  2015-01-17 11:49 ` [PATCH 3/5] player: enqueued commands cannot use bypass Eric Wong
@ 2015-01-17 11:49 ` Eric Wong
  2015-01-17 11:49 ` [PATCH 5/5] dtas-sourceedit: update player as user saves in the editor Eric Wong
  4 siblings, 0 replies; 6+ messages in thread
From: Eric Wong @ 2015-01-17 11:49 UTC (permalink / raw)
  To: dtas-all; +Cc: e

Attempting to perform operations on a file which which cannot
handle it should not cause dtas-console to die with a backtrace
---
 bin/dtas-console | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/bin/dtas-console b/bin/dtas-console
index ee0c126..2ed2f0b 100755
--- a/bin/dtas-console
+++ b/bin/dtas-console
@@ -104,6 +104,10 @@ def rg_string(rg, current)
   rv
 end
 
+def may_fail(res, events)
+  events << res if res != "OK"
+end
+
 enc_locale = Encoding.find("locale")
 $stdout.set_encoding(enc_locale)
 enc_opts = { undef: :replace, invalid: :replace, replace: '?' }
@@ -202,8 +206,8 @@ begin
         when "f" then c.req_ok("rg fallback_gain-=1")
         when ">" then c.req_ok("tl next")
         when "<" then c.req_ok("tl prev")
-        when "!" then c.req_ok("cue prev")
-        when "@" then c.req_ok("cue next")
+        when "!" then may_fail(c.req("cue prev"), events)
+        when "@" then may_fail(c.req("cue next"), events)
         when " "
           c.req("play_pause")
         when "r" # cycle through replaygain modes
-- 
EW



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 5/5] dtas-sourceedit: update player as user saves in the editor
  2015-01-17 11:49 [PATCH 0/5] misc updates, major sourceedit feature! Eric Wong
                   ` (3 preceding siblings ...)
  2015-01-17 11:49 ` [PATCH 4/5] dtas-console: avoid crashing on failed cue seeks Eric Wong
@ 2015-01-17 11:49 ` Eric Wong
  4 siblings, 0 replies; 6+ messages in thread
From: Eric Wong @ 2015-01-17 11:49 UTC (permalink / raw)
  To: dtas-all; +Cc: e

This allows changes in the source YAML file to be reflected
immediately in player after the user saves the file in their
favorite $EDITOR.  Previously, a user would need to:

	1) start dtas-sourceedit, spawning $EDITOR
	2) edit the file
	3) save changes
	4) exit $EDITOR
	5) repeat starting from 1) until happy with the results

Now, the workflow allows avoiding the context switch between their
$EDITOR and terminal to restart dtas-sourcedit:

	1) start dtas-sourceedit, spawning $EDITOR
	2) edit the file
	3) save changes
	4) repeat starting from 1) until happy with the results
	5) exit $EDITOR

In my experience, this greatly speeds up tuning of the playback
change, giving all the repeatability and flexibility of editing text
files while having the immediacy of an interactive UI.

Keep in mind this can cause problems for those with auto-save
enabled in their $EDITOR buffer at inopportune times, so a
-N/--no-watch option is added.
---
 Documentation/dtas-sourceedit.txt  | 16 ++++++++
 bin/dtas-sourceedit                | 84 ++++++++++++++++++++++++++++----------
 lib/dtas/source/splitfx.rb         |  4 +-
 lib/dtas/{source => }/watchable.rb |  2 +-
 4 files changed, 81 insertions(+), 25 deletions(-)
 rename lib/dtas/{source => }/watchable.rb (97%)

diff --git a/Documentation/dtas-sourceedit.txt b/Documentation/dtas-sourceedit.txt
index 4335f14..cff3bbc 100644
--- a/Documentation/dtas-sourceedit.txt
+++ b/Documentation/dtas-sourceedit.txt
@@ -17,6 +17,22 @@ a pipe or file, it is parsed as YAML and fed to the dtas-player(1) instance
 non-interactively.  This is useful for loading various profiles from the
 filesystem.
 
+On Linux machines with the sleepy_penguin RubyGem installed, inotify(7)
+is used to monitor the file for changes while the text exitor is running.
+Each time a user finishes saving a file, changes are committed immediately.
+This behavior may be disabled by using the -N or --no-watch command-line
+switch.
+
+# OPTIONS
+-N, \--no-watch
+:   Disable inotify(7) support on Linux systems
+
+-n, \--dry-run
+:   Only print commands which would be sent to dtas-player
+
+-V, \--verbose
+:   Print out commands as they are sent to dtas-player
+
 # EXAMPLES
 
 Invoking dtas-sourceedit will spawn your favorite text editor on "sox":
diff --git a/bin/dtas-sourceedit b/bin/dtas-sourceedit
index b411b11..1980141 100755
--- a/bin/dtas-sourceedit
+++ b/bin/dtas-sourceedit
@@ -1,16 +1,32 @@
 #!/usr/bin/env ruby
-# Copyright (C) 2013-2014, Eric Wong <e@80x24.org> and all contributors
+# Copyright (C) 2013-2015, all contributors <dtas-all@nongnu.org>
 # License: GPLv3 or later (https://www.gnu.org/licenses/gpl-3.0.txt)
+require 'optparse'
 require 'dtas/edit_client'
+require 'dtas/sigevent'
+require 'dtas/watchable'
 include DTAS::EditClient
 c = client_socket
 sources = c.req('source ls') || "(unknown)"
-usage = "Usage: #{DTAS_PROGNAME} [-n|--dry-run][-V|--verbose] SOURCENAME\n" \
-        "available SOURCENAME values: #{sources}"
+usage = "Usage: #{DTAS_PROGNAME} [OPTIONS] SOURCENAME\n" \
+        "available SOURCENAME values: #{sources}\n" \
 
-# use a real option parser if we have anything more complex
-dry_run = !!(ARGV.delete('-n') || ARGV.delete('--dry-run'))
-verbose = !!(ARGV.delete('-V') || ARGV.delete('--verbose'))
+dry_run = verbose = false
+watch = defined?(DTAS::Watchable)
+OptionParser.new('', 24, '  ') do |op|
+  op.banner = usage
+  watch and
+    op.on('-N', '--no-watch', 'disable inotify support') { watch = false }
+
+  op.on('-n', '--dry-run', 'only print commands, do not run them') {
+    dry_run = true
+  }
+  op.on('-V', '--verbose', 'print out commands sent to change the source') {
+    verbose = true
+  }
+  op.on('-h', '--help') { puts(op.to_s); exit }
+  op.parse!(ARGV)
+end
 
 ARGV.size <= 1 or abort usage
 name = ARGV[0] || "sox"
@@ -21,27 +37,51 @@ buf = c.req(%W(source cat #{name}))
 abort(buf) if buf =~ /\AERR/
 orig = YAML.load(buf)
 
+commit_update = lambda do |buf|
+  source = YAML.load(buf)
+  cmd = %W(source ed #{name})
+  update_cmd_env(cmd, orig, source)
+
+  # nil OK
+  %w(tryorder command).each { |field| cmd << "#{field}=#{source[field]}" }
+
+  warn(Shellwords.join(cmd)) if verbose || dry_run
+  c.req_ok(cmd) unless dry_run
+  orig = source
+end
+
 if st_in.file? || st_in.pipe?
   buf = $stdin.read
+  commit_update.call(buf)
 else
   tmp = tmpyaml
+  tmp_path = tmp.path
+  do_update = lambda { commit_update.call(File.read(tmp_path)) }
   tmp.write(buf << DTAS_DISCLAIMER)
-  cmd = "#{editor} #{tmp.path}"
-  system(cmd) or abort "#{cmd} failed: #$?"
-  buf = File.read(tmp.path)
-end
+  cmd = "#{editor} #{tmp_path}"
 
-source = YAML.load(buf)
-cmd = %W(source ed #{name})
-update_cmd_env(cmd, orig, source)
+  sev = DTAS::Sigevent.new
+  rset = [ sev ]
+  if watch
+    ino = DTAS::Watchable::InotifyReadableIter.new
+    ino.watch_file(tmp_path, do_update)
+    rset << ino
+  end
 
-# nil OK
-%w(tryorder command).each do |field|
-  cmd << "#{field}=#{source[field]}"
+  trap(:CHLD) { sev.signal }
+  pid = Process.spawn(cmd)
+  begin
+    r = IO.select(rset) or next
+    r[0].each do |io|
+      case io
+      when sev
+        _, status = Process.waitpid2(pid)
+        status.success? or abort "#{cmd} failed: #{status.inspect}"
+        do_update.call
+        exit
+      when ino
+        ino.readable_iter # calls do_update
+      end
+    end
+  end while true
 end
-
-if verbose || dry_run
-  warn Shellwords.join(cmd)
-end
-
-c.req_ok(cmd) unless dry_run
diff --git a/lib/dtas/source/splitfx.rb b/lib/dtas/source/splitfx.rb
index 19b2c16..80d8473 100644
--- a/lib/dtas/source/splitfx.rb
+++ b/lib/dtas/source/splitfx.rb
@@ -3,12 +3,12 @@
 require 'yaml'
 require_relative 'sox'
 require_relative '../splitfx'
-require_relative 'watchable'
+require_relative '../watchable'
 
 class DTAS::Source::SplitFX < DTAS::Source::Sox # :nodoc:
   MAX_YAML_SIZE = 512 * 1024
   attr_writer :sox, :sfx
-  include DTAS::Source::Watchable if defined?(DTAS::Source::Watchable)
+  include DTAS::Watchable if defined?(DTAS::Watchable)
 
   SPLITFX_DEFAULTS = SOX_DEFAULTS.merge(
     "command" => "#{SOX_DEFAULTS["command"]} $FX",
diff --git a/lib/dtas/source/watchable.rb b/lib/dtas/watchable.rb
similarity index 97%
rename from lib/dtas/source/watchable.rb
rename to lib/dtas/watchable.rb
index 3ff9ef8..d4c384c 100644
--- a/lib/dtas/source/watchable.rb
+++ b/lib/dtas/watchable.rb
@@ -7,7 +7,7 @@ end
 
 # used to restart DTAS::Source::SplitFX processing in dtas-player
 # if the YAML file is edited
-module DTAS::Source::Watchable
+module DTAS::Watchable
   class InotifyReadableIter < SleepyPenguin::Inotify
     def self.new
       super(:CLOEXEC)
-- 
EW



^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-01-17 11:49 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-17 11:49 [PATCH 0/5] misc updates, major sourceedit feature! Eric Wong
2015-01-17 11:49 ` [PATCH 1/5] partstats: use Etc.nprocessors on Ruby 2.2+ Eric Wong
2015-01-17 11:49 ` [PATCH 2/5] splitfx: remove unnecessary assignment Eric Wong
2015-01-17 11:49 ` [PATCH 3/5] player: enqueued commands cannot use bypass Eric Wong
2015-01-17 11:49 ` [PATCH 4/5] dtas-console: avoid crashing on failed cue seeks Eric Wong
2015-01-17 11:49 ` [PATCH 5/5] dtas-sourceedit: update player as user saves in the editor Eric Wong

Code repositories for project(s) associated with this public inbox

	http://80x24.org/dtas.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).