From 9ff44f5182e52203973a73626291fd881fc0d6c7 Mon Sep 17 00:00:00 2001 From: brevalferrari Date: Wed, 4 Jun 2025 12:24:39 +0200 Subject: [PATCH] bin log --- src/cli/main.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/cli/main.rs b/src/cli/main.rs index f4ed3f6..c79745f 100644 --- a/src/cli/main.rs +++ b/src/cli/main.rs @@ -9,20 +9,25 @@ use bliplib::{ use clap::Parser as _; use cli::Cli; use dasp_sample::Sample; +use log::{debug, warn}; use rodio::{OutputStream, Sink, buffer::SamplesBuffer}; fn main() -> anyhow::Result<()> { env_logger::init(); let cli = Cli::parse(); + debug!("options: {cli:?}"); use Cli::*; match cli { Play(opts) => { let (_stream, stream_handle) = OutputStream::try_default() .context("Failed to find (or use) default audio device")?; + debug!("output stream acquired"); let sink = Sink::try_new(&stream_handle).context("Epic audio playback failure")?; + debug!("audio sink acquired"); let default_variables = HashMap::from([('l', 4f64), ('L', 0.0), ('t', 0.0)]); + debug!("building parser"); let parser = Parser::new( opts.notes(), opts.slopes() @@ -33,12 +38,19 @@ fn main() -> anyhow::Result<()> { .map(|(v, _)| *v) .collect::>(), ); + debug!("reading input"); let input = read_to_string(opts.input().get()).context("Failed to read input")?; + debug!("parsing tokens"); let tokens = parser .parse_all(&input) .map_err(|e| anyhow!("{e}")) .context("Failed to parse input")?; + debug!("found {} tokens", tokens.as_ref().len()); + if tokens.as_ref().len() == 0 { + warn!("0 tokens parsed"); + } + debug!("building compiler"); let compiler = Compiler::from(Context::new( 'L', 'n', @@ -48,14 +60,21 @@ fn main() -> anyhow::Result<()> { opts.instrument().clone(), opts.slopes().map(|(_, (a, b))| (*a, b.clone())), )); + debug!("compiling to samples"); let samples: Vec = compiler .compile_all(tokens) .context("Failed to process input tokens")? .into_iter() .map(Sample::to_sample) .collect(); + debug!("result: {} samples", samples.len()); + if samples.len() == 0 { + warn!("0 samples generated"); + } + debug!("appending samples to sink"); sink.append(SamplesBuffer::new(1, SAMPLE_RATE as u32, samples)); + debug!("sleeping until end of sink"); sink.sleep_until_end(); } Export(_opts) => todo!(),