-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAudio Control Master.ahk
More file actions
784 lines (684 loc) · 34.7 KB
/
Audio Control Master.ahk
File metadata and controls
784 lines (684 loc) · 34.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
/*==================================================================\
| Audio Control (Sw Bal) - Version 1.44.1 |
\===================================================================/
DESCRIPTION:
Script to automate common interactions with Win7/10 "Sound" (mmsys.cpl) interface
Primarily to switch audio devices (set default) and change balance values on 5.1 devices (hence 'sw' & 'bal')
Limited support for toggling some 'Enhancements' (Fill, Loudness..) exists but no longer a focus of this script
HOW TO USE:
This script was built around my own needs but can be adjusted to your own needs in 'CUSTOMISATION' section below
TO-DO:
Experiment with making changes with Sound window hidden
Extra help for closing any possible sub-windows of Sound main window (eg 'HDMI Audio Device Properties')
CUSTOMISATION:
Replace with (or add) your device* official and preferred names:
*/
dev1Name = Speakers
dev1Nick = Desk
dev2Name = Headphones
dev2Nick = Bed
dev3Name = Bluetooth Audio Renderer
dev3Nick = Blu
dev4Name = AMD HDMI Output
dev4Nick = TV
dev5Name = Your Device Name Here
dev5Nick = Your device nickname here
/*Device names are displayed and can be renamed in the classic 'Sound' interface (Start->run->mmsys.cpl)
To rename: Open properties and the device name should be highlighted and editable
CHANGELOG:
1.44.1 15-08-2019 More tidy up, improved search for device, checks names of as many devices as listed in customisation
1.44.0 02-08-2019 Big tidy up, added simple customisation support
1.43.3 27-07-2019 TV Speakers added
1.43.2 2018 Minor Text Fixes (lol)
1.43.1 2018 Increased bluetooth wait time
1.43 2017 More 'Bal51' options and standard set (no space/dot)
1.42 2017 Loudness Equalisation Update (loudMode,loudToggle)
1.41 2017 Set Update
1.40 2017 Set Update
1.32 2017 Manual shift update 27.11.2017
1.30.0 01/11/2017 Log starts Nov 2017
*/
;--------------------------------------------------------------------------------------------------------------
;=========SETTINGS=============================================================================================
#NoEnv
;#Warn
#SingleInstance force
SetTitleMatchMode, RegEx
SetWorkingDir %A_ScriptDir%
;========MAIN PROGRAM==========================================================================================
Loop
IfWinNotActive Launchy ;Ensure Launchy is hidden
break ;Usually not a problem
WinGet, restoreActiveWindow, ID, A
restoreActiveWindow = ahk_id %restoreActiveWindow% ;Ensure previously top-most window is active again after
GoSub, GetOpsInfo ;Get info about which operation+arguments from filename
;Loop { ;RetryLoop ;On second and later loops values come fron user input
if shiftMode {
GoSub, GetShiftValues
GoSub, FindDevice ;When setting bal fill hsould always be off, this ensures it
GoSub, PropertiesLevelsBalance ;Properties should already be open but skips just that button press and jumps to second (tab1) tab
GoSub, DoShifts
GoSub, CloseAll
Sleep 3000
ExitApp
}
if setMode {
GoSub, GetSetValues
GoSub, FindDevice
GoSub, PropertiesLevelsBalance ;Properties should already be open but skips just that button press and jumps to second (tab1) tab
GoSub, GetCurrentVals
GoSub, SetBalance
GoSub, CloseAll
Sleep 3000
ExitApp
}
if balanceMode { ;From filename, Balance mode IS selected
if !defaultMode && !manualMode
GoSub, BalValsFilename ;Get desired balance values from filename
if !balValsRaw && !defaultMode && !manualMode ;filename values not found
GoSub, BalValsUserInput ;Request balance values from user
if !balValsRaw and !desBal1 and !desBal2 and !desBal3 and !desBal4 and !desBal5 and !desBal6
GoSub, DefaultInput ;still no values, use defaults set in this script
GoSub, ParseValues ;Finally, parse the values
GoSub, FindDevice ;When setting bal fill hsould always be off, this ensures it
; GoSub, PropertiesEnhancements ;When adjusting balance..
; GoSub, FillToggle ;..fill should always be off. SubRoutines BackToSound and BackToProperties were for this but unnecessary
GoSub, PropertiesLevelsBalance ;Properties should already be open but skips just that button press and jumps to second (tab1) tab
GoSub, GetCurrentVals
GoSub, SetBalance
GoSub, CloseAll
Sleep 3000
ExitApp
}
else if fillMode { ;Fill mode first to allow 'sp fill mode' in filename
GoSub, FindDevice
GoSub, PropertiesEnhancements
GoSub, FillToggle
GoSub, CloseAll
Sleep 3000
}
else if loudMode { ;Fill mode first to allow 'sp fill mode' in filename
GoSub, FindDevice
GoSub, PropertiesEnhancements
GoSub, LoudToggle
GoSub, CloseAll
Sleep 3000
}
else if switchMode { ;From filename, SWITCH mode is selected
ToolTip Setting %desDev% as default device
GoSub, FindDevice
GoSub, SetDefaultDevice
GoSub, CloseAll
Sleep 3000
ExitApp
}
else
MsgBox Fail idk
;} ;RetryLoop
Return
;--------------------------------------------------------------------------------------------------------------
;=========SUB-ROUTINES=========================================================================================
GetOpsInfo:
opsInfoRaw := A_ScriptName ;On first run script checks filename for options
Loop { ;GetOpsLoop ;Loop to try again: First from filename info, subsequent from user inputs
;Operations
if (InStr(opsInfoRaw, "Shift")) or (InStr(opsInfoRaw, "Up")) or (InStr(opsInfoRaw, "Increase")) or (InStr(opsInfoRaw, "Down")) or (InStr(opsInfoRaw, "decrease"))
shiftMode = 1 ;Shift mode on (SHIFT, UP, INCREASE, DOWN, DECREASE)
else if InStr(opsInfoRaw, "Set") ;Set mode on (SET)
setMode = 1
else if InStr(opsInfoRaw, "Bal") ;Balance mode on (BAL)
balanceMode := 1 ;, toggleOff = 1 (disabling this as fill off causes difficulties
if (InStr(opsInfoRaw, "Sw")) ;not (InStr(opsInfoRaw, "Sp"))
switchMode = 1 ;Device switch mode only on SW
;Legacy commands, leave for now
if InStr(opsInfoRaw, "Fill") ;Speaker Fill mode
fillMode := 1 ;, toggleOff := ""
if InStr(opsInfoRaw, "Loud") ;Speaker Fill mode
loudMode := 1 ;, toggleOff := ""
;----------------------------------
;Devices
;To-Do:
; if matches official name up to 10
; use that
; else check nickname arrays up to 10
; use associated official name 'device#OfficialName' I guess
; else
; NoDeviceFlag = 1 and continue
Loop
if InStr(opsInfoRaw, dev%A_Index%Name) or InStr(opsInfoRaw, dev%A_Index%Nick)
{ ;if script filename or user input matches a hard-coded device name or nickname
desDev := dev%A_Index%Name ;eg desDev = dev3Name = "Speakers"
desDevNum = %A_Index% ;eg desDev = 3
break ;continue script with a desired device set
}
else if !desDev := dev%A_Index%Name ;Device doesn't exist. End of list of devices in CUSTOMISATION section (or gap in numbering)
break ;continue script WITHOUT a desired device set
;----------------------------------
;Special Options
if (InStr(opsInfoRaw, "Manual")) or (InStr(opsInfoRaw, "Menu"))
manualMode = 1 ;Manual: just open to desired menu
if (InStr(opsInfoRaw, "Default"))
defaultMode = 1 ;Default skips to using default bal vals
if InStr(opsInfoRaw, "Off") ;Toggle Speaker Fill, Loudness Equalisation (possibly more later) OFF
toggleOff = 1 ; Default Fill, LoudEq etc mode is on, turning it off requires this additional 'off'
;else if (InStr(opsInfoRaw, "On")) ;Disabled for now because ON is default
;onMode = 1
;----------------------------------
;Presets ;Passes on preset values ultimately to BalValsFilename SubRoutine
if (InStr(opsInfoRaw, "bal51 30")) or (InStr(opsInfoRaw, "bal 51 30")) {
opsInfoRaw = bal 30 30 90 10 100 100
userOpsMode = 1
}
else if (InStr(opsInfoRaw, "bal51 50")) {
opsInfoRaw = bal 50 50 90 10 100 100
userOpsMode = 1
}
else if (InStr(opsInfoRaw, "bal51")) {
opsInfoRaw = bal 70 70 90 01 100 100
userOpsMode = 1
}
else if (InStr(opsInfoRaw, "Stereo")) {
opsInfoRaw = bal 100 100 0 10 0 0 ;Passes on preset values ultimately to BalValsFilename SubRoutine
userOpsMode = 1
balanceMode = 1 ;This line removes necessary to add 'bal'
}
else if (InStr(opsInfoRaw, "Annoy")) {
opsInfoRaw = bal 0 0 0 0 0 100 ;Back Right only (used to fight back against very inconsiderate neighbours with a loud TV
userOpsMode = 1
}
;----------------------------------
;Special Rules
if !desDev ;If no desired device is set..
if balanceMode or shiftMode or setMode or fillMode or loudMode ;..currently for all modes..
desDev = Speakers ;..assume Desk Speakers
;desDev = Default Device ; NOT ..assume current (Default) Device
;if (InStr(opsInfoRaw, "Stereo")) ;idk was to do with fill but now meh
;if fillMode && !onMode && !toggleOff ;If fill mode selected but not on or off
; onMode = 1
;..assume on. UNNECESSARY due "if not 'off' turn on"
;---------------------------------- ;test MsgBox opsInfoRaw %opsInfoRaw%`nfillMode: %fillMode%`ntoggleOff: "%toggleOff%"
;Continue Or Try Again With User Input (UserOps)
if userOpsMode or shiftMode or setMode or balanceMode or switchMode or fillMode or loudMode ;At least one operation recognised
break ;break GetOpsLoop
else {
userOpsMode = 1
inputMode = User Input (UserOps)
InputBox, opsInfoRaw, Operation Select, Enter desired Operation: Switch`, Balance`, Shift`, Fill`nDevice: Desk`, Bed`, Bluetooth`nAnd values/arguments (optional):`nManual`, Default`, Off`, 80 80 90 20 100 100 (bal)`, 20 (shift) etc`n%errorText%
errorText = Error try again...
}
} ;GetOpsLoop
inputErrorCount =
errorText =
Return
;--------------------------------------------------------------------------------------------------------------
GetShiftValues:
if userOpsMode ;User has input UserOps instructions
shiftValRaw := opsInfoRaw ;Initially grab potential raw shift values from OpsInfo user input
else
shiftValRaw := A_ScriptName ;Initially grab potential raw shift values from filename
inputMode = Filename ;Mode is filename unless changed to userinput
Loop { ;MainShiftLoop ;Test raw shift values (initially from filename then from user input)
if InStr(shiftValRaw, "front") ;CHANNELS
shiftChan1 := 1, shiftChan2 = 2 ;If front is found the channels to shift are 1 and 2
else if InStr(shiftValRaw, "cen") ;If cen: just channel 3 etc...
shiftChan1 := 3
else if InStr(shiftValRaw, "sub")
shiftChan1 := 4
else if InStr(shiftValRaw, "back left")
shiftChan1 := 5
else if InStr(shiftValRaw, "back right")
shiftChan1 := 6
else if InStr(shiftValRaw, "rear") ;
shiftChan1 := 5, shiftChan2 = 6 ;
else { ;NoChannel ;None of 'front' 'cen' 'sub' or 'rear' were found
chanError := "Channel"
} ;NoChannel
if InStr(shiftValRaw, "down") ;SHIFT DIRECTION (look for 'up' or 'down' in raw values)
shiftDir := "Left"
else if InStr(shiftValRaw, "up")
shiftDir := "Right"
else { ;NoDir ;Neither 'up' nor 'down' was found
if chanError
dirError := ", Direction"
else
dirError := "Direction"
} ;NoDir
RegExMatch(shiftValRaw, "\d+", shiftMag) ;SHIFT MAGNITUDE (Find a 1 or more digit number)
if shiftMag not between 1 and 100 ;Check 1 - 100 inclusive
{
if chanError or dirError
magError1 := ", Magnitude"
else
magError1 := "Magnitude" ;magError2 := % "# Magnitude not valid (" shiftMag ") #`n"
shiftMag =
}
if shiftChan1 && shiftDir && shiftMag ;Everything was successful
break ;break out of the loop
else { ;UserInputMode ;One or more element was not successful (channel direction magnitude)
inputmode = User Input (Shift) ;Just for reporting outcome
if !shiftFail ;No previous fails do first input box
InputBox, shiftValRaw, Input desired SHIFT, %chanError%%dirError%%magError1% not found/valid in filename%magError2%`nEnter desired shift:,,,150
else ;Previous fails, do second input box with error message
InputBox, shiftValRaw, Input desired SHIFT (try again), %chanError%%dirError%%magError1% still not found/valid%magError2%`nEnter desired shift and include:`nFRONT`, CEN`, SUB or REAR and..`nUP or DOWN and..`nA value from 1 to 100
if ErrorLevel {
ToolTip Giving up`, huh?`nQuitting...
Sleep 1000
WinActivate, %restoreActiveWindow%
ExitApp
}
shiftFail++
} ;UserInputMode
chanError =
dirError =
magError1 =
magError2 =
} ;MainShiftLoop
shiftFail =
Return
;--------------------------------------------------------------------------------------------------------------
GetSetValues:
if userOpsMode ;User has input UserOps instructions
setValRaw := opsInfoRaw ;Initially grab potential raw set values from OpsInfo user input
else
setValRaw := A_ScriptName ;Initially grab potential raw set values from filename
inputMode = Filename ;Mode is filename unless changed to userinput
Loop { ;MainSetLoop ;Test raw set values (initially from filename then from user input)
if InStr(setValRaw, "front left")
setChan1 := 1
else if InStr(setValRaw, "front right")
setChan1 := 2
else if InStr(setValRaw, "front") ;CHANNELS
setChan1 := 1, setChan2 = 2 ;If front/rear setChan1 and 2 are used to hold 1/2 and 5/6
else if InStr(setValRaw, "cen") ;If cen: just channel 3 etc...
setChan1 := 3
else if InStr(setValRaw, "sub")
setChan1 := 4
else if InStr(setValRaw, "back left")
setChan1 := 5
else if InStr(setValRaw, "back right")
setChan1 := 6
else if InStr(setValRaw, "rear")
setChan1 := 5, setChan2 = 6
else { ;NoChannel ;None of 'front' 'cen' 'sub' or 'rear' were found
chanError := "Channel"
} ;NoChannel
RegExMatch(setValRaw, "\d+", setVal) ;SHIFT MAGNITUDE (Find a 1 or more digit number)
if setVal not between -1 and 100 ;Check 0 - 100 inclusive
{
if chanError
magError1 := ", Magnitude"
else
magError1 := "Magnitude" ;
shiftMag =
}
if setChan1 && (setVal > -1) ;Everything was successful
break ;break out of the loop
else { ;UserInputMode ;One or more element was not successful (channel or value)
inputmode = User Input (Set) ;Just for reporting outcome
if !setFail ;No previous fails do first input box
InputBox, setValRaw, Input desired SET value, %chanError%%magError1% not found/valid in filename`nEnter desired SET value:,,,150
else ;Previous fails, do second input box with error message
InputBox, setValRaw, Input desired SET value (try again), %chanError%%magError1% still not found/valid`nEnter desired SET value and include:`nFRONT`, CEN`, SUB or REAR and..`nA value from 0 to 100
if ErrorLevel {
ToolTip Giving up`, huh?`nQuitting...
Sleep 1000
WinActivate, %restoreActiveWindow%
ExitApp
}
setFail++
} ;UserInputMode
chanError =
magError1 =
} ;MainSetLoop
setFail =
balanceMode = 1
desBal%setChan1% := setVal
if setChan2
desBal%setChan2% := setVal
Return
;--------------------------------------------------------------------------------------------------------------
BalValsFilename:
if userOpsMode ;User has input UserOps instructions
RegExMatch(opsInfoRaw, "(\d+[\s,-\.]+){5,5}\d+", balValsRaw)
;OLD balValRaw := opsInfoRaw ;Initially grab potential raw balance values from this OpsInfo user input
else { ;Original filename mode
;Get values from filename (one or more digit followed by space or ,-.)x5 then one more digit (more robust)
RegExMatch(A_ScriptName, "(\d+[\s,-\.]+){5,5}\d+", balValsRaw)
inputMode = Filename ;Over-written if other balance value input mode used instead
}
Return
;--------------------------------------------------------------------------------------------------------------
BalValsUserInput:
InputBox, balValsRaw, Enter Balance Values (# # # # # #), Filename values missing or invalid`nEnter desired balance values for these speakers:`nLeft`, Right`, Centre`, SubWoofer`, Rear-Left`, Rear-Right`neg: 80 80 70 10 100 100
inputMode = User Input (Balance Grouped)
Loop {
if !balValsRaw
break
if (balValsRaw = "x") {
balValsRaw =
GoSub, GetLevelsIndivid ;Legacy option: request each value individually (this only completes with valid values)
break
}
valuesOk := RegExMatch(balValsRaw, "(\d+[\s,-\.]+){5,5}\d+", balValsRaw)
if valuesOk
break
InputBox, balValsRaw, Enter Balance Values (# # # # # #), Filename values missing or invalid`nEnter desired balance values for these speakers:`nLeft`, Right`, Centre`, SubWoofer`, Rear-Left`, Rear-Right`neg: 80 80 70 10 100 100`nError`, try again
}
Return
;--------------------------------------------------------------------------------------------------------------
DefaultInput: ;Default values
inputMode = Default (Balance)
desBal1 = 80 ;Left
desBal2 = 80 ;Right ;Manually edit these values as desired!
desBal3 = 70 ;Centr
desBal4 = 10 ;Sub
desBal5 = 100 ;RearL
desBal6 = 100 ;RearR
Return
;--------------------------------------------------------------------------------------------------------------
SoundCloseOpen:
;Close Existing Sound window
Loop
if WinExist("^Sound$") { ;Check if Sound is open already
WinClose ^Balance$
WinClose Properties$
WinClose ^Sound$
if (A_Index > 10)
run TASKKILL /F /IM "rundll32.exe",, Hide ;Slow, only if necessary
}
else ;If it isn't open
break ;Continue
;Open Sound options
Loop {
Run, mmsys.cpl ;Open Sound menu (to Playback tab)
WinWait, ^Sound$,, 2 ;Wait for it for 2 seconds
if ErrorLevel { ;Sound menu failed to load
Loop 3 ;
run TASKKILL /F /IM "rundll32.exe",, Hide ;Task Kill x3 to close any bugged instance
Sleep 200 ;
}
else ;Sound loaded successfully
break ;continue on to next block
ToolTip Fails: %A_Index% ;Display fail count
if (A_Index > 4) {
MsgBox, Part 1 failed`, try again? idk ;Something unexpected happened
ExitApp
}
}
Return
;--------------------------------------------------------------------------------------------------------------
GetLevelsIndivid: ;Request inputs for each speaker individually
inputMode = User Input (Balance Individual)
ch1Name := "LEFT", ch2Name = "RIGHT", ch3Name = "CENTER", ch4Name = "SUB", ch5Name = "REAR-LEFT", ch6Name = "REAR-RIGHT" ;Set name for each channel
Loop 6 { ;Six channels
j := A_Index ;Counter for sub-loop
InputBox, desBal%j%, % "desBalance Levels: " ch%j%Name, % "Enter desired " ch%j%Name " speaker balance (1-100)" ;First input
Loop { ;loop to escape only on valid entry
if desBal%j% = ;blank entry is valid
break ;break sub-loop to enter next channel
if desBal%j% is number ;must be a number AND..
if (desBal%j% > -1) and (desBal%j% < 101) ;Between 0 and 100 inclusive
break ;as 3 above re break
InputBox, desBal%j%, % "Balance Levels: " ch%j%Name, % "Enter desired " ch%j%Name " speaker balance (1-100)`nError`,try again" ;Second input includes error message
} ;sub-loop to ensure correct entry
} ;per channel loop
Return
;--------------------------------------------------------------------------------------------------------------
ParseValues:
StringReplace, balVals, balValsRaw, `,, %A_SPACE%, All ;Change commas, to spaces
StringReplace, balVals, balVals, ., %A_SPACE%, All ;Change periods. to spaces
StringReplace, balVals, balVals, -, %A_SPACE%, All ;Change hyphens- to spaces
Loop { ;Reduce all multi spaces to single spaces
StringReplace, balVals, balVals, %A_SPACE%%A_SPACE%, %A_SPACE%, UseErrorLevel
if ErrorLevel = 0 ; No more replacements needed.
break
}
Loop, parse, balVals, %A_Space%`, ;Split eg 80 80 70 10 100 100 into desBal1 desBal2 etc
{
desBal%A_Index% := A_LoopField
}
Return
;--------------------------------------------------------------------------------------------------------------
FindDevice:
Loop
{ ;RetryLoop ;Retries whole Switch process once or more
if ((A_Index = 1) or !mod(A_Index, 20))
GoSub, SoundCloseOpen ;Only close and re-open Sound window on first and SOME subsequent attempts for efficiency v reliability
if (switchMode and manualMode) or !desDev ;manual + switchmode OR no desired device set so just end script now that sound dialogue should already be open ready for manual switching or other
{ ;In either case just quit (ExitApp) after displaying the appropriaet ToolTip message:
if (switchMode and manualMode) ;aka "sw man"
ToolTip Sound dialogue opened for manual use (or error maybe idk)`nQuitting...
else ;
ToolTip Sound options opened`, no device specified`nQuitting...
Sleep 1000 ;Display the ToolTip for 1sec and..
ExitApp ;Just exit at this point
}
ToolTip Searching for "%desDev%"
Loop ;ListRestartLoop ;Restarts search from top of list
{
ControlSend, SysListView321, {HOME}, ^Sound$ ;Focus on first item in list
ControlGet, i, List, Count, SysListView321, Sound ;Get number of devices
Loop ;PerDeviceWaitLoop ;Allows script to wait for "Not Plugged In" / "Disconnected" devices
{
ControlGet, x, List, Selected, SysListView321, Sound ;Get info (x = Device: Name, Description, Status)
if InStr(x, desDev) ;If device info (x) contains desired device (desDev) name
{
if (InStr(x, "Not Plugged In") or InStr(x, "Disconnected")) ;Device exists but not connected, Bluetooth device is off or unplugged cable
{
i = 100 ;NEW: Back to i OLD:Timer to search for approx 0.5sec per 1 (Previously multi-use of i variable but unnecessarily complicated)
notConnected = 1 ;Desired device found but not connected (usually Bluetooth)
ToolTip (%A_Index%/%i%) Waiting for "%DesDev%"`nPress [ESC] to cancel
Sleep 500 ;Display allowed time to connect (a few sec or i/2)
}
else ;if InStr(x, "Not Plug.. ;Device is NOT disconnected/not-plugged-in (probably connected)
break 3 ;success, break all 3 loops (DeviceWait, ListRestart, and Retryloop) to continue (next hits the return at end of this SR). Just "return" would probably work
}
else ;if InStr(x, desDev) ;Not correct device
{
;GoSub, DebugMsgBox
if notConnected ;Correct device was selected but has disappeared (expected baheviour briefly before device connects)
break ;break per device loop to restart list (to re-find now-connected device)
ControlSend, SysListView321, {Down}, ^Sound$ ;Normal ops: Not correct device so move down one to check next list item
}
if (A_Index >= i) ;or (A_Index >= k)) ;NEW: Back to multi-use of i, it's surprisingly clever for an amateur like me. OLD: Checked all list items OR reached end of i timer (previously just i for both)
break 2 ;Breaks PerDeviceLoop AND ListRestartLoop (Still in RetryLoop though)
} ;DeviceWaitLoop
notConnected = ;notPlug is cleared for restarting list to (hopefully) find newly connected device
Sleep 2000 ;allowance for BT headset to report available
} ;/ListRestartLoop
failedAttempts++
if (A_Index >= 200) ;Previously only 5
{
MsgBox Failed attempts: %failedAttempts%`nDevice not found`nEnsure "show disconnected devices" is checked`nCheck name of device `/ filename`nQuitting...
ExitApp
}
} ;/RetryLoop
Return
;--------------------------------------------------------------------------------------------------------------
PropertiesEnhancements: ;0 (no tab) is General, 1 Levels, 2 Enhancements
if !WinExist("Properties$")
ControlClick, &Properties, Sound,,,na ;[Properties] button if not already open
Sleep 50
SendMessage, 0x1330, 2,, SysTabControl321, Properties$ ;1 Fancy-ass way to tab
Sleep 0 ; This line and the next are necessary only for certain tab controls. ;2 "
SendMessage, 0x130C, 2,, SysTabControl321, Properties$ ;3 "
if fillMode && manualMode { ;Manual mode, just opens to Balance so quit at this point
MsgBox Enhancements window opened for manual control press [OK] when done
Sleep 500
Exitapp
}
Return
;--------------------------------------------------------------------------------------------------------------
PropertiesLevelsBalance:
sleep 50
if !WinExist("Properties$")
ControlClick, &Properties, Sound,,,na ;[Properties] button if not already open
Sleep 50
WinWait Properties$
SendMessage, 0x1330, 1,, SysTabControl321, Properties$ ;1 Fancy-ass way to tab
Sleep 0 ; This line and the next are necessary only for certain tab controls. ;2 "
SendMessage, 0x130C, 1,, SysTabControl321, Properties$ ;3 "
Loop
if !WinExist("Balance") { ;If it's not open, open it
ControlClick,Button3, Properties$,,,na ;Ctrl Click for Balance loop for efficiency+reliability
sleep 100
}
else ;If it IS open stop trying to open it -> break -> return
break
if manualMode { ;Manual mode, just opens to Balance so quit at this point
MsgBox Balance window opened for manual control press [OK] when done
Sleep 500
Exitapp
}
Return
;--------------------------------------------------------------------------------------------------------------
FillToggle:
Sleep 50
ControlClick, &Restore Defaults, Properties$
Sleep 50
ControlFocus, SysListView321, Properties$
if !toggleOff
Send {Up 3}{Down}{Space}
Sleep 50
ControlClick, OK, Properties$
Sleep 50
Return
;--------------------------------------------------------------------------------------------------------------
LoudToggle:
Sleep 50
ControlClick, &Restore Defaults, Properties$
Sleep 50
ControlFocus, SysListView321, Properties$
if !toggleOff
Send {Up 3}{Down 3}{Space}
Sleep 50
ControlClick, OK, Properties$
Sleep 50
Return
/*
EnhancementsControl:
Sleep 50
ControlClick, &Restore Defaults, Properties$
Sleep 50
ControlFocus, SysListView321, Properties$
if bassManagement {
Send {Space}
}
Send {Down}
if speakerFill {
Send {Space}
Sleep 50
}
Send {Down}
if roomCorrect {
Send {Space}
Sleep 50
}
Send {Down}
if loudnessEq {
Send {Space}
}
Sleep 50
ControlClick, OK, Properties$
Sleep 50
*/
;--------------------------------------------------------------------------------------------------------------
GetCurrentVals:
;Get balance values: Find literal L,R,Sub,RL etc
WinGetText, winStuff, Balance
RegExMatch(winStuff, "L\s*\K\d+", curVal1) ;L Match literal L (or R, Sub, RL etc)
RegExMatch(winStuff, "R\s*\K\d+", curVal2) ;\s* none or more whitespace
RegExMatch(winStuff, "C\s*\K\d+", curVal3) ;\K but don't return this***
RegExMatch(winStuff, "Sub\s*\K\d+", curVal4) ;\d+ then return 1 or more digits
RegExMatch(winStuff, "RL\s*\K\d+", curVal5) ;RegExMatch auto terminates on \r or \n idk
RegExMatch(winStuff, "RR\s*\K\d+", curVal6) ;***Previously used extra line: RegExMatch(balRR, "\d+", balRR)
;MsgBox %winStuff%`n`nL: %balL%`nR: %balR%`nC: %balC%`nSub: %balSub%`nRL: %balRL%`nRR: %balRR%
Return
;--------------------------------------------------------------------------------------------------------------
SetBalance:
Loop 6 {
dir%A_Index% = Right ;Initialise each movement direction as Right
move%A_Index% := desBal%A_Index% - curVal%A_Index% ;Get movement value (difference between
if move%A_Index% > 50 ;If movement value is over 50..
ToolTip VOLUME WARNING! ;display a volume warning tooltip
if (move%A_Index% < 0) ;if movement value is negative.. (if not keep dir:Right and Move val is already positive)
dir%A_Index% := "Left", move%A_Index% := Abs(move%A_Index%) ;set "Left" movement and take absoute value (-2 becomes 2)
if move%A_Index% && !(desBal%A_Index% = "") ;Skip if movement value is 0
;MsgBox % "Yes`, move" A_Index " & desBal: '" desBal%A_Index% else MsgBox % "No`, move" A_Index " & desBal: '" desBal%A_Index%
;Info: trackbar321 322 323 etc (luckily end # is 1-6), dir# = L or R for 1-6 similar move# is movement value for 1-6, sent to Balance window
ControlSend, msctls_trackbar32%A_Index%, % "{" dir%A_Index% " " move%A_Index% "}", ^Balance$
; MsgBox % "move" A_Index ": "move%A_Index% " = desBal" A_Index ": " desBal%A_Index% " - curVal" A_Index ": " curVal%A_Index% "dir" A_Index ": " dir%A_Index%
}
sleep 50 ;Delay here prevents final keystroke from being lost
ToolTip Speaker balance set`n%inputMode% values used`n_ %desBal1%_ %desBal2%_ %desBal3%_ %desBal4%_ %desBal5%_ %desBal6%_`nQuitting...
;Sometimes values shift up or down one due to rounding I guess
Return
;--------------------------------------------------------------------------------------------------------------
DoShifts:
; ControlSend, msctls_trackbar32%shiftChan1%, % "{" dir%A_Index% " " move%A_Index% "}", ^Balance$
ControlSend, msctls_trackbar32%shiftChan1%, {%shiftDir% %shiftMag%}, ^Balance$
if shiftChan2 { ;if rear or front
ControlSend, msctls_trackbar32%shiftChan2%, {%shiftDir% %shiftMag%}, ^Balance$ ;do second channel/speaker as well
ToolTip %A_ScriptName%`nChannels %shiftChan1% & %shiftChan2% shifted %shiftDir% by %shiftMag%`nQuitting...
}
else ;Do single channel tooltip
ToolTip %A_ScriptName%`nChannel %shiftChan1% shifted %shiftDir% by %shiftMag%`nQuitting...
Sleep 50 ;sleep here prevents final notch being lost
Return
;--------------------------------------------------------------------------------------------------------------
SetDefaultDevice:
ControlClick,&Set Default,^Sound$,,,,na ;Control Click Set Active button (no mouse move)
Sleep 50
ControlClick,&Apply,^Sound$,,,,na ;As above for Apply
Sleep 50
ToolTip %desDev% set as default device`nQuitting...
Return
;--------------------------------------------------------------------------------------------------------------
CloseAll:
;Done and OK to close ..until closed lol
Loop
if WinExist("^Sound$") {
ControlClick,&OK,^Balance$,,,,na
ControlClick,OK,Properties$,,,,na
ControlClick,OK,^Sound$,,,,na
}
else
break
WinActivate, %restoreActiveWindow%
Return
;--------------------------------------------------------------------------------------------------------------
BackToSound:
;Done and OK to close only back to sound window
Loop
if WinExist("^Balance$") or WinExist("Properties$") {
ControlClick,&OK,^Balance$,,,,na
ControlClick,OK,Properties$,,,,na
}
else
break
Return
;--------------------------------------------------------------------------------------------------------------
BackToProperties: ;Probs won't use this, currently might as well just be single line: ControlClick,&OK,^Balance$,,,,na
;Done and OK to close only back to properties
Loop
if WinExist("^Balance$") {
ControlClick,&OK,^Balance$,,,,na
}
else
break
Return
;--------------------------------------------------------------------------------------------------------------
debugMsgBox:
;MsgBox % "A_Index: " A_Index "`ni (list count): " i "`nj: " j "`nk (attempts/waiting before RetryLoop): " k "`ndesDev: "desDev "`ndesDevNum: " desDevNum "`ndev" desDevNum "Name: " dev%desDevNum%Name "`ndev" desDevNum "Nick: " dev%desDevNum%Nick "`nfailedAttempts: " failedAttempts "`n`nx: " x
Return
;--------------------------------------------------------------------------------------------------------------
;=============HOTKEYS==========================================================================================
ESC::
ToolTip Quitting
Sleep 400
ExitApp
Return
;--------------------------------------------------------------------------------------------------------------
;==============TIMERS==============
;No timers used for now
;--------------------------------------------------------------------------------------------------------------