Skip to content

Commit c4af630

Browse files
authored
Merge pull request #1 from indiscipline/dev
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
2 parents c27875f + 89bb6b8 commit c4af630

6 files changed

Lines changed: 258 additions & 193 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
target
22
Thumbs.db
3+
reaper
34

Cargo.lock

Lines changed: 17 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "zrtstr"
3-
version = "0.1.0"
3+
version = "0.1.2"
44
authors = ["Kirill I. <elephanttalk@protonmail.com>"]
55

66
exclude = [

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ and the executable will be in `target/release/zrtstr`.
3333

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

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

48-
See `LICENSE` file for full details.
47+
See `LICENSE` file for full details.

src/config.rs

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
extern crate clap;
2+
3+
use clap::{Arg, App};
4+
use std::fs;
5+
use std::process;
6+
7+
static LICENSE: &'static str = "zrtstr licensed under GNU General Public License version 2 or later;
8+
Full License available at <http://gnu.org/licenses/gpl.html>.
9+
This is free software: you are free to change and redistribute it.
10+
There is NO WARRANTY, to the extent permitted by law.";
11+
12+
pub struct Conf {
13+
pub dither: u32,
14+
pub dry_run: bool,
15+
pub no_overwrites: bool,
16+
}
17+
18+
pub fn get() -> (Option<String>, Conf) {
19+
let matches = App::new("zrtstr")
20+
.author(crate_authors!())
21+
.version(crate_version!())
22+
.about("Check stereo WAV-file for identical channels, detecting \
23+
faux-stereo files generated by some audio-editing software and \
24+
DAWs.\nOutputs a true-mono WAV file on detection of \
25+
faux-stereo. Takes left channel of the input file, writes in the \
26+
same location with -MONO suffix in file name.")
27+
.arg(Arg::with_name("INPUT")
28+
.help("Path to the input file to process. If no input given, \
29+
process all WAV files in current directory.")
30+
.index(1)
31+
.validator(validate_path))
32+
.arg(Arg::with_name("dither")
33+
.short("d")
34+
.long("dither")
35+
.value_name("THRESHOLD")
36+
.required(false)
37+
.help("Set threshold for sample level difference to process \
38+
dithered audio.{n}Positive number (amplitude delta).")
39+
.next_line_help(true)
40+
.takes_value(true)
41+
.default_value("10")
42+
.validator(validate_u32))
43+
.arg(Arg::with_name("license")
44+
.short("l")
45+
.long("license")
46+
.help("Display the license information."))
47+
.arg(Arg::with_name("dry_run")
48+
.short("n")
49+
.long("nowrite")
50+
.help("Disable saving converted mono files. Analyze pass only.")
51+
.required(false))
52+
.arg(Arg::with_name("no_overwrites")
53+
.short("p")
54+
.long("protect")
55+
.help("Disable overwriting when saving converted mono files.")
56+
.required(false))
57+
.get_matches();
58+
59+
if matches.is_present("license") {
60+
println!("{}", LICENSE);
61+
println!("\nclap (Command Line Argument Parser) License:");
62+
println!(include_str!("../LICENSE-CLAP"));
63+
process::exit(0);
64+
}
65+
66+
let conf = Conf {
67+
dither: if matches.is_present("dither") {
68+
value_t!(matches, "dither", u32).unwrap_or(10)
69+
} else {
70+
0
71+
},
72+
dry_run: matches.is_present("dry_run"),
73+
no_overwrites: matches.is_present("no_overwrites"),
74+
};
75+
let input_fname = if matches.is_present("INPUT") {
76+
Some(matches.value_of("INPUT").unwrap().to_string())
77+
} else {
78+
None
79+
};
80+
(input_fname, conf)
81+
}
82+
83+
pub fn validate_u32(value: String) -> Result<(), String> {
84+
value.parse::<u32>()
85+
.map(|_| ())
86+
.map_err(|_| "Supplied parameter is not a valid number!".to_owned())
87+
}
88+
89+
pub fn validate_path(path: String) -> Result<(), String> {
90+
if fs::metadata(&path).is_ok() {
91+
if path.to_lowercase().ends_with(".wav") {
92+
Ok(())
93+
} else {
94+
// clap automatically adds "error: " to the beginning of the message.
95+
Err(String::from("Input file must have .wav extension!"))
96+
}
97+
} else {
98+
Err(String::from("Input file doesn't exist"))
99+
}
100+
}

0 commit comments

Comments
 (0)