Skip to content

Commit

Permalink
Added High/Low filter plugin. Added parameter range power.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeoliphant committed Jul 27, 2024
1 parent 064f549 commit 93d071b
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 7 deletions.
1 change: 1 addition & 0 deletions StompboxPlugin/UnmanagedAudioPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public virtual void SetUnmanagedWrapper(PluginWrapper unmanagedWrapper)
MinValue = unmanagedWrapper.GetParameterMinValue(handle),
MaxValue = unmanagedWrapper.GetParameterMaxValue(handle),
DefaultValue = unmanagedWrapper.GetParameterDefaultValue(handle),
RangePower = unmanagedWrapper.GetParameterRangePower(handle),
ParameterType = paramType,
IsAdvanced = unmanagedWrapper.GetParameterIsAdvanced(handle),
CanSyncToHostBPM = unmanagedWrapper.GetParameterCanSyncToHostBPM(handle),
Expand Down
26 changes: 26 additions & 0 deletions StompboxShared/AudioPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class PluginParameter
public double MinValue { get; set; }
public double MaxValue { get; set; }
public double DefaultValue { get; set; }
public double RangePower { get; set; }
public EParameterType ParameterType { get; set; }
public bool CanSyncToHostBPM { get; set; }
public int HostBPMSyncNumerator { get; set; }
Expand Down Expand Up @@ -51,6 +52,17 @@ public virtual double Value
}
}
}
public double NormalizedValue
{
get
{
return GetNormalizedValue(Value);
}
set
{
Value = GetRangeValue(value);
}
}
public string DisplayValue { get { return String.Format(ValueFormat, Value); } }
public String[] EnumValues { get; set; }
public int[] IntValues { get; set; }
Expand All @@ -77,6 +89,20 @@ public PluginParameter()
ValueFormat = "{0:0.00}";
}

public double GetNormalizedValue(double value)
{
double val = (value - MinValue) / (MaxValue - MinValue);

return (RangePower < 0) ? (1 - (Math.Pow(1 - val, 1 / -RangePower))) : Math.Pow(val, 1 / RangePower);
}

public double GetRangeValue(double normalizedValue)
{
double val = (RangePower < 0) ? (1 - Math.Pow(1 - normalizedValue, -RangePower)) : Math.Pow(normalizedValue, RangePower);

return MinValue + ((MaxValue - MinValue) * val);
}

public override string ToString()
{
return Name + ": " + DisplayValue;
Expand Down
13 changes: 7 additions & 6 deletions StompboxShared/Interface/PluginInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,9 @@ protected UIElement CreateControl(PluginParameter parameter)

ParameterDial dial = new ParameterDial()
{
MinValue = parameter.MinValue,
MaxValue = parameter.MaxValue,
DefaultValue = parameter.DefaultValue
MinValue = 0,
MaxValue = 1,
DefaultValue = parameter.GetNormalizedValue(parameter.DefaultValue)
};

controlDock.Children.Add(dial);
Expand All @@ -364,9 +364,9 @@ protected UIElement CreateControl(PluginParameter parameter)

dial.ValueChangedAction = delegate (double val)
{
parameter.Value = val;
parameter.NormalizedValue = val;

valueDisplay.SetValue(val);
valueDisplay.SetValue(parameter.Value);
};

//dial.HoldAction = delegate
Expand All @@ -376,7 +376,7 @@ protected UIElement CreateControl(PluginParameter parameter)

parameter.SetValue = delegate (double value)
{
dial.SetValue(value);
dial.SetValue(parameter.GetNormalizedValue(value));
};

if (parameter.CanSyncToHostBPM)
Expand Down Expand Up @@ -1260,6 +1260,7 @@ public class ParameterDial : Dock
public double MinValue { get; set; }
public double MaxValue { get; set; }
public double DefaultValue { get; set; }
public double RangePower { get; set; } = 1.0;
public Action<double> ValueChangedAction { get; set; }
public Action HoldAction { get; set; }

Expand Down
5 changes: 5 additions & 0 deletions StompboxShared/ProtocolClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,11 @@ public void HandleCommand(string cmd)
Double.TryParse(propValue, out maxValue);
newParameter.MaxValue = maxValue;
break;
case "RangePower":
double rangePower = 0;
Double.TryParse(propValue, out rangePower);
newParameter.RangePower = rangePower;
break;
case "DefaultValue":
double defaultValue = 0;
Double.TryParse(propValue, out defaultValue);
Expand Down
5 changes: 5 additions & 0 deletions UnmanagedBridge/PluginWrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ namespace UnmanagedPlugins
return ((StompBoxParameter*)(void*)parameter)->DefaultValue;
}

double GetParameterRangePower(IntPtr parameter)
{
return ((StompBoxParameter*)(void*)parameter)->RangePower;
}

int GetParameterType(IntPtr parameter)
{
return ((StompBoxParameter*)(void*)parameter)->ParameterType;
Expand Down

0 comments on commit 93d071b

Please sign in to comment.