use std::fmt;
use crate::{
SystemExclusiveData,
ParseError
};
use crate::k5000::{
PitchEnvelopeLevel,
PitchEnvelopeTime,
VelocitySensitivity
};
#[derive(Debug)]
pub struct Envelope {
pub start: PitchEnvelopeLevel,
pub attack_time: PitchEnvelopeTime,
pub attack_level: PitchEnvelopeLevel,
pub decay_time: PitchEnvelopeTime,
pub time_vel_sens: VelocitySensitivity,
pub level_vel_sens: VelocitySensitivity,
}
impl Envelope {
pub fn new() -> Envelope {
Envelope {
start: PitchEnvelopeLevel::new(0),
attack_time: PitchEnvelopeTime::new(0),
attack_level: PitchEnvelopeLevel::new(0),
decay_time: PitchEnvelopeTime::new(0),
time_vel_sens: VelocitySensitivity::new(0),
level_vel_sens: VelocitySensitivity::new(0),
}
}
}
impl Default for Envelope {
fn default() -> Self {
Self::new()
}
}
impl fmt::Display for Envelope {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Start Level={} Attack Time={} Attack Level={} Decay Time={}\nVelocity to: Level={} Time={}\n",
self.start, self.attack_time, self.attack_level, self.decay_time, self.level_vel_sens, self.time_vel_sens
)
}
}
impl SystemExclusiveData for Envelope {
fn from_bytes(data: &[u8]) -> Result<Self, ParseError> {
Ok(Envelope {
start: PitchEnvelopeLevel::from(data[0]),
attack_time: PitchEnvelopeTime::from(data[1]),
attack_level: PitchEnvelopeLevel::from(data[2]),
decay_time: PitchEnvelopeTime::from(data[3]),
time_vel_sens: VelocitySensitivity::from(data[4]),
level_vel_sens: VelocitySensitivity::from(data[5]),
})
}
fn to_bytes(&self) -> Vec<u8> {
vec![
self.start.into(),
self.attack_time.into(),
self.attack_level.into(),
self.decay_time.into(),
self.time_vel_sens.into(),
self.level_vel_sens.into()
]
}
fn data_size() -> usize { 6 }
}