commit 87ebfa05273ef685130abb690a6a289b8ac410f5
parent f9bdfa5fc6397ccd40acbd150a86784ca850bc33
Author: Alexandre BIQUE <bique.alexandre@gmail.com>
Date: Fri, 28 May 2021 22:31:37 +0200
Rethinking how the parameters are working
Diffstat:
8 files changed, 81 insertions(+), 44 deletions(-)
diff --git a/examples/gui/CMakeLists.txt b/examples/gui/CMakeLists.txt
@@ -8,4 +8,4 @@ add_executable(clap-gui
main.cc
)
-set_target_properties(clap-gui PROPERTIES CXX_STANDARD 17)
-\ No newline at end of file
+set_target_properties(clap-gui PROPERTIES CXX_STANDARD 20)
+\ No newline at end of file
diff --git a/examples/host/plugin-host.cc b/examples/host/plugin-host.cc
@@ -792,7 +792,7 @@ void PluginHost::clapParamsRescan(const clap_host *host, uint32_t flags) {
for (int32_t i = 0; i < count; ++i) {
clap_param_info info;
- if (!h->pluginParams_->get_info(h->plugin_, i, &info))
+ if (!h->pluginParams_->info(h->plugin_, i, &info))
throw std::logic_error("clap_plugin_params.get_info did return false!");
if (info.id == CLAP_INVALID_ID) {
@@ -905,7 +905,7 @@ void PluginHost::clapParamsRescan(const clap_host *host, uint32_t flags) {
clap_param_value PluginHost::getParamValue(const clap_param_info &info) {
clap_param_value value;
- if (pluginParams_->get_value(plugin_, info.id, &value))
+ if (pluginParams_->value(plugin_, info.id, &value))
return value;
std::ostringstream msg;
diff --git a/examples/plugins/CMakeLists.txt b/examples/plugins/CMakeLists.txt
@@ -1,8 +1,11 @@
-add_library(clap-plugin SHARED
- clap-entry.cc
- plugin.cc
- plugin.hh
+add_library(
+ clap-plugin SHARED
+ clap-entry.cc
+ parameters.cc
+ parameters.hh
+ plugin.cc
+ plugin.hh
+ gain/gain.hh
+ gain/gain.cc)
- gain/gain.hh
- gain/gain.cc
- )
-\ No newline at end of file
+set_target_properties(clap-plugin PROPERTIES CXX_STANDARD 20)
diff --git a/examples/plugins/gain/gain.cc b/examples/plugins/gain/gain.cc
@@ -22,7 +22,35 @@ namespace clap {
return &desc;
}
- Gain::Gain(const clap_host *host) : Plugin(descriptor(), host) {}
+ enum {
+ kParamIdGain = 0,
+ };
+
+ Gain::Gain(const clap_host *host) : Plugin(descriptor(), host) {
+ parameters_.addParameter({
+ .info = {
+ .id = kParamIdGain,
+ .name = "gain",
+ .module = "/",
+ .is_per_note = false,
+ .is_per_channel = false,
+ .is_used = true,
+ .is_periodic = false,
+ .is_locked = false,
+ .is_automatable = true,
+ .is_hidden = false,
+ .is_bypass = false,
+ .type = CLAP_PARAM_FLOAT,
+ .min_value = { .d = -120 },
+ .max_value = { .d = 20 },
+ .default_value = { .d = 0 },
+ .enum_entry_count = 0,
+ },
+ .enumDefinition = {},
+ .value = { .d = 0 },
+ .modulation = { .d = 0 },
+ });
+ }
bool Gain::activate(int sample_rate) {
channelCount_ = trackChannelCount();
diff --git a/examples/plugins/gain/gain.hh b/examples/plugins/gain/gain.hh
@@ -24,5 +24,7 @@ namespace clap {
private:
int channelCount_ = 0;
+
+ Parameters parameters_;
};
} // namespace clap
\ No newline at end of file
diff --git a/examples/plugins/params.hh b/examples/plugins/params.hh
@@ -1,30 +0,0 @@
-#include <clap/all.h>
-
-#include <string>
-#include <unordered_map>
-#include <vector>
-
-namespace clap {
- struct EnumEntry {
- std::string name;
- int64_t value;
- };
-
- struct EnumDefinition {
- std::vector<EnumEntry> entries;
- };
-
- struct Parameter {
- clap_param_info info;
- EnumDefinition enumDefinition;
- clap_param_value value;
- clap_param_value modulation;
- double valueRamp;
- double modulationRamp;
- };
-
- struct ParameterBank {
- std::vector<Parameter> params;
- std::unordered_map<clap_id, Parameter *> hmap;
- };
-} // namespace clap
-\ No newline at end of file
diff --git a/examples/plugins/plugin.hh b/examples/plugins/plugin.hh
@@ -7,6 +7,8 @@
#include <clap/all.h>
+#include "parameters.hh"
+
namespace clap {
class Plugin {
public:
diff --git a/include/clap/ext/params.h b/include/clap/ext/params.h
@@ -6,6 +6,40 @@
extern "C" {
#endif
+/// @page Parameters
+/// @brief parameters management
+///
+/// Scenarios:
+///
+/// I. Loading a preset
+/// - load the preset in a temporary state, if the plugin is activated and preset will introduce
+/// breaking change like latency, audio ports change, parameter changes, ...
+/// report those to the host and wait for the host to deactivate the plugin
+/// to apply those changes. If there are no breaking changes, the plugin can apply them
+/// them right away.
+/// The plugin is resonsible to update both its audio processor and its gui.
+///
+/// II. Turning a knob on the DAW interface
+/// - if the plugin is active, the host will send a CLAP_PARAM_SET event to the plugin
+/// - if the plugin is not active, the host will call plugin_params->set_value(...)
+///
+/// III. Turning a knob on the Plugin interface
+/// - host_params->begin_adjust(...)
+/// - host_params->adjust(...) many times -> updates host's knob and record automation
+/// - host_params->end_adjust(...)
+/// - the plugin is responsible to send the parameter value to its audio processor
+///
+/// IV. Turning a knob via automation
+/// - host sends a CLAP_PARAM_SET event
+/// - the plugin is responsible to update its GUI
+///
+/// V. Turning a knob via MIDI mapping
+/// - the plugin sends a CLAP_PARAM_SET output event
+///
+/// VI. Adding or removing parameters
+/// - call host_params->rescan(CLAP_PARAM_RESCAN_ALL)
+/// - if the plugin is activated, apply the new parameters once the host deactivates the plugin
+
#define CLAP_EXT_PARAMS "clap/params"
enum {