Skip to content

Commit

Permalink
Ignore negative step count in parameter info - fixes kind of garbage …
Browse files Browse the repository at this point in the history
…values for some plugins
  • Loading branch information
azeno committed Nov 8, 2024
1 parent 5afd745 commit bc379de
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static SymbolicSampleSizes GetSymbolicSampleSizes(WaveFormat waveFormat)

public static Type GetPinType(this ParameterInfo parameterInfo)
{
return parameterInfo.StepCount switch
return parameterInfo.GetStepCount() switch
{
0 => typeof(float),
1 => typeof(bool),
Expand All @@ -80,11 +80,11 @@ public static Type GetPinType(this ParameterInfo parameterInfo)
public static object GetValueAsObject(this ParameterInfo parameterInfo, double normalizedValue)
{
//var plain = controller.normalizedParamToPlain(parameterInfo.ID, normalizedValue);
return parameterInfo.StepCount switch
return parameterInfo.GetStepCount() switch
{
0 => (float)normalizedValue,
1 => normalizedValue >= 0.5,
_ => ToDiscrete(normalizedValue, parameterInfo.StepCount)
_ => ToDiscrete(normalizedValue, parameterInfo.GetStepCount())
};
}

Expand All @@ -98,14 +98,16 @@ public static object GetCurrentValue(this ParameterInfo parameterInfo, IEditCont

public static double Normalize(this ParameterInfo parameterInfo, object value)
{
return parameterInfo.StepCount switch
return parameterInfo.GetStepCount() switch
{
0 => value is float f ? f : default,
1 => value is bool b ? b ? 1d : 0d : default,
_ => value is int i ? ToDiscrete(i, parameterInfo.StepCount) : default
_ => value is int i ? ToDiscrete(i, parameterInfo.GetStepCount()) : default
};
}

public static int GetStepCount(this ParameterInfo parameterInfo) => Math.Max(0, parameterInfo.StepCount);

public static double Normalize(int discrete, int stepCount) => discrete / (double)stepCount;

public static int ToDiscrete(double normalized, int stepCount) => (int)Math.Min(stepCount, normalized * (stepCount + 1));
Expand Down

0 comments on commit bc379de

Please sign in to comment.