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

4
.gitignore vendored
View file

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

View file

@ -1,5 +1,5 @@
mod cli; 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 anyhow::{Context as _, anyhow};
use bliplib::{ use bliplib::{
@ -25,7 +25,13 @@ fn main() -> anyhow::Result<()> {
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"); 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"); debug!("building parser");
let parser = Parser::new( let parser = Parser::new(
@ -58,7 +64,9 @@ fn main() -> anyhow::Result<()> {
.map(|(a, b)| (*a, *b)) .map(|(a, b)| (*a, *b))
.chain(default_variables), .chain(default_variables),
opts.instrument().clone(), 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"); debug!("compiling to samples");
let samples: Vec<f32> = compiler let samples: Vec<f32> = compiler