-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementing param-indication extension
- Loading branch information
1 parent
e72d59a
commit 65540c0
Showing
7 changed files
with
213 additions
and
2 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#pragma once | ||
|
||
#include <juce_audio_processors/juce_audio_processors.h> | ||
|
||
class ParamIndicationHelper | ||
{ | ||
public: | ||
ParamIndicationHelper() = default; | ||
|
||
struct ParamIndicatorInfo | ||
{ | ||
juce::Colour colour; | ||
juce::String text; | ||
}; | ||
|
||
const ParamIndicatorInfo *getParamIndicatorInfo(juce::RangedAudioParameter ¶m) const | ||
{ | ||
const auto entry = indicatorInfoMap.find(¶m); | ||
if (entry == indicatorInfoMap.end()) | ||
return nullptr; | ||
return &entry->second; | ||
} | ||
|
||
void paramIndicationSetMapping(const juce::RangedAudioParameter ¶m, bool has_mapping, | ||
const juce::Colour *colour, const juce::String &label, | ||
const juce::String &description) noexcept | ||
{ | ||
if (!has_mapping) | ||
{ | ||
removeIndicatorInfo(param); | ||
} | ||
else | ||
{ | ||
ParamIndicatorInfo info; | ||
info.colour = colour == nullptr ? juce::Colours::transparentBlack : *colour; | ||
info.text = label + ", " + description; | ||
indicatorInfoMap[¶m] = std::move(info); | ||
} | ||
|
||
listeners.call(&Listener::paramIndicatorInfoChanged, param); | ||
} | ||
|
||
void paramIndicationSetAutomation(const juce::RangedAudioParameter ¶m, | ||
uint32_t automation_state, | ||
const juce::Colour *colour) noexcept | ||
{ | ||
if (automation_state == CLAP_PARAM_INDICATION_AUTOMATION_NONE) | ||
{ | ||
removeIndicatorInfo(param); | ||
} | ||
else | ||
{ | ||
ParamIndicatorInfo info; | ||
info.colour = colour == nullptr ? juce::Colours::transparentBlack : *colour; | ||
info.text = "Automation: " + [automation_state]() -> juce::String { | ||
if (automation_state == CLAP_PARAM_INDICATION_AUTOMATION_PRESENT) | ||
return "PRESENT"; | ||
else if (automation_state == CLAP_PARAM_INDICATION_AUTOMATION_RECORDING) | ||
return "RECORDING"; | ||
else if (automation_state == CLAP_PARAM_INDICATION_AUTOMATION_PLAYING) | ||
return "PLAYING"; | ||
else if (automation_state == CLAP_PARAM_INDICATION_AUTOMATION_OVERRIDING) | ||
return "OVERRIDING"; | ||
return ""; | ||
}(); | ||
indicatorInfoMap[¶m] = std::move(info); | ||
} | ||
|
||
listeners.call(&Listener::paramIndicatorInfoChanged, param); | ||
} | ||
|
||
struct Listener | ||
{ | ||
virtual ~Listener() = default; | ||
virtual void paramIndicatorInfoChanged(const juce::RangedAudioParameter &) {} | ||
}; | ||
|
||
void addListener(Listener *listener) { listeners.add(listener); } | ||
void removeListener(Listener *listener) { listeners.remove(listener); } | ||
|
||
private: | ||
void removeIndicatorInfo(const juce::RangedAudioParameter ¶m) | ||
{ | ||
const auto entry = indicatorInfoMap.find(¶m); | ||
if (entry != indicatorInfoMap.end()) | ||
indicatorInfoMap.erase(entry); | ||
} | ||
|
||
std::unordered_map<const juce::RangedAudioParameter *, ParamIndicatorInfo> indicatorInfoMap; | ||
|
||
juce::ListenerList<Listener> listeners; | ||
|
||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(ParamIndicationHelper) | ||
}; |
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
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