Skip to content

Commit

Permalink
* improve setup
Browse files Browse the repository at this point in the history
  • Loading branch information
jbleyel committed Jan 19, 2025
1 parent ecd7ed9 commit c7a1335
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 22 deletions.
15 changes: 8 additions & 7 deletions data/setup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1055,12 +1055,13 @@
<!-- This is just a placeholder, the Videomode plugin implements this sub menu. -->
</setup>
<setup key="VolumeAdjust" title="Volume Adjust Settings">
<item level="0" text="Default volume offset" description="This is the initial / default volume offset applied to any services added the the volume adjust list.">config.volume.defaultOffset</item>
<item level="0" text="Enable Dolby Digital / Dolby AC-3 offsets" description="Select 'Yes' if volume adjustments should be applied to Dolby sound tracks.">config.volume.dolbyEnabled</item>
<item level="0" text="Default Dolby Digital / Dolby AC-3 offset" description="This offset will only be used if the channel does not have its own volume offset.">config.volume.dolbyOffset</item>
<item level="0" text="Mode" description="">config.volume.adjustMode</item>
<item level="0" text="Only AC3/DTS(HD)" description="">config.volume.adjustOnlyAC3</item>
<item level="0" text="Max. volume for mpeg audio" description="">config.volume.mpegMax</item>
<item level="0" text="Show volumebar when volume-value was changed" description="">config.volume.showVolumeBar</item>
<item level="0" text="Operational mode" description="Disabled - VolumeAdjust will not automatically change service volume levels. 'Defined' - VolumeAdjust will assign a defined offset to the service's volume level. 'Remember' - Remember the last used volume level for each service.">config.volume.adjustMode</item>
<if conditional="config.volume.adjustMode.value">
<item level="0" text="Default volume offset" description="This is the initial / default volume offset applied to any services added the the volume adjust list.">config.volume.defaultOffset</item>
<item level="0" text="Enable Dolby Digital / Dolby AC-3 offsets" description="Select 'Yes' if volume adjustments should be applied to Dolby sound tracks.">config.volume.dolbyEnabled</item>
<item level="0" text="Default Dolby Digital / Dolby AC-3 offset" description="This offset will only be used if the channel does not have its own volume offset.">config.volume.dolbyOffset</item>
<item level="0" text="Maximum MPEG volume" description="Set a maximum limit for MPEG audio levels so as to reduce the risk of hearing damage due to an unexpected increased in volume level.">config.volume.mpegMax</item>
<item level="0" text="Auto show volume level pop" description="When 'Yes' this will cause the volume level pop up to be displayed on any change of volume levels.">config.volume.showVolumeBar</item>
</if>
</setup>
</setupxml>
40 changes: 25 additions & 15 deletions lib/python/Screens/VolumeAdjust.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
config.volume.defaultOffset = ConfigSelectionNumber(min=OFFSET_MIN, max=OFFSET_MAX, stepwidth=1, default=DEFAULT_OFFSET, wraparound=False)
config.volume.dolbyEnabled = ConfigYesNo(default=False)
config.volume.dolbyOffset = ConfigSelectionNumber(min=OFFSET_MIN, max=OFFSET_MAX, stepwidth=1, default=DEFAULT_OFFSET, wraparound=False)
config.volume.adjustMode = ConfigSelection(choices=[(0, _("Disabled")), (1, _("Enabled")), (2, _("Remember service volume value"))], default=0)
config.volume.adjustOnlyAC3 = ConfigYesNo(default=True) # "Only AC3/DTS(HD)"
config.volume.adjustMode = ConfigSelection(choices=[(0, _("Disabled")), (1, _("Defined")), (2, _("Remember"))], default=0)
config.volume.mpegMax = ConfigSelectionNumber(10, 100, 5, default=100)
config.volume.showVolumeBar = ConfigYesNo(default=False)

Expand Down Expand Up @@ -106,6 +105,7 @@ def changedEntry(self): # Override the Setup method that calls createSetup() wh
def keySave(self):
if self.serviceVolumeOffsets != self.initialVolumeOffsets: # Save the volume configuration data if there are any changes.
VolumeInstance.setServiceVolumeOffsets(self.serviceVolumeOffsets)
VolumeInstance.refreshSettings()
Setup.keySave(self)

def cancelConfirm(self, result):
Expand Down Expand Up @@ -226,23 +226,33 @@ def __init__(self, session): # Autostart instance, comes active when info is up
})

self.serviceList = {}
if config.volume.adjustMode.value == 1: # Automatic volume adjust mode
self.adjustMode = config.volume.adjustMode.value
self.mpegMax = config.volume.mpegMax.value
self.dolbyEnabled = config.volume.dolbyEnabled.value
self.defaultOffset = config.volume.defaultOffset.value
if self.adjustMode == 1: # Automatic volume adjust mode
for name, ref, offset in self.serviceVolumeOffsets:
self.serviceList[ref] = offset
else: # Remember channel volume mode
if exists(SERVICE_VOLUME_FILE):
with open(SERVICE_VOLUME_FILE, "rb") as fd:
self.serviceList = load(fd)

def refreshSettings(self):
self.defaultOffset = config.volume.defaultOffset.value
self.adjustMode = config.volume.adjustMode.value
self.mpegMax = config.volume.mpegMax.value
self.dolbyEnabled = config.volume.dolbyEnabled.value

def eventStart(self):
self.newService = [True, None]

def eventEnd(self):
if config.volume.adjustMode.value == 1: # Automatic volume adjust mode
if self.adjustMode == 1: # Automatic volume adjust mode
# if played service had AC3||DTS audio and volume value was changed with RC, take new delta value from the config
if self.currentVolume and self.volumeControl.getVolume() != self.currentVolume:
self.lastAdjustedValue = self.newService[1] and self.serviceList.get(self.newService[1].toString(), self.defaultValue) or self.defaultValue
elif config.volume.adjustMode.value == 2: # Remember channel volume mode
self.lastAdjustedValue = self.newService[1] and self.serviceList.get(self.newService[1].toString(), self.defaultOffset) or self.defaultOffset
elif self.adjustMode == 2: # Remember channel volume mode
ref = self.newService[1]
if ref and ref.valid():
self.serviceList[ref.toString()] = self.volumeControl.getVolume()
Expand Down Expand Up @@ -297,21 +307,21 @@ def getNormalVolume(self):

def processVolumeOffset(self): # This is the routine to change the volume offset.
# taken from the plugin !!!!
if config.volume.adjustMode.value and self.newService[0]:
if self.adjustMode and self.newService[0]:
serviceRef = self.session.nav.getCurrentlyPlayingServiceReference()
if serviceRef:
print("[VolumeAdjustment] service changed")
self.newService = [False, serviceRef]
self.currentVolume = 0 # init
if config.volume.adjustMode.value == 1: # Automatic volume adjust mode
if self.adjustMode == 1: # Automatic volume adjust mode
self.currentAC3DTS = self.isCurrentAudioAC3DTS()
if self.pluginStarted:
if self.currentAC3DTS: # ac3 dts?
ref = self.getPlayingServiceReference()
vol = self.volumeControl.getVolume()
currentvol = vol # remember current vol
vol -= self.lastAdjustedValue # go back to origin value first
ajvol = self.serviceList.get(ref.toString(), self.defaultValue) # get delta from config
ajvol = self.serviceList.get(ref.toString(), self.defaultOffset) # get delta from config
if ajvol < 0: # adjust vol down
if vol + ajvol < 0:
ajvol = (-1) * vol
Expand All @@ -331,13 +341,13 @@ def processVolumeOffset(self): # This is the routine to change the volume offse
# go back to origin value
vol = self.volumeControl.getVolume()
ajvol = vol - self.lastAdjustedValue
if ajvol > config.volume.mpegMax.value:
ajvol = config.volume.mpegMax.value
if ajvol > self.mpegMax:
ajvol = self.mpegMax
self.setVolume(ajvol)
print(f"[VolumeAdjustment] Change volume for service: '{self.getServiceName(self.session.nav.getCurrentlyPlayingServiceReference())}' (-{vol - ajvol}) to {self.volumeControl.getVolume()}")
self.lastAdjustedValue = 0 # mpeg audio, no delta here
return # get out of here, nothing to do anymore
elif config.volume.adjustMode.value == 2: # modus = Remember channel volume
elif self.adjustMode == 2: # modus = Remember channel volume
if self.pluginStarted:
ref = self.getPlayingServiceReference()
if ref.valid():
Expand All @@ -350,10 +360,10 @@ def processVolumeOffset(self): # This is the routine to change the volume offse
return # get out of here, nothing to do anymore

if not self.pluginStarted:
if config.volume.adjustMode.value == 1: # Automatic volume adjust mode
if self.adjustMode == 1: # Automatic volume adjust mode
# starting plugin, if service audio is ac3 or dts --> get delta from config...volume value is set by enigma2-system at start
if self.currentAC3DTS:
self.lastAdjustedValue = self.serviceList.get(self.session.nav.getCurrentlyPlayingServiceReference().toString(), self.defaultValue)
self.lastAdjustedValue = self.serviceList.get(self.session.nav.getCurrentlyPlayingServiceReference().toString(), self.defaultOffset)
self.currentVolume = self.volumeControl.getVolume() # ac3||dts service , save current volume
self.pluginStarted = True # plugin started...

Expand All @@ -373,7 +383,7 @@ def isCurrentAudioAC3DTS(self):
try: # Uhh, servicemp3 leads sometimes to OverflowError Error.
description = audio.getTrackInfo(audio.getCurrentTrack()).getDescription()
print(f"[VolumeAdjust] Description: '{description}'.")
if config.volume.adjustOnlyAC3.value:
if self.dolbyEnabled:
if "AC3" in description or "DTS" in description or "Dolby Digital" == description:
print("[VolumeAdjust] AudioAC3Dolby = YES")
return True
Expand Down

0 comments on commit c7a1335

Please sign in to comment.