use sim_lib_music_core::Music;
use sim_lib_pitch_core::Pitch;
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum TransformDiagnosticCode {
InvalidAxis,
InvalidMatrix,
InvalidRatio,
InvalidTimeMap,
MissingMidiKey,
NonPositiveDuration,
PitchOutOfScale,
UnsupportedMapping,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct TransformDiagnostic {
pub code: TransformDiagnosticCode,
pub transform: &'static str,
pub message: String,
}
impl TransformDiagnostic {
pub fn new(
code: TransformDiagnosticCode,
transform: &'static str,
message: impl Into<String>,
) -> Self {
Self {
code,
transform,
message: message.into(),
}
}
}
#[derive(Clone, Debug)]
pub struct TransformReport {
pub music: Music,
pub diagnostics: Vec<TransformDiagnostic>,
}
impl TransformReport {
pub fn clean(music: Music) -> Self {
Self {
music,
diagnostics: Vec::new(),
}
}
pub fn with_diagnostic(music: Music, diagnostic: TransformDiagnostic) -> Self {
Self {
music,
diagnostics: vec![diagnostic],
}
}
pub fn has_diagnostics(&self) -> bool {
!self.diagnostics.is_empty()
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct CallablePitchMap {
pub name: String,
pub semitone_delta: i32,
}
impl CallablePitchMap {
pub fn new(name: impl Into<String>, semitone_delta: i32) -> Self {
Self {
name: name.into(),
semitone_delta,
}
}
pub fn map_pitch(&self, pitch: Pitch) -> Pitch {
pitch.transpose(self.semitone_delta)
}
}