Skip to content

Commit

Permalink
add argument to disable mute
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonoughe committed Nov 14, 2017
1 parent 52dc025 commit 8a6f6ca
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 9 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [1.1.0] - 2017-11-13
### Added
- Muting can be disabled by passing `-m false`.

## [1.0.0] - 2017-11-11
### Added
- Dump command to show or save current configuration.
Expand All @@ -14,6 +18,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Changed
- Previous functionality for switching the output device has changed significantly. `sbz-switch --speakers 3003 --volume 60` becomes `sbz-switch set -i "Processing Control" SpeakerConfig 12291 --volume 60` (3003 was a hex value and 12291 is decimal), however it seems `-i "Device Control" SelectOutput 1` is a better way of doing the same thing. See README.md for more information about the new syntax.

## [0.1.0] - 2017-10-30
## 0.1.0 - 2017-10-30
### Added
- Command to switch speaker configuration and adjust volume.

[Unreleased]: https://github.com/mdonoughe/sbz-switch/compare/v1.1.0...HEAD
[1.1.0]: https://github.com/mdonoughe/sbz-switch/compare/v1.0.0...v1.1.0
[1.0.0]: https://github.com/mdonoughe/sbz-switch/compare/v0.1.0...v1.0.0
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "sbz-switch"
version = "1.0.0"
version = "1.1.0"
authors = ["Matthew Donoughe <[email protected]>"]
description = "Utility for changing Sound Blaster parameters on Windows"
repository = "https://github.com/mdonoughe/sbz-switch/"
Expand Down
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,41 @@ This may have bugs. Use at your own risk, especially if you have configured your

## Usage

```
USAGE:
sbz-switch.exe [SUBCOMMAND]
FLAGS:
-h, --help Prints help information
-V, --version Prints version information
SUBCOMMANDS:
apply applies a saved configuration
dump prints out the current configuration
help Prints this message or the help of the given subcommand(s)
set sets specific parameters
```

### Set

> Set a small number of parameters
```
USAGE:
sbz-switch.exe set [OPTIONS]
FLAGS:
-h, --help Prints help information
-V, --version Prints version information
OPTIONS:
-b <FEATURE> <PARAMETER> <true|false> Sets a boolean value
-f <FEATURE> <PARAMETER> <VALUE> Sets a floating-point value
-i <FEATURE> <PARAMETER> <VALUE> Sets an integer value
-m <true|false> Temporarily mutes while changing parameters [default: true]
-v, --volume <VOLUME> Sets the volume, in percent
```

Switch to speakers at 60% volume with effects turned on:

sbz-switch set -i "Device Control" SelectOutput 1 -b EfxMasterControl "THXEfx Master OnOff" true -v 60
Expand All @@ -36,6 +67,18 @@ Switch to headphones at 10% volume with effects turned off:

> See or save the current parameters
```
USAGE:
sbz-switch.exe dump [OPTIONS]
FLAGS:
-h, --help Prints help information
-V, --version Prints version information
OPTIONS:
-o, --output <FILE> Saves the current settings to a file
```

See the current settings:

sbz-switch dump
Expand All @@ -48,6 +91,19 @@ Save the current settings to headphones.toml:

> Set many parameters at once
```
USAGE:
sbz-switch.exe apply [OPTIONS]
FLAGS:
-h, --help Prints help information
-V, --version Prints version information
OPTIONS:
-f <FILE> Reads the settings from a file instead of stdin
-m <true|false> Temporarily mutes while changing parameters [default: true]
```

Apply the previously saved headphones.toml file:

sbz-switch apply -f headphones.toml
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,14 @@ pub fn dump(logger: &Logger) -> Result<Table, Box<Error>> {
Ok(output)
}

pub fn set(logger: &Logger, configuration: &Configuration) -> Result<(), Box<Error>> {
pub fn set(logger: &Logger, configuration: &Configuration, mute: bool) -> Result<(), Box<Error>> {
let endpoint = get_default_endpoint(logger)?;
let premuted = endpoint.get_mute()?;
if !premuted {
let mute_unmute = mute && !endpoint.get_mute()?;
if mute_unmute {
endpoint.set_mute(true)?;
}
let result = set_internal(logger, configuration, &endpoint);
if !premuted {
if mute_unmute {
endpoint.set_mute(false)?;
}

Expand Down
24 changes: 22 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[macro_use]
extern crate clap;
#[macro_use]
extern crate slog;
Expand Down Expand Up @@ -52,6 +53,14 @@ fn main() {
.value_name("FILE")
.help("Reads the settings from a file instead of stdin")
.takes_value(true),
)
.arg(
Arg::with_name("mute")
.short("m")
.value_name("true|false")
.default_value("true")
.help("Temporarily mutes while changing parameters")
.takes_value(true),
),
)
.subcommand(
Expand Down Expand Up @@ -91,6 +100,14 @@ fn main() {
.value_name("VOLUME")
.help("Sets the volume, in percent")
.takes_value(true),
)
.arg(
Arg::with_name("mute")
.short("m")
.value_name("true|false")
.default_value("true")
.help("Temporarily mutes while changing parameters")
.takes_value(true),
),
)
.get_matches();
Expand Down Expand Up @@ -142,7 +159,8 @@ fn apply(logger: &Logger, matches: &ArgMatches) -> Result<(), Box<Error>> {
let configuration: Configuration = toml::from_str(&text)?;
mem::drop(text);

sbz_switch::set(logger, &configuration)
let mute = value_t!(matches, "mute", bool)?;
sbz_switch::set(logger, &configuration, mute)
}

struct Collator<I, F> {
Expand Down Expand Up @@ -235,5 +253,7 @@ fn set(logger: &Logger, matches: &ArgMatches) -> Result<(), Box<Error>> {
}),
creative: Some(creative_table),
};
sbz_switch::set(logger, &configuration)

let mute = value_t!(matches, "mute", bool)?;
sbz_switch::set(logger, &configuration, mute)
}

0 comments on commit 8a6f6ca

Please sign in to comment.