Skip to content

Commit

Permalink
Drop thiserror dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
PolyMeilex committed Dec 28, 2024
1 parent 2363911 commit a10151d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 15 deletions.
1 change: 0 additions & 1 deletion oxisynth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ getrandom = { version = "0.2", features = ["js"], optional = true }
rand = { version = "0.8.3", optional = true }

lewton = { version = "0.10.2", optional = true }
thiserror = "2.0.9"

[dev-dependencies]
env_logger = "0.11"
Expand Down
63 changes: 49 additions & 14 deletions oxisynth/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,68 @@
use crate::SoundFontId;

#[derive(thiserror::Error, Debug)]
#[derive(Debug)]
pub enum OxiError {
#[error("Key out of range (0-127)")]
KeyOutOfRange,
#[error("Velocity out of range (0-127)")]
VelocityOutOfRange,
#[error("Channel out of range")]
ChannelOutOfRange,
#[error("Ctrl out of range (0-127)")]
CtrlOutOfRange,
#[error("CC Value out of range (0-127)")]
CCValueOutOfRange,
#[error("Program out of range")]
ProgramOutOfRange,
#[error("Key pressure out of range (0-127)")]
KeyPressureOutOfRange,
#[error("Channel pressure out of range (0-127)")]
ChannelPressureOutOfRange,
#[error("PithBend out of range")]
PithBendOutOfRange,
#[error("Channel has no preset")]
ChannelHasNoPreset,
#[error(
"There is no preset with bank number {bank_id} and preset number {preset_id} in SoundFont {sfont_id:?}"
)]
PresetNotFound {
bank_id: u32,
preset_id: u8,
sfont_id: SoundFontId,
},
}

impl std::error::Error for OxiError {}

impl std::fmt::Display for OxiError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
OxiError::KeyOutOfRange => {
write!(f, "Key out of range (0-127)")?;
}
OxiError::VelocityOutOfRange => {
write!(f, "Velocity out of range (0-127)")?;
}
OxiError::ChannelOutOfRange => {
write!(f, "Channel out of range")?;
}
OxiError::CtrlOutOfRange => {
write!(f, "Ctrl out of range (0-127)")?;
}
OxiError::CCValueOutOfRange => {
write!(f, "CC Value out of range (0-127)")?;
}
OxiError::ProgramOutOfRange => {
write!(f, "Program out of range")?;
}
OxiError::KeyPressureOutOfRange => {
write!(f, "Key pressure out of range (0-127)")?;
}
OxiError::ChannelPressureOutOfRange => {
write!(f, "Channel pressure out of range (0-127)")?;
}
OxiError::PithBendOutOfRange => {
write!(f, "PithBend out of range")?;
}
OxiError::ChannelHasNoPreset => {
write!(f, "Channel has no preset")?;
}
OxiError::PresetNotFound {
bank_id,
preset_id,
sfont_id,
} => {
write!(f,"There is no preset with bank number {bank_id} and preset number {preset_id} in SoundFont {sfont_id:?}")?;
}
};

Ok(())
}
}

0 comments on commit a10151d

Please sign in to comment.