Skip to content

Commit 1c560e4

Browse files
committed
Initial version
0 parents  commit 1c560e4

File tree

8 files changed

+321
-0
lines changed

8 files changed

+321
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.exe
2+
SoundVolumeView

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# AudioSwitcher
2+
3+
Quickly switch active audio devices for example from webcam & speakers to headset and back
4+
5+
![Screenshot](screenshot.png)
6+
7+
## Configuration
8+
The correct device-IDs have to be configured in audioswitcher.ini.
9+
10+
For the device-IDs start SoundVolumeView in the subdirectory SoundVolumeView, sort entries after column "Type" and go to the entries with "Type" = device,
11+
click on the right mouse button, select "Properties" and then use the entry for "Command-Line Friendly ID".
12+
13+
## Download
14+
Windows: ![audioswitcher.zip](https://github.com/alexgit2k/audioswitcher/releases/latest/download/audioswitcher.zip)
15+
16+
## Third Party Inclusions
17+
SoundVolumeView from NirSoft: https://www.nirsoft.net/utils/sound_volume_view.html \
18+
Icon from Dtaf Alonso: https://www.iconarchive.com/show/yosemite-flat-icons-by-dtafalonso/Music-icon.html
19+
20+
## License and Copyright
21+
This software is copyright (c) 2020 by alexgit2k.
22+
23+
This is free software, licensed under MIT License.

audioswitcher-window.pbf

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
; Form Designer for Purebasic - 5.72
2+
; Warning: this file uses a strict syntax, if you edit it, make sure to respect the Form Designer limitation or it won't be opened again.
3+
4+
;
5+
; This code is automatically generated by the FormDesigner.
6+
; Manual modification is possible to adjust existing commands, but anything else will be dropped when the code is compiled.
7+
; Event procedures needs to be put in another source file.
8+
;
9+
10+
Global WindowMain
11+
12+
Global ButtonDevices1, ButtonDevices2
13+
14+
15+
Procedure OpenWindowMain(x = 0, y = 0, width = 250, height = 150)
16+
WindowMain = OpenWindow(#PB_Any, x, y, width, height, "AudioSwitcher", #PB_Window_SystemMenu | #PB_Window_TitleBar | #PB_Window_ScreenCentered)
17+
;ButtonDevices1 = ButtonImageGadget(#PB_Any, 10, 10, 230, 60, 0, #PB_Button_Toggle)
18+
;ButtonDevices2 = ButtonImageGadget(#PB_Any, 10, 80, 230, 60, 0, #PB_Button_Toggle)
19+
ButtonDevices1 = BevelButton::New(10, 10, 230, 60, 0, "Webcam", font, #PB_Button_Toggle)
20+
ButtonDevices2 = BevelButton::New(10, 80, 230, 60, 0, "Headset", font, #PB_Button_Toggle)
21+
EndProcedure
22+
23+
Procedure WindowMain_Events(event)
24+
Select event
25+
Case #PB_Event_CloseWindow
26+
ProcedureReturn #False
27+
28+
Case #PB_Event_Menu
29+
Select EventMenu()
30+
EndSelect
31+
32+
Case #PB_Event_Gadget
33+
Select EventGadget()
34+
EndSelect
35+
EndSelect
36+
ProcedureReturn #True
37+
EndProcedure

audioswitcher.ini

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[base]
2+
font = Segoe UI
3+
fontSize = 19
4+
last = devices1
5+
6+
[devices1]
7+
devices1Text = Webcam
8+
devices1Speaker = Logitech Speaker\Device\Speaker\Render
9+
devices1Mic = Logitech Webcam\Device\Microphone\Capture
10+
11+
[devices2]
12+
devices2Text = Headset
13+
devices2Speaker = Realtek High Definition Audio\Device\Headset\Render
14+
devices2Mic = Realtek High Definition Audio\Device\Headset Microphone\Capture

audioswitcher.pb

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
; AudioSwitcher - Switch audio from speakers & webcam to headset
2+
; 2020 by Alex
3+
4+
; Variables
5+
Global NewMap Config$()
6+
7+
; Procedures
8+
Declare ReadPreference(Map PrefMap$())
9+
Declare SoundDevice(Device$, Type = -1, Wait = #False)
10+
Declare WritePreference(Device$)
11+
12+
; Config
13+
ReadPreference(Config$())
14+
15+
; GUI
16+
XIncludeFile "bevelbutton.pb"
17+
XIncludeFile "audioswitcher-window.pbf"
18+
19+
; Font
20+
gadgetFont = LoadFont(#PB_Any, Config$("font"), Val(Config$("fontSize")), #PB_Font_HighQuality)
21+
font = FontID(gadgetFont)
22+
23+
; Window
24+
OpenWindowMain()
25+
BevelButton::SetText(ButtonDevices1, Config$("devices1Text"), font)
26+
BevelButton::SetText(ButtonDevices2, Config$("devices2Text"), font)
27+
28+
; Set current state
29+
Select Config$("last")
30+
Case "devices1"
31+
BevelButton::Enable(ButtonDevices1)
32+
BevelButton::Disable(ButtonDevices2)
33+
Case "devices2"
34+
BevelButton::Enable(ButtonDevices2)
35+
BevelButton::Disable(ButtonDevices1)
36+
EndSelect
37+
38+
; ----------------------------------------------------------------------------------------------------------------------------------
39+
40+
; Loop
41+
Repeat
42+
Event = WaitWindowEvent()
43+
44+
Select Event
45+
Case #PB_Event_Gadget
46+
Select EventGadget()
47+
Case BevelButton::GetGadgetID(ButtonDevices1)
48+
49+
; Toggle Buttons
50+
BevelButton::Enable(ButtonDevices1)
51+
BevelButton::Disable(ButtonDevices2)
52+
53+
; Switch Audio
54+
SoundDevice(Config$("devices1Mic"))
55+
SoundDevice(Config$("devices1Speaker"))
56+
SoundDevice(Config$("devices1Mic"), 2)
57+
SoundDevice(Config$("devices1Speaker"), 2, True)
58+
59+
Config$("last") = "devices1"
60+
Case BevelButton::GetGadgetID(ButtonDevices2)
61+
62+
; Toggle Buttons
63+
BevelButton::Enable(ButtonDevices2)
64+
BevelButton::Disable(ButtonDevices1)
65+
66+
; Switch Audio
67+
SoundDevice(Config$("devices2Mic"))
68+
SoundDevice(Config$("devices2Speaker"))
69+
SoundDevice(Config$("devices2Mic"), 2)
70+
SoundDevice(Config$("devices2Speaker"), 2, True)
71+
72+
Config$("last") = "devices2"
73+
EndSelect
74+
EndSelect
75+
Until Event = #PB_Event_CloseWindow
76+
77+
; Write last state
78+
WritePreference(Config$("last"))
79+
80+
; Free Memory
81+
BevelButton::Delete(ButtonDevices2)
82+
BevelButton::Delete(ButtonDevices1)
83+
84+
End
85+
86+
; ----------------------------------------------------------------------------------------------------------------------------------
87+
88+
Procedure SoundDevice(Device$, Type = -1, Wait = #False)
89+
param$ = "/SetDefault " + Chr(34) + Device$ + Chr(34)
90+
; Add type if available
91+
If Type <> -1
92+
param$ = param$ + " " + Str(Type)
93+
EndIf
94+
; Flags
95+
Flags = 0
96+
If Wait = True
97+
Flags = #PB_Program_Wait
98+
EndIf
99+
; Run SoundVolumeView
100+
RunProgram("SoundVolumeView/SoundVolumeView", param$, "", Flags)
101+
EndProcedure
102+
103+
Procedure ReadPreference(Map PrefMap$())
104+
; Open Preferences
105+
FileIni.s = GetFilePart(ProgramFilename(),#PB_FileSystem_NoExtension) + ".ini"
106+
If (OpenPreferences(FileIni) = 0)
107+
MessageRequester("Error", "Can not open ini-file: "+FileIni)
108+
End
109+
EndIf
110+
111+
; Read
112+
ExaminePreferenceGroups()
113+
While NextPreferenceGroup()
114+
ExaminePreferenceKeys()
115+
While NextPreferenceKey()
116+
; Debug PreferenceGroupName() + ": " + PreferenceKeyName() + "=" + PreferenceKeyValue()
117+
PrefMap$(PreferenceKeyName())=PreferenceKeyValue()
118+
Wend
119+
Wend
120+
121+
; Close
122+
ClosePreferences()
123+
EndProcedure
124+
125+
Procedure WritePreference(Device$)
126+
; Open Preferences
127+
FileIni.s = GetFilePart(ProgramFilename(),#PB_FileSystem_NoExtension) + ".ini"
128+
If (OpenPreferences(FileIni) = 0)
129+
MessageRequester("Error", "Can not open ini-file: "+FileIni)
130+
End
131+
EndIf
132+
133+
; Write
134+
PreferenceGroup("base")
135+
WritePreferenceString("last", Device$)
136+
137+
; Close
138+
ClosePreferences()
139+
EndProcedure
140+
141+
; IDE Options = PureBasic 5.72 (Windows - x86)
142+
; CursorPosition = 61
143+
; FirstLine = 21
144+
; Folding = -
145+
; EnableXP
146+
; UseIcon = icon.ico
147+
; Executable = audioswitcher.exe
148+
; DisableDebugger

bevelbutton.pb

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
; BevelButton Menu
2+
3+
DeclareModule BevelButton
4+
Structure button
5+
gadget.l
6+
width.i
7+
height.i
8+
text.s
9+
font.i
10+
EndStructure
11+
12+
Declare New(x, y, width, height, image, text.s, font = 0, flags = 0)
13+
Declare Delete(*button.button)
14+
Declare Redraw(*button.button)
15+
Declare Enable(*button.button)
16+
Declare Disable(*button.button)
17+
Declare GetGadgetID(*button.button)
18+
Declare SetText(*button.button, text.s, font = 0)
19+
Declare.s GetText(*button.button)
20+
Declare SetFont(*button.button, font)
21+
EndDeclareModule
22+
23+
Module BevelButton
24+
Procedure New(x, y, width, height, image, text.s, font = 0, flags = 0)
25+
Protected *button.button
26+
*button = AllocateMemory(SizeOf(button))
27+
*button\gadget = ButtonImageGadget(#PB_Any, x, y, width, height, image, flags)
28+
*button\width = width
29+
*button\height = height
30+
*button\font = font
31+
*button\text = text
32+
33+
Redraw(*button)
34+
ProcedureReturn *button
35+
EndProcedure
36+
37+
Procedure Delete(*button.button)
38+
FreeMemory(*button)
39+
EndProcedure
40+
41+
Procedure Redraw(*button.button)
42+
Protected color, image
43+
44+
; Button state
45+
If GetGadgetState(*button\gadget) = #True
46+
color = RGB(0, 255, 0)
47+
Else
48+
color = GetSysColor_(#COLOR_BTNFACE)
49+
EndIf
50+
51+
; Draw button-image
52+
image = CreateImage(#PB_Any, *button\width, *button\height)
53+
StartDrawing(ImageOutput(image))
54+
DrawingMode(#PB_2DDrawing_Transparent)
55+
; Background
56+
Box(0, 0, *button\width, *button\height, color)
57+
; Text
58+
If *button\font <> 0
59+
DrawingFont(*button\font)
60+
EndIf
61+
FrontColor(GetSysColor_(#COLOR_BTNTEXT))
62+
DrawText((*button\width - TextWidth(*button\text)) / 2, (*button\height - TextHeight(*button\text)) / 2, *button\text)
63+
StopDrawing()
64+
SetGadgetAttribute(*button\gadget, #PB_Button_Image, ImageID(image))
65+
EndProcedure
66+
67+
Procedure Enable(*button.button)
68+
SetGadgetState(*button\gadget, #True)
69+
Redraw(*button)
70+
EndProcedure
71+
72+
Procedure Disable(*button.button)
73+
SetGadgetState(*button\gadget, #False)
74+
Redraw(*button)
75+
EndProcedure
76+
77+
Procedure GetGadgetID(*button.button)
78+
ProcedureReturn *button\gadget
79+
EndProcedure
80+
81+
Procedure SetText(*button.button, text.s, font = 0)
82+
*button\text = text
83+
If font <> 0
84+
*button\font = font
85+
EndIf
86+
Redraw(*button)
87+
EndProcedure
88+
89+
Procedure.s GetText(*button.button)
90+
ProcedureReturn *button\text
91+
EndProcedure
92+
93+
Procedure SetFont(*button.button, font)
94+
*button\font = font
95+
Redraw(*button)
96+
EndProcedure
97+
EndModule

icon.ico

166 KB
Binary file not shown.

screenshot.png

2.21 KB
Loading

0 commit comments

Comments
 (0)