Skip to content

Commit

Permalink
Add optional output file for adsloopfind
Browse files Browse the repository at this point in the history
  • Loading branch information
SalsaGal committed Sep 8, 2024
1 parent a86f3e4 commit da6e617
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,16 @@ This program takes an [ADS](https://github.com/SalsaGal/unlokable/wiki/File-Form

#### Usage

`adsloopfind [input_file]`
```
Usage: adsloopfind [OPTIONS] <ADS_INPUT>
Arguments:
<ADS_INPUT> The `ads` file to find loops in
Options:
-o <OUTPUT> The file to write the loop locations to, writes to STDOUT otherwise
-h, --help Print help
```

If there is a loop, the output will be a text echo showing the sample-based loop markers.

Expand Down
14 changes: 12 additions & 2 deletions adsloopfind/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::path::PathBuf;
use std::{fs::File, io::Write, path::PathBuf};

use clap::Parser;

Expand All @@ -8,6 +8,9 @@ const MAGIC_NUMBER: [u8; 4] = [0x53, 0x53, 0x68, 0x64];
struct Args {
/// The `ads` file to find loops in
ads_input: PathBuf,
/// The file to write the loop locations to, writes to STDOUT otherwise.
#[clap(short)]
output: Option<PathBuf>,
}

fn main() {
Expand All @@ -24,15 +27,22 @@ fn main() {
&mut std::iter::once(args.ads_input.clone())
};

let mut file = args.output.map(|path| File::create(path).unwrap());

for path in files {
if let Some((lb, le)) = find_loops(&std::fs::read(&path).unwrap()) {
print!(
let text = format!(
"{lb} {le} {}\r\n",
path.with_extension("wav")
.file_name()
.unwrap()
.to_string_lossy()
);
if let Some(file) = &mut file {
write!(file, "{}", text).unwrap();
} else {
print!("{}", text);
}
}
}
}
Expand Down

0 comments on commit da6e617

Please sign in to comment.