1 from Screens.Screen import Screen
2 from Components.ConfigList import ConfigListScreen
3 from Components.config import config, ConfigSubsection, ConfigSelection, getConfigListEntry
4 from Components.ActionMap import ActionMap
5 from Screens.MessageBox import MessageBox
6 from Components.Sources.StaticText import StaticText
7 from Plugins.Plugin import PluginDescriptor
8 from Tools.Directories import fileExists
10 AUDIOEFFECT_PROC_PATH = {
11 "3D_SURROUND" : "/proc/stb/audio/3d_surround",
12 "AVL" : "/proc/stb/audio/avl",
13 "3D_SURROUND_CHOICE" : "/proc/stb/audio/3d_surround_choices",
14 "AVL_CHOICE" : "/proc/stb/audio/avl_choices",
15 "3D_SURROUND_SPEAKER_POSITION" : "/proc/stb/audio/3d_surround_speaker_position",
16 "3D_SURROUND_SPEAKER_POSITION_CHOICE" : "/proc/stb/audio/3d_surround_speaker_position_choices"
19 AUDIOOUT_ENTRY_NAME = {
20 "dac" : "Analog Audio"
23 AUDIOEFFECT_DEFAULT = "none"
24 AUDIOOUT_DEFAULT = "off"
25 SPEAKER_POSITION_DEFAULT = "wide"
27 SUPPORT_AUDIOEFFECT = False
28 SUPPORT_3D_SURROUND = False
29 SUPPORT_3D_SURROUND_SPEAKER_POSITION = False
32 if fileExists(AUDIOEFFECT_PROC_PATH["3D_SURROUND"]) and fileExists(AUDIOEFFECT_PROC_PATH["3D_SURROUND_CHOICE"]):
33 SUPPORT_3D_SURROUND = True
35 if SUPPORT_3D_SURROUND is True:
36 if fileExists(AUDIOEFFECT_PROC_PATH["3D_SURROUND_SPEAKER_POSITION"]) and fileExists(AUDIOEFFECT_PROC_PATH["3D_SURROUND_SPEAKER_POSITION_CHOICE"]):
37 SUPPORT_3D_SURROUND_SPEAKER_POSITION = True
39 if fileExists(AUDIOEFFECT_PROC_PATH["AVL"]) and fileExists(AUDIOEFFECT_PROC_PATH["AVL_CHOICE"]):
42 if SUPPORT_3D_SURROUND or SUPPORT_AVL:
43 SUPPORT_AUDIOEFFECT = True
45 def getProcValue(procPath):
46 fd = open(procPath,'r')
47 curValue = fd.read().strip(' ').strip('\n')
49 # print "[AudioEffect] get %s from %s" % (curValue, procPath)
52 def setProcValue(procPath, value):
53 # print "[AudioEffect] set %s to %s" % (value, procPath)
54 fd = open(procPath,'w')
58 def setConfigValue(procPath, value):
59 # print "[AudioEffect][setConfigValue] try set %s to %s" % (value, procPath)
60 curValue = getProcValue(procPath)
62 setProcValue(procPath, value)
65 def getEffectChoices():
66 choices = [ ("none", _("none")) ]
67 if SUPPORT_3D_SURROUND :
68 choices.append( ("3D_Surround", _("3D Surround") ) )
70 choices.append( ("AVL", _("AVL (Automatic Volume Leveler)") ) )
73 def getAudioOutTypes():
74 if SUPPORT_3D_SURROUND:
75 data = getProcValue(AUDIOEFFECT_PROC_PATH["3D_SURROUND_CHOICE"])
77 data = getProcValue(AUDIOEFFECT_PROC_PATH["AVL_CHOICE"])
79 for aType in data.split(' '):
82 aTypes.append( aType )
85 AUDIOOUT_TYPES = getAudioOutTypes()
87 def getSpeakerPosition():
89 data = getProcValue(AUDIOEFFECT_PROC_PATH["3D_SURROUND_SPEAKER_POSITION_CHOICE"])
90 for choice in data.split(' '):
91 choices.append( (choice, _(choice)) )
94 config.plugins.audioeffect = ConfigSubsection()
95 config.plugins.audioeffect.effect = ConfigSelection( default = AUDIOEFFECT_DEFAULT, choices = getEffectChoices() )
96 if SUPPORT_AUDIOEFFECT:
97 for aout in AUDIOOUT_TYPES:
98 setattr(config.plugins.audioeffect, aout, ConfigSelection( default = AUDIOOUT_DEFAULT, choices = [("on", _("On")), ("off", _("Off"))] ) )
99 if SUPPORT_3D_SURROUND_SPEAKER_POSITION:
100 config.plugins.audioeffect.speakerposition = ConfigSelection( default = SPEAKER_POSITION_DEFAULT, choices = getSpeakerPosition() )
102 def setAudioEffectConfigs():
103 if not SUPPORT_AUDIOEFFECT:
105 _3DSurroundValue = None
107 if config.plugins.audioeffect.effect.value == "none":
108 _3DSurroundValue = "none"
110 elif SUPPORT_AUDIOEFFECT:
112 for aout in AUDIOOUT_TYPES:
113 if getattr(config.plugins.audioeffect, aout).value == "on":
114 _audioOnList.append(aout)
116 audioOnList = ' '.join(_audioOnList)
119 if config.plugins.audioeffect.effect.value == "3D_Surround":
120 _3DSurroundValue = audioOnList
122 elif config.plugins.audioeffect.effect.value == "AVL":
123 _3DSurroundValue = "none"
124 _AvlValue = audioOnList
126 if SUPPORT_3D_SURROUND:
127 setConfigValue(AUDIOEFFECT_PROC_PATH["3D_SURROUND"], _3DSurroundValue)
129 setConfigValue(AUDIOEFFECT_PROC_PATH["AVL"], _AvlValue)
130 if SUPPORT_3D_SURROUND_SPEAKER_POSITION:
131 _3DSpeakerPosition = config.plugins.audioeffect.speakerposition.value
132 setConfigValue(AUDIOEFFECT_PROC_PATH["3D_SURROUND_SPEAKER_POSITION"], _3DSpeakerPosition)
134 class AudioEffect(Screen, ConfigListScreen):
136 <screen position="center,center" size="540,300">
137 <ePixmap pixmap="skin_default/buttons/red.png" position="30,10" size="140,40" alphatest="on" />
138 <ePixmap pixmap="skin_default/buttons/green.png" position="200,10" size="140,40" alphatest="on" />
139 <ePixmap pixmap="skin_default/buttons/yellow.png" position="370,10" size="140,40" alphatest="on" />
140 <widget source="key_red" render="Label" position="30,10" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" foregroundColor="#ffffff" transparent="1" />
141 <widget source="key_green" render="Label" position="200,10" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" foregroundColor="#ffffff" transparent="1" />
142 <widget source="key_yellow" render="Label" position="370,10" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#a08500" foregroundColor="#ffffff" transparent="1" />
143 <widget name="config" zPosition="2" position="20,70" size="500,170" scrollbarMode="showOnDemand" transparent="1" />
144 <widget source="description" render="Label" position="30,240" size="480,60" font="Regular;18" halign="center" valign="center" />
148 def __init__(self, session):
149 Screen.__init__(self, session)
150 self.setTitle(_("Audio Effect Setup"))
151 self.skin = AudioEffect.skin
153 self.session = session
155 self["key_red"] = StaticText(_("Cancel"))
156 self["key_green"] = StaticText(_("Save"))
157 self["key_yellow"] = StaticText(_("Default"))
158 self["description"] = StaticText(_("Audio Effect Setup is not supported."))
160 self["shortcuts"] = ActionMap(["AudioEffectActions" ],
163 "cancel": self.keyCancel,
164 "red": self.keyCancel,
165 "green": self.keySave,
166 "yellow" : self.keyDefault,
170 ConfigListScreen.__init__(self, self.setupList, session = self.session)
171 self.configEffect = None
174 def createSetup(self):
175 if not SUPPORT_AUDIOEFFECT:
178 self.configEffect = getConfigListEntry(_("Effect"), config.plugins.audioeffect.effect)
179 self.setupList.append(self.configEffect)
180 if config.plugins.audioeffect.effect.value != "none" :
181 for aout in AUDIOOUT_TYPES:
182 entryName = AUDIOOUT_ENTRY_NAME.get(aout, aout.upper())
183 self.setupList.append(getConfigListEntry(_(entryName), getattr(config.plugins.audioeffect, aout)))
184 if config.plugins.audioeffect.effect.value == "3D_Surround" and SUPPORT_3D_SURROUND_SPEAKER_POSITION is True:
185 self.setupList.append(getConfigListEntry(_("3D Surround Speaker Position"), config.plugins.audioeffect.speakerposition))
186 self["config"].list = self.setupList
187 self["config"].l.setList(self.setupList)
188 if not self.showDescription in self["config"].onSelectionChanged:
189 self["config"].onSelectionChanged.append(self.showDescription)
196 ConfigListScreen.keyLeft(self)
197 setAudioEffectConfigs()
198 if self.configEffect and (self["config"].getCurrent() == self.configEffect) :
202 ConfigListScreen.keyRight(self)
203 setAudioEffectConfigs()
204 if self.configEffect and (self["config"].getCurrent() == self.configEffect) :
207 def cancelConfirm(self, result):
211 for x in self["config"].list:
213 setAudioEffectConfigs()
217 if self["config"].isChanged():
218 self.session.openWithCallback(self.cancelConfirm, MessageBox, _("Really close without saving settings?"))
222 def keyDefault(self):
223 for (configName, configElement) in config.plugins.audioeffect.dict().items():
224 configElement.value = configElement.default
225 setAudioEffectConfigs()
228 def showDescription(self):
230 return C.__class__.__name__
232 configName = "<%s>\n"%self["config"].getCurrent()[0]
233 currentConfig = self["config"].getCurrent()[1]
234 className = getClassName(currentConfig)
236 if className == "ConfigSelection":
238 for choice in currentConfig.choices.choices:
239 if text == configName:
242 text += ', ' + choice[1]
243 self["description"].setText( _(text) )
245 def main(session, **kwargs):
246 session.open(AudioEffect)
248 def OnSessionStart(session, **kwargs):
249 setAudioEffectConfigs()
251 def Plugins(**kwargs):
253 pList.append( PluginDescriptor(where=PluginDescriptor.WHERE_SESSIONSTART, fnc=OnSessionStart))
254 pList.append( PluginDescriptor(name=_("AudioEffect"), description=_("support 3D Surround and AVL effect."), where = PluginDescriptor.WHERE_PLUGINMENU, needsRestart = False, fnc=main) )