From 5560d4b462e10c5430d7a74f445ffe0d1611d0cc Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 4 Oct 2015 23:11:57 +0000 Subject: player: cleanup command dispatch 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 ++++++++++++++++++------------------------------------ 1 file changed, 20 insertions(+), 42 deletions(-) (limited to 'lib/dtas/player.rb') 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 -- cgit v1.2.3-24-ge0c7