Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defaults in the JUCE knob on double click and delete #53

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src-juce/AWConsolidatedEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,9 +489,9 @@ struct AWLink : public juce::Component

struct ParamKnob : juce::Component
{
juce::AudioParameterFloat *weakParam{nullptr};
AWConsolidatedAudioProcessor::AWParam *weakParam{nullptr};
const std::atomic<bool> &active;
ParamKnob(const juce::String &cn, juce::AudioParameterFloat *param, const std::atomic<bool> &a)
ParamKnob(const juce::String &cn, AWConsolidatedAudioProcessor::AWParam *param, const std::atomic<bool> &a)
: juce::Component(cn), weakParam{param}, active{a}
{
refreshModel();
Expand Down Expand Up @@ -669,9 +669,23 @@ struct ParamKnob : juce::Component
setValue(0.);
return true;
}

if (key.getKeyCode() == juce::KeyPress::deleteKey && weakParam)
{
setValue(weakParam->getDefaultValue());
return true;
}
return false;
}

void mouseDoubleClick(const juce::MouseEvent &event) override
{
if (weakParam)
{
setValue(weakParam->getDefaultValue());
}
}

std::unique_ptr<juce::AccessibilityHandler> createAccessibilityHandler() override
{
return std::make_unique<AH>(this);
Expand Down
4 changes: 4 additions & 0 deletions src-juce/AWConsolidatedProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ AWConsolidatedAudioProcessor::AWConsolidatedAudioProcessor()
}
return this->fxParams[i]->get();
};
fxParams[i]->getDefaultValueHandler = [i, this]()
{
return this->defaultValues[i];
};
fxParams[i]->addListener(this);
addParameter(fxParams[i]);
}
Expand Down
7 changes: 7 additions & 0 deletions src-juce/AWConsolidatedProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ class AWConsolidatedAudioProcessor : public juce::AudioProcessor,
{
return getTextToValue(text);
}

std::function<float()> getDefaultValueHandler{nullptr};
float getDefaultValue() const override {
if (getDefaultValueHandler)
return getDefaultValueHandler();
return 0;
}
};

//==============================================================================
Expand Down
Loading