Skip to content

Commit

Permalink
Add hook-in for plugin to report that a preset has been loaded (#142)
Browse files Browse the repository at this point in the history
  • Loading branch information
jatinchowdhury18 authored Jan 29, 2024
1 parent d37977e commit e72d59a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
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

0 comments on commit e72d59a

Please sign in to comment.