Skip to content

Commit

Permalink
Merge pull request #1 from indiscipline/dev
Browse files Browse the repository at this point in the history
v0.1.2:
feat: Support reading IEEE Float files
fix: Showing errors when processing multiple files
refactor: Separate config module
refactor: Abstracting sample copying logic to macros
refactor: Clippy warnings fix
  • Loading branch information
indiscipline authored Aug 11, 2016
2 parents c27875f + 89bb6b8 commit c4af630
Show file tree
Hide file tree
Showing 6 changed files with 258 additions and 193 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
target
Thumbs.db
reaper

22 changes: 17 additions & 5 deletions 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 = "zrtstr"
version = "0.1.0"
version = "0.1.2"
authors = ["Kirill I. <[email protected]>"]

exclude = [
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ and the executable will be in `target/release/zrtstr`.

## TODO
Here are the current problems and planned features:
- [ ] **Float support**: Add support for IEEE Float files
- [ ] **Float support**: Add writing support for IEEE Float files (upstream-dependent)
- [ ] **Add automatic tests**
- [ ] **Refactor excessive copy-pasted nested blocks in code**

## Contributing ##
This is an enthusiast project, so any help and/or critique will be much appreciated.
Expand All @@ -45,4 +44,4 @@ Feel free to file a bug report or feature request via [Issues](https://github.co
## License ##
**zrtstr** licensed under GNU General Public License version 2 or later;

See `LICENSE` file for full details.
See `LICENSE` file for full details.
100 changes: 100 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
extern crate clap;

use clap::{Arg, App};
use std::fs;
use std::process;

static LICENSE: &'static str = "zrtstr licensed under GNU General Public License version 2 or later;
Full License available at <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.";

pub struct Conf {
pub dither: u32,
pub dry_run: bool,
pub no_overwrites: bool,
}

pub fn get() -> (Option<String>, Conf) {
let matches = App::new("zrtstr")
.author(crate_authors!())
.version(crate_version!())
.about("Check stereo WAV-file for identical channels, detecting \
faux-stereo files generated by some audio-editing software and \
DAWs.\nOutputs a true-mono WAV file on detection of \
faux-stereo. Takes left channel of the input file, writes in the \
same location with -MONO suffix in file name.")
.arg(Arg::with_name("INPUT")
.help("Path to the input file to process. If no input given, \
process all WAV files in current directory.")
.index(1)
.validator(validate_path))
.arg(Arg::with_name("dither")
.short("d")
.long("dither")
.value_name("THRESHOLD")
.required(false)
.help("Set threshold for sample level difference to process \
dithered audio.{n}Positive number (amplitude delta).")
.next_line_help(true)
.takes_value(true)
.default_value("10")
.validator(validate_u32))
.arg(Arg::with_name("license")
.short("l")
.long("license")
.help("Display the license information."))
.arg(Arg::with_name("dry_run")
.short("n")
.long("nowrite")
.help("Disable saving converted mono files. Analyze pass only.")
.required(false))
.arg(Arg::with_name("no_overwrites")
.short("p")
.long("protect")
.help("Disable overwriting when saving converted mono files.")
.required(false))
.get_matches();

if matches.is_present("license") {
println!("{}", LICENSE);
println!("\nclap (Command Line Argument Parser) License:");
println!(include_str!("../LICENSE-CLAP"));
process::exit(0);
}

let conf = Conf {
dither: if matches.is_present("dither") {
value_t!(matches, "dither", u32).unwrap_or(10)
} else {
0
},
dry_run: matches.is_present("dry_run"),
no_overwrites: matches.is_present("no_overwrites"),
};
let input_fname = if matches.is_present("INPUT") {
Some(matches.value_of("INPUT").unwrap().to_string())
} else {
None
};
(input_fname, conf)
}

pub fn validate_u32(value: String) -> Result<(), String> {
value.parse::<u32>()
.map(|_| ())
.map_err(|_| "Supplied parameter is not a valid number!".to_owned())
}

pub fn validate_path(path: String) -> Result<(), String> {
if fs::metadata(&path).is_ok() {
if path.to_lowercase().ends_with(".wav") {
Ok(())
} else {
// clap automatically adds "error: " to the beginning of the message.
Err(String::from("Input file must have .wav extension!"))
}
} else {
Err(String::from("Input file doesn't exist"))
}
}
Loading

0 comments on commit c4af630

Please sign in to comment.