Skip to content

Commit

Permalink
update undo
Browse files Browse the repository at this point in the history
  • Loading branch information
abique committed Sep 20, 2024
1 parent 8527574 commit 5979139
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 82 deletions.
13 changes: 6 additions & 7 deletions include/clap/helpers/host-proxy.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
27 changes: 13 additions & 14 deletions include/clap/helpers/host-proxy.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,8 @@ namespace clap { namespace helpers {
}

template <MisbehaviourHandler h, CheckingLevel l>
bool HostProxy<h, l>::posixFdSupportRegister(int fd, clap_posix_fd_flags_t flags) const noexcept {
bool HostProxy<h, l>::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);
Expand Down Expand Up @@ -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;
Expand All @@ -714,35 +715,33 @@ namespace clap { namespace helpers {

template <MisbehaviourHandler h, CheckingLevel l>
void HostProxy<h, l>::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 <MisbehaviourHandler h, CheckingLevel l>
void HostProxy<h, l>::undoUndo(const clap_host_t *host) const noexcept {
void HostProxy<h, l>::undoRequestUndo() const noexcept {
assert(canUseUndo());
ensureMainThread("undo.undo");
_hostUndo->undo(_host);
_hostUndo->request_undo(_host);
}

template <MisbehaviourHandler h, CheckingLevel l>
void HostProxy<h, l>::undoRedo(const clap_host_t *host) const noexcept {
void HostProxy<h, l>::undoRequestRedo() const noexcept {
assert(canUseUndo());
ensureMainThread("undo.redo");
_hostUndo->redo(_host);
_hostUndo->request_redo(_host);
}

template <MisbehaviourHandler h, CheckingLevel l>
void HostProxy<h, l>::undoSetContextInfoSubscription(const clap_host_t *host,
bool wants_info) const noexcept {
void HostProxy<h, l>::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
88 changes: 58 additions & 30 deletions include/clap/helpers/plugin.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 //
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
102 changes: 71 additions & 31 deletions include/clap/helpers/plugin.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <exception>
#include <iostream>
#include <sstream>
#include <stdexcept>
#include <utility>

#include "host-proxy.hxx"
Expand Down Expand Up @@ -67,7 +66,6 @@ namespace clap { namespace helpers {
clapConfigurableAudioPortsApplyConfiguration,
};


template <MisbehaviourHandler h, CheckingLevel l>
const clap_plugin_params Plugin<h, l>::_pluginParams = {
clapParamsCount,
Expand Down Expand Up @@ -155,11 +153,19 @@ namespace clap { namespace helpers {
};

template <MisbehaviourHandler h, CheckingLevel l>
const clap_plugin_undo Plugin<h, l>::_pluginUndo = {
clapUndoGetDeltaProperties,
clapUndoCanUseDeltaFormatVersion,
clapUndoApplyDelta,
clapUndoSetContextInfo,
const clap_plugin_undo_delta Plugin<h, l>::_pluginUndoDelta = {
clapUndoDeltaGetDeltaProperties,
clapUndoDeltaCanUseDeltaFormatVersion,
clapUndoDeltaUndo,
clapUndoDeltaRedo,
};

template <MisbehaviourHandler h, CheckingLevel l>
const clap_plugin_undo_context Plugin<h, l>::_pluginUndoContext = {
clapUndoContextSetCanUndo,
clapUndoContextSetCanRedo,
clapUndoContextSetUndoName,
clapUndoContextSetRedoName,
};

template <MisbehaviourHandler h, CheckingLevel l>
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1714,40 +1723,71 @@ namespace clap { namespace helpers {
// clap_plugin_undo //
//------------------//
template <MisbehaviourHandler h, CheckingLevel l>
void
Plugin<h, l>::clapUndoGetDeltaProperties(const clap_plugin_t *plugin,
clap_undo_delta_properties_t *properties) noexcept {
void Plugin<h, l>::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 <MisbehaviourHandler h, CheckingLevel l>
bool Plugin<h, l>::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 <MisbehaviourHandler h, CheckingLevel l>
bool Plugin<h, l>::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 <MisbehaviourHandler h, CheckingLevel l>
bool Plugin<h, l>::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 <MisbehaviourHandler h, CheckingLevel l>
void Plugin<h, l>::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 <MisbehaviourHandler h, CheckingLevel l>
bool Plugin<h, l>::clapUndoCanUseDeltaFormatVersion(const clap_plugin_t *plugin,
clap_id format_version) noexcept {
void Plugin<h, l>::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 <MisbehaviourHandler h, CheckingLevel l>
bool Plugin<h, l>::clapUndoApplyDelta(const clap_plugin_t *plugin,
clap_id format_version,
const void *delta,
size_t delta_size) noexcept {
void Plugin<h, l>::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 <MisbehaviourHandler h, CheckingLevel l>
void Plugin<h, l>::clapUndoSetContextInfo(const clap_plugin_t *plugin,
uint64_t flags,
const char *undo_name,
const char *redo_name) noexcept {
void Plugin<h, l>::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);
}

/////////////
Expand Down

0 comments on commit 5979139

Please sign in to comment.