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

Add hook-in for plugin to report that a preset has been loaded #142

Merged
merged 1 commit into from
Jan 29, 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
13 changes: 13 additions & 0 deletions include/clap-juce-extensions/clap-juce-extensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,17 @@ struct clap_juce_audio_processor_capabilities
onPresetLoadError(location_kind, location, load_key, os_error, message);
}

/**
* The plugin should call this when it has loaded a preset (whether requested from the host,
* or from internally within the plugin). The provided information will help the host to
* keep it's preset browser in-sync with the plugin.
*/
void reportPresetLoaded(uint32_t location_kind, const char *location, const char *load_key)
{
if (onPresetLoaded != nullptr)
onPresetLoaded(location_kind, location, load_key);
}

/*
* If you are working with a host that chooses to not implement cookies you will
* need to look up parameters by param_id. Use this method to do so.
Expand Down Expand Up @@ -320,6 +331,8 @@ struct clap_juce_audio_processor_capabilities
std::function<void(uint32_t location_kind, const char *location, const char *load_key,
int32_t os_error, const juce::String &msg)>
onPresetLoadError = nullptr;
std::function<void(uint32_t location_kind, const char *location, const char *load_key)>
onPresetLoaded = nullptr;
std::function<const void *(const char *)> extensionGet = nullptr;

friend const clap_plugin *ClapAdapter::clap_create_plugin(const struct clap_plugin_factory *,
Expand Down
7 changes: 6 additions & 1 deletion src/wrapper/clap-juce-wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ JUCE_BEGIN_IGNORE_WARNINGS_MSVC(4100 4127 4244)
#include <clap/helpers/plugin.hh>
#include <clap/helpers/plugin.hxx>

#if CLAP_VERSION_LT(1,2,0)
#if CLAP_VERSION_LT(1, 2, 0)
static_assert(false, "CLAP juce wrapper requires at least clap 1.2.0");
#endif

Expand Down Expand Up @@ -442,6 +442,11 @@ class ClapJuceWrapper : public clap::helpers::Plugin<
_host.presetLoadOnError(location_kind, location, load_key, os_error,
msg.toRawUTF8());
};
processorAsClapExtensions->onPresetLoaded =
[this](uint32_t location_kind, const char *location, const char *load_key) {
if (_host.canUsePresetLoad())
_host.presetLoadLoaded(location_kind, location, load_key);
};
processorAsClapExtensions->extensionGet = [this](const char *name) {
return _host.host()->get_extension(_host.host(), name);
};
Expand Down
Loading