From d0ddaf0b581e083a1f615d6509f1af907a5ce82c Mon Sep 17 00:00:00 2001 From: Alexandros Theodotou Date: Thu, 23 Apr 2026 12:53:42 +0900 Subject: [PATCH] Add clap_host_preset_load support to Host base class --- include/clap/helpers/host.hh | 24 ++++++++++++++++++++++++ include/clap/helpers/host.hxx | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/include/clap/helpers/host.hh b/include/clap/helpers/host.hh index 5d11332..21aef96 100644 --- a/include/clap/helpers/host.hh +++ b/include/clap/helpers/host.hh @@ -108,6 +108,17 @@ namespace clap { namespace helpers { virtual bool implementsThreadPool() const noexcept { return false; } virtual bool threadPoolRequestExec(uint32_t numTasks) noexcept { return false; } + // clap_host_preset_load + virtual bool implementsPresetLoad() const noexcept { return false; } + virtual void presetLoadLoaded(uint32_t locationKind, + const char *location, + const char *loadKey) noexcept {} + virtual void presetLoadOnError(uint32_t locationKind, + const char *location, + const char *loadKey, + int32_t osError, + const char *msg) noexcept {} + // clap_host_surround virtual bool implementsSurround() const noexcept { return false; } virtual void surroundChanged() noexcept {} @@ -197,6 +208,18 @@ namespace clap { namespace helpers { // clap_host_thread_pool static bool clapThreadPoolRequestExec(const clap_host *host, uint32_t num_tasks) noexcept; + // clap_host_preset_load + static void clapPresetLoadLoaded(const clap_host *host, + uint32_t location_kind, + const char *location, + const char *load_key) noexcept; + static void clapPresetLoadOnError(const clap_host *host, + uint32_t location_kind, + const char *location, + const char *load_key, + int32_t os_error, + const char *msg) noexcept; + // clap_host_surround static void clapSurroundChanged(const clap_host_t *host) noexcept; @@ -210,6 +233,7 @@ namespace clap { namespace helpers { static const clap_host_log _hostLog; static const clap_host_params _hostParams; static const clap_host_posix_fd_support _hostPosixFdSupport; + static const clap_host_preset_load _hostPresetLoad; static const clap_host_remote_controls _hostRemoteControls; static const clap_host_state _hostState; static const clap_host_timer_support _hostTimerSupport; diff --git a/include/clap/helpers/host.hxx b/include/clap/helpers/host.hxx index e1bd0fa..e8e0508 100644 --- a/include/clap/helpers/host.hxx +++ b/include/clap/helpers/host.hxx @@ -48,6 +48,12 @@ namespace clap { namespace helpers { clapPosixFdSupportUnregisterFd, }; + template + const clap_host_preset_load Host::_hostPresetLoad = { + clapPresetLoadOnError, + clapPresetLoadLoaded, + }; + template const clap_host_remote_controls Host::_hostRemoteControls = { clapRemoteControlsChanged, @@ -156,6 +162,10 @@ namespace clap { namespace helpers { return &_hostParams; if (!strcmp(extension_id, CLAP_EXT_POSIX_FD_SUPPORT) && self.implementsPosixFdSupport()) return &_hostPosixFdSupport; + if ((!strcmp(extension_id, CLAP_EXT_PRESET_LOAD) || + !strcmp(extension_id, CLAP_EXT_PRESET_LOAD_COMPAT)) && + self.implementsPresetLoad()) + return &_hostPresetLoad; if ((!strcmp(extension_id, CLAP_EXT_REMOTE_CONTROLS) || !strcmp(extension_id, CLAP_EXT_REMOTE_CONTROLS_COMPAT)) && self.implementsRemoteControls()) @@ -329,6 +339,31 @@ namespace clap { namespace helpers { return self.posixFdSupportUnregisterFd(fd); } + //-------------------------// + // clap_host_preset_load // + //-------------------------// + template + void Host::clapPresetLoadLoaded(const clap_host *host, + uint32_t location_kind, + const char *location, + const char *load_key) noexcept { + auto &self = from(host); + self.ensureMainThread("preset_load.loaded"); + self.presetLoadLoaded(location_kind, location, load_key); + } + + template + void Host::clapPresetLoadOnError(const clap_host *host, + uint32_t location_kind, + const char *location, + const char *load_key, + int32_t os_error, + const char *msg) noexcept { + auto &self = from(host); + self.ensureMainThread("preset_load.on_error"); + self.presetLoadOnError(location_kind, location, load_key, os_error, msg); + } + //---------------------------// // clap_host_remote_controls // //---------------------------//