commit f9bdfa5fc6397ccd40acbd150a86784ca850bc33
parent 3b9260f5c628760ef02093fc98d8c9d4f46c4d5c
Author: Alexandre BIQUE <bique.alexandre@gmail.com>
Date: Fri, 28 May 2021 16:17:42 +0200
Some more work on the plugin
Diffstat:
3 files changed, 84 insertions(+), 37 deletions(-)
diff --git a/examples/plugins/params.hh b/examples/plugins/params.hh
@@ -0,0 +1,30 @@
+#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.cc b/examples/plugins/plugin.cc
@@ -9,16 +9,16 @@
namespace clap {
Plugin::Plugin(const clap_plugin_descriptor *desc, const clap_host *host) : host_(host) {
- plugin_.plugin_data = this;
- plugin_.desc = desc;
- plugin_.init = Plugin::clapInit;
- plugin_.destroy = Plugin::clapDestroy;
- plugin_.extension = nullptr;
- plugin_.process = nullptr;
- plugin_.activate = nullptr;
- plugin_.deactivate = nullptr;
+ plugin_.plugin_data = this;
+ plugin_.desc = desc;
+ plugin_.init = Plugin::clapInit;
+ plugin_.destroy = Plugin::clapDestroy;
+ plugin_.extension = nullptr;
+ plugin_.process = nullptr;
+ plugin_.activate = nullptr;
+ plugin_.deactivate = nullptr;
plugin_.start_processing = nullptr;
- plugin_.stop_processing = nullptr;
+ plugin_.stop_processing = nullptr;
}
/////////////////////
@@ -29,12 +29,12 @@ namespace clap {
bool Plugin::clapInit(const clap_plugin *plugin) {
auto &self = from(plugin);
- self.plugin_.extension = Plugin::clapExtension;
- self.plugin_.process = Plugin::clapProcess;
- self.plugin_.activate = Plugin::clapActivate;
- self.plugin_.deactivate = Plugin::clapDeactivate;
+ self.plugin_.extension = Plugin::clapExtension;
+ self.plugin_.process = Plugin::clapProcess;
+ self.plugin_.activate = Plugin::clapActivate;
+ self.plugin_.deactivate = Plugin::clapDeactivate;
self.plugin_.start_processing = Plugin::clapStartProcessing;
- self.plugin_.stop_processing = Plugin::clapStopProcessing;
+ self.plugin_.stop_processing = Plugin::clapStopProcessing;
self.initInterfaces();
self.ensureMainThread("clap_plugin.init");
@@ -83,7 +83,7 @@ namespace clap {
return false;
}
- self.isActive_ = true;
+ self.isActive_ = true;
self.sampleRate_ = sample_rate;
return true;
}
@@ -191,7 +191,7 @@ namespace clap {
const bool didChannelChange = info.channel_count != self.trackInfo_.channel_count ||
info.channel_map != self.trackInfo_.channel_map;
- self.trackInfo_ = info;
+ self.trackInfo_ = info;
self.hasTrackInfo_ = true;
if (didChannelChange && self.canChangeAudioPorts() &&
@@ -275,7 +275,7 @@ namespace clap {
return;
// compare the list of ports to the old one
- inputAudioPorts_ = inputs;
+ inputAudioPorts_ = inputs;
outputAudioPorts_ = outputs;
hostAudioPorts_->rescan(host_, flags);
@@ -386,8 +386,8 @@ namespace clap {
uint32_t Plugin::compareAudioPortsInfo(const clap_audio_port_info &a,
const clap_audio_port_info &b) noexcept {
- if (a.sample_size != b.sample_size || a.in_place != b.in_place ||
- a.is_cv != b.is_cv || a.is_main != b.is_main || a.channel_count != b.channel_count ||
+ if (a.sample_size != b.sample_size || a.in_place != b.in_place || a.is_cv != b.is_cv ||
+ a.is_main != b.is_main || a.channel_count != b.channel_count ||
a.channel_map != b.channel_map || a.id != b.id)
return CLAP_AUDIO_PORTS_RESCAN_ALL;
diff --git a/examples/plugins/plugin.hh b/examples/plugins/plugin.hh
@@ -18,7 +18,7 @@ namespace clap {
// not copyable, not moveable
Plugin(const Plugin &) = delete;
- Plugin(Plugin &&) = delete;
+ Plugin(Plugin &&) = delete;
Plugin &operator=(const Plugin &) = delete;
Plugin &operator=(Plugin &&) = delete;
@@ -26,8 +26,9 @@ namespace clap {
// Methods to override //
/////////////////////////
+ // clap_plugin
virtual bool init() { return true; }
- virtual bool activate(int sample_rate) { return true; }
+ virtual bool activate(int sampleRate) { return true; }
virtual void deactivate() {}
virtual bool startProcessing() { return true; }
virtual void stopProcessing() {}
@@ -42,8 +43,23 @@ namespace clap {
return false;
}
+ // clap_plugin_track_info
virtual void trackInfoChanged() {}
+ // clap_plugin_params
+ virtual uint32_t paramsCount() const { return 0; }
+ virtual bool paramsInfo(int32_t paramIndex, clap_param_info *info) const { return false; }
+ virtual bool paramsEnumValue(clap_id paramId, int32_t valueIndex, clap_param_value *value) {
+ return false;
+ }
+ virtual bool paramsValue(clap_id paramId, clap_param_value *value) { return false; }
+ virtual void
+ paramsSetValue(clap_id paramId, clap_param_value value, clap_param_value modulation) {}
+ virtual bool
+ paramsValueToText(clap_id paramId, clap_param_value value, char *display, uint32_t size) { return false; }
+ virtual bool
+ paramsTextToValue(clap_id param_id, const char *display, clap_param_value *value) { return false; }
+
//////////////////
// Invalidation //
//////////////////
@@ -125,20 +141,20 @@ namespace clap {
clap_plugin_gui_x11 pluginGuiX11_;
clap_plugin_event_loop pluginEventLoop_;
- const clap_host *const host_ = nullptr;
- const clap_host_log * hostLog_ = nullptr;
- const clap_host_thread_check * hostThreadCheck_ = nullptr;
- const clap_host_thread_pool * hostThreadPool_ = nullptr;
- const clap_host_audio_ports * hostAudioPorts_ = nullptr;
- const clap_host_event_filter * hostEventFilter_ = nullptr;
+ const clap_host *const host_ = nullptr;
+ const clap_host_log * hostLog_ = nullptr;
+ const clap_host_thread_check * hostThreadCheck_ = nullptr;
+ const clap_host_thread_pool * hostThreadPool_ = nullptr;
+ const clap_host_audio_ports * hostAudioPorts_ = nullptr;
+ const clap_host_event_filter * hostEventFilter_ = nullptr;
const clap_host_file_reference *hostFileReference_ = nullptr;
- const clap_host_latency * hostLatency_ = nullptr;
- const clap_host_gui * hostGui_ = nullptr;
- const clap_host_event_loop * hostEventLoop_ = nullptr;
- const clap_host_params * hostParams_ = nullptr;
- const clap_host_track_info * hostTrackInfo_ = nullptr;
- const clap_host_state * hostState_ = nullptr;
- const clap_host_note_name * hostNoteName_ = nullptr;
+ const clap_host_latency * hostLatency_ = nullptr;
+ const clap_host_gui * hostGui_ = nullptr;
+ const clap_host_event_loop * hostEventLoop_ = nullptr;
+ const clap_host_params * hostParams_ = nullptr;
+ const clap_host_track_info * hostTrackInfo_ = nullptr;
+ const clap_host_state * hostState_ = nullptr;
+ const clap_host_note_name * hostNoteName_ = nullptr;
private:
/////////////////////
@@ -169,14 +185,14 @@ namespace clap {
clap_audio_port_info *info);
void updateAudioPorts();
- static const constexpr clap_plugin_track_info pluginTrackInfo_ = {clapTrackInfoChanged};
+ static const constexpr clap_plugin_track_info pluginTrackInfo_ = {clapTrackInfoChanged};
static const constexpr clap_plugin_audio_ports pluginAudioPorts_ = {clapAudioPortsCount,
clapAudioPortsInfo};
// state
- bool isActive_ = false;
+ bool isActive_ = false;
bool isProcessing_ = false;
- int sampleRate_ = 0;
+ int sampleRate_ = 0;
bool hasTrackInfo_ = false;
clap_track_info trackInfo_;