fixed missing variable & length slope, flamegraph

This commit is contained in:
brevalferrari 2025-06-04 22:07:18 +02:00
parent 17525717e8
commit fb9b57f753
4 changed files with 517 additions and 25 deletions

6
.gitignore vendored
View file

@ -21,4 +21,8 @@ Cargo.lock
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
out/
out/
# Flamegraph
*.old
*.data

491
flamegraph.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 167 KiB

View file

@ -32,8 +32,7 @@ use thiserror::Error;
const DEFAULT_INSTRUMENT: &str = "sin(2*pi()*(442+442*((n+1)/N))*t)";
const DEFAULT_LENGTH: &str = "2^(2-log(2, l))*(60/T)";
#[derive(Parser)]
#[cfg_attr(debug_assertions, derive(Debug))]
#[derive(Debug, Parser)]
#[command(version, author, about)]
pub(super) enum Cli {
/// Play a song
@ -45,8 +44,7 @@ pub(super) enum Cli {
Memo(Memo),
}
#[derive(Parser, Clone, Getters)]
#[cfg_attr(debug_assertions, derive(Debug))]
#[derive(Debug, Parser, Clone, Getters)]
#[getset(get = "pub(super)")]
pub(super) struct PlayOpts {
/// Use this sheet music [default: stdin]
@ -104,8 +102,7 @@ impl InputGroup {
}
}
#[derive(Clone, Copy, AsRef)]
#[cfg_attr(debug_assertions, derive(Debug))]
#[derive(Debug, Clone, Copy, AsRef)]
struct Letter(char);
#[derive(Debug, Error)]
@ -127,8 +124,7 @@ impl FromStr for Letter {
}
}
#[derive(Clone, Copy, AsRef)]
#[cfg_attr(debug_assertions, derive(Debug))]
#[derive(Debug, Clone, Copy, AsRef)]
struct NotALetter(char);
#[derive(Debug, Error)]
@ -151,8 +147,7 @@ impl FromStr for NotALetter {
}
}
#[derive(Clone, AsRef)]
#[cfg_attr(debug_assertions, derive(Debug))]
#[derive(Debug, Clone, AsRef)]
struct LetterString(String);
#[derive(Debug, Error)]
@ -218,8 +213,7 @@ where
))
}
#[derive(Parser, Clone)]
#[cfg_attr(debug_assertions, derive(Debug))]
#[derive(Debug, Parser, Clone)]
#[group(required = false, multiple = false)]
pub(super) struct InputGroup {
/// Set the path to your sheet music file [default: stdin]
@ -245,8 +239,7 @@ impl FromStr for ClonableFile {
}
}
#[derive(Parser, Clone)]
#[cfg_attr(debug_assertions, derive(Debug))]
#[derive(Debug, Parser, Clone)]
pub(super) struct ExportOpts {
#[command(flatten)]
playopts: PlayOpts,
@ -282,7 +275,6 @@ enum AudioFormat {
Raw(RawAudioFormat),
}
#[cfg(debug_assertions)]
impl Debug for AudioFormat {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
@ -403,8 +395,7 @@ fn audio_format_parser(input: &str) -> Result<AudioFormat, anyhow::Error> {
.map_err(|e| anyhow!("{e:?}"))
}
#[derive(Parser, Clone, EnumString, Default)]
#[cfg_attr(debug_assertions, derive(Debug))]
#[derive(Debug, Parser, Clone, EnumString, Default)]
#[strum(ascii_case_insensitive)]
enum RawAudioFormat {
ALaw,
@ -430,8 +421,7 @@ enum RawAudioFormat {
U32Le,
}
#[derive(Parser, Clone)]
#[cfg_attr(debug_assertions, derive(Debug))]
#[derive(Debug, Parser, Clone)]
pub(super) enum Memo {
Syntax,
#[command(subcommand)]
@ -439,8 +429,7 @@ pub(super) enum Memo {
Formats,
}
#[derive(Parser, Clone)]
#[cfg_attr(debug_assertions, derive(Debug))]
#[derive(Debug, Parser, Clone)]
pub(super) enum Example {
List,
N { id: u8 },

View file

@ -1,5 +1,5 @@
mod cli;
use std::{collections::HashMap, io::read_to_string};
use std::{collections::HashMap, io::read_to_string, iter::once};
use anyhow::{Context as _, anyhow};
use bliplib::{
@ -25,7 +25,13 @@ fn main() -> anyhow::Result<()> {
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),
('T', 60.0),
('N', opts.notes().len() as f64),
]);
debug!("building parser");
let parser = Parser::new(
@ -58,7 +64,9 @@ fn main() -> anyhow::Result<()> {
.map(|(a, b)| (*a, *b))
.chain(default_variables),
opts.instrument().clone(),
opts.slopes().map(|(_, (a, b))| (*a, b.clone())),
opts.slopes()
.map(|(_, (a, b))| (*a, b.clone()))
.chain(once(('L', opts.length().clone()))),
));
debug!("compiling to samples");
let samples: Vec<f32> = compiler