Skip to content

Commit

Permalink
added "active sink/source"
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelMiksits committed Sep 7, 2023
1 parent 2a68be4 commit 20467b1
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
View/switch sinks and sources through pactl with a lot less typing and or headache. Example output from my system:

```
Active sink/source:
Default sink: CA0132 Sound Core3D [Sound Blaster Recon3D / Z-Series / Sound BlasterX AE-5 Plus] Analog Stereo
Default source: Meteor condenser microphone Analog Stereo
------------------------------
Selectable sinks/sources:
Sinks:
1. CA0132 Sound Core3D [Sound Blaster Recon3D / Z-Series / Sound BlasterX AE-5 Plus] Analog Stereo
2. Starship/Matisse HD Audio Controller Digital Stereo (IEC958)
3. Navi 21/23 HDMI/DP Audio Controller Digital Stereo (HDMI 3)
4. Meteor condenser microphone Analog Stereo
Sources:
5. Monitor of CA0132 Sound Core3D [Sound Blaster Recon3D / Z-Series / Sound BlasterX AE-5 Plus] Analog Stereo
6. CA0132 Sound Core3D [Sound Blaster Recon3D / Z-Series / Sound BlasterX AE-5 Plus] Analog Stereo
7. Monitor of Starship/Matisse HD Audio Controller Digital Stereo (IEC958)
8. Starship/Matisse HD Audio Controller Analog Stereo
9. Monitor of Navi 21/23 HDMI/DP Audio Controller Digital Stereo (HDMI 3)
10. Monitor of Meteor condenser microphone Analog Stereo
11. Meteor condenser microphone Analog Stereo
Select sink/source with number, 'e' for exit, any input to refresh list
```
36 changes: 35 additions & 1 deletion audiomux.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ def getSources():
sourcesRaw = re.split(r"[\t\n]", subprocess.getoutput("pactl list sources"))
return parseSources(sourcesRaw)

#grabs the default sink
def getDefaultSink():
return subprocess.getoutput("pactl get-default-sink")

#grabs the default source
def getDefaultSource():
return subprocess.getoutput("pactl get-default-source")

#parses sinks string returned from shell
def parseSinks(sinksRaw):
sinks = list()
Expand Down Expand Up @@ -51,6 +59,32 @@ def main():
for i in range(len(sources)):
fullList.append(sources[i])

defaultSink = getDefaultSink()
defaultSource = getDefaultSource()

defaultSinkAt = 0 #find where it is in the sinks list, grab description
defaultSourceAt = 0

for i in range(len(sinks)):
if defaultSink in sinks[i][0]:
defaultSinkAt = i

for i in range(len(sources)):
if defaultSource in sources[i][0]:
defaultSourceAt = i

print("Active sink/source:")

print("Default sink: ", end="")
print(sinks[defaultSinkAt][1])

print("Default source: ", end="")
print(sources[defaultSourceAt][1])

print("------------------------------")

print("Selectable sinks/sources:")

j = 0
print("Sinks: ")
for i in range(len(sinks)):
Expand All @@ -64,7 +98,7 @@ def main():
print(sources[i][1])
j += 1

print("Select sink/source with number, 'e' for exit")
print("Select sink/source with number, 'e' for exit, any input to refresh list")
userInput = input()

userInputParsed = -1
Expand Down

0 comments on commit 20467b1

Please sign in to comment.