-
Notifications
You must be signed in to change notification settings - Fork 315
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[VolumeControl] Rewrite and refactor VolumeControl code
[StartEnigma.py] - Save the current volume state once on shutdown of Enigma2 rather than saving the volume on every step/change. [AVSwitch.py] - Remove the duplicated volume control code. [VolumeControl.py] - Rewrite and simplify the code. - Remove some of the Python code and use the existing C++ code in eDVBVolumecontrol. - Don't remember the current volume but rather get it directly from the C++ code. This resolves issues where some code communicates directly with the C++ code. - Save the mute state over shutdown, reboots, and GUI restarts. If mute was active when Enigma2 was ended then mute will be activated on restart. The mute icon will be shown and remain on the screen to warn users that mute is active. - Allow the mute and volume control screens to time out from 1 to 10 seconds (user selectable) and respect the user's selection. - Allow the volume steps on a single press of VOL-/+ to be defined from 1 to 10 (user selectable) per button press. - Allow the rate of volume change to be accelerated to a rate defined from 1 to 10 (user selectable) when the VOL-/+ button is long pressed. When the button is released the single button press rate is restored. - Allow the mute icon to remain on screen by long pressing the MUTE button. It will hide on pressing MUTE again or VOL-/+. [InfoBarGenerics.py] - Use the updated method names in VolumeControl.py. [Mute.py] [Volume.py] [VolumeControl.py] - Fold Mute.py and Volume.py screens into a new screen VolumeControl.py. [keymap.xml] - Add new action map entries for long VOL-/+ and the VOL-/+ Stop events. [setup.xml] - Remove old settings and replace them with the new setting.
- Loading branch information
Showing
8 changed files
with
122 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,161 +1,122 @@ | ||
from enigma import eDVBVolumecontrol, eTimer | ||
|
||
from GlobalActions import globalActionMap | ||
from Components.config import ConfigInteger, ConfigSelectionNumber, ConfigSubsection, ConfigYesNo, config | ||
from Screens.Mute import Mute | ||
from Screens.Volume import Volume | ||
from Components.config import ConfigBoolean, ConfigInteger, ConfigSelectionNumber, ConfigSubsection, config | ||
from Screens.VolumeControl import Mute, Volume | ||
|
||
|
||
# NOTE: This code does not remember the current volume as other code can change | ||
# the volume directly. Always get the current volume from the driver. | ||
# | ||
class VolumeControl: | ||
"""Volume control, handles volUp, volDown, volMute actions and display a corresponding dialog.""" | ||
"""Volume control, handles volumeUp, volumeDown, volumeMute, and other actions and display a corresponding dialog.""" | ||
instance = None | ||
|
||
def __init__(self, session): | ||
global globalActionMap | ||
globalActionMap.actions["volumeUp"] = self.volUp | ||
globalActionMap.actions["volumeDown"] = self.volDown | ||
globalActionMap.actions["volumeMute"] = self.volMute | ||
globalActionMap.actions["volumeMuteLong"] = self.volMuteLong | ||
assert not VolumeControl.instance, "[VolumeControl] Error: Only one VolumeControl instance is allowed!" | ||
VolumeControl.instance = self | ||
config.audio = ConfigSubsection() | ||
config.audio.volume = ConfigInteger(default=50, limits=(0, 100)) | ||
config.audio.volumeLogSteps = ConfigYesNo(default=True) | ||
config.audio.volumeHideTimer = ConfigSelectionNumber(1, 10, 1, default=3) | ||
self.volumeDialog = session.instantiateDialog(Volume) | ||
self.volumeDialog.setAnimationMode(0) | ||
self.muteDialog = session.instantiateDialog(Mute) | ||
self.muteDialog.setAnimationMode(0) | ||
self.hideVolTimer = eTimer() | ||
self.hideVolTimer.callback.append(self.volHide) | ||
self.stepVolTimer = eTimer() | ||
self.repeat = 500 | ||
self.delay = 3000 | ||
vol = config.audio.volume.value | ||
self.volumeDialog.setValue(vol) | ||
self.volctrl = eDVBVolumecontrol.getInstance() | ||
self.volctrl.setVolume(vol, vol) | ||
self.last_vol = vol | ||
def updateStep(configElement): | ||
self.volumeControl.setVolumeSteps(configElement.value) | ||
|
||
def volSave(self): | ||
if self.volctrl.isMuted(): | ||
config.audio.volume.setValue(0) | ||
if VolumeControl.instance: | ||
print("[VolumeControl] Error: Only one VolumeControl instance is allowed!") | ||
else: | ||
config.audio.volume.setValue(self.volctrl.getVolume()) | ||
config.audio.volume.save() | ||
VolumeControl.instance = self | ||
global globalActionMap | ||
globalActionMap.actions["volumeUp"] = self.keyVolumeUp | ||
globalActionMap.actions["volumeUpLong"] = self.keyVolumeLong | ||
globalActionMap.actions["volumeUpStop"] = self.keyVolumeStop | ||
globalActionMap.actions["volumeDown"] = self.keyVolumeDown | ||
globalActionMap.actions["volumeDownLong"] = self.keyVolumeLong | ||
globalActionMap.actions["volumeDownStop"] = self.keyVolumeStop | ||
globalActionMap.actions["volumeMute"] = self.keyVolumeMute | ||
globalActionMap.actions["volumeMuteLong"] = self.keyVolumeMuteLong | ||
self.volumeControl = eDVBVolumecontrol.getInstance() | ||
config.volumeControl = ConfigSubsection() | ||
config.volumeControl.volume = ConfigInteger(default=20, limits=(0, 100)) | ||
config.volumeControl.mute = ConfigBoolean(default=False) | ||
config.volumeControl.pressStep = ConfigSelectionNumber(1, 10, 1, default=1) | ||
config.volumeControl.pressStep.addNotifier(updateStep, initial_call=True, immediate_feedback=True) | ||
config.volumeControl.longStep = ConfigSelectionNumber(1, 10, 1, default=5) | ||
config.volumeControl.hideTimer = ConfigSelectionNumber(1, 10, 1, default=3) | ||
self.muteDialog = session.instantiateDialog(Mute) | ||
self.muteDialog.setAnimationMode(0) | ||
self.volumeDialog = session.instantiateDialog(Volume) | ||
self.volumeDialog.setAnimationMode(0) | ||
self.hideTimer = eTimer() | ||
self.hideTimer.callback.append(self.hideVolume) | ||
if config.volumeControl.mute.value: | ||
self.volumeControl.volumeMute() | ||
self.muteDialog.show() | ||
volume = config.volumeControl.volume.value | ||
self.volumeDialog.setValue(volume) | ||
self.volumeControl.setVolume(volume, volume) | ||
# Compatibility interface for shared plugins. | ||
self.volctrl = self.volumeControl | ||
self.hideVolTimer = self.hideTimer | ||
|
||
def volUp(self): | ||
vol = self.volctrl.getVolume() | ||
step = self.stepVolume() | ||
if config.audio.volumeLogSteps.value: | ||
if vol < 3: | ||
step = 1 | ||
elif vol < 9: | ||
if step > 2: | ||
step = 2 | ||
elif vol < 18: | ||
if step > 3: | ||
step = 3 | ||
elif vol < 30: | ||
if step > 4: | ||
step = 4 | ||
self.setVolume(vol + step) | ||
def keyVolumeUp(self): | ||
self.volumeControl.volumeUp(0, 0) | ||
self.updateVolume() | ||
|
||
def volDown(self): | ||
vol = self.volctrl.getVolume() | ||
step = self.stepVolume() | ||
if config.audio.volumeLogSteps.value: | ||
if vol <= 3: | ||
step = 1 | ||
elif vol <= 9: | ||
if step > 2: | ||
step = 2 | ||
elif vol <= 18: | ||
if step > 3: | ||
step = 3 | ||
elif vol <= 30: | ||
if step > 4: | ||
step = 4 | ||
self.setVolume(vol - step) | ||
|
||
def stepVolume(self): | ||
if self.stepVolTimer.isActive(): | ||
step = config.av.volume_stepsize_fastmode.value | ||
else: | ||
self.getInputConfig() | ||
step = config.av.volume_stepsize.value | ||
self.stepVolTimer.start(self.repeat, True) | ||
return step | ||
|
||
def getInputConfig(self): | ||
if self.hideVolTimer.isActive(): | ||
return | ||
try: | ||
inputconfig = config.inputDevices.getSavedValue() | ||
except KeyError: | ||
return | ||
delay = 0 | ||
repeat = 0 | ||
|
||
for device in inputconfig.values(): | ||
if "enabled" in device and bool(device["enabled"]): | ||
if "delay" in device: | ||
val = int(device["delay"]) | ||
if val > delay: | ||
delay = val | ||
if "repeat" in device: | ||
val = int(device["repeat"]) | ||
if val > repeat: | ||
repeat = val | ||
if repeat + 100 > self.repeat: | ||
self.repeat = repeat + 100 | ||
if delay + 100 > self.delay: | ||
self.delay = delay + 100 | ||
|
||
def setVolume(self, newvol): | ||
self.volctrl.setVolume(newvol, newvol) | ||
is_muted = self.volctrl.isMuted() | ||
vol = self.volctrl.getVolume() | ||
self.last_vol = vol | ||
self.volumeDialog.show() | ||
if is_muted: | ||
self.volMute() # Unmute. | ||
elif not vol: | ||
self.volMute(False, True) # Mute but don't show mute symbol. | ||
if self.volctrl.isMuted(): | ||
self.volumeDialog.setValue(0) | ||
else: | ||
self.volumeDialog.setValue(self.volctrl.getVolume()) | ||
self.volSave() | ||
self.hideVolTimer.start(self.delay, True) | ||
def keyVolumeDown(self): | ||
self.volumeControl.volumeDown(0, 0) | ||
self.updateVolume() | ||
|
||
def volHide(self): | ||
self.volumeDialog.hide() | ||
# Set volume on if muted and volume is changed in OpenWebif. | ||
vol = self.volctrl.getVolume() | ||
if self.volctrl.isMuted() and self.last_vol != vol: | ||
self.volctrl.volumeUnMute() | ||
self.last_vol = vol | ||
# | ||
if not self.volctrl.isMuted() or config.av.volume_hide_mute.value: | ||
self.muteDialog.hide() | ||
|
||
def showMute(self): | ||
if self.volctrl.isMuted(): | ||
self.muteDialog.show() | ||
self.hideVolTimer.start(int(config.audio.volumeHideTimer.value) * 1000, True) | ||
|
||
def volMute(self, showMuteSymbol=True, force=False): | ||
vol = self.volctrl.getVolume() | ||
if vol or force: | ||
self.volctrl.volumeToggleMute() | ||
if self.volctrl.isMuted(): | ||
if showMuteSymbol: | ||
self.showMute() | ||
self.volumeDialog.setValue(0) | ||
def keyVolumeLong(self): | ||
self.volumeControl.setVolumeSteps(config.volumeControl.longStep.value) | ||
|
||
def keyVolumeStop(self): | ||
self.volumeControl.setVolumeSteps(config.volumeControl.pressStep.value) | ||
|
||
def keyVolumeMute(self): # This will toggle the current mute status. Mute will not be activated if the volume is at 0. | ||
volume = self.volumeControl.getVolume() | ||
isMuted = self.volumeControl.isMuted() | ||
if volume or (volume == 0 and isMuted): | ||
self.volumeControl.volumeToggleMute() | ||
if self.volumeControl.isMuted(): | ||
self.muteDialog.show() | ||
self.volumeDialog.hide() | ||
else: | ||
self.muteDialog.hide() | ||
self.volumeDialog.setValue(vol) | ||
self.volumeDialog.setValue(volume) | ||
self.volumeDialog.show() | ||
self.hideTimer.start(config.volumeControl.hideTimer.value * 1000, True) | ||
|
||
def keyVolumeMuteLong(self): # Long press MUTE will keep the mute icon on-screen without a timeout. | ||
if self.volumeControl.isMuted(): | ||
self.hideTimer.stop() | ||
|
||
def updateVolume(self): | ||
if self.volumeControl.isMuted(): | ||
self.keyVolumeMute() # Unmute. | ||
else: | ||
self.volumeDialog.setValue(self.volumeControl.getVolume()) | ||
self.volumeDialog.show() | ||
self.hideTimer.start(config.volumeControl.hideTimer.value * 1000, True) | ||
|
||
def volMuteLong(self): | ||
def hideVolume(self): | ||
self.muteDialog.hide() | ||
self.volumeDialog.hide() | ||
|
||
def saveVolumeState(self): | ||
config.volumeControl.mute.value = self.volumeControl.isMuted() | ||
config.volumeControl.volume.setValue(self.volumeControl.getVolume()) | ||
config.volumeControl.save() | ||
|
||
def showMute(self): # This method is only called by InfoBarGenerics.py: | ||
if self.volumeControl.isMuted(): | ||
self.muteDialog.show() | ||
self.hideTimer.start(config.volumeControl.hideTimer.value * 1000, True) | ||
|
||
# These methods are provided for compatibly with shared plugins. | ||
# | ||
def volUp(self): | ||
self.keyVolumeUp() | ||
|
||
def volDown(self): | ||
self.keyVolumeDown() | ||
|
||
def volMute(self): | ||
self.keyVolumeMute() | ||
|
||
def volSave(self): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters