commit 872207b2a343acd6db7f2b47ba3cd0f73869341e
parent fe727585fec232a361c443b6334114adefb4d8b5
Author: Alexandre BIQUE <bique.alexandre@gmail.com>
Date: Wed, 20 Oct 2021 21:52:03 +0200
More work on param flush
Diffstat:
2 files changed, 74 insertions(+), 12 deletions(-)
diff --git a/examples/glue/clap-plugin.cc b/examples/glue/clap-plugin.cc
@@ -438,6 +438,50 @@ namespace clap {
return self.paramsValue(param_id, value);
}
+ void Plugin::clapParamsFlush(const clap_plugin *plugin,
+ const clap_event_list *input_parameter_changes,
+ const clap_event_list *output_parameter_changes) noexcept {
+ auto &self = from(plugin);
+ self.ensureParamThread("clap_plugin_params.flush");
+
+ if (!input_parameter_changes)
+ self.hostMisbehaving("clap_plugin_params.flush called with an null input parameter change list");
+ else {
+ uint32_t N = input_parameter_changes->size(input_parameter_changes);
+ for (uint32_t i = 0; i < N; ++i)
+ {
+ auto ev = input_parameter_changes->get(input_parameter_changes, i);
+ if (!ev) {
+ std::ostringstream msg;
+ msg << "clap_plugin_params.flush called null event inside the input list at index: " << i;
+ self.hostMisbehaving(msg.str());
+ continue;
+ }
+
+ if (ev->type != CLAP_EVENT_PARAM_VALUE) {
+ self.hostMisbehaving("clap_plugin_params.flush must only contain CLAP_EVENT_PARAM_VALUE event type");
+ continue;
+ }
+
+ if (!self.isValidParamId(ev->param_value.param_id)) {
+ std::ostringstream msg;
+ msg << "clap_plugin_params.flush called unknown paramId: " << ev->param_value.param_id;
+ self.hostMisbehaving(msg.str());
+ continue;
+ }
+
+ // TODO: check range?
+ }
+ }
+
+ if (!output_parameter_changes)
+ self.hostMisbehaving("clap_plugin_params.flush called with an null output parameter change list");
+ else if (output_parameter_changes->size(output_parameter_changes) > 0)
+ self.hostMisbehaving("clap_plugin_params.flush called with an non-empty output parameter change list");
+
+ self.paramsFlush(input_parameter_changes, output_parameter_changes);
+ }
+
bool Plugin::clapParamsValueToText(const clap_plugin *plugin,
clap_id param_id,
double value,
@@ -454,12 +498,14 @@ namespace clap {
}
if (!display) {
- self.hostMisbehaving("clap_plugin_params.value_to_text called with a null display pointer");
+ self.hostMisbehaving(
+ "clap_plugin_params.value_to_text called with a null display pointer");
return false;
}
if (size <= 1) {
- self.hostMisbehaving("clap_plugin_params.value_to_text called with a empty buffer (less than one character)");
+ self.hostMisbehaving("clap_plugin_params.value_to_text called with a empty buffer (less "
+ "than one character)");
return false;
}
@@ -481,7 +527,8 @@ namespace clap {
}
if (!display) {
- self.hostMisbehaving("clap_plugin_params.text_to_value called with a null display pointer");
+ self.hostMisbehaving(
+ "clap_plugin_params.text_to_value called with a null display pointer");
return false;
}
@@ -769,8 +816,8 @@ namespace clap {
self.ensureMainThread("clap_plugin_gui_x11.attach");
if (!self._isGuiCreated) {
- self.hostMisbehaving(
- "clap_plugin_gui_x11.attach() was called without a prior call to clap_plugin_gui.create()");
+ self.hostMisbehaving("clap_plugin_gui_x11.attach() was called without a prior call to "
+ "clap_plugin_gui.create()");
return false;
}
@@ -794,8 +841,8 @@ namespace clap {
self.ensureMainThread("clap_plugin_gui_win32.attach");
if (!self._isGuiCreated) {
- self.hostMisbehaving(
- "clap_plugin_gui_win32.attach() was called without a prior call to clap_plugin_gui.create()");
+ self.hostMisbehaving("clap_plugin_gui_win32.attach() was called without a prior call to "
+ "clap_plugin_gui.create()");
return false;
}
@@ -819,8 +866,8 @@ namespace clap {
self.ensureMainThread("clap_plugin_gui_cocoa.attach");
if (!self._isGuiCreated) {
- self.hostMisbehaving(
- "clap_plugin_gui_cocoa.attach() was called without a prior call to clap_plugin_gui.create()");
+ self.hostMisbehaving("clap_plugin_gui_cocoa.attach() was called without a prior call to "
+ "clap_plugin_gui.create()");
return false;
}
@@ -844,13 +891,14 @@ namespace clap {
self.ensureMainThread("clap_plugin_gui_free_standing.open");
if (!self._isGuiCreated) {
- self.hostMisbehaving(
- "clap_plugin_gui_free_standing.open() was called without a prior call to clap_plugin_gui.create()");
+ self.hostMisbehaving("clap_plugin_gui_free_standing.open() was called without a prior "
+ "call to clap_plugin_gui.create()");
return false;
}
if (self._isGuiAttached) {
- self.hostMisbehaving("clap_plugin_gui_free_standing.open() but the gui was already attached");
+ self.hostMisbehaving(
+ "clap_plugin_gui_free_standing.open() but the gui was already attached");
return true;
}
@@ -992,6 +1040,13 @@ namespace clap {
checkMainThread();
}
+ void Plugin::ensureParamThread(const char *method) const noexcept {
+ if (isActive())
+ ensureAudioThread(method);
+ else
+ ensureMainThread(method);
+ }
+
void Plugin::ensureMainThread(const char *method) const noexcept {
if (!_hostThreadCheck || !_hostThreadCheck->is_main_thread ||
_hostThreadCheck->is_main_thread(_host))
diff --git a/examples/glue/clap-plugin.hh b/examples/glue/clap-plugin.hh
@@ -116,6 +116,8 @@ namespace clap {
virtual bool paramsTextToValue(clap_id paramId, const char *display, double *value) noexcept {
return false;
}
+ virtual void paramsFlush(const clap_event_list *input_parameter_changes,
+ const clap_event_list *output_parameter_changes) noexcept {}
virtual bool isValidParamId(clap_id paramId) const noexcept;
//----------------------------//
@@ -219,6 +221,7 @@ namespace clap {
void checkParamThread() const noexcept;
void ensureMainThread(const char *method) const noexcept;
void ensureAudioThread(const char *method) const noexcept;
+ void ensureParamThread(const char *method) const noexcept;
///////////////
// Utilities //
@@ -327,6 +330,9 @@ namespace clap {
clap_id param_id,
const char *display,
double *value) noexcept;
+ static void clapParamsFlush(const clap_plugin *plugin,
+ const clap_event_list *input_parameter_changes,
+ const clap_event_list *output_parameter_changes) noexcept;
// clap_plugin_quick_controls
static uint32_t clapQuickControlsPageCount(const clap_plugin *plugin) noexcept;
@@ -413,6 +419,7 @@ namespace clap {
clapParamsValue,
clapParamsValueToText,
clapParamsTextToValue,
+ clapParamsFlush,
};
static const constexpr clap_plugin_quick_controls _pluginQuickControls = {