This commit is contained in:
Arthur Beck 2025-05-07 16:20:08 -05:00
parent 2677e3650b
commit da49e2223b
Signed by: ArthurB
GPG key ID: CA200B389F0F6BC9
3 changed files with 90 additions and 0 deletions

4
Cargo.toml Normal file
View file

@ -0,0 +1,4 @@
[package]
name = "compactadventure2"
version = "0.1.0"
edition = "2024"

59
src/cue.rs Normal file
View file

@ -0,0 +1,59 @@
//! Cue sheet writing
use std::path::PathBuf;
pub enum CueItem<'a> {
Comment(&'a str),
Performer(&'a str),
Title(&'a str),
File {
path: PathBuf,
filetype: &'a str
},
Track {
/// should be 99 or less
idx: u8,
tracktype: &'a str
},
Index {
// should be 99 or less
num: u8,
timestamp: &'a str
}
}
pub struct CueBuilder<'a> {
items: Vec<CueItem<'a>>
}
impl<'a> CueBuilder<'a> {
pub fn new() -> Self {
Self { items: vec![] }
}
pub fn add(mut self, item: CueItem<'a>) -> Self {
self.items.push(item);
self
}
pub fn finish(self) -> String {
let mut out = String::new();
let mut indent = 0usize;
for item in self.items {
out.push_str(&(" ".repeat(indent)+&match item {
CueItem::Comment(s) => format!("REM {}", s),
CueItem::Performer(s) => format!("PERFORMER \"{}\"", s),
CueItem::Title(s) => format!("TITLE \"{}\"", s),
CueItem::File{path, filetype} => {
indent = 1;
format!("FILE \"{}\" {}", path.to_string_lossy(), filetype)
},
CueItem::Track{idx, tracktype} => {
indent = 2;
format!("TRACK {} {}", format!("{:0>2}", idx), tracktype)
},
CueItem::Index { num, timestamp } => format!("INDEX {} {}", format!("{:0>2}", num), timestamp)
}+"\n"));
}
out = out.trim().to_string();
out
}
}

27
src/main.rs Normal file
View file

@ -0,0 +1,27 @@
//! Create choose-your-own-adventures for CDDAs
#![warn(missing_docs, clippy::missing_docs_in_private_items)]
use std::path::PathBuf;
mod cue;
fn main() {
println!(
"{}",
cue::CueBuilder::new()
.add(cue::CueItem::Comment("test"))
.add(cue::CueItem::File {
path: PathBuf::from("./test.mp3"),
filetype: "MP3"
})
.add(cue::CueItem::Track {
idx: 1,
tracktype: "AUDIO"
})
.add(cue::CueItem::Index {
num: 1,
timestamp: "00:00:00"
})
.finish()
);
}