From 7bed564d979ce7eceac9cd382be5c993cf0acfc5 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 14 Dec 2015 08:04:32 +0000 Subject: player: implement software volume control This is on a linear scale from 0.0 (mute) to 1.0 (no change) This is in the MPRIS spec and mpd as well (scaled to 0-100) This changes dtas-console key bindings (0/9) slightly to match mplayer more closely. ReplayGain preamp adjustment has moved from '0'/'9' to '7'/'8' keys. The 'm' key also toggles mute state (the pre-mute volume is stored in the dtas-console instance, not in dtas-player itself). --- bin/dtas-console | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'bin/dtas-console') diff --git a/bin/dtas-console b/bin/dtas-console index a98244b..a8e1838 100755 --- a/bin/dtas-console +++ b/bin/dtas-console @@ -114,6 +114,7 @@ def may_fail(res, events) events << res if res != "OK" end +pre_mute_vol = 1.0 enc_locale = Encoding.find("locale") $stdout.set_encoding(enc_locale) enc_opts = { undef: :replace, invalid: :replace, replace: '?' } @@ -163,12 +164,18 @@ begin Curses.setpos(lineno += 1, 0) Curses.clrtoeol end - - rgs = rg_string(cur["rg"] || {}, current) + rg = cur['rg'] || {} + rgs = rg_string(rg, current) Curses.setpos(lineno += 1, 0) Curses.clrtoeol Curses.addstr(rgs) + Curses.setpos(lineno += 1, 0) + Curses.clrtoeol + cur_vol = rg['volume'] || 1.0 + Curses.addstr("volume=#{cur_vol}") + pre_mute_vol = cur_vol if cur_vol != 0 + show_events(lineno, screen, events) Curses.refresh # draw and wait @@ -206,8 +213,12 @@ begin # yes, some of us have long audio files when Curses::KEY_PPAGE then c.req_ok("seek +600") when Curses::KEY_NPAGE then c.req_ok("seek -600") - when "9" then c.req_ok("rg preamp-=1") - when "0" then c.req_ok("rg preamp+=1") + when '9' then c.req_ok('rg volume-=0.01') + when '0' then c.req_ok('rg volume+=0.01') + when '=' then c.req_ok('rg volume=1') + when '7' then c.req_ok('rg preamp-=1') + when '8' then c.req_ok('rg preamp+=1') + when 'm' then c.req_ok("rg volume=#{cur_vol == 0 ? pre_mute_vol : 0}") when "F" then c.req_ok("rg fallback_gain+=1") when "f" then c.req_ok("rg fallback_gain-=1") when ">" then c.req_ok("tl next") -- cgit v1.2.3-24-ge0c7