aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2018-12-20 15:11:17 +0100
committerHarald Eilertsen <haraldei@anduin.net>2018-12-20 15:11:17 +0100
commit004005688eff68d12043cc388146af30819f4b00 (patch)
treea44fbb7c312a5340d1a118be2627245a6e84dcfa
parentfc5877b7b8095a6ec0bb11eba2cd16c2ce5e2feb (diff)
downloadtrriggy-004005688eff68d12043cc388146af30819f4b00.tar.gz
trriggy-004005688eff68d12043cc388146af30819f4b00.tar.bz2
trriggy-004005688eff68d12043cc388146af30819f4b00.zip
Use clap for command line parsing.
-rw-r--r--Cargo.lock123
-rw-r--r--Cargo.toml4
-rw-r--r--src/main.rs32
3 files changed, 153 insertions, 6 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 2d2362f..242b1cd 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1,14 +1,137 @@
[[package]]
+name = "ansi_term"
+version = "0.11.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "atty"
+version = "0.2.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)",
+ "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "bitflags"
+version = "1.0.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "clap"
+version = "2.32.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
+ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
+ "strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "hound"
version = "3.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
+name = "libc"
+version = "0.2.45"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "redox_syscall"
+version = "0.1.44"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "redox_termios"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "redox_syscall 0.1.44 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "strsim"
+version = "0.7.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "termion"
+version = "1.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)",
+ "redox_syscall 0.1.44 (registry+https://github.com/rust-lang/crates.io-index)",
+ "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "textwrap"
+version = "0.10.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "trriggy"
version = "0.1.0"
dependencies = [
+ "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hound 3.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
+[[package]]
+name = "unicode-width"
+version = "0.1.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "vec_map"
+version = "0.8.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "winapi"
+version = "0.3.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
+name = "winapi-i686-pc-windows-gnu"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
+[[package]]
+name = "winapi-x86_64-pc-windows-gnu"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+
[metadata]
+"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
+"checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652"
+"checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12"
+"checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e"
"checksum hound 3.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8a164bb2ceaeff4f42542bdb847c41517c78a60f5649671b2a07312b6e117549"
+"checksum libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)" = "2d2857ec59fadc0773853c664d2d18e7198e83883e7060b63c924cb077bd5c74"
+"checksum redox_syscall 0.1.44 (registry+https://github.com/rust-lang/crates.io-index)" = "a84bcd297b87a545980a2d25a0beb72a1f490c31f0a9fde52fca35bfbb1ceb70"
+"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76"
+"checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550"
+"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096"
+"checksum textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "307686869c93e71f94da64286f9a9524c0f308a9e1c87a583de8e9c9039ad3f6"
+"checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526"
+"checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a"
+"checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0"
+"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
+"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
diff --git a/Cargo.toml b/Cargo.toml
index bcfcb5f..d45828f 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,8 +1,10 @@
[package]
name = "trriggy"
+description = "A naive trigger/drum replacer in Rust."
version = "0.1.0"
-authors = ["haraldei"]
+authors = ["Harald Eilertsen <haraldei@anduin.net>"]
edition = "2018"
[dependencies]
+clap = "2.32.0"
hound = "3.4.0"
diff --git a/src/main.rs b/src/main.rs
index 0c7e74d..063db5f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -14,6 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
+use clap::{self, crate_name, crate_authors, crate_version, crate_description};
use hound;
use std::io::Read;
use std::iter::FromIterator;
@@ -79,7 +80,26 @@ fn print_wavspec<R: Read>(spec: &hound::WavSpec, r: &hound::WavReader<R>) {
}
fn main() {
- let filename = "test.wav";
+ let m = clap::app_from_crate!()
+ .arg(clap::Arg::with_name("sample")
+ .short("s")
+ .long("sample")
+ .value_name("SAMPLE_FILE")
+ .help("The sample to replace when trigged.")
+ .takes_value(true)
+ .required(true))
+ .arg(clap::Arg::with_name("output")
+ .short("o")
+ .long("output")
+ .value_name("OUTPUT_FILE")
+ .help("Where to store the result.")
+ .takes_value(true))
+ .arg(clap::Arg::with_name("INPUT")
+ .help("The input file")
+ .required(true))
+ .get_matches();
+
+ let filename = m.value_of("INPUT").unwrap();
let mut reader = hound::WavReader::open(&filename).unwrap();
println!("Reading file {}:", &filename);
@@ -87,13 +107,15 @@ fn main() {
let spec = reader.spec();
print_wavspec(&spec, &reader);
- println!("Using sample file: {}", "bd.wav");
- let mut sample_file = hound::WavReader::open("bd.wav").unwrap();
+ let sample_filename = m.value_of("sample").unwrap();
+ println!("Using sample file: {}", sample_filename);
+ let mut sample_file = hound::WavReader::open(sample_filename).unwrap();
print_wavspec(&sample_file.spec(), &sample_file);
- println!("Writing to output: {}", "output.wav");
- let mut output = hound::WavWriter::create("output.wav", spec).unwrap();
+ let output_filename = m.value_of("output").unwrap_or("output.wav");
+ println!("Writing to output: {}", output_filename);
+ let mut output = hound::WavWriter::create(output_filename, spec).unwrap();
let samples = reader.samples::<i16>();
let mut triggey = Trigger::new(sample_file);