#include <WindowsConstants.au3>
#include <GuiTab.au3>
#include <GuiTreeView.au3>
#include <GuiListView.au3>
#include <GuiComboBox.au3>
#include <array.au3>
; 0) Deactivate playing music to avoid programm corruption on later reactivation
Send("{MEDIA_STOP}")
; 1) Close old Sound Control Panel
$windowTitle = "Sound"
$oldwindow = WinGetHandle($windowTitle)
If $oldWindow Then
WinClose($oldWindow)
Endif
$oldWindow = WinGetHandle($windowTitle)
If $oldWindow Then
MsgBox(48, "AutoIt Fehler", "Sound Control already opened. Exiting AutoIt Process")
Exit 1
Endif
; 1b) Open new Sound Control Panel
Run("c:\windows\system32\control.exe mmsys.cpl")
WinActivate($windowTitle)
WinSetOnTop($windowTitle, "", 1)
WinWaitActive($windowTitle)
; 2) Find Tab
$window = WinGetHandle($windowTitle)
$tabBar = ControlGetHandle($window, "", "SysTabControl321")
$tabID = DllCall("user32.dll", "int", "GetDlgCtrlID", "hwnd", $tabBar)
$tabID = $TabID[0]
If Not $tabBar Then
MsgBox(48, "AutoIt Fehler", "Error when searching for the OutputDevice Tab")
Exit 1
Endif
; 3) Select correct Tab Item
_GUICtrlTab_SetCurFocus($tabBar, 0)
$result = _SendMessage($window, $WM_NOTIFY, $tabID, $TCN_SELCHANGE)
If $result <> 0 Then
MsgBox(48, "AutoIt Fehler", "Error when selecting the OutputDevice Tab")
Exit 1
Endif
; 4) Get List View
$listView = ControlGetHandle($window, "", "SysListView321");
If Not $listView Then
MsgBox(48, "AutoIt Fehler", "Error when finding the list view")
Exit 1
Endif
; 5) Find and select Scarlett
$scarlettTitle = "Ausgang"
$scarlettIndex = _GUICtrlListView_FindText($listView, $scarlettTitle, 0, True)
If $scarlettIndex == -1 Then
MsgBox(48, "AutoIt Fehler", "Error when finding the Scarlett device >" & $scarlettTitle & "<")
Exit 1
Endif
_GUICtrlListView_ClickItem ($listView, $scarlettIndex)
; 6) Hit "Eigenschaften"
ControlClick($windowTitle, "", 1003)
; 7a) Switch to "Advanced" Tab
$propertiesWindowTitle = "Eigenschaften von " & $scarlettTitle
WinWaitActive($propertiesWindowTitle)
$propertiesWindow = WinGetHandle($propertiesWindowTitle)
$advancedTitle = "Erweitert"
$propertiesTabControl = ControlGetHandle($propertiesWindow, "", 12320)
$advancedTabIndex = _GUICtrlTab_FindTab($propertiesTabControl, $advancedTitle)
If $advancedTabIndex == -1 Then
MsgBox(48, "AutoIt Fehler", "Cannot find Tab index for >" & $advancedTitle & "<")
Exit 1
Endif
_GUICtrlTab_ClickTab($propertiesTabControl, $advancedTabIndex)
; 7b) Get ComboBox
$sampleRateComboBoxID = 1410
$sampleRateComboBox = ControlGetHandle($propertiesWindow, "", $sampleRateComboBoxID)
If Not $sampleRateComboBox Then
MsgBox(48, "AutoIt Fehler", "Cannot find Combo-Box in >" & $propertiesWindowTitle & "<")
Exit 1
Endif
; 8) Set Combo Box items to a shitty samplerate...
; Function to ignore "Gerät zurücksetzen" warning
Func IgnoreWarning()
$warningWindowTitle = "Gerät wird zurzeit verwendet"
$warningWindow = WinGetHandle($warningWindowTitle)
If $warningWindow Then
; click Yes
WinWaitActive($warningWindow)
ControlClick($warningWindow, "", 6)
Endif
EndFunc
; function to manually go through options, as the SetCurSel method does not notify the buttons to change their state -.-
Func SelectComboBoxItem($window, $comboBox, $desiredItemName, $applyButtionID)
Local $oldIndex = _GUICtrlComboBox_GetCurSel($comboBox)
WinWaitActive($window)
ControlFocus($window, "", $comboBox);
_GUICtrlComboBox_SetCurSel($comboBox, 1)
Send("{UP}")
; we are now at first item
Local $index = 0
Local $itemName
_GUICtrlComboBox_GetLBText($comboBox, $index, $itemName)
While ($itemName <> $desiredItemName)
Send("{DOWN}")
$index += 1
If ($index >= _GUICtrlComboBox_GetCount($comboBox)) Then
MsgBox(48, "AutoIt Fehler", "Cannot find Combo-Box item >" & $desiredItemName & "<")
Exit 1
Endif
_GUICtrlComboBox_GetLBText($comboBox, $index, $itemName)
WEnd
If ($index == $oldIndex) Then
MsgBox(48, "AutoIt Fehler", "Combo Box Item >" & $desiredItemName & "< already selected")
Exit 1
Endif
; Hit "Apply"
$isControlEnabled = ControlCommand($window, "", $applyButtionID, "IsEnabled")
ControlClick($window, "", $applyButtionID)
If Not $isControlEnabled Then
MsgBox(48, "AutoIt Fehler", "Cannot apply new Combo Box Item (Index " & $index & ")")
Exit 1
Endif
IgnoreWarning()
EndFunc
; Get Old Index and Name
$comboBoxItemIndexOld = _GUICtrlComboBox_GetCurSel($sampleRateComboBox)
$comboBoxItemNameOld = "Invalid Name"
_GUICtrlComboBox_GetLBText($sampleRateComboBox, $comboBoxItemIndexOld, $comboBoxItemNameOld)
; Select New Index
$comboBoxTmpItemName = "2 Kanal, 16 Bit, 96000 Hz (Studioqualität)"
SelectComboBoxItem($propertiesWindow, $sampleRateComboBox, $comboBoxTmpItemName, 12321);
; 9) ... then back to old one
SelectComboBoxItem($propertiesWindow, $sampleRateComboBox, $comboBoxItemNameOld, 12321);
; 10) Apply by clicking OK
$success = ControlClick($propertiesWindowTitle, "", 1)
$success += ControlClick($windowTitle, "", 1)
If $success <> 2 Then
MsgBox(48, "AutoIt Fehler", "Could not apply settings")
Exit 1
Endif
; 11) Show Baloon tip and wait until display time ended
$message = "Resetted Scarlett Sample Rate"
TrayTip("AutoIt-Script", $message, 5)
sleep(5000)