Author: titmuss
Date: Wed Jan 23 03:08:19 2008
New Revision: 1577
URL: http://svn.slimdevices.com?rev=1577&root=Jive&view=rev
Log:
Bug: 6419, 6671, 5416
Description:
When changing the volume in some situations timers could be left that kept
increasing or
decreasing the volume until jive was rebooted. This was bad. The volume code
has been
moved into it's own lua file and rewritten to make sure this can't happen.
Added support
for mute (press vol+ and vol- together), and crude acceleration on key holds.
Added:
branches/7.0/jive/src/pkg/jive/share/applets/SlimBrowser/Volume.lua
Modified:
branches/7.0/jive/src/pkg/jive/Makefile.am
branches/7.0/jive/src/pkg/jive/Makefile.in
branches/7.0/jive/src/pkg/jive/share/applets/SlimBrowser/SlimBrowserApplet.lua
branches/7.0/jive/src/pkg/jive/share/jive/slim/Player.lua
Modified: branches/7.0/jive/src/pkg/jive/Makefile.am
URL:
http://svn.slimdevices.com/branches/7.0/jive/src/pkg/jive/Makefile.am?rev=1577&root=Jive&r1=1576&r2=1577&view=diff
==============================================================================
--- branches/7.0/jive/src/pkg/jive/Makefile.am (original)
+++ branches/7.0/jive/src/pkg/jive/Makefile.am Wed Jan 23 03:08:19 2008
@@ -182,7 +182,8 @@
share/applets/SlimBrowser/SlimBrowserApplet.lua \
share/applets/SlimBrowser/SlimBrowserMeta.lua \
share/applets/SlimBrowser/strings.txt \
- share/applets/SlimBrowser/DB.lua
+ share/applets/SlimBrowser/DB.lua \
+ share/applets/SlimBrowser/Volume.lua
applets_slimdiscoverydir = $(pkgdatadir)/applets/SlimDiscovery
dist_applets_slimdiscovery_DATA = \
Modified: branches/7.0/jive/src/pkg/jive/Makefile.in
URL:
http://svn.slimdevices.com/branches/7.0/jive/src/pkg/jive/Makefile.in?rev=1577&root=Jive&r1=1576&r2=1577&view=diff
==============================================================================
--- branches/7.0/jive/src/pkg/jive/Makefile.in (original)
+++ branches/7.0/jive/src/pkg/jive/Makefile.in Wed Jan 23 03:08:19 2008
@@ -461,7 +461,8 @@
share/applets/SlimBrowser/SlimBrowserApplet.lua \
share/applets/SlimBrowser/SlimBrowserMeta.lua \
share/applets/SlimBrowser/strings.txt \
- share/applets/SlimBrowser/DB.lua
+ share/applets/SlimBrowser/DB.lua \
+ share/applets/SlimBrowser/Volume.lua
applets_slimdiscoverydir = $(pkgdatadir)/applets/SlimDiscovery
dist_applets_slimdiscovery_DATA = \
Modified:
branches/7.0/jive/src/pkg/jive/share/applets/SlimBrowser/SlimBrowserApplet.lua
URL:
http://svn.slimdevices.com/branches/7.0/jive/src/pkg/jive/share/applets/SlimBrowser/SlimBrowserApplet.lua?rev=1577&root=Jive&r1=1576&r2=1577&view=diff
==============================================================================
---
branches/7.0/jive/src/pkg/jive/share/applets/SlimBrowser/SlimBrowserApplet.lua
(original)
+++
branches/7.0/jive/src/pkg/jive/share/applets/SlimBrowser/SlimBrowserApplet.lua
Wed Jan 23 03:08:19 2008
@@ -49,11 +49,13 @@
local DateTime = require("jive.utils.datetime")
local DB = require("applets.SlimBrowser.DB")
+local Volume = require("applets.SlimBrowser.Volume")
local debug = require("jive.utils.debug")
local log =
require("jive.utils.log").logger("player.browse")
local logd =
require("jive.utils.log").logger("player.browse.data")
+
local EVENT_KEY_ALL = jive.ui.EVENT_KEY_ALL
local EVENT_KEY_DOWN = jive.ui.EVENT_KEY_DOWN
@@ -217,124 +219,6 @@
end
--- _openVolumePopup
--- manages the volume pop up window
-local function _openVolumePopup(vol)
-
--- log:debug("_openVolumePopup START ------------------- (", vol, ")")
-
- local volume = _player:getVolume()
-
- -- take no action if we don't know the players volume, for example
- -- shortly after changing players.
- if not volume then
- return
- end
-
- local popup = Popup("volumePopup")
-
- popup:addWidget(Label("title", "Volume"))
-
- local slider = Slider("volume")
- slider:setRange(-1, 100, volume)
- popup:addWidget(Group("volumeGroup", {
- Icon("volumeMin"),
- slider,
- Icon("volumeMax")
- }))
-
- local volumeStep = 100 / VOLUME_STEPS
-
- local _updateVolume =
- function(delta)
- local new = volume + delta * volumeStep
-
- if new > 100 then new = 100 elseif new < 0 then new = 0
end
-
- volume = _player:volume(new) or volume
- slider:setValue(volume)
-
- popup:showBriefly()
- end
-
- -- timer to change volume
- local timer = Timer(300,
- function()
--- log:debug("_openVolumePopup - timer ", timer)
- _updateVolume(vol)
- end
- )
-
- -- listener for volume up and down keys
- popup:addListener(
- EVENT_KEY_ALL,
- function(event)
- local evtCode = event:getKeycode()
-
- -- we're only interested in volume keys
- if evtCode == KEY_VOLUME_UP then
- vol = 1
- elseif evtCode == KEY_VOLUME_DOWN then
- vol = -1
- else
- return EVENT_UNUSED
- end
-
- -- if timer is gone, don't do anything => the window is
closing
- if not timer then
- return EVENT_CONSUME
- end
-
- local evtType = event:getType()
- if evtType == EVENT_KEY_UP then
- -- stop volume timer
--- log:debug("stop timer (listener) ", timer)
- timer:stop()
- -- ensure we send an update for the final
volume setting
- _player:volume(volume, true)
- elseif evtType == EVENT_KEY_DOWN then
- -- start volume timer
--- log:debug("start timer (listener) ", timer)
- timer.callback()
- timer:restart()
- end
-
- -- make sure we don't hide popup
- return EVENT_CONSUME
- end
- )
-
- -- scroll listener
- popup:addListener(EVENT_SCROLL,
- function(event)
- _updateVolume(event:getScroll())
- end)
-
-
- -- we handle events
- popup.brieflyHandler = 1
-
- popup:showBriefly(2000,
- function()
- if timer then
--- log:debug("stop timer (showBriefly timeout), ",
timer)
- timer:stop()
- -- make sure it cannot ever be started again
- timer = nil
- end
- end,
- Window.transitionPushPopupUp,
- Window.transitionPushPopupDown
- )
-
- timer:start()
-
- -- update volume from initial key press
- _updateVolume(vol)
-
--- log:debug("_openVolumePopup END --------------------------")
-end
-
local function _pushToNewWindow(step)
if not step then
return
@@ -1008,14 +892,12 @@
return EVENT_CONSUME
end,
- ["volup-down"] = function()
- _openVolumePopup(1)
- return EVENT_CONSUME
+ ["volup-down"] = function(self, event)
+ return self.volume:event(event)
end,
- ["voldown-down"] = function()
- _openVolumePopup(-1)
- return EVENT_CONSUME
+ ["voldown-down"] = function(self, event)
+ return self.volume:event(event)
end,
}
@@ -1629,7 +1511,7 @@
end
-local function _installPlayerKeyHandler()
+local function _installPlayerKeyHandler(self)
if _playerKeyHandler then
return
end
@@ -1657,15 +1539,14 @@
end
-- call the action
- func()
- return EVENT_CONSUME
+ return func(self, event)
end,
false
)
end
-local function _removePlayerKeyHandler()
+local function _removePlayerKeyHandler(self)
if not _playerKeyHandler then
return
end
@@ -1881,6 +1762,9 @@
-- clear any errors, we may have changed servers
iconbar:setServerError("OK")
+
+ -- update the volume object
+ self.volume:setPlayer(player)
-- nothing to do if we don't have a player
-- NOTE don't move this, the code above needs to run when disconnecting
@@ -1934,7 +1818,7 @@
_connectingToPlayer(self, player)
jiveMain:setTitle(player:getName())
- _installPlayerKeyHandler()
+ _installPlayerKeyHandler(self)
end
function notify_serverConnected(self, server)
@@ -2044,7 +1928,7 @@
_player:offStage()
end
- _removePlayerKeyHandler()
+ _removePlayerKeyHandler(self)
-- remove player menus
jiveMain:setTitle(nil)
@@ -2085,6 +1969,8 @@
--]]
function init(self)
jnt:subscribe(self)
+
+ self.volume = Volume()
end
--[[
Added: branches/7.0/jive/src/pkg/jive/share/applets/SlimBrowser/Volume.lua
URL:
http://svn.slimdevices.com/branches/7.0/jive/src/pkg/jive/share/applets/SlimBrowser/Volume.lua?rev=1577&root=Jive&view=auto
==============================================================================
--- branches/7.0/jive/src/pkg/jive/share/applets/SlimBrowser/Volume.lua (added)
+++ branches/7.0/jive/src/pkg/jive/share/applets/SlimBrowser/Volume.lua Wed Jan
23 03:08:19 2008
@@ -1,0 +1,224 @@
+
+-- Private class to handle player volume
+
+local tostring = tostring
+
+local oo = require("loop.base")
+local os = require("os")
+local math = require("math")
+
+local Group = require("jive.ui.Group")
+local Icon = require("jive.ui.Icon")
+local Label = require("jive.ui.Label")
+local Popup = require("jive.ui.Popup")
+local Slider = require("jive.ui.Slider")
+local Timer = require("jive.ui.Timer")
+local Window = require("jive.ui.Window")
+
+local debug = require("jive.utils.debug")
+local log = require("jive.utils.log").logger("player")
+
+
+local EVENT_KEY_ALL = jive.ui.EVENT_KEY_ALL
+local EVENT_KEY_DOWN = jive.ui.EVENT_KEY_DOWN
+local EVENT_KEY_UP = jive.ui.EVENT_KEY_UP
+local EVENT_KEY_PRESS = jive.ui.EVENT_KEY_PRESS
+local EVENT_SCROLL = jive.ui.EVENT_SCROLL
+
+local EVENT_CONSUME = jive.ui.EVENT_CONSUME
+local EVENT_UNUSED = jive.ui.EVENT_UNUSED
+
+local KEY_VOLUME_DOWN = jive.ui.KEY_VOLUME_DOWN
+local KEY_VOLUME_UP = jive.ui.KEY_VOLUME_UP
+
+
+-- number of volume steps
+local VOLUME_STEP = 100 / 40
+
+
+module(..., oo.class)
+
+
+local function _openPopup(self)
+ if self.player == nil then
+ return
+ end
+
+ -- we need a local copy of the volume
+ self.volume = self.player:getVolume()
+
+ local popup = Popup("volumePopup")
+ popup:setAutoHide(false)
+
+ popup:addWidget(Label("title", "Volume"))
+
+ local slider = Slider("volume")
+ slider:setRange(-1, 100, self.volume)
+ popup:addWidget(Group("volumeGroup", {
+ Icon("volumeMin"),
+ slider,
+ Icon("volumeMax")
+ }))
+
+ popup:addListener(EVENT_KEY_ALL | EVENT_SCROLL,
+ function(event)
+ return self:event(event)
+ end)
+
+ -- we handle events
+ popup.brieflyHandler = false
+
+ -- open the popup
+ self.popup = popup
+ self.slider = slider
+
+ popup:showBriefly(2000,
+ function()
+ self.popup = nil
+ end,
+ Window.transitionPushPopupUp,
+ Window.transitionPushPopupDown
+ )
+end
+
+
+local function _updateVolume(self, mute)
+ if not self.popup then
+ self.timer:stop()
+ return
+ end
+
+ -- keep the popup window open
+ self.popup:showBriefly()
+
+ -- ignore updates while muting
+ if self.muting then
+ return
+ end
+
+ -- mute?
+ if mute then
+ self.muting = true
+ self.volume = self.player:mute(true)
+ return
+ end
+
+ -- accelation for key holds
+ local accel = 1
+ if self.downAt then
+ accel = 1 + (os.time() - self.downAt)
+ end
+
+ -- change volume
+ local new = math.abs(self.volume) + self.delta * accel * VOLUME_STEP
+
+ if new > 100 then
+ new = 100
+ elseif new < 0 then
+ new = 0
+ end
+
+ self.volume = self.player:volume(new) or self.volume
+ self.slider:setValue(self.volume)
+end
+
+
+function __init(self)
+ local obj = oo.rawnew(self, {})
+
+ self.muting = false
+ self.downAt = false
+ obj.timer = Timer(300, function()
+ _updateVolume(obj)
+ end)
+
+ return obj
+end
+
+
+function setPlayer(self, player)
+ self.player = player
+end
+
+
+function event(self, event)
+ if not self.popup then
+ _openPopup(self)
+ else
+ self.popup:showBriefly()
+ end
+
+ local type = event:getType()
+
+ if type == EVENT_SCROLL then
+ local scroll = event:getScroll()
+
+ if scroll > 0 then
+ self.delta = 1
+ elseif scroll < 0 then
+ self.delta = -1
+ else
+ self.delta = 0
+ end
+ _updateVolume(self)
+
+ elseif type == EVENT_KEY_PRESS then
+ local keycode = event:getKeycode()
+
+ -- we're only interested in volume keys
+ if keycode & (KEY_VOLUME_UP|KEY_VOLUME_DOWN) ~=
(KEY_VOLUME_UP|KEY_VOLUME_DOWN) then
+ return EVENT_CONSUME
+ end
+
+ self.downAt = false
+ _updateVolume(self, self.volume >= 0)
+
+ else
+ local keycode = event:getKeycode()
+
+ -- we're only interested in volume keys
+ if keycode & (KEY_VOLUME_UP|KEY_VOLUME_DOWN) == 0 then
+ return EVENT_CONSUME
+ end
+
+ -- stop volume update on key up
+ if type == EVENT_KEY_UP then
+ self.delta = 0
+ self.muting = false
+ self.downAt = false
+ self.timer:stop()
+ return EVENT_CONSUME
+ end
+
+ -- update volume
+ if type == EVENT_KEY_DOWN then
+ if keycode == KEY_VOLUME_UP then
+ self.delta = 1
+ elseif keycode == KEY_VOLUME_DOWN then
+ self.delta = -1
+ else
+ self.delta = 0
+ end
+
+ self.downAt = os.time()
+ self.timer:restart()
+ _updateVolume(self)
+
+ return EVENT_CONSUME
+ end
+ end
+
+ return EVENT_CONSUME
+end
+
+
+--[[
+
+=head1 LICENSE
+
+Copyright 2007 Logitech. All Rights Reserved.
+
+This file is subject to the Logitech Public Source License Version 1.0. Please
see the LICENCE file for details.
+
+=cut
+--]]
Modified: branches/7.0/jive/src/pkg/jive/share/jive/slim/Player.lua
URL:
http://svn.slimdevices.com/branches/7.0/jive/src/pkg/jive/share/jive/slim/Player.lua?rev=1577&root=Jive&r1=1576&r2=1577&view=diff
==============================================================================
--- branches/7.0/jive/src/pkg/jive/share/jive/slim/Player.lua (original)
+++ branches/7.0/jive/src/pkg/jive/share/jive/slim/Player.lua Wed Jan 23
03:08:19 2008
@@ -32,6 +32,7 @@
local _assert, setmetatable, tonumber, tostring, pairs = _assert,
setmetatable, tonumber, tostring, pairs
local os = require("os")
+local math = require("math")
local string = require("string")
local table = require("table")
@@ -825,7 +826,7 @@
-- volume
--- send new volume value to SS
+-- send new volume value to SS, returns a negitive value if the player is muted
function volume(self, vol, send)
local now = Framework:getTicks()
if self.mixerTo == nil or self.mixerTo < now or send then
@@ -840,6 +841,27 @@
end
end
+
+-- mute
+-- mutes or ummutes the player, returns a negitive value if the player is muted
+function mute(self, mute)
+ local vol = self.state["mixer volume"]
+ if mute and vol >= 0 then
+ -- mute
+ self:send({'mixer', 'muting'})
+ vol = -math.abs(vol)
+
+ elseif vol < 0 then
+ -- unmute
+ self:send({'mixer', 'muting'})
+ vol = math.abs(vol)
+ end
+
+ self.state["mixer volume"] = vol
+ return vol
+end
+
+
-- getVolume
-- returns current volume (from last status update)
function getVolume(self)
_______________________________________________
Jive-checkins mailing list
[email protected]
http://lists.slimdevices.com/cgi-bin/mailman/listinfo/jive-checkins