Skip to content

Commit

Permalink
change steps field on Range::Discrete to min and max
Browse files Browse the repository at this point in the history
  • Loading branch information
micahrj committed Jan 7, 2024
1 parent 369e969 commit 0af0f50
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/format/clap/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,10 +512,10 @@ impl<P: Plugin> Instance<P> {
param_info.min_value = *min;
param_info.max_value = *max;
}
Range::Discrete { steps } => {
Range::Discrete { min, max } => {
param_info.flags |= CLAP_PARAM_IS_STEPPED;
param_info.min_value = 0.0;
param_info.max_value = ((*steps).max(2) - 1) as f64;
param_info.min_value = *min as f64;
param_info.max_value = *max as f64;
}
}
param_info.default_value = param.default;
Expand Down
6 changes: 3 additions & 3 deletions src/format/vst3/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ fn speaker_arrangement_to_format(speaker_arrangement: SpeakerArrangement) -> Opt
fn map_param(param: &ParamInfo, value: ParamValue) -> ParamValue {
match param.range {
Range::Continuous { min, max } => (1.0 - value) * min + value * max,
Range::Discrete { steps } => value * steps as f64,
Range::Discrete { min, max } => (1.0 - value) * min as f64 + value * max as f64,
}
}

fn unmap_param(param: &ParamInfo, value: ParamValue) -> ParamValue {
match param.range {
Range::Continuous { min, max } => (value - min) / (max - min),
Range::Discrete { steps } => value / steps as f64,
Range::Discrete { min, max } => (value - min as f64) / ((max - min) as f64),
}
}

Expand Down Expand Up @@ -579,7 +579,7 @@ impl<P: Plugin> IEditControllerTrait for Component<P> {
copy_wstring("", &mut info.units);
info.stepCount = match param.range {
Range::Continuous { .. } => 0,
Range::Discrete { steps } => (steps as int32 - 1).max(1),
Range::Discrete { min, max } => (max - min).max(1),
};
info.defaultNormalizedValue = map_param(param, param.default);
info.unitId = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct ParamInfo {

pub enum Range {
Continuous { min: f64, max: f64 },
Discrete { steps: u64 },
Discrete { min: i32, max: i32 },
}

pub trait Display {
Expand Down

0 comments on commit 0af0f50

Please sign in to comment.