Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
2.2 kB · 74 lines
Rust
at main
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475use std::{ fs, io::{BufRead, BufReader},};
use torque_tracker_engine::{ file::{InFilePtr, SansIO, header::ImpulseHeader, pattern::PatternParser}, project::song::Song,};
/// Move the Read Cursor to the value of the file ptrpub fn move_to_ptr<S: std::io::Seek>(ptr: InFilePtr, seeker: &mut S) -> Result<(), std::io::Error> { seeker .seek(std::io::SeekFrom::Start(ptr.get().get().into())) .map(|_| ())}
fn load_file(path: &str) -> Song { let file = fs::File::open(path).unwrap();
let mut buf = BufReader::new(file); let mut header_parser = ImpulseHeader::parse(buf.fill_buf().unwrap().first_chunk().unwrap()).unwrap(); buf.consume(ImpulseHeader::BASE_SIZE);
let header = loop { match header_parser.parse(buf.fill_buf().unwrap()) { SansIO::Finished(res, amount) => { buf.consume(amount); break res; } SansIO::Pending(amount) => buf.consume(amount), } };
let mut song = Song::default(); header.copy_values_into_song(&mut song);
for (idx, ptr) in header .pattern_offsets .iter() // number the slots .enumerate() // filter out empty slots, while keeping the numbering the same .flat_map(|(idx, ptr)| ptr.map(|ptr| (idx, ptr))) { move_to_ptr(ptr, &mut buf).unwrap(); let mut parser = PatternParser::new(buf.fill_buf().unwrap().first_chunk().unwrap()).unwrap(); buf.consume(PatternParser::HEADER_SIZE); let pattern = loop { match parser.parse(buf.fill_buf().unwrap()) { SansIO::Finished(res, amount) => { buf.consume(amount); break res; } SansIO::Pending(amount) => buf.consume(amount), } }; song.patterns[idx] = pattern; }
song}
fn main() { let path = std::env::args().nth(1).unwrap(); println!("path: {path}"); let file = std::fs::File::open(&path).unwrap(); println!("file len: {}", file.metadata().unwrap().len());
let song = load_file(&path); print!("{:?}", song)}