pub mod error;
pub mod note;
use std::convert::TryFrom;
use crate::model::mnx::error::{MnxError, MnxIdError};
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct MnxId(String);
impl MnxId {
pub fn as_str(&self) -> &str {
&self.0
}
}
impl TryFrom<String> for MnxId {
type Error = MnxIdError;
fn try_from(value: String) -> Result<Self, Self::Error> {
if value.is_empty() {
return Err(MnxIdError::Empty);
}
if value.len() > 256 {
return Err(MnxIdError::TooLong);
}
if !value.is_ascii() || value.chars().any(|c| c.is_whitespace()) {
return Err(MnxIdError::InvalidCharacters);
}
Ok(MnxId(value))
}
}
impl std::ops::Deref for MnxId {
type Target = str;
fn deref(&self) -> &Self::Target {
&self.0
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub struct MidiNumber(u8);
impl MidiNumber {
pub const MIN: u8 = 0;
pub const MAX: u8 = 127;
pub fn new(value: u8) -> Result<Self, MnxError> {
if value <= Self::MAX {
Ok(Self(value))
} else {
Err(MnxError::InvalidMidiNumber(value))
}
}
pub fn get(&self) -> u8 {
self.0
}
}
#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
pub struct Support {
pub use_accidental_display: bool,
pub use_beams: bool,
}
pub struct Metadata {
pub support: Option<Support>,
pub version: u16,
}
pub enum Orientation {
Up,
Down,
}
pub struct Global {
}
pub struct Pitch {
pub alter: Option<i8>,
pub octave: u8,
pub step: char,
}