Compare commits

...

2 commits

Author SHA1 Message Date
9269b00235
spline & deref macro for wrappers 2024-09-02 22:05:42 -04:00
c944db2ab7
cli files dispatch 2024-09-02 22:04:05 -04:00
4 changed files with 50 additions and 50 deletions

View file

@ -7,7 +7,9 @@ edition = "2021"
anyhow = "1.0" anyhow = "1.0"
cfg-if = "1.0.0" cfg-if = "1.0.0"
clap = { version = "4.5", features = ["derive"] } clap = { version = "4.5", features = ["derive"] }
derived-deref = "2.1.0"
fasteval = "0.2.4" fasteval = "0.2.4"
splines = "4.3.1"
tinyaudio = { version = "0.1", optional = true } tinyaudio = { version = "0.1", optional = true }
[features] [features]

View file

@ -1,14 +1,18 @@
use std::{fs::read_to_string, ops::Deref, path::Path, str::FromStr}; use std::str::FromStr;
cfg_if! { cfg_if! {
if #[cfg(feature = "save")] { if #[cfg(feature = "save")] {
use std::path::PathBuf; use std::path::PathBuf;
} }
} }
use anyhow::{Context, Error};
use cfg_if::cfg_if; use cfg_if::cfg_if;
use clap::Parser; use clap::Parser;
mod instrument;
mod score;
pub use instrument::Instrument;
pub use score::Score;
#[derive(Parser)] #[derive(Parser)]
#[cfg_attr(debug_assertions, derive(Debug))] #[cfg_attr(debug_assertions, derive(Debug))]
pub(super) struct Args { pub(super) struct Args {
@ -22,51 +26,3 @@ pub(super) struct Args {
silent: bool, silent: bool,
score: Score, score: Score,
} }
#[derive(Clone)]
#[cfg_attr(debug_assertions, derive(Debug))]
pub(super) struct Score(String);
impl FromStr for Score {
type Err = Error;
fn from_str(value: &str) -> Result<Self, Self::Err> {
let maybe_a_path = Path::new(&value);
Ok(Score(if maybe_a_path.is_file() {
read_to_string(maybe_a_path)
.context("you gave me the path of a real file but reading it is hard!")?
} else {
value.to_owned() // hope it's a good one
}))
}
}
impl Deref for Score {
type Target = <String as Deref>::Target;
fn deref(&self) -> &Self::Target {
&self.0
}
}
#[derive(Clone)]
#[cfg_attr(debug_assertions, derive(Debug))]
pub(super) struct Instrument(String);
impl FromStr for Instrument {
type Err = Error;
fn from_str(value: &str) -> Result<Self, Self::Err> {
let maybe_a_path = Path::new(&value);
Ok(Instrument(if maybe_a_path.is_file() {
read_to_string(maybe_a_path)
.context("you gave me the path of a real file but reading it is hard!")?
} else {
value.to_owned() // hope it's a good one
}))
}
}
impl Deref for Instrument {
type Target = <String as Deref>::Target;
fn deref(&self) -> &Self::Target {
&self.0
}
}

21
src/cli/instrument.rs Normal file
View file

@ -0,0 +1,21 @@
use std::{fs::read_to_string, path::Path, str::FromStr};
use anyhow::{Context, Error};
use derived_deref::Deref;
#[derive(Clone, Deref)]
#[cfg_attr(debug_assertions, derive(Debug))]
pub struct Instrument(String);
impl FromStr for Instrument {
type Err = Error;
fn from_str(value: &str) -> Result<Self, Self::Err> {
let maybe_a_path = Path::new(&value);
Ok(Instrument(if maybe_a_path.is_file() {
read_to_string(maybe_a_path)
.context("you gave me the path of a real file but reading it is hard!")?
} else {
value.to_owned() // hope it's a good one
}))
}
}

21
src/cli/score.rs Normal file
View file

@ -0,0 +1,21 @@
use std::{fs::read_to_string, path::Path, str::FromStr};
use anyhow::{Context, Error};
use derived_deref::Deref;
#[derive(Clone, Deref)]
#[cfg_attr(debug_assertions, derive(Debug))]
pub struct Score(String);
impl FromStr for Score {
type Err = Error;
fn from_str(value: &str) -> Result<Self, Self::Err> {
let maybe_a_path = Path::new(&value);
Ok(Score(if maybe_a_path.is_file() {
read_to_string(maybe_a_path)
.context("you gave me the path of a real file but reading it is hard!")?
} else {
value.to_owned() // hope it's a good one
}))
}
}