Compare commits

..

No commits in common. "9269b0023522d78e9ec9ba7eb62a09f6ca6bb50e" and "5e6044eaf51b4caef420029928ceae143b8ffcd6" have entirely different histories.

4 changed files with 50 additions and 50 deletions

View file

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

View file

@ -1,18 +1,14 @@
use std::str::FromStr;
use std::{fs::read_to_string, ops::Deref, path::Path, str::FromStr};
cfg_if! {
if #[cfg(feature = "save")] {
use std::path::PathBuf;
}
}
use anyhow::{Context, Error};
use cfg_if::cfg_if;
use clap::Parser;
mod instrument;
mod score;
pub use instrument::Instrument;
pub use score::Score;
#[derive(Parser)]
#[cfg_attr(debug_assertions, derive(Debug))]
pub(super) struct Args {
@ -26,3 +22,51 @@ pub(super) struct Args {
silent: bool,
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
}
}

View file

@ -1,21 +0,0 @@
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
}))
}
}

View file

@ -1,21 +0,0 @@
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
}))
}
}