use game_audio::track::{parse, render_song_stereo};
use std::time::Instant;

fn main() {
    let path = std::env::args().nth(1).unwrap_or_default();
    let source = std::fs::read_to_string(&path).unwrap_or_default();

    let start = Instant::now();
    let song = match parse(&source) {
        Ok(song) => song,
        Err(error) => {
            eprintln!("parse error: {error}");
            return;
        }
    };
    let parse_time = start.elapsed();

    let note_count: usize = song.layers.iter().map(|layer| layer.notes.len()).sum();
    let start = Instant::now();
    let samples = match render_song_stereo(&song, None) {
        Ok(samples) => samples,
        Err(error) => {
            eprintln!("render error: {error}");
            return;
        }
    };
    let render_time = start.elapsed();
    let seconds = samples.len() as f32 / 2.0 / 44100.0;

    println!(
        "{note_count} notes, {seconds:.0}s audio: parse {parse_time:?}, render {render_time:?}"
    );
}
