Merge branch 'ToolBox_TODOs_SupportSFX' into ToolBox_TODOs

This commit is contained in:
2024-09-28 13:02:26 +02:00
38 changed files with 977 additions and 299 deletions

View File

@@ -1,6 +1,6 @@
[package]
name = "jaby_engine_fconv"
version = "0.1.6"
version = "0.2.0"
edition = "2021"
[profile.release]

View File

@@ -1 +1,43 @@
pub mod xa;
pub mod xa;
pub mod vag;
use std::{env, path::PathBuf, process::Command};
use tool_helper::Error;
fn run_psxavenc<I, S>(input: PathBuf, output: PathBuf, args: I) -> Result<(), Error>
where
I: IntoIterator<Item = S>,
S: AsRef<std::ffi::OsStr>, {
let psxavenc = get_psxavenc_path()?;
let result = Command::new(psxavenc).args(args).arg(input.to_string_lossy().as_ref()).arg(output.to_string_lossy().as_ref()).output()?;
let stderr = tool_helper::vec_helper::to_string(result.stderr)?;
let stdout = tool_helper::vec_helper::to_string(result.stdout)?;
if !result.status.success() {
return Err(Error::from_text(format!("psxavenc returned: {}. {}", result.status, stderr)));
}
if !stdout.is_empty() {
println!("{}", stdout);
}
Ok(())
}
fn get_psxavenc_path() -> Result<PathBuf, Error> {
let tool_path = {
let mut my_path = env::current_exe()?;
my_path.pop();
my_path.push("extern");
my_path.push("psxavenc");
my_path
};
if !tool_path.exists() {
return Err(Error::from_str("Could not locate psxavenc. Make sure it is installed under \"<Jaby Engine>/bin/extern\""));
}
Ok(tool_path)
}

View File

@@ -0,0 +1,22 @@
use clap::Args;
use std::path::PathBuf;
use tool_helper::Error;
#[derive(Args)]
pub struct Arguments {
frequency: Option<u32>
}
pub fn convert(args: Arguments, input: PathBuf, output: PathBuf) -> Result<(), Error> {
let mut cmd_args = vec!["-t", "vag"];
let frequency_str;
if let Some(frequency) = args.frequency {
frequency_str = frequency.to_string().to_owned();
cmd_args.push("-f");
cmd_args.push(frequency_str.as_ref());
}
super::run_psxavenc(input, output, cmd_args)
}

View File

@@ -1,5 +1,5 @@
use clap::{Args, ValueEnum};
use std::{env, path::PathBuf, process::Command, str};
use std::{path::PathBuf, str};
use tool_helper::Error;
#[derive(Args)]
@@ -43,39 +43,13 @@ impl Sample {
pub fn convert(args: Arguments, input: PathBuf, output: PathBuf) -> Result<(), Error> {
let quality = args.quality;
let sample = args.sample;
let tool_path = {
let mut my_path = env::current_exe()?;
my_path.pop();
my_path.push("extern");
my_path.push("psxavenc");
my_path
};
if !tool_path.exists() {
return Err(Error::from_str("Could not locate psxavenc. Make sure it is installed under \"<Jaby Engine>/bin/extern\""));
}
let result = Command::new(tool_path).args([
super::run_psxavenc(input, output, [
"-t", "xacd",
"-f", quality.get_frequency().to_string().as_ref(),
"-b", "4",
"-c", sample.get_channel().to_string().as_ref(),
"-F", "0",
"-C", "0",
input.to_string_lossy().as_ref(), output.to_string_lossy().as_ref()
]) .output()?;
let stderr = tool_helper::vec_helper::to_string(result.stderr)?;
let stdout = tool_helper::vec_helper::to_string(result.stdout)?;
if !result.status.success() {
return Err(Error::from_text(format!("psxavenc returned: {}. {}", result.status, stderr)));
}
if !stdout.is_empty() {
println!("{}", stdout);
}
Ok(())
])
}

View File

@@ -21,9 +21,25 @@ struct CommandLine {
#[derive(Subcommand)]
enum SubCommands {
// === Internal Commands ===
Nothing,
SimpleTIM(reduced_tim::Arguments),
XA(xa::Arguments)
// === External Commands ===
VAG(vag::Arguments),
XA(xa::Arguments),
}
impl SubCommands {
pub fn is_external_command(&self) -> bool {
match self {
SubCommands::Nothing => false,
SubCommands::SimpleTIM(_) => false,
SubCommands::VAG(_) => true,
SubCommands::XA(_) => true
}
}
}
fn run_internal_conversion(cmd: CommandLine) -> Result<(), Error> {
@@ -44,7 +60,7 @@ fn run_internal_conversion(cmd: CommandLine) -> Result<(), Error> {
match cmd.sub_command {
SubCommands::Nothing => nothing::copy(&mut input, dst_buffer),
SubCommands::SimpleTIM(args) => reduced_tim::convert(args, input, dst_buffer),
_ => Err(Error::not_implemented("External functions can not be called for internal conversion"))
_ => Err(Error::from_str("External functions can not be called for internal conversion"))
}
};
@@ -74,13 +90,14 @@ fn run_external_conversion(cmd: CommandLine) -> Result<(), Error> {
let output_file = cmd.output_file.ok_or(Error::from_str("Output has to be a file"))?;
match cmd.sub_command {
SubCommands::XA(args) => xa::convert(args, input_file, output_file),
_ => Err(Error::not_implemented("Internal functions can not be called for external conversion"))
SubCommands::VAG(args) => vag::convert(args, input_file, output_file),
SubCommands::XA(args) => xa::convert(args, input_file, output_file),
_ => Err(Error::from_str("Internal functions can not be called for external conversion"))
}
}
fn run_main(cmd: CommandLine) -> Result<(), Error> {
if matches!(cmd.sub_command, SubCommands::XA(_)) {
if cmd.sub_command.is_external_command() {
run_external_conversion(cmd)
}