-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0db4467
commit ee16a95
Showing
6 changed files
with
249 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
modules/plugin/chowdsp_plugin_state/Frontend/chowdsp_SliderChoiceAttachment.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
namespace chowdsp | ||
{ | ||
SliderChoiceAttachment::SliderChoiceAttachment (ChoiceParameter& param, | ||
PluginState& pluginState, | ||
juce::Slider& paramSlider) | ||
: SliderChoiceAttachment (param, pluginState.getParameterListeners(), paramSlider, pluginState.undoManager) | ||
{ | ||
} | ||
|
||
SliderChoiceAttachment::SliderChoiceAttachment (ChoiceParameter& param, | ||
ParameterListeners& listeners, | ||
juce::Slider& paramSlider, | ||
juce::UndoManager* undoManager) | ||
: slider (¶mSlider), | ||
attachment (param, listeners, ParameterAttachmentHelpers::SetValueCallback { *this }), | ||
um (undoManager) | ||
{ | ||
slider->valueFromTextFunction = [&p = static_cast<juce::RangedAudioParameter&> (param)] (const juce::String& text) | ||
{ | ||
return (double) p.convertFrom0to1 (p.getValueForText (text)); | ||
}; | ||
slider->textFromValueFunction = [&p = static_cast<juce::RangedAudioParameter&> (param)] (double value) | ||
{ | ||
return p.getText (p.convertTo0to1 ((float) value), 0); | ||
}; | ||
slider->setDoubleClickReturnValue (true, param.getDefaultIndex()); | ||
|
||
slider->setRange (0.0, static_cast<double> (param.choices.size() - 1), 1.0); | ||
|
||
setValue (param.getIndex()); | ||
slider->valueChanged(); | ||
slider->addListener (this); | ||
} | ||
|
||
SliderChoiceAttachment::~SliderChoiceAttachment() | ||
{ | ||
if (slider != nullptr) | ||
slider->removeListener (this); | ||
} | ||
|
||
void SliderChoiceAttachment::setValue (int newValue) | ||
{ | ||
if (slider != nullptr) | ||
{ | ||
juce::ScopedValueSetter svs { skipSliderChangedCallback, true }; | ||
slider->setValue (static_cast<double> (newValue), juce::sendNotificationSync); | ||
} | ||
} | ||
|
||
void SliderChoiceAttachment::sliderValueChanged (juce::Slider*) | ||
{ | ||
if (skipSliderChangedCallback) | ||
return; | ||
|
||
attachment.setValueAsPartOfGesture (static_cast<int> (slider->getValue())); | ||
} | ||
|
||
void SliderChoiceAttachment::sliderDragStarted (juce::Slider*) | ||
{ | ||
valueAtStartOfGesture = attachment.param->getIndex(); | ||
attachment.beginGesture(); | ||
} | ||
|
||
void SliderChoiceAttachment::sliderDragEnded (juce::Slider*) | ||
{ | ||
if (um != nullptr) | ||
{ | ||
um->beginNewTransaction(); | ||
um->perform ( | ||
new ParameterAttachmentHelpers::ParameterChangeAction<ChoiceParameter> ( | ||
*attachment.param, | ||
valueAtStartOfGesture, | ||
attachment.param->getIndex())); | ||
} | ||
|
||
attachment.endGesture(); | ||
} | ||
} // namespace chowdsp |
47 changes: 47 additions & 0 deletions
47
modules/plugin/chowdsp_plugin_state/Frontend/chowdsp_SliderChoiceAttachment.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#pragma once | ||
|
||
namespace chowdsp | ||
{ | ||
class SliderChoiceAttachment : private juce::Slider::Listener | ||
{ | ||
public: | ||
/** Creates an attachment for a given parameter, using the undo manager from the plugin state. */ | ||
SliderChoiceAttachment (ChoiceParameter& param, | ||
PluginState& pluginState, | ||
juce::Slider& paramSlider); | ||
|
||
/** Creates an attachment for a given parameter. */ | ||
SliderChoiceAttachment (ChoiceParameter& param, | ||
ParameterListeners& listeners, | ||
juce::Slider& paramSlider, | ||
juce::UndoManager* undoManager); | ||
|
||
SliderChoiceAttachment() = default; | ||
SliderChoiceAttachment (SliderChoiceAttachment&&) noexcept = default; | ||
SliderChoiceAttachment& operator= (SliderChoiceAttachment&&) noexcept = default; | ||
|
||
~SliderChoiceAttachment() override; | ||
|
||
/** Sets the initial value of the slider */ | ||
void setValue (int newValue); | ||
|
||
/** Returns the attached parameter */ | ||
[[nodiscard]] const ChoiceParameter* getParameter() const { return attachment.param; } | ||
|
||
private: | ||
void sliderValueChanged (juce::Slider*) override; | ||
void sliderDragStarted (juce::Slider*) override; | ||
void sliderDragEnded (juce::Slider*) override; | ||
|
||
juce::Slider* slider = nullptr; | ||
ParameterAttachment<ChoiceParameter, | ||
ParameterAttachmentHelpers::SetValueCallback<SliderChoiceAttachment>> | ||
attachment; | ||
juce::UndoManager* um = nullptr; | ||
|
||
bool skipSliderChangedCallback = false; | ||
int valueAtStartOfGesture = 0; | ||
|
||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SliderChoiceAttachment) | ||
}; | ||
} // namespace chowdsp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters