Skip to content

Commit

Permalink
Update xOptionsMenu.py for new device selection method.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoikas committed May 11, 2020
1 parent f9ae38c commit b03a504
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
4 changes: 2 additions & 2 deletions Scripts/Python/xIniAudio.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,9 @@ def SetAudioMode(init, device, eax):

PtDebugPrint(device)
if entryDev:
entryDev.setValue(0, "\"" + device + "\"")
entryDev.setValue(0, "\"" + device.encode("utf-8") + "\"")
else:
gIniFile.addEntry("Audio.SetDeviceName \"" + device + "\"")
gIniFile.addEntry("Audio.SetDeviceName \"" + device.encode("utf-8") + "\"")

if eax:
val = kBeTrue
Expand Down
34 changes: 18 additions & 16 deletions Scripts/Python/xOptionsMenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
kDemoMovieName = "avi/UruPreview.webm"
gPreviewStarted = 0
prevAudioDeviceName = None
gAudioDevices = ()

# =====================================
# Aspect Ratios
Expand Down Expand Up @@ -1243,15 +1244,15 @@ def OnGUINotify(self,id,control,event):
if self.restartAudio:
audio = ptAudioControl()
audioField = ptGUIControlKnob(AudioSettingsDlg.dialog.getControlFromTag(kAudioModeID))
audModeNum = audio.getNumAudioDevices() - 1
audModeNum = len(gAudioDevices) - 1
curSelection = round(audioField.getValue() * audModeNum)
intCurSelection = int(curSelection)

#Enable EAX Support
EAXcheckbox = ptGUIControlCheckBox(AudioSettingsDlg.dialog.getControlFromTag(kAudioModeCBID03))
audio.useEAXAcceleration(EAXcheckbox.isChecked())

audio.setDeviceName(audio.getAudioDeviceName(intCurSelection), 1)
audio.setPlaybackDevice(gAudioDevices[intCurSelection], 1)
self.WriteAudioControls()

elif event == kAction or event == kValueChanged:
Expand Down Expand Up @@ -1309,23 +1310,21 @@ def OnGUINotify(self,id,control,event):
self.restartAudio = 1
audio = ptAudioControl()
#~ PtDebugPrint("Number of Audio Devices: %d" % (audio.getNumAudioDevices()))
audModeNum = audio.getNumAudioDevices() - 1
audModeNum = len(gAudioDevices) - 1
curSelection = round(control.getValue() * audModeNum)
intCurSelection = int(curSelection)
control.setValue(curSelection/audModeNum)

audioDeviceName = audio.getAudioDeviceName(intCurSelection)
audioDeviceName = gAudioDevices[intCurSelection]

audioModeCtrlTextBox = ptGUIControlTextBox(AudioSettingsDlg.dialog.getControlFromTag(kAudioModeTextID))
curText = audioModeCtrlTextBox.getString()
if curText != audio.getAudioDeviceName(intCurSelection):
audioModeCtrlTextBox.setString(audioDeviceName)
audioModeCtrlTextBox.setStringW(audio.getFriendlyDeviceName(audioDeviceName))

if audioDeviceName != prevAudioDeviceName: #Only update the EAX checkbox when the mouse has been let up...
PtDebugPrint("Audio Device Name changed!")
prevAudioDeviceName = audioDeviceName
EAXcheckbox = ptGUIControlCheckBox(AudioSettingsDlg.dialog.getControlFromTag(kAudioModeCBID03))
if not audio.supportsEAX(audioDeviceName):
if not audio.isEAXSupported():
PtDebugPrint("Disabling EAX checkbox")
#Disable EAX checkbox
EAXcheckbox.disable()
Expand Down Expand Up @@ -1669,7 +1668,7 @@ def WriteAudioControls(self):

EAXcheckbox = ptGUIControlCheckBox(AudioSettingsDlg.dialog.getControlFromTag(kAudioModeCBID03))

xIniAudio.SetAudioMode( True, audio.getDeviceName(), EAXcheckbox.isChecked() )
xIniAudio.SetAudioMode( True, audio.getPlaybackDevice(), EAXcheckbox.isChecked() )
#xIniAudio.SetAudioMode( audio.isEnabled(), audio.getDeviceName(), EAXcheckbox.isChecked() )
#xIniAudio.SetAudioMode( audio.isEnabled(), audio.getDeviceName(), audio.isUsingEAXAcceleration() )
#xIniAudio.SetMicLevel( audio.getMicLevel() )
Expand All @@ -1678,11 +1677,14 @@ def WriteAudioControls(self):
xIniAudio.WriteIni()

def InitAudioControlsGUI(self):
global gAudioDevices
global prevAudioDeviceName

xIniAudio.ReadIni()
audio = ptAudioControl()

gAudioDevices = audio.getPlaybackDevices()

audioField = ptGUIControlKnob(AudioSettingsDlg.dialog.getControlFromTag(kAudioNumberOfSoundsSliderTag))
audioField.setValue( audio.getPriorityCutoff() )

Expand Down Expand Up @@ -1713,21 +1715,21 @@ def InitAudioControlsGUI(self):
respDisableItems.run(self.key, state="enableEAX")

audioField = ptGUIControlKnob(AudioSettingsDlg.dialog.getControlFromTag(kAudioModeID))
numAudioDevices = audio.getNumAudioDevices() - 1.0
numAudioDevices = len(gAudioDevices) - 1.0

if numAudioDevices > 0:
for num in range(audio.getNumAudioDevices()):
if audio.getAudioDeviceName(num) == audio.getDeviceName():
if not audio.supportsEAX(audio.getDeviceName()):
for num, device in enumerate(gAudioDevices):
if gAudioDevices[num] == audio.getPlaybackDevice():
if not audio.isEAXSupported():
EAXcheckbox.disable()
respDisableItems.run(self.key, state="disableEAX")
EAXcheckbox.setChecked(False)
EAXcheckbox.setChecked(false)
ptGUIControlTextBox(AudioSettingsDlg.dialog.getControlFromTag(kAudioModeEAXTextID)).setForeColor(ptColor(0.839, 0.785, 0.695, 1))

audioField.setValue(num/numAudioDevices)
audioModeCtrlTextBox = ptGUIControlTextBox(AudioSettingsDlg.dialog.getControlFromTag(kAudioModeTextID))
audioDeviceName = prevAudioDeviceName = audio.getAudioDeviceName(num)
audioModeCtrlTextBox.setString(audioDeviceName)
audioDeviceName = prevAudioDeviceName = audio.getPlaybackDevice()
audioModeCtrlTextBox.setStringW(audio.getFriendlyDeviceName(device))
else:
EAXcheckbox.disable()
respDisableItems.run(self.key, state="disableEAX")
Expand Down

0 comments on commit b03a504

Please sign in to comment.