mirror of
https://github.com/italicsjenga/ableton-rack-converter.git
synced 2024-11-22 07:01:30 +11:00
more filetypes & works better
This commit is contained in:
parent
38b04ced37
commit
df9f56bd8e
|
@ -9,12 +9,15 @@ fn main() {
|
|||
return;
|
||||
}
|
||||
let file_load = PathBuf::from(args[1].as_str());
|
||||
if file_load.extension().expect("wrong/no extension") != "xml" {
|
||||
let extension = file_load
|
||||
.extension()
|
||||
.expect("wrong/no extension")
|
||||
.to_str()
|
||||
.unwrap();
|
||||
if extension != "xml" {
|
||||
return;
|
||||
}
|
||||
let mut path_str = String::from("");
|
||||
path_str.push_str(file_load.file_stem().unwrap().to_str().unwrap());
|
||||
path_str.push_str("-compressed.adg");
|
||||
let path_str = file_load.file_stem().unwrap().to_str().unwrap();
|
||||
let file_save = PathBuf::from(path_str);
|
||||
ableton_rack_converter::compress_file(file_load, file_save);
|
||||
}
|
||||
|
|
|
@ -9,14 +9,22 @@ fn main() {
|
|||
return;
|
||||
}
|
||||
let file_load = PathBuf::from(args[1].as_str());
|
||||
if file_load.extension().expect("wrong/no extension") != "adg" {
|
||||
let extension = file_load
|
||||
.extension()
|
||||
.expect("wrong/no extension")
|
||||
.to_str()
|
||||
.unwrap();
|
||||
if !ableton_rack_converter::validate_filetype(extension) {
|
||||
return;
|
||||
}
|
||||
let mut path_str = String::from("");
|
||||
path_str.push_str(file_load.file_stem().unwrap().to_str().unwrap());
|
||||
path_str.push_str("-live10.adg");
|
||||
let path_str = format!(
|
||||
"{}{}{}",
|
||||
file_load.file_stem().unwrap().to_str().unwrap(),
|
||||
"-live10.",
|
||||
extension
|
||||
);
|
||||
let file_save = PathBuf::from(path_str);
|
||||
let mut device = ableton_rack_converter::load_adg(file_load);
|
||||
let mut device = ableton_rack_converter::load_ableton_file(file_load);
|
||||
fixers::traverse_children(&mut device);
|
||||
ableton_rack_converter::save_adg(&device, file_save);
|
||||
ableton_rack_converter::save_ableton_file(&device, file_save);
|
||||
}
|
||||
|
|
|
@ -9,13 +9,22 @@ fn main() {
|
|||
return;
|
||||
}
|
||||
let file_load = PathBuf::from(args[1].as_str());
|
||||
if file_load.extension().expect("wrong/no extension") != "adg" {
|
||||
let extension = file_load
|
||||
.extension()
|
||||
.expect("wrong/no extension")
|
||||
.to_str()
|
||||
.unwrap();
|
||||
if !ableton_rack_converter::validate_filetype(extension) {
|
||||
return;
|
||||
}
|
||||
let mut path_str = String::from("");
|
||||
path_str.push_str(file_load.file_stem().unwrap().to_str().unwrap());
|
||||
path_str.push_str("-decompressed.xml");
|
||||
let path_str = format!(
|
||||
"{}{}{}{}",
|
||||
file_load.file_stem().unwrap().to_str().unwrap(),
|
||||
"-decompressed.",
|
||||
extension,
|
||||
".xml"
|
||||
);
|
||||
let file_save = PathBuf::from(path_str);
|
||||
let dom = ableton_rack_converter::load_adg(file_load);
|
||||
ableton_rack_converter::save_uncompressed(&dom, file_save);
|
||||
let raw = ableton_rack_converter::load_raw_decompressed_file(file_load);
|
||||
ableton_rack_converter::save_uncompressed_raw(raw, file_save);
|
||||
}
|
||||
|
|
27
src/lib.rs
27
src/lib.rs
|
@ -9,10 +9,24 @@ use xml_dom::{level2::RefNode, parser};
|
|||
|
||||
pub mod fixers;
|
||||
|
||||
pub fn load_adg(filename: PathBuf) -> RefNode {
|
||||
pub fn validate_filetype(ft: &str) -> bool {
|
||||
// als - ableton live set
|
||||
// adg - ableton device group
|
||||
// adv - ableton device preset
|
||||
let types = ["adg", "als", "adv"];
|
||||
if types.contains(&ft) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
pub fn load_ableton_file(filename: PathBuf) -> RefNode {
|
||||
decode(&load_raw_decompressed_file(filename))
|
||||
}
|
||||
|
||||
pub fn load_raw_decompressed_file(filename: PathBuf) -> String {
|
||||
let contents = File::open(filename).expect("failed to load file");
|
||||
let xml = decompress(contents);
|
||||
decode(&xml)
|
||||
return decompress(contents);
|
||||
}
|
||||
|
||||
fn decompress(loaded_file: File) -> String {
|
||||
|
@ -28,16 +42,19 @@ fn decode(xml: &str) -> RefNode {
|
|||
parser::read_xml(xml).expect("failed to parse xml")
|
||||
}
|
||||
|
||||
pub fn save_adg(dom: &RefNode, filename: PathBuf) {
|
||||
pub fn save_ableton_file(dom: &RefNode, filename: PathBuf) {
|
||||
let xml = encode(dom);
|
||||
let compressed = compress(&xml);
|
||||
fs::write(filename, compressed).expect("could not write file");
|
||||
}
|
||||
|
||||
pub fn save_uncompressed(dom: &RefNode, filename: PathBuf) {
|
||||
pub fn save_uncompressed_xmldom(dom: &RefNode, filename: PathBuf) {
|
||||
let xml = encode(dom);
|
||||
fs::write(filename, xml.as_bytes()).expect("could not write file");
|
||||
}
|
||||
pub fn save_uncompressed_raw(raw: String, filename: PathBuf) {
|
||||
fs::write(filename, raw.as_bytes()).expect("could not write file");
|
||||
}
|
||||
|
||||
pub fn compress_file(loadpath: PathBuf, savepath: PathBuf) {
|
||||
let mut contents = File::open(loadpath).expect("failed to load file");
|
||||
|
|
Loading…
Reference in a new issue