mdonoughe / sbz-switch

Utility for switching Sound Blaster outputs on Windows
Apache License 2.0
43 stars 5 forks source link

Added a "quick-switch" switch #3

Open EXTREMEGABEL opened 3 years ago

EXTREMEGABEL commented 3 years ago

Hi I built a feature which basically switches from The Headphones on and off while changing the audio levels via a simple command line flag since that is a scenario that I needed this thing to do.

There's 4 added Constants in main.rs which let you define the levels aswell as the for lack of a better term: DeviceID

I'm however a Rust noob so there's probably a better way to do this but that's for you to decide :D

mdonoughe commented 3 years ago

The volume levels shouldn't be constants :)

I saw this PR when it was created but it has been sitting for a while because this is something I have already done and something I want to do in a very different way.

Being able to change between headphones and speakers was really the motivation for writing this library. However, in the library there's nothing specifically about that. Instead, either through the Rust API or through the command line options, the functionality is exposed such that some external software can do the output switching, or anything else it might want to do.

For example, if you wanted to write a simple PowerShell or Python script to switch devices, you can call sbz-switch -f json dump and pass the output through ConvertFrom-Json/json.loads to read in the current state, and then use sbz-switch -f json apply to perform the switch.

I use https://github.com/mdonoughe/sbzdeck to switch outputs, which probably isn't very interesting to you if you don't have a Stream Deck. It's much more sophisticated than this PR because it allows user configuration of which attributes should be saved and restored across switches, and tracks changes to those attributes so the correct values are restored even if the output device is switched by some other software. In my case, I have sound enhancements turned on only for speakers.

The problem with sbzdeck is that it is tied to the Stream Deck and, although it tries to account for other software, it doesn't really play nice with other software trying to do the same thing at the same time. I expect if you could somehow run multiple instances of sbzdeck they would confuse each other.

So what I wanted to do was make something like a common service where multiple applications could call into it and the service would handle the switching. That way there is only one thing which owns the sound configuration and there won't be any fighting. However, Windows doesn't really do dbus and I never settled on an appropriate alternative.

EXTREMEGABEL commented 3 years ago

You are absolutely right about the constants that just didn't occur to me since in my scenario I can get away with constants but I guess some sort of config file would be a way better solution for this

My main motivation behind this was to have one shortcut on my desktop that just switches between the two settings I use and achieving this inside the application seemed more straight forward than building a PS script that has to call and parse the applications output several times

EXTREMEGABEL commented 3 years ago

I have now added a configuration file for the quickswitch operation (Even though this still doesn't make this compatible with your vision for this (as far as i understand it) :D)