Compare commits

..

8 commits

5 changed files with 362 additions and 238 deletions

9
Cargo.lock generated
View file

@ -104,12 +104,6 @@ version = "1.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "abd57806937c9cc163efc8ea3910e00a62e2aeb0b8119f1793a978088f8f6b04" checksum = "abd57806937c9cc163efc8ea3910e00a62e2aeb0b8119f1793a978088f8f6b04"
[[package]]
name = "file-format"
version = "0.26.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7ef3d5e8ae27277c8285ac43ed153158178ef0f79567f32024ca8140a0c7cd8"
[[package]] [[package]]
name = "heck" name = "heck"
version = "0.5.0" version = "0.5.0"
@ -270,11 +264,10 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
[[package]] [[package]]
name = "xbst" name = "xbst"
version = "0.1.1" version = "0.2.0"
dependencies = [ dependencies = [
"clap", "clap",
"deunicode", "deunicode",
"file-format",
"thiserror", "thiserror",
"zerocopy", "zerocopy",
] ]

View file

@ -1,6 +1,6 @@
[package] [package]
name = "xbst" name = "xbst"
version = "0.1.1" version = "0.2.0"
edition = "2021" edition = "2021"
[dependencies] [dependencies]
@ -8,4 +8,3 @@ thiserror = "2.0.12"
clap = { version = "4.5.31", features = ["derive"] } clap = { version = "4.5.31", features = ["derive"] }
zerocopy = { version = "0.8.26", features = ["derive"] } zerocopy = { version = "0.8.26", features = ["derive"] }
deunicode = "1.6.2" deunicode = "1.6.2"
file-format = "0.26.0"

View file

@ -26,7 +26,9 @@ The input music folder needs the following structure:
└ 💾 Music 1 └ 💾 Music 1
``` ```
Directory/File names must not exceed 31 characters. Directory/File names must not exceed 31~ characters.
If you encounter issues with song not playing you could try to change the codec to wmav1 or lower the bitrate.
``` ```
Usage: xbst [OPTIONS] [INPUT] [OUTPUT] Usage: xbst [OPTIONS] [INPUT] [OUTPUT]
@ -36,14 +38,16 @@ Arguments:
[OUTPUT] Output folder for the database and converted musics [default: ./output] [OUTPUT] Output folder for the database and converted musics [default: ./output]
Options: Options:
-b, --bitrate <BITRATE> Bitrate for the output [default: 192] -b, --bitrate <BITRATE> Bitrate for the output [default: 128]
-c, --codec <CODEC> Codec to use for conversion [default: wmav2] [possible values: wmav1, wmav2]
-h, --help Print help -h, --help Print help
-V, --version Print version -V, --version Print version
``` ```
## Known issues ## Known issues
- The progress bar on soundtrack other than the first one doesn't progress - The progress bar on soundtrack other than the first one doesn't progress.
- Some files, once converted, are quieter than usual? - Some files, once converted, are quieter than usual?
- When using wmav1, some audio files might sounds absolute ass.
- Untested with a large library, probably has issues? - Untested with a large library, probably has issues?
- Code is poo poo - Code is still poo poo but a bit better

View file

@ -1,8 +1,8 @@
use std::{ use std::{
ffi::OsStr, ffi::OsStr,
fs::{self, read_dir, File}, fs::{self, read_dir, DirEntry, File},
io::{stdout, Write}, io::{stdout, Write},
path::PathBuf, path::{Path, PathBuf},
process::Command, process::Command,
string::FromUtf8Error, string::FromUtf8Error,
}; };
@ -11,11 +11,10 @@ mod utils;
use clap::Parser; use clap::Parser;
use deunicode::AsciiChars; use deunicode::AsciiChars;
use file_format::{FileFormat, Kind};
use thiserror::Error; use thiserror::Error;
use zerocopy::IntoBytes; use zerocopy::IntoBytes;
use crate::utils::{Header, MusicFile, Song, Soundtrack}; use crate::utils::{Ansi, Codec, Header, Song, SongGroup, Soundtrack};
#[derive(Error, Debug)] #[derive(Error, Debug)]
enum Errors { enum Errors {
@ -27,7 +26,7 @@ enum Errors {
FromUtf8(#[from] FromUtf8Error), FromUtf8(#[from] FromUtf8Error),
#[error("Skill issue on the programmer part ngl, report this to dev pls")] #[error("Skill issue on the programmer part ngl, report this to dev pls")]
SkillIssue(), SkillIssue(),
#[error("Didn't find any file to convert, is your input folder structued correctly?")] #[error("Didn't find any file to convert, is your input folder structured correctly?")]
NoFileToConvert(), NoFileToConvert(),
#[error("You are missing ffprobe in your PATH")] #[error("You are missing ffprobe in your PATH")]
@ -46,8 +45,12 @@ struct Args {
#[arg(default_value = "./output")] #[arg(default_value = "./output")]
output: String, output: String,
/// Bitrate for the output /// Bitrate for the output
#[arg(short, long, default_value_t = 192)] #[arg(short, long, default_value_t = 128)]
bitrate: i16, bitrate: i16,
/// Codec to use for conversion
#[clap(value_enum)]
#[arg(short, long, default_value_t = Codec::Wmav2)]
codec: Codec,
} }
fn main() { fn main() {
@ -76,21 +79,16 @@ fn main() {
} }
fn process(args: &Args) -> Result<(), Errors> { fn process(args: &Args) -> Result<(), Errors> {
let mut soundtrack_count: i32 = 0; let mut soundtrack_count = 0;
let mut songs_count: u32 = 0;
let mut total_songs_count: u32 = 0;
let mut total_song_groups_count: i32 = 0;
let mut song_time_miliseconds: [i32; 6] = [0; 6];
let mut song_group_id: i32;
let mut soundtracks: Vec<Soundtrack> = Default::default();
let mut songs: Vec<Song> = Default::default();
let mut sound_groups_ids: Vec<i32> = Vec::with_capacity(84);
let mut files_to_convert: Vec<MusicFile> = Vec::new();
let input_path = PathBuf::from(&args.input); let input_path = PathBuf::from(&args.input);
let music_directory = read_dir(input_path).map_err(Errors::UnknownFolder)?; let music_directory = read_dir(input_path).map_err(Errors::UnknownFolder)?;
let mut soundtracks: Vec<Soundtrack> = Default::default();
let mut song_groups: Vec<Vec<SongGroup>> = Default::default();
let mut total_songs = 0;
let mut total_song_groups = 0;
let mut files_to_convert: Vec<PathBuf> = Default::default();
// Loop through each folders for the soundtrack struct // Loop through each folders for the soundtrack struct
for (i, soundtrack_dirs) in music_directory.enumerate() { for (i, soundtrack_dirs) in music_directory.enumerate() {
@ -102,167 +100,56 @@ fn process(args: &Args) -> Result<(), Errors> {
} }
soundtrack_count += 1; soundtrack_count += 1;
song_group_id = 0;
let soundtrack_name_str = soundtrack let st;
.file_name() let song_group;
.map_or(OsStr::new("Unknown soundtrack"), |f| f) let mut unprocessed_files;
.to_string_lossy()
.trim()
.ascii_chars()
.to_string();
// Convert the folder name into 2 bytes
let mut soundtrack_name = soundtrack_name_str
.bytes()
.map(|b| [b, 0])
.collect::<Vec<[u8; 2]>>();
// Max value of 32
soundtrack_name.resize(32, [0; 2]);
let mut song_name: [[u8; 2]; 192] = [[0; 2]; 192];
let files = read_dir(soundtrack)
.map_err(Errors::UnknownIO)?
.collect::<Vec<_>>();
// Loop through each files in chunk of 6 (max songs allowed in a song group)
files.chunks(6).for_each(|song_files| {
let mut song_id: [i32; 6] = [0; 6];
song_group_id += 1;
sound_groups_ids.push(total_song_groups_count);
total_song_groups_count += 1;
let mut char_count = 0;
song_time_miliseconds = [0; 6];
for (g, f) in song_files.iter().enumerate() {
let song = f.as_ref().unwrap();
let song_path = song.path();
// Get file format kind for the files inside soundtracks
let format = match FileFormat::from_file(&song_path).map_err(Errors::UnknownIO) {
Ok(f) => f.kind(),
Err(e) => {
eprintln!("\x1b[0;31m{}\x1b[0;20m", e);
Kind::Other
}
};
// Ignore non audio kind
if format != Kind::Audio {
continue;
}
song_id[g] = total_songs_count as i32;
song_time_miliseconds[g] = match get_duration(song_path) {
Ok(s) => s,
Err(e) => {
eprintln!("\x1b[0;31mFailed to get duration: {}\x1b[0;20m", e);
0
}
};
songs_count += 1;
total_songs_count += 1;
let filepath = song.path();
let filename = filepath
.file_stem()
.map_or(OsStr::new("Unknown track"), |f| f)
.to_string_lossy()
.ascii_chars()
.to_string();
let mut name = filename.trim().bytes().collect::<Vec<u8>>();
name.resize(32, 0);
for b in name.iter() {
song_name[char_count] = [*b, 0];
char_count += 1;
}
files_to_convert.push(MusicFile {
path: song.path(),
soundtrack_name: soundtrack_name_str.clone(),
soundtrack_index: 0,
index: total_songs_count - 1,
});
}
let s = Song {
magic: 200819,
id: song_group_id - 1,
ipadding: 0,
soundtrack_id: i as i32,
song_id,
song_time_miliseconds,
song_name,
cpadding: [char::MIN; 16],
};
songs.push(s);
song_name = [[0; 2]; 192];
});
let mut total_time_miliseconds: i32 = 0;
for s in &songs {
if s.soundtrack_id == i as i32 {
total_time_miliseconds += s.song_time_miliseconds.iter().sum::<i32>()
}
}
sound_groups_ids.resize(84, 0);
let song_groups_ids: [i32; 84] = sound_groups_ids
.clone()
.try_into()
.map_err(|_| Errors::SkillIssue())?;
let st = Soundtrack {
magic: 136049,
id: i as i32,
num_songs: songs_count,
song_groups_ids: song_groups_ids,
total_time_miliseconds,
name: soundtrack_name
.try_into()
.map_err(|_| Errors::SkillIssue())?,
padding: [char::MIN; 24],
};
(
st,
song_group,
total_songs,
total_song_groups,
unprocessed_files,
) = process_soundtrack(
soundtrack,
i,
soundtrack_count,
total_songs,
total_song_groups,
)?;
soundtracks.push(st); soundtracks.push(st);
sound_groups_ids = Vec::with_capacity(84); song_groups.push(song_group);
songs_count = 0; files_to_convert.append(&mut unprocessed_files);
} }
let mut soundtrack_ids: [i32; 100] = [0; 100]; let mut soundtrack_ids: [i32; 100] = [0; 100];
for i in 0..soundtrack_count { for i in 0..soundtrack_count {
soundtrack_ids[i as usize] = i; soundtrack_ids[i] = i as i32;
} }
let header = Header { let header = Header {
magic: 0001, magic: 1,
num_soundtracks: soundtrack_count, num_soundtracks: soundtrack_count as i32,
next_soundtrack_id: soundtrack_count + 1, next_soundtrack_id: (soundtrack_count + 1) as i32,
soundtrack_ids, soundtrack_ids,
next_song_id: (songs_count as i32), next_song_id: (total_songs + 1) as i32,
padding: [char::MIN; 24], padding: [char::MIN; 24],
}; };
if files_to_convert.len() == 0 { if files_to_convert.is_empty() {
return Err(Errors::NoFileToConvert()); return Err(Errors::NoFileToConvert());
} }
write_database(&args.output, header, soundtracks, songs)?; write_database(&args.output, header, soundtracks, song_groups)?;
for f in files_to_convert { for (i, f) in files_to_convert.iter().enumerate() {
let percentage: f64 = ((f.index + 1) as f64 / total_songs_count as f64) * 100.0; let percentage: f64 = ((i + 1) as f64 / total_songs as f64) * 100.0;
print!( print!(
"{}{}\r{:3}% [{}{}] {:3}/{}", "{}{}\r{:3}% [{}{}] {:3}/{}",
"\x1B[1A", Ansi::CursorUp,
"\x1B[K", Ansi::ClearLine,
percentage as usize, percentage as usize,
{ {
let mut bar = "=".repeat(percentage as usize / 3); let mut bar = "=".repeat(percentage as usize / 3);
@ -272,30 +159,26 @@ fn process(args: &Args) -> Result<(), Errors> {
bar bar
}, },
" ".repeat(100 / 3 - percentage as usize / 3), " ".repeat(100 / 3 - percentage as usize / 3),
f.index + 1, i + 1,
total_songs_count total_songs
); );
print!( print!(
"{}\r{}Processing {} - {}", "{}\r{}Processing {} - {}",
"\x1B[1B", Ansi::CursorDown,
"\x1B[K", Ansi::ClearLine,
f.soundtrack_name, f.parent()
f.path .and_then(|f| f.file_stem())
.file_stem() .unwrap_or_else(|| OsStr::new("Unknown soundtrack"))
.map_or(OsStr::new("Unknown track"), |f| f) .to_string_lossy(),
f.file_stem()
.unwrap_or_else(|| OsStr::new("Unknown track"))
.to_string_lossy() .to_string_lossy()
); );
stdout().flush().map_err(Errors::UnknownIO)?; stdout().flush().map_err(Errors::UnknownIO)?;
convert_to_wma( convert_to_wma(f, &args.output, args.bitrate, &args.codec, i)?;
f.path,
&args.output,
args.bitrate,
f.soundtrack_index as usize,
f.index as usize,
)?;
} }
print!("\x1B[1A\x1B[K\r\x1B[K Done."); print!("\x1B[1A\x1B[K\r\x1B[K Done.");
@ -303,6 +186,173 @@ fn process(args: &Args) -> Result<(), Errors> {
Ok(()) Ok(())
} }
fn build_songs_group(
chunks: &[DirEntry],
song_group_id: usize,
soundtrack_id: usize,
total_songs: usize,
) -> Result<(SongGroup, Vec<PathBuf>), Errors> {
let mut files_to_convert: Vec<PathBuf> = Default::default();
let mut songs: Vec<Song> = Default::default();
let mut song_group: SongGroup = SongGroup::default();
// Loop through each files in chunk of 6 (max songs allowed in a song group)
chunks.iter().enumerate().for_each(|(i, song)| {
let song_path = song.path();
// Ignore non files for song groups
if !song_path.is_file() {
return;
}
let song_id: i32 = (total_songs - chunks.len() + i) as i32;
let song_time_miliseconds = match get_duration(song_path) {
Ok(s) => s,
Err(e) => {
eprintln!("\x1b[0;31mFailed to get duration: {}\x1b[0;20m", e);
0
}
};
let filepath = song.path();
let filename = filepath
.file_stem()
.unwrap_or_else(|| OsStr::new("Unknown track"))
.to_string_lossy()
.ascii_chars()
.to_string();
let mut name = filename.trim().bytes().collect::<Vec<u8>>();
name.resize(32, 0);
let mut song_name: [[u8; 2]; 32] = [[0; 2]; 32];
for (char_count, b) in name.iter().enumerate() {
song_name[char_count] = [*b, 0];
}
let s = Song {
song_id,
song_time_miliseconds,
song_name,
};
songs.push(s);
files_to_convert.push(song.path());
});
for s in songs.chunks(6) {
let empty_song = Song::default();
let mut empty_song_groups = s.to_vec();
empty_song_groups.resize(6, empty_song);
song_group = SongGroup {
magic: 200819,
soundtrack_id: soundtrack_id as i32,
id: song_group_id as i32,
ipadding: 0,
songs: empty_song_groups.try_into().unwrap(),
cpadding: [char::MIN; 16],
};
}
Ok((song_group, files_to_convert))
}
fn process_soundtrack(
soundtrack: PathBuf,
soundtrack_index: usize,
soundtrack_count: usize,
mut total_songs: usize,
total_song_groups: usize,
) -> Result<(Soundtrack, Vec<SongGroup>, usize, usize, Vec<PathBuf>), Errors> {
let mut files_to_convert: Vec<PathBuf> = Default::default();
let mut songs_count = 0;
let mut song_groups: Vec<SongGroup> = Default::default();
let mut song_groups_ids: Vec<i32> = Vec::with_capacity(84);
let mut song_group_id = total_song_groups;
let soundtrack_name_str = soundtrack
.file_name()
.unwrap_or_else(|| OsStr::new("Unknown soundtrack"))
.to_string_lossy()
.trim()
.ascii_chars()
.to_string();
// Convert the folder name into 2 bytes
let mut soundtrack_name = soundtrack_name_str
.bytes()
.map(|b| [b, 0])
.collect::<Vec<[u8; 2]>>();
// Max value of 32
soundtrack_name.resize(32, [0; 2]);
let files = read_dir(soundtrack)?
.filter_map(|x| x.ok())
.collect::<Vec<_>>();
let mut total_time_miliseconds: i32 = 0;
for chunk in files.chunks(6) {
total_songs += chunk.len();
songs_count += chunk.len();
let (songs, mut unconverted_files) =
build_songs_group(chunk, song_group_id, soundtrack_index, total_songs)?;
songs.songs.iter().for_each(|x| {
if songs.soundtrack_id == soundtrack_index as i32 {
total_time_miliseconds += x.song_time_miliseconds;
}
});
song_groups.push(songs);
song_group_id += 1;
files_to_convert.append(&mut unconverted_files);
}
for s in &song_groups {
song_groups_ids.push(s.id);
}
song_groups_ids.resize(84, 0);
let song_groups_ids: [i32; 84] = song_groups_ids
.clone()
.try_into()
.map_err(|_| Errors::SkillIssue())?;
let st = Soundtrack {
magic: 136049,
id: soundtrack_index as i32,
num_songs: songs_count as u32,
song_groups_ids,
total_time_miliseconds,
name: soundtrack_name
.try_into()
.map_err(|_| Errors::SkillIssue())?,
padding: [char::MIN; 24],
};
let mut soundtrack_ids: [i32; 100] = [0; 100];
for i in 0..soundtrack_count {
soundtrack_ids[i] = i as i32;
}
Ok((
st,
song_groups,
total_songs,
song_group_id,
files_to_convert,
))
}
fn get_duration(path: PathBuf) -> Result<i32, Errors> { fn get_duration(path: PathBuf) -> Result<i32, Errors> {
let output = Command::new("ffprobe") let output = Command::new("ffprobe")
.args([ .args([
@ -324,24 +374,23 @@ fn get_duration(path: PathBuf) -> Result<i32, Errors> {
} }
fn convert_to_wma( fn convert_to_wma(
input: PathBuf, input: &Path,
output: &String, output: &String,
bitrate: i16, bitrate: i16,
soundtrack_index: usize, codec: &Codec,
song_index: usize, song_index: usize,
) -> Result<(), Errors> { ) -> Result<(), Errors> {
let binding = input.into_os_string(); let binding = input.as_os_str();
let input = binding.to_str().unwrap(); let input = binding.to_str().unwrap();
fs::create_dir_all(format!("{}/{:0>4}", output, soundtrack_index)) fs::create_dir_all(format!("{}/0000", output)).map_err(Errors::UnknownIO)?;
.map_err(Errors::UnknownIO)?;
Command::new("ffmpeg") Command::new("ffmpeg")
.args([ .args([
"-i", "-i",
input, input,
"-acodec", "-acodec",
"wmav1", &codec.to_string(),
"-ac", "-ac",
"2", "2",
"-ar", "-ar",
@ -353,10 +402,7 @@ fn convert_to_wma(
"-map", "-map",
"0:a", "0:a",
"-y", "-y",
&format!( &format!("{}/0000/{:0>8x}.wma", output, song_index),
"{}/{:0>4}/{:0>8x}.wma",
output, soundtrack_index, song_index
),
]) ])
.output() .output()
.map_err(Errors::MissingFfmpeg)?; .map_err(Errors::MissingFfmpeg)?;
@ -368,41 +414,42 @@ fn write_database(
output: &String, output: &String,
header: Header, header: Header,
soundtracks: Vec<Soundtrack>, soundtracks: Vec<Soundtrack>,
songs: Vec<Song>, songs: Vec<Vec<SongGroup>>,
) -> Result<(), Errors> { ) -> Result<(), Errors> {
fs::create_dir_all(format!("{}/", &output)).map_err(Errors::UnknownIO)?; fs::create_dir_all(format!("{}/", &output)).map_err(Errors::UnknownIO)?;
let mut database = File::create(format!("{}/ST.DB", &output)).map_err(Errors::UnknownIO)?; let mut database = File::create(format!("{}/ST.DB", &output)).map_err(Errors::UnknownIO)?;
database.write_all(&header.magic.as_bytes())?; database.write_all(header.as_bytes())?;
database.write_all(&header.num_soundtracks.as_bytes())?;
database.write_all(&header.next_soundtrack_id.as_bytes())?;
database.write_all(&header.soundtrack_ids.as_bytes())?;
database.write_all(&header.next_song_id.as_bytes())?;
database.write_all(&header.padding.as_bytes())?;
for st in &soundtracks { database.write_all(soundtracks.as_bytes())?;
database.write_all(&st.magic.as_bytes())?;
database.write_all(&st.id.as_bytes())?;
database.write_all(&st.num_songs.as_bytes())?;
database.write_all(&st.song_groups_ids.as_bytes())?;
database.write_all(&st.total_time_miliseconds.as_bytes())?;
database.write_all(&st.name.as_bytes())?;
database.write_all(&st.padding.as_bytes())?;
}
for _ in 0..100 - &soundtracks.len() { for _ in 0..100 - &soundtracks.len() {
database.write_all(&[0 as u8; 512])?; database.write_all(&[0_u8; 512])?;
} }
for s in songs { for s in songs {
database.write_all(&s.magic.as_bytes())?; for s in s {
database.write_all(&s.soundtrack_id.as_bytes())?; database.write_all(s.magic.as_bytes())?;
database.write_all(&s.id.as_bytes())?; database.write_all(s.soundtrack_id.as_bytes())?;
database.write_all(&s.ipadding.as_bytes())?; database.write_all(s.id.as_bytes())?;
database.write_all(&s.song_id.as_bytes())?; database.write_all(s.ipadding.as_bytes())?;
database.write_all(&s.song_time_miliseconds.as_bytes())?;
database.write_all(&s.song_name.as_bytes())?; for x in s.songs.chunks(6) {
database.write_all(&s.cpadding.as_bytes())?; for chunk in x {
database.write_all(chunk.song_id.as_bytes())?;
}
for chunk in x {
database.write_all(chunk.song_time_miliseconds.as_bytes())?;
}
for chunk in x {
database.write_all(chunk.song_name.as_bytes())?;
}
}
database.write_all(s.cpadding.as_bytes())?;
}
} }
Ok(()) Ok(())

View file

@ -1,17 +1,22 @@
use std::path::PathBuf; use zerocopy::{Immutable, IntoBytes};
use zerocopy::TryFromBytes; #[derive(clap::ValueEnum, Debug, Clone)]
pub enum Codec {
Wmav1,
Wmav2,
}
pub struct MusicFile { impl std::fmt::Display for Codec {
pub path: PathBuf, fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
pub soundtrack_index: u32, match self {
pub soundtrack_name: String, Codec::Wmav1 => write!(f, "wmav1"),
pub index: u32, Codec::Wmav2 => write!(f, "wmav2"),
}
}
} }
// https://xboxdevwiki.net/Soundtracks#ST.DB // https://xboxdevwiki.net/Soundtracks#ST.DB
#[derive(Debug, Immutable, IntoBytes)]
#[derive(Debug, TryFromBytes)]
#[repr(C)] #[repr(C)]
pub struct Header { pub struct Header {
pub magic: i32, pub magic: i32,
@ -22,7 +27,7 @@ pub struct Header {
pub padding: [char; 24], pub padding: [char; 24],
} }
#[derive(Debug, TryFromBytes)] #[derive(Debug, Immutable, IntoBytes)]
#[repr(C)] #[repr(C)]
pub struct Soundtrack { pub struct Soundtrack {
pub magic: i32, pub magic: i32,
@ -34,15 +39,91 @@ pub struct Soundtrack {
pub padding: [char; 24], pub padding: [char; 24],
} }
#[derive(Debug, TryFromBytes)] #[derive(Debug, Immutable, IntoBytes, Clone, Copy)]
#[repr(C)] #[repr(C)]
pub struct Song { pub struct Song {
pub song_id: i32,
pub song_time_miliseconds: i32,
pub song_name: [[u8; 2]; 32],
}
#[derive(Debug, Immutable, IntoBytes, Clone, Copy)]
#[repr(C)]
pub struct SongGroup {
pub magic: i32, pub magic: i32,
pub soundtrack_id: i32, pub soundtrack_id: i32,
pub id: i32, pub id: i32,
pub ipadding: i32, pub ipadding: i32,
pub song_id: [i32; 6], pub songs: [Song; 6],
pub song_time_miliseconds: [i32; 6],
pub song_name: [[u8; 2]; 192],
pub cpadding: [char; 16], pub cpadding: [char; 16],
} }
impl Default for Header {
#[inline]
fn default() -> Header {
Header {
magic: 0,
num_soundtracks: 0,
next_soundtrack_id: 0,
soundtrack_ids: [0; 100],
next_song_id: 0,
padding: [char::MIN; 24],
}
}
}
impl Default for Soundtrack {
#[inline]
fn default() -> Soundtrack {
Soundtrack {
magic: 0,
id: 0,
num_songs: 0,
song_groups_ids: [0; 84],
total_time_miliseconds: 0,
name: [[0; 2]; 32],
padding: [char::MIN; 24],
}
}
}
impl Default for Song {
#[inline]
fn default() -> Song {
Song {
song_id: 0,
song_time_miliseconds: 0,
song_name: [[0; 2]; 32],
}
}
}
impl Default for SongGroup {
#[inline]
fn default() -> SongGroup {
SongGroup {
magic: 0,
soundtrack_id: 0,
id: 0,
ipadding: 0,
songs: [Song::default(); 6],
cpadding: [char::MIN; 16],
}
}
}
pub enum Ansi {
ClearLine,
CursorUp,
CursorDown,
}
impl std::fmt::Display for Ansi {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Ansi::ClearLine => write!(f, "\x1B[K"),
Ansi::CursorUp => write!(f, "\x1B[1A"),
Ansi::CursorDown => write!(f, "\x1B[1B"),
}
}
}