mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-26 02:14:22 +00:00
Passed the valueToTextFunction and textToValueFunction lambdas from an AudioProcessorValueTreeState parameter to an attached slider
This commit is contained in:
parent
a2cd9be3b9
commit
c2a877cac8
3 changed files with 19 additions and 2 deletions
|
|
@ -421,7 +421,7 @@ struct AudioProcessorValueTreeState::SliderAttachment::Pimpl : private Attached
|
|||
Pimpl (AudioProcessorValueTreeState& s, const String& p, Slider& sl)
|
||||
: AttachedControlBase (s, p), slider (sl), ignoreCallbacks (false)
|
||||
{
|
||||
NormalisableRange<float> range (s.getParameterRange (paramID));
|
||||
NormalisableRange<float> range (state.getParameterRange (paramID));
|
||||
|
||||
if (range.interval != 0 || range.skew != 0)
|
||||
{
|
||||
|
|
@ -463,8 +463,13 @@ struct AudioProcessorValueTreeState::SliderAttachment::Pimpl : private Attached
|
|||
snapToLegalValueFunction });
|
||||
}
|
||||
|
||||
if (auto* param = state.getParameter (paramID))
|
||||
if (auto* param = dynamic_cast<AudioProcessorValueTreeState::Parameter*> (state.getParameter (paramID)))
|
||||
{
|
||||
slider.valueFromTextFunction = [param] (const String& text) { return (double) param->textToValueFunction (text); };
|
||||
slider.textFromValueFunction = [param] (double value) { return param->valueToTextFunction ((float) value); };
|
||||
|
||||
slider.setDoubleClickReturnValue (true, range.convertFrom0to1 (param->getDefaultValue()));
|
||||
}
|
||||
|
||||
sendInitialUpdate();
|
||||
slider.addListener (this);
|
||||
|
|
|
|||
|
|
@ -1539,6 +1539,9 @@ String Slider::getTextValueSuffix() const
|
|||
|
||||
String Slider::getTextFromValue (double v)
|
||||
{
|
||||
if (textFromValueFunction != nullptr)
|
||||
return textFromValueFunction (v);
|
||||
|
||||
if (getNumDecimalPlacesToDisplay() > 0)
|
||||
return String (v, getNumDecimalPlacesToDisplay()) + getTextValueSuffix();
|
||||
|
||||
|
|
@ -1547,6 +1550,9 @@ String Slider::getTextFromValue (double v)
|
|||
|
||||
double Slider::getValueFromText (const String& text)
|
||||
{
|
||||
if (valueFromTextFunction != nullptr)
|
||||
return valueFromTextFunction (text);
|
||||
|
||||
auto t = text.trimStart();
|
||||
|
||||
if (t.endsWith (getTextValueSuffix()))
|
||||
|
|
|
|||
|
|
@ -602,6 +602,12 @@ public:
|
|||
/** You can assign a lambda to this callback object to have it called when the slider's drag ends. */
|
||||
std::function<void()> onDragEnd;
|
||||
|
||||
/** You can assign a lambda that will be used to convert textual values to the slider's normalised position. */
|
||||
std::function<double (const String&)> valueFromTextFunction;
|
||||
|
||||
/** You can assign a lambda that will be used to convert the slider's normalised position to a textual value. */
|
||||
std::function<String (double)> textFromValueFunction;
|
||||
|
||||
//==============================================================================
|
||||
/** This lets you choose whether double-clicking moves the slider to a given position.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue