diff --git a/README.md b/README.md new file mode 100644 index 0000000..6bd39ac --- /dev/null +++ b/README.md @@ -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 +``` \ No newline at end of file diff --git a/audiomux.py b/audiomux.py index f023477..5f44991 100644 --- a/audiomux.py +++ b/audiomux.py @@ -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() @@ -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)): @@ -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