diff --git a/Cargo.toml b/Cargo.toml index 535c67b..bca068d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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] diff --git a/src/cli.rs b/src/cli.rs index bc5587c..ea8bb94 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -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 { + 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 = ::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 { + 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 = ::Target; + fn deref(&self) -> &Self::Target { + &self.0 + } +} diff --git a/src/cli/instrument.rs b/src/cli/instrument.rs deleted file mode 100644 index c9bfe64..0000000 --- a/src/cli/instrument.rs +++ /dev/null @@ -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 { - 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 - })) - } -} diff --git a/src/cli/score.rs b/src/cli/score.rs deleted file mode 100644 index a1fac87..0000000 --- a/src/cli/score.rs +++ /dev/null @@ -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 { - 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 - })) - } -}