#[derive(Debug, Clone, PartialEq)]
pub struct MidiMapping {
pub cc: u8,
pub field_name: String,
pub control_type: ControlType,
pub min_value: f32,
pub max_value: f32,
}
#[derive(Debug, Clone, PartialEq)]
pub enum ControlType {
Range { min: f32, max: f32 },
Button,
}
impl MidiMapping {
pub fn range(cc: u8, field_name: impl Into<String>, min: f32, max: f32) -> Self {
Self {
cc,
field_name: field_name.into(),
control_type: ControlType::Range { min, max },
min_value: min,
max_value: max,
}
}
pub fn button(cc: u8, field_name: impl Into<String>) -> Self {
Self {
cc,
field_name: field_name.into(),
control_type: ControlType::Button,
min_value: 0.0,
max_value: 1.0,
}
}
pub fn scale_value(&self, normalized: f32) -> f32 {
match self.control_type {
ControlType::Range { min, max } => min + normalized * (max - min),
ControlType::Button => {
if normalized > 0.5 {
1.0
} else {
0.0
}
}
}
}
}