everything related to duct tape audio suite (dtas)
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH] player: cleanup command dispatch
@ 2015-10-04 23:13  6% Eric Wong
  0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2015-10-04 23:13 UTC (permalink / raw)
  To: dtas-all

We can generate many command calls easily and dynamically, so
avoid the code and cognitive overhead for the majority of commands.
---
 lib/dtas/player.rb                 | 62 ++++++++++++--------------------------
 lib/dtas/player/client_handler.rb  | 32 ++++++++++++--------
 test/test_player_client_handler.rb | 24 +++++++--------
 3 files changed, 51 insertions(+), 67 deletions(-)

diff --git a/lib/dtas/player.rb b/lib/dtas/player.rb
index a1e2040..554a53f 100644
--- a/lib/dtas/player.rb
+++ b/lib/dtas/player.rb
@@ -190,7 +190,7 @@ class DTAS::Player # :nodoc:
     io.emit("OK")
   end
 
-  def do_enq_head(io, msg)
+  def dpc_enq_head(io, msg)
     # check @queue[0] in case we have no sinks
     if need_to_queue
       @queue.unshift(msg)
@@ -207,55 +207,33 @@ class DTAS::Player # :nodoc:
     case command
     when "enq"
       enq_handler(io, msg[0])
-    when "enq-head"
-      do_enq_head(io, msg)
     when "enq-cmd"
       enq_handler(io, { "command" => msg[0]})
     when "pause", "play", "play_pause"
       play_pause_handler(io, command)
-    when "seek"
-      do_seek(io, msg[0])
-    when "clear"
-      @queue.clear
-      wall("clear")
-      io.emit("OK")
-    when "rg"
-      rg_handler(io, msg)
-    when "cue"
-      cue_handler(io, msg)
-    when "skip"
-      skip_handler(io, msg)
-    when "sink"
-      sink_handler(io, msg)
-    when "current"
-      current_handler(io, msg)
-    when "watch"
-      @watchers[io] = true
-      io.emit("OK")
-    when "format"
-      format_handler(io, msg)
-    when "env"
-      env_handler(io, msg)
-    when "restart"
-      restart_pipeline
-      io.emit("OK")
-    when "source"
-      source_handler(io, msg)
-    when "state"
-      state_file_handler(io, msg)
-    when "cd"
-      chdir_handler(io, msg)
     when "pwd"
       io.emit(Dir.pwd)
-    when "tl"
-      tl_handler(io, msg)
-    when "trim"
-      trim_handler(io, msg)
-    when "queue"
-      msg[0] == "cat" and io.emit(@queue.to_yaml)
+    else
+      m = "dpc_#{command.tr('-', '_')}"
+      __send__(m, io, msg) if respond_to?(m)
     end
   end
 
+  def dpc_clear(io, msg)
+    @queue.clear
+    wall('clear')
+    io.emit('OK')
+  end
+
+  def dpc_queue(io, msg)
+    'cat' == msg[0] and io.emit(@queue.to_yaml)
+  end
+
+  def dpc_watch(io, _)
+    @watchers[io] = true
+    io.emit('OK')
+  end
+
   def event_loop_iter
     @srv.run_once do |io, msg| # readability handler, request/response
       case io
@@ -309,7 +287,7 @@ class DTAS::Player # :nodoc:
     return unless sink.active
 
     if (@current || @queue[0]) && !@paused
-      # we get here if source/sinks are all killed in restart_pipeline
+      # we get here if source/sinks are all killed in dpc_restart
       __sink_activate(sink)
       next_source(_next) unless @current
     end
diff --git a/lib/dtas/player/client_handler.rb b/lib/dtas/player/client_handler.rb
index b04872b..fab60f3 100644
--- a/lib/dtas/player/client_handler.rb
+++ b/lib/dtas/player/client_handler.rb
@@ -117,7 +117,7 @@ module DTAS::Player::ClientHandler # :nodoc:
   end
 
   # returns a wait_ctl arg
-  def sink_handler(io, msg)
+  def dpc_sink(io, msg)
     name = msg[1]
     case msg[0]
     when "ls"
@@ -240,7 +240,7 @@ module DTAS::Player::ClientHandler # :nodoc:
     out_samples(in_samples, @current.format, @format)
   end
 
-  def rg_handler(io, msg)
+  def dpc_rg(io, msg)
     return io.emit(@rg.to_hsh.to_yaml) if msg.empty?
     before = @rg.to_hsh
     msg.each do |kv|
@@ -277,7 +277,7 @@ module DTAS::Player::ClientHandler # :nodoc:
 
   # show current info about what's playing
   # returns non-blocking iterator retval
-  def current_handler(io, msg)
+  def dpc_current(io, msg)
     tmp = {}
     if @current
       tmp["current"] = s = @current.to_hsh
@@ -321,7 +321,7 @@ module DTAS::Player::ClientHandler # :nodoc:
     @srv.wait_ctl(buf, :wait_readable)
   end
 
-  def skip_handler(io, msg)
+  def dpc_skip(io, msg)
     __current_drop
     wall("skip")
     io.emit("OK")
@@ -371,7 +371,8 @@ module DTAS::Player::ClientHandler # :nodoc:
     end
   end
 
-  def do_seek(io, offset)
+  def dpc_seek(io, msg)
+    offset = msg[0]
     if @current
       if @current.respond_to?(:infile)
         begin
@@ -408,7 +409,12 @@ module DTAS::Player::ClientHandler # :nodoc:
     stop_sinks
   end
 
-  def format_handler(io, msg)
+  def dpc_restart(io, _)
+    restart_pipeline
+    io.emit('OK')
+  end
+
+  def dpc_format(io, msg)
     new_fmt = @format.dup
     msg.each do |kv|
       k, v = kv.split(/=/, 2)
@@ -443,7 +449,7 @@ module DTAS::Player::ClientHandler # :nodoc:
     io.emit("OK")
   end
 
-  def env_handler(io, msg)
+  def dpc_env(io, msg)
     if msg.empty?
       # this may fail for large envs due to SEQPACKET size restrictions
       # do we care?
@@ -465,7 +471,7 @@ module DTAS::Player::ClientHandler # :nodoc:
     io.emit("OK")
   end
 
-  def source_handler(io, msg)
+  def dpc_source(io, msg)
     map = @source_map
     op = msg.shift
     case op
@@ -509,7 +515,7 @@ module DTAS::Player::ClientHandler # :nodoc:
     end
   end
 
-  def chdir_handler(io, msg)
+  def dpc_cd(io, msg)
     msg.size == 1 or return io.emit("ERR usage: cd DIRNAME")
     begin
       Dir.chdir(msg[0])
@@ -520,7 +526,7 @@ module DTAS::Player::ClientHandler # :nodoc:
     io.emit("OK")
   end
 
-  def state_file_handler(io, msg)
+  def dpc_state(io, msg)
     case msg.shift
     when "dump"
       dest = msg.shift
@@ -546,7 +552,7 @@ module DTAS::Player::ClientHandler # :nodoc:
     __current_drop
   end
 
-  def tl_handler(io, msg)
+  def dpc_tl(io, msg)
     case msg.shift
     when "add"
       path = msg.shift
@@ -663,7 +669,7 @@ module DTAS::Player::ClientHandler # :nodoc:
     io.emit("OK")
   end
 
-  def cue_handler(io, msg)
+  def dpc_cue(io, msg)
     cur = @current
     if cur.respond_to?(:cuebreakpoints)
       bp = cur.cuebreakpoints
@@ -684,7 +690,7 @@ module DTAS::Player::ClientHandler # :nodoc:
     end
   end
 
-  def trim_handler(io, msg)
+  def dpc_trim(io, msg)
     case msg.size
     when 0
       io.emit({ 'trim' => @trim }.to_yaml)
diff --git a/test/test_player_client_handler.rb b/test/test_player_client_handler.rb
index 1f349b9..a100ad1 100644
--- a/test/test_player_client_handler.rb
+++ b/test/test_player_client_handler.rb
@@ -19,23 +19,23 @@ class TestPlayerClientHandler < Testcase
   def test_delete
     @sinks["default"] = DTAS::Sink.new
     @targets = []
-    sink_handler(@io, %w(rm default))
+    dpc_sink(@io, %w(rm default))
     assert @sinks.empty?
     assert_equal %w(OK), @io.to_a
   end
 
   def test_delete_noexist
-    sink_handler(@io, %w(rm default))
+    dpc_sink(@io, %w(rm default))
     assert @sinks.empty?
     assert_equal ["ERR default not found"], @io.to_a
   end
 
   def test_env
-    sink_handler(@io, %w(ed default env.FOO=bar))
+    dpc_sink(@io, %w(ed default env.FOO=bar))
     assert_equal "bar", @sinks["default"].env["FOO"]
-    sink_handler(@io, %w(ed default env.FOO=))
+    dpc_sink(@io, %w(ed default env.FOO=))
     assert_equal "", @sinks["default"].env["FOO"]
-    sink_handler(@io, %w(ed default env#FOO))
+    dpc_sink(@io, %w(ed default env#FOO))
     assert_nil @sinks["default"].env["FOO"]
   end
 
@@ -47,12 +47,12 @@ class TestPlayerClientHandler < Testcase
       --disable-format --disable-resample --disable-channels \
       -t raw -c $SINK_CHANNELS -f S${SINK_BITS}_3LE -r $SINK_RATE
     '
-    sink_handler(@io, %W(ed foo command=#{command}))
+    dpc_sink(@io, %W(ed foo command=#{command}))
     assert_equal command, @sinks["foo"].command
     assert_empty @sinks["foo"].env
-    sink_handler(@io, %W(ed foo env.SINK_BITS=24))
-    sink_handler(@io, %W(ed foo env.SINK_CHANNELS=2))
-    sink_handler(@io, %W(ed foo env.SINK_RATE=48000))
+    dpc_sink(@io, %W(ed foo env.SINK_BITS=24))
+    dpc_sink(@io, %W(ed foo env.SINK_CHANNELS=2))
+    dpc_sink(@io, %W(ed foo env.SINK_RATE=48000))
     expect = {
       "SINK_BITS" => "24",
       "SINK_CHANNELS" => "2",
@@ -68,7 +68,7 @@ class TestPlayerClientHandler < Testcase
     sink.name = "default"
     sink.command += "dither -s"
     @sinks["default"] = sink
-    sink_handler(@io, %W(cat default))
+    dpc_sink(@io, %W(cat default))
     assert_equal 1, @io.size
     hsh = YAML.load(@io[0])
     assert_kind_of Hash, hsh
@@ -79,12 +79,12 @@ class TestPlayerClientHandler < Testcase
   def test_ls
     expect = %w(a b c d)
     expect.each { |s| @sinks[s] = true }
-    sink_handler(@io, %W(ls))
+    dpc_sink(@io, %W(ls))
     assert_equal expect, Shellwords.split(@io[0])
   end
 
   def test_env_dump
-    env_handler(@io, [])
+    dpc_env(@io, [])
     res = @io[0]
     result = {}
     Shellwords.split(res).each do |kv|
-- 
EW



^ permalink raw reply related	[relevance 6%]

* [ANN] dtas 0.12.0 - duct tape audio suite for *nix
@ 2015-12-14  4:03  7% Eric Wong
  0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2015-12-14  4:03 UTC (permalink / raw)
  To: ruby-talk; +Cc: dtas-all

Free Software command-line tools for audio playback, mastering, and
whatever else related to audio.  dtas follows the worse-is-better
philosophy and acts as duct tape to combine existing command-line tools
for flexibility and ease-of-development.  dtas is currently implemented
in Ruby (and some embedded shell), but may use other languages in the
future.

Changes: dtas 0.12.0 - many player updates

Notable additions for dtas-player music listeners.

  dtas-ctl queue cat - display the internal queue
  dtas-tl shuffle [true|false] - toggle tracklist shuffle
  dtas-tl edit - open tracklist in an editor
                 see dtas-tl(1) manpage for more details on this:
                 http://dtas.80x24.org/dtas-tl.txt

The player tracklist now uses sequential track IDs instead of Ruby
object IDs, so it should be easier to use existing commands such as
"dtas-tl goto" and "dtas-tl remove"

For people using dtas-player for applying real-time effects to
splitfx YAML files, dtas-player can now watch for changes in scripts
specified in the "command" field of the splitfx YAML file.
Previously, dtas-player could only read the splitfx YAML file
itself.  This requires GNU/Linux and the sleepy_penguin RubyGem
installed.

dtas-splitfx also learned some switches to allow easier
interoperability with other processing tools:

  -p/--sox-pipe - identical to the sox(1) option

  -t/--trim - only expose part of the track, useful when
              combined with the above -p switch

See http://dtas.80x24.org/dtas-splitfx.txt for more details.

There's also some work-in-progress stuff that's not well documented
at the moment.  As with anything pre-1.0, expect the possibility
of incompatible changes.

Since I'm not good at designing protocols, I've also started working
on mpd compatibility layer to allow using the normal music playback
stuff with more clients (some of the clients I actually like, unlike
the seemingly GUI-only landscape of MPRIS :P).

Of course, dtas-player itself has most the capabilities of a
Unix shell; and those capabilities will certainly not be available
to mpd or MPRIS clients.

64 changes since dtas 0.11.0
      INSTALL: update documentation for 0.11.0 release
      splitfx: fix lossy output with player command is in use
      splitfx: fix non-generic, user-specified targets
      use monotonic clock on Ruby 2.1+
      dtas-splitfx: no arguments for quiet and --no-dither
      dtas-splitfx: support --trim argument
      process: implement array expansion to preserve spaces
      splitfx: show correct command for output
      splitfx: remove support for encoding opus
      dtas-console: bind "o" to display time in absolute seconds
      splitfx: avoid double-truncation with user command
      source/splitfx: allow watching extra external scripts
      splitfx: drop unnecessary variable
      splitfx: documentation for subclasses
      splitfx: simplify output display
      dtas-splitfx: comment describing -j (nothing) as infinite
      dtas-*edit: fix inotify watch invocations
      splitfx: allow -p/--sox-pipe option
      splitfx: ensure rate is an integer
      splitfx: set OUTFMT correctly for subenv if command is set
      favor recv and recv_nonblock over recvmsg variants
      parse_time: pass through numeric types
      parse_freq: trivial new module for parsing frequencies
      use a common /dev/null
      player: add "queue cat" command
      dtas-readahead: new script for -player users on Linux
      dtas-readahead: avoid polling on pause
      dtas-cueedit: escape path to temporary file
      dtas-readahead: make executable
      gemspec: use SPDX-compatible license
      README: add link to NNTP and Atom feeds
      player: cleanup command dispatch
      dtas-archive: allow specifying SoX compression factor
      gemspec: duplicate frozen string for older Rubygems
      allow building the gem without pandoc
      introduce dtas-mlib for music library functions
      dtas-mlib: add dump support for debugging
      tracklist: use lower number unique track IDs
      tracklist: do not mutate @list when serializing
      tracklist: avoid needlessly building a hash for track IDs
      tracklist: shuffle support
      tracklist: support limiting maximum tracklist size
      player: refactor and document tracklist interface
      player: tl (repeat|shuffle|max) and trim swap values
      tracklist: fixup idempotent "tl shuffle false"
      switch to exception-free non-blocking I/O
      add .gitattributes for Ruby method detection
      mlib: remove non-existent entries
      mlib: add stats support
      mlib: no kwargs for 1.9.3 compatibility
      mlib: add find/search functionality based on mpd
      mlib: split out the output format from the library
      mlib: remove kwargs harder
      player: reduce I/O priority of connected clients
      mlib: SYSTEM_DEFAULT handlers for SIGINT and SIGPIPE
      player: support "tl clear" internally
      test_unixserver: remove test for element limit
      player: dump state file asynchronously when requested
      parse_time: enable frozen_string_literal
      unix_accepted: enable checking for readability after emit
      tracklist: swap functionality
      player: show "tracklist" hash with summary info with "current"
      dtas-tl: learn an "edit" sub command
      doc: document additions to tracklist handling

* homepage: http://dtas.80x24.org/README
* http://dtas.80x24.org/INSTALL
* http://dtas.80x24.org/dtas-player.txt
* http://dtas.80x24.org/NEWS
* git clone git://80x24.org/dtas
* dtas-all@nongnu.org (plain-text only, no HTML mail, please)
* mailing list archives http://80x24.org/dtas-all/

-- 
EW


^ permalink raw reply	[relevance 7%]

Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2015-10-04 23:13  6% [PATCH] player: cleanup command dispatch Eric Wong
2015-12-14  4:03  7% [ANN] dtas 0.12.0 - duct tape audio suite for *nix Eric Wong

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

	https://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).