diff --git a/include/clap/helpers/host-proxy.hh b/include/clap/helpers/host-proxy.hh index 0b65f9b..c16e19d 100644 --- a/include/clap/helpers/host-proxy.hh +++ b/include/clap/helpers/host-proxy.hh @@ -192,13 +192,12 @@ namespace clap { namespace helpers { void undoBeginChange() const noexcept; void undoCancelChange() const noexcept; void undoChangeMade(const char *name, - const void *redo_delta, - size_t redo_delta_size, - const void *undo_delta, - size_t undo_delta_size) const noexcept; - void undoUndo(const clap_host_t *host) const noexcept; - void undoRedo(const clap_host_t *host) const noexcept; - void undoSetContextInfoSubscription(const clap_host_t *host, bool wants_info) const noexcept; + const void *delta, + size_t delta_size, + bool delta_can_undo) const noexcept; + void undoRequestUndo() const noexcept; + void undoRequestRedo() const noexcept; + void undoSetWantsContextUpdates(bool is_subscribed) const noexcept; protected: void ensureMainThread(const char *method) const noexcept; diff --git a/include/clap/helpers/host-proxy.hxx b/include/clap/helpers/host-proxy.hxx index 068f81c..e164840 100644 --- a/include/clap/helpers/host-proxy.hxx +++ b/include/clap/helpers/host-proxy.hxx @@ -474,7 +474,8 @@ namespace clap { namespace helpers { } template - bool HostProxy::posixFdSupportRegister(int fd, clap_posix_fd_flags_t flags) const noexcept { + bool HostProxy::posixFdSupportRegister(int fd, + clap_posix_fd_flags_t flags) const noexcept { assert(canUsePosixFdSupport()); ensureMainThread("posix_fd_support.register"); return _hostPosixFdSupport->register_fd(_host, fd, flags); @@ -692,7 +693,7 @@ namespace clap { namespace helpers { return false; if (_hostUndo->begin_change && _hostUndo->cancel_change && _hostUndo->change_made && - _hostUndo->undo && _hostUndo->redo && _hostUndo->set_context_info_subscription) + _hostUndo->request_undo && _hostUndo->request_redo && _hostUndo->set_wants_context_updates) return true; return false; @@ -714,35 +715,33 @@ namespace clap { namespace helpers { template void HostProxy::undoChangeMade(const char *name, - const void *redo_delta, - size_t redo_delta_size, - const void *undo_delta, - size_t undo_delta_size) const noexcept { + const void *delta, + size_t delta_size, + bool delta_can_undo) const noexcept { assert(canUseUndo()); ensureMainThread("undo.change_made"); - _hostUndo->change_made(_host, name, redo_delta, redo_delta_size, undo_delta, undo_delta_size); + _hostUndo->change_made(_host, name, delta, delta_size, delta_can_undo); } template - void HostProxy::undoUndo(const clap_host_t *host) const noexcept { + void HostProxy::undoRequestUndo() const noexcept { assert(canUseUndo()); ensureMainThread("undo.undo"); - _hostUndo->undo(_host); + _hostUndo->request_undo(_host); } template - void HostProxy::undoRedo(const clap_host_t *host) const noexcept { + void HostProxy::undoRequestRedo() const noexcept { assert(canUseUndo()); ensureMainThread("undo.redo"); - _hostUndo->redo(_host); + _hostUndo->request_redo(_host); } template - void HostProxy::undoSetContextInfoSubscription(const clap_host_t *host, - bool wants_info) const noexcept { + void HostProxy::undoSetWantsContextUpdates(bool is_subscribed) const noexcept { assert(canUseUndo()); ensureMainThread("undo.set_context_info_subscription"); - _hostUndo->set_context_info_subscription(_host, wants_info); + _hostUndo->set_wants_context_updates(_host, is_subscribed); } }} // namespace clap::helpers diff --git a/include/clap/helpers/plugin.hh b/include/clap/helpers/plugin.hh index 22be257..bb0d496 100644 --- a/include/clap/helpers/plugin.hh +++ b/include/clap/helpers/plugin.hh @@ -154,12 +154,13 @@ namespace clap { namespace helpers { // clap_plugin_configurable_audio_ports // //--------------------------------------// virtual bool implementsConfigurableAudioPorts() const noexcept { return false; } - virtual bool configurableAudioPortsCanApplyConfiguration(const clap_audio_port_configuration_request *requests, - uint32_t request_count) const noexcept { + virtual bool configurableAudioPortsCanApplyConfiguration( + const clap_audio_port_configuration_request *requests, + uint32_t request_count) const noexcept { return false; } - virtual bool configurableAudioPortsApplyConfiguration(const clap_audio_port_configuration_request *requests, - uint32_t request_count) noexcept { + virtual bool configurableAudioPortsApplyConfiguration( + const clap_audio_port_configuration_request *requests, uint32_t request_count) noexcept { return false; } @@ -299,13 +300,28 @@ namespace clap { namespace helpers { //------------------// // clap_plugin_undo // //------------------// - virtual bool implementsUndo() const noexcept { return false; } - virtual void undoGetDeltaProperties(clap_undo_delta_properties_t *properties) noexcept {} - virtual bool undoCanUseDeltaFormatVersion(clap_id format_version) noexcept { return false; } + virtual bool implementsUndoDelta() const noexcept { return false; } + virtual void undoDeltaGetDeltaProperties(clap_undo_delta_properties_t *properties) noexcept {} + virtual bool undoDeltaCanUseDeltaFormatVersion(clap_id format_version) noexcept { + return false; + } + virtual bool + undoDeltaUndo(clap_id format_version, const void *delta, size_t delta_size) noexcept { + return false; + } virtual bool - undoApplyDelta(clap_id format_version, const void *delta, size_t delta_size) noexcept { return false; } - virtual void - undoSetContextInfo(uint64_t flags, const char *undo_name, const char *redo_name) noexcept {} + undoDeltaRedo(clap_id format_version, const void *delta, size_t delta_size) noexcept { + return false; + } + + //--------------------------// + // clap_plugin_undo_context // + //--------------------------// + virtual bool implementsUndoContext() const noexcept { return false; } + virtual void undoContextSetCanUndo(bool can_undo) noexcept {} + virtual void undoContextSetCanRedo(bool can_redo) noexcept {} + virtual void undoContextSetUndoName(const char *name) noexcept {} + virtual void undoContextSetRedoName(const char *name) noexcept {} ///////////// // Logging // @@ -447,12 +463,14 @@ namespace clap { namespace helpers { uint32_t sample_size) noexcept; // clap_plugin_configurable_audio_ports - static bool clapConfigurableAudioPortsCanApplyConfiguration(const clap_plugin_t *plugin, - const clap_audio_port_configuration_request *requests, - uint32_t request_count) noexcept; - static bool clapConfigurableAudioPortsApplyConfiguration(const clap_plugin_t *plugin, - const clap_audio_port_configuration_request *requests, - uint32_t request_count) noexcept; + static bool clapConfigurableAudioPortsCanApplyConfiguration( + const clap_plugin_t *plugin, + const clap_audio_port_configuration_request *requests, + uint32_t request_count) noexcept; + static bool clapConfigurableAudioPortsApplyConfiguration( + const clap_plugin_t *plugin, + const clap_audio_port_configuration_request *requests, + uint32_t request_count) noexcept; // clap_plugin_params static uint32_t clapParamsCount(const clap_plugin *plugin) noexcept; @@ -561,19 +579,28 @@ namespace clap { namespace helpers { char *path, uint32_t path_size) noexcept; - // clap_plugin_undo - static void clapUndoGetDeltaProperties(const clap_plugin_t *plugin, - clap_undo_delta_properties_t *properties) noexcept; - static bool clapUndoCanUseDeltaFormatVersion(const clap_plugin_t *plugin, - clap_id format_version) noexcept; - static bool clapUndoApplyDelta(const clap_plugin_t *plugin, - clap_id format_version, - const void *delta, - size_t delta_size) noexcept; - static void clapUndoSetContextInfo(const clap_plugin_t *plugin, - uint64_t flags, - const char *undo_name, - const char *redo_name) noexcept; + // clap_plugin_undo_delta + static void + clapUndoDeltaGetDeltaProperties(const clap_plugin_t *plugin, + clap_undo_delta_properties_t *properties) noexcept; + static bool clapUndoDeltaCanUseDeltaFormatVersion(const clap_plugin_t *plugin, + clap_id format_version) noexcept; + static bool clapUndoDeltaUndo(const clap_plugin_t *plugin, + clap_id format_version, + const void *delta, + size_t delta_size) noexcept; + static bool clapUndoDeltaRedo(const clap_plugin_t *plugin, + clap_id format_version, + const void *delta, + size_t delta_size) noexcept; + + // clap_plugin_undo_context + static void clapUndoContextSetCanUndo(const clap_plugin_t *plugin, bool can_undo) noexcept; + static void clapUndoContextSetCanRedo(const clap_plugin_t *plugin, bool can_redo) noexcept; + static void clapUndoContextSetUndoName(const clap_plugin_t *plugin, + const char *name) noexcept; + static void clapUndoContextSetRedoName(const clap_plugin_t *plugin, + const char *name) noexcept; // interfaces static const clap_plugin_audio_ports _pluginAudioPorts; @@ -599,7 +626,8 @@ namespace clap { namespace helpers { static const clap_plugin_voice_info _pluginVoiceInfo; static const clap_plugin_context_menu _pluginContextMenu; static const clap_plugin_resource_directory _pluginResourceDirectory; - static const clap_plugin_undo _pluginUndo; + static const clap_plugin_undo_delta _pluginUndoDelta; + static const clap_plugin_undo_context _pluginUndoContext; // state bool _wasInitialized = false; diff --git a/include/clap/helpers/plugin.hxx b/include/clap/helpers/plugin.hxx index c9b4f56..3af46e7 100644 --- a/include/clap/helpers/plugin.hxx +++ b/include/clap/helpers/plugin.hxx @@ -3,7 +3,6 @@ #include #include #include -#include #include #include "host-proxy.hxx" @@ -67,7 +66,6 @@ namespace clap { namespace helpers { clapConfigurableAudioPortsApplyConfiguration, }; - template const clap_plugin_params Plugin::_pluginParams = { clapParamsCount, @@ -155,11 +153,19 @@ namespace clap { namespace helpers { }; template - const clap_plugin_undo Plugin::_pluginUndo = { - clapUndoGetDeltaProperties, - clapUndoCanUseDeltaFormatVersion, - clapUndoApplyDelta, - clapUndoSetContextInfo, + const clap_plugin_undo_delta Plugin::_pluginUndoDelta = { + clapUndoDeltaGetDeltaProperties, + clapUndoDeltaCanUseDeltaFormatVersion, + clapUndoDeltaUndo, + clapUndoDeltaRedo, + }; + + template + const clap_plugin_undo_context Plugin::_pluginUndoContext = { + clapUndoContextSetCanUndo, + clapUndoContextSetCanRedo, + clapUndoContextSetUndoName, + clapUndoContextSetRedoName, }; template @@ -459,7 +465,8 @@ namespace clap { namespace helpers { if (!strcmp(id, CLAP_EXT_STATE) && self.implementsState()) return &_pluginState; - if (!strcmp(id, CLAP_EXT_STATE_CONTEXT) && self.implementsStateContext() && self.implementsState()) + if (!strcmp(id, CLAP_EXT_STATE_CONTEXT) && self.implementsStateContext() && + self.implementsState()) return &_pluginStateContext; if ((!strcmp(id, CLAP_EXT_PRESET_LOAD) || !strcmp(id, CLAP_EXT_PRESET_LOAD_COMPAT)) && self.implementsPresetLoad()) @@ -513,8 +520,10 @@ namespace clap { namespace helpers { if (self.enableDraftExtensions()) { if (!strcmp(id, CLAP_EXT_RESOURCE_DIRECTORY) && self.implementsResourceDirectory()) return &_pluginResourceDirectory; - if (!strcmp(id, CLAP_EXT_UNDO) && self.implementsUndo()) - return &_pluginUndo; + if (!strcmp(id, CLAP_EXT_UNDO_DELTA) && self.implementsUndoDelta()) + return &_pluginUndoDelta; + if (!strcmp(id, CLAP_EXT_UNDO_CONTEXT) && self.implementsUndoContext()) + return &_pluginUndoContext; } return self.extension(id); @@ -1714,40 +1723,71 @@ namespace clap { namespace helpers { // clap_plugin_undo // //------------------// template - void - Plugin::clapUndoGetDeltaProperties(const clap_plugin_t *plugin, - clap_undo_delta_properties_t *properties) noexcept { + void Plugin::clapUndoDeltaGetDeltaProperties( + const clap_plugin_t *plugin, clap_undo_delta_properties_t *properties) noexcept { + auto &self = from(plugin); + self.ensureMainThread("clap_undo_delta.get_delta_properties"); + return self.undoDeltaGetDeltaProperties(properties); + } + + template + bool Plugin::clapUndoDeltaCanUseDeltaFormatVersion(const clap_plugin_t *plugin, + clap_id format_version) noexcept { + auto &self = from(plugin); + self.ensureMainThread("clap_undo_delta.can_use_delta_format_version"); + return self.undoDeltaCanUseDeltaFormatVersion(format_version); + } + + template + bool Plugin::clapUndoDeltaUndo(const clap_plugin_t *plugin, + clap_id format_version, + const void *delta, + size_t delta_size) noexcept { + auto &self = from(plugin); + self.ensureMainThread("clap_undo_delta.undo"); + return self.undoDeltaUndo(format_version, delta, delta_size); + } + + template + bool Plugin::clapUndoDeltaRedo(const clap_plugin_t *plugin, + clap_id format_version, + const void *delta, + size_t delta_size) noexcept { + auto &self = from(plugin); + self.ensureMainThread("clap_undo_delta.redo"); + return self.undoDeltaRedo(format_version, delta, delta_size); + } + + template + void Plugin::clapUndoContextSetCanUndo(const clap_plugin_t *plugin, + bool can_undo) noexcept { auto &self = from(plugin); - self.ensureMainThread("clap_undo.get_delta_properties"); - return self.undoGetDeltaProperties(properties); + self.ensureMainThread("clap_undo.set_can_undo"); + self.undoContextSetCanUndo(can_undo); } template - bool Plugin::clapUndoCanUseDeltaFormatVersion(const clap_plugin_t *plugin, - clap_id format_version) noexcept { + void Plugin::clapUndoContextSetCanRedo(const clap_plugin_t *plugin, + bool can_redo) noexcept { auto &self = from(plugin); - self.ensureMainThread("clap_undo.can_use_delta_format_version"); - return self.undoCanUseDeltaFormatVersion(format_version); + self.ensureMainThread("clap_undo_context.set_can_redo"); + self.undoContextSetCanRedo(can_redo); } template - bool Plugin::clapUndoApplyDelta(const clap_plugin_t *plugin, - clap_id format_version, - const void *delta, - size_t delta_size) noexcept { + void Plugin::clapUndoContextSetUndoName(const clap_plugin_t *plugin, + const char *name) noexcept { auto &self = from(plugin); - self.ensureMainThread("clap_undo.apply_delta"); - return self.undoApplyDelta(format_version, delta, delta_size); + self.ensureMainThread("clap_undo_context.set_undo_name"); + self.undoContextSetUndoName(name); } template - void Plugin::clapUndoSetContextInfo(const clap_plugin_t *plugin, - uint64_t flags, - const char *undo_name, - const char *redo_name) noexcept { + void Plugin::clapUndoContextSetRedoName(const clap_plugin_t *plugin, + const char *name) noexcept { auto &self = from(plugin); - self.ensureMainThread("clap_undo.set_context_info"); - return self.undoSetContextInfo(flags, undo_name, redo_name); + self.ensureMainThread("clap_undo_context.set_redo_name"); + self.undoContextSetRedoName(name); } /////////////