bin log
This commit is contained in:
parent
0ccc81551a
commit
9ff44f5182
1 changed files with 19 additions and 0 deletions
|
@ -9,20 +9,25 @@ use bliplib::{
|
||||||
use clap::Parser as _;
|
use clap::Parser as _;
|
||||||
use cli::Cli;
|
use cli::Cli;
|
||||||
use dasp_sample::Sample;
|
use dasp_sample::Sample;
|
||||||
|
use log::{debug, warn};
|
||||||
use rodio::{OutputStream, Sink, buffer::SamplesBuffer};
|
use rodio::{OutputStream, Sink, buffer::SamplesBuffer};
|
||||||
|
|
||||||
fn main() -> anyhow::Result<()> {
|
fn main() -> anyhow::Result<()> {
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
|
debug!("options: {cli:?}");
|
||||||
use Cli::*;
|
use Cli::*;
|
||||||
match cli {
|
match cli {
|
||||||
Play(opts) => {
|
Play(opts) => {
|
||||||
let (_stream, stream_handle) = OutputStream::try_default()
|
let (_stream, stream_handle) = OutputStream::try_default()
|
||||||
.context("Failed to find (or use) default audio device")?;
|
.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")?;
|
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)]);
|
let default_variables = HashMap::from([('l', 4f64), ('L', 0.0), ('t', 0.0)]);
|
||||||
|
|
||||||
|
debug!("building parser");
|
||||||
let parser = Parser::new(
|
let parser = Parser::new(
|
||||||
opts.notes(),
|
opts.notes(),
|
||||||
opts.slopes()
|
opts.slopes()
|
||||||
|
@ -33,12 +38,19 @@ fn main() -> anyhow::Result<()> {
|
||||||
.map(|(v, _)| *v)
|
.map(|(v, _)| *v)
|
||||||
.collect::<Vec<_>>(),
|
.collect::<Vec<_>>(),
|
||||||
);
|
);
|
||||||
|
debug!("reading input");
|
||||||
let input = read_to_string(opts.input().get()).context("Failed to read input")?;
|
let input = read_to_string(opts.input().get()).context("Failed to read input")?;
|
||||||
|
debug!("parsing tokens");
|
||||||
let tokens = parser
|
let tokens = parser
|
||||||
.parse_all(&input)
|
.parse_all(&input)
|
||||||
.map_err(|e| anyhow!("{e}"))
|
.map_err(|e| anyhow!("{e}"))
|
||||||
.context("Failed to parse input")?;
|
.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(
|
let compiler = Compiler::from(Context::new(
|
||||||
'L',
|
'L',
|
||||||
'n',
|
'n',
|
||||||
|
@ -48,14 +60,21 @@ fn main() -> anyhow::Result<()> {
|
||||||
opts.instrument().clone(),
|
opts.instrument().clone(),
|
||||||
opts.slopes().map(|(_, (a, b))| (*a, b.clone())),
|
opts.slopes().map(|(_, (a, b))| (*a, b.clone())),
|
||||||
));
|
));
|
||||||
|
debug!("compiling to samples");
|
||||||
let samples: Vec<f32> = compiler
|
let samples: Vec<f32> = compiler
|
||||||
.compile_all(tokens)
|
.compile_all(tokens)
|
||||||
.context("Failed to process input tokens")?
|
.context("Failed to process input tokens")?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(Sample::to_sample)
|
.map(Sample::to_sample)
|
||||||
.collect();
|
.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));
|
sink.append(SamplesBuffer::new(1, SAMPLE_RATE as u32, samples));
|
||||||
|
debug!("sleeping until end of sink");
|
||||||
sink.sleep_until_end();
|
sink.sleep_until_end();
|
||||||
}
|
}
|
||||||
Export(_opts) => todo!(),
|
Export(_opts) => todo!(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue