clap

CLAP Audio Plugin API
Log | Files | Refs | README | LICENSE

commit be828efc29c456accbd057268780b9a4303aa94f
parent 63d49ec3ba0ed9f94d0b6fb7b204f089a971e0ca
Author: Alexandre BIQUE <bique.alexandre@gmail.com>
Date:   Mon, 24 May 2021 21:05:49 +0200

Refactoring

Diffstat:
Mexamples/host/plugin-host.cc | 38+++++++++++++++++++-------------------
Mexamples/host/plugin-host.hh | 42+++++++++++++++++++++---------------------
Mexamples/plugins/clap-entry.cc | 8++++----
Mexamples/plugins/gain/gain.cc | 6+++---
Mexamples/plugins/gain/gain.hh | 2+-
Mexamples/plugins/plugin.cc | 29++++++++++++++---------------
Mexamples/plugins/plugin.hh | 30+++++++++++++++---------------
Minclude/clap/clap.h | 20++++++++++----------
Minclude/clap/ext/audio-ports.h | 25+++++++++++++++----------
Minclude/clap/ext/draft/event-filter.h | 4++--
Minclude/clap/ext/draft/file-reference.h | 14+++++++-------
Minclude/clap/ext/draft/key-name.h | 6+++---
Minclude/clap/ext/draft/preset-load.h | 2+-
Minclude/clap/ext/draft/quick-controls.h | 12++++++------
Minclude/clap/ext/draft/thread-pool.h | 8++++----
Minclude/clap/ext/draft/track-info.h | 4++--
Minclude/clap/ext/draft/tuning.h | 2+-
Minclude/clap/ext/draft/vst2-convert.h | 8++++----
Minclude/clap/ext/draft/vst3-convert.h | 8++++----
Minclude/clap/ext/event-loop.h | 14+++++++-------
Minclude/clap/ext/gui-cocoa.h | 2+-
Minclude/clap/ext/gui-free-standing.h | 2+-
Minclude/clap/ext/gui-win32.h | 2+-
Minclude/clap/ext/gui-x11.h | 2+-
Minclude/clap/ext/gui.h | 12++++++------
Minclude/clap/ext/latency.h | 4++--
Minclude/clap/ext/log.h | 2+-
Minclude/clap/ext/params.h | 22+++++++++++-----------
Minclude/clap/ext/render.h | 2+-
Minclude/clap/ext/state.h | 6+++---
Minclude/clap/ext/thread-check.h | 4++--
31 files changed, 173 insertions(+), 169 deletions(-)

diff --git a/examples/host/plugin-host.cc b/examples/host/plugin-host.cc @@ -258,7 +258,7 @@ void PluginHost::setParentWindow(WId parentWindow) { Application::instance().mainWindow()->resizePluginView(width, height); } -void PluginHost::clapLog(clap_host *host, clap_log_severity severity, const char *msg) { +void PluginHost::clapLog(const clap_host *host, clap_log_severity severity, const char *msg) { switch (severity) { case CLAP_LOG_DEBUG: qDebug() << msg; @@ -286,7 +286,7 @@ void PluginHost::initPluginExtension(const T *&ext, const char *id) { ext = static_cast<const T *>(plugin_->extension(plugin_, id)); } -const void *PluginHost::clapExtension(clap_host *host, const char *extension) { +const void *PluginHost::clapExtension(const clap_host *host, const char *extension) { checkForMainThread(); PluginHost *h = static_cast<PluginHost *>(host->host_data); @@ -311,7 +311,7 @@ const void *PluginHost::clapExtension(clap_host *host, const char *extension) { return nullptr; } -PluginHost *PluginHost::fromHost(clap_host *host) { +PluginHost *PluginHost::fromHost(const clap_host *host) { if (!host) throw std::invalid_argument("Passed a null host pointer"); @@ -326,9 +326,9 @@ PluginHost *PluginHost::fromHost(clap_host *host) { return h; } -bool PluginHost::clapIsMainThread(clap_host *host) { return g_thread_type == MainThread; } +bool PluginHost::clapIsMainThread(const clap_host *host) { return g_thread_type == MainThread; } -bool PluginHost::clapIsAudioThread(clap_host *host) { return g_thread_type == AudioThread; } +bool PluginHost::clapIsAudioThread(const clap_host *host) { return g_thread_type == AudioThread; } void PluginHost::checkForMainThread() { if (g_thread_type != MainThread) @@ -340,7 +340,7 @@ void PluginHost::checkForAudioThread() { throw std::logic_error("Requires Audio Thread!"); } -bool PluginHost::clapThreadPoolRequestExec(clap_host *host, uint32_t num_tasks) { +bool PluginHost::clapThreadPoolRequestExec(const clap_host *host, uint32_t num_tasks) { checkForAudioThread(); auto h = fromHost(host); @@ -356,7 +356,7 @@ bool PluginHost::clapThreadPoolRequestExec(clap_host *host, uint32_t num_tasks) return true; } -bool PluginHost::clapEventLoopRegisterTimer(clap_host *host, +bool PluginHost::clapEventLoopRegisterTimer(const clap_host *host, uint32_t period_ms, clap_id * timer_id) { checkForMainThread(); @@ -382,7 +382,7 @@ bool PluginHost::clapEventLoopRegisterTimer(clap_host *host, return true; } -bool PluginHost::clapEventLoopUnregisterTimer(clap_host *host, clap_id timer_id) { +bool PluginHost::clapEventLoopUnregisterTimer(const clap_host *host, clap_id timer_id) { checkForMainThread(); auto h = fromHost(host); @@ -399,7 +399,7 @@ bool PluginHost::clapEventLoopUnregisterTimer(clap_host *host, clap_id timer_id) return true; } -bool PluginHost::clapEventLoopRegisterFd(clap_host *host, clap_fd fd, uint32_t flags) { +bool PluginHost::clapEventLoopRegisterFd(const clap_host *host, clap_fd fd, uint32_t flags) { checkForMainThread(); auto h = fromHost(host); @@ -419,7 +419,7 @@ bool PluginHost::clapEventLoopRegisterFd(clap_host *host, clap_fd fd, uint32_t f return true; } -bool PluginHost::clapEventLoopModifyFd(clap_host *host, clap_fd fd, uint32_t flags) { +bool PluginHost::clapEventLoopModifyFd(const clap_host *host, clap_fd fd, uint32_t flags) { checkForMainThread(); auto h = fromHost(host); @@ -438,7 +438,7 @@ bool PluginHost::clapEventLoopModifyFd(clap_host *host, clap_fd fd, uint32_t fla return true; } -bool PluginHost::clapEventLoopUnregisterFd(clap_host *host, clap_fd fd) { +bool PluginHost::clapEventLoopUnregisterFd(const clap_host *host, clap_fd fd) { checkForMainThread(); auto h = fromHost(host); @@ -498,7 +498,7 @@ void PluginHost::eventLoopSetFdNotifierFlags(clap_fd fd, uint32_t flags) { it->second->err->setEnabled(false); } -bool PluginHost::clapGuiResize(clap_host *host, int32_t width, int32_t height) { +bool PluginHost::clapGuiResize(const clap_host *host, int32_t width, int32_t height) { checkForMainThread(); PluginHost *h = static_cast<PluginHost *>(host->host_data); @@ -704,7 +704,7 @@ void PluginHost::checkValidParamValue(const PluginParam &param, clap_param_value } } -void PluginHost::clapParamsAdjustBegin(clap_host *host, clap_id param_id) { +void PluginHost::clapParamsAdjustBegin(const clap_host *host, clap_id param_id) { checkForMainThread(); auto h = fromHost(host); @@ -721,7 +721,7 @@ void PluginHost::clapParamsAdjustBegin(clap_host *host, clap_id param_id) { param.beginAdjust(); } -void PluginHost::clapParamsAdjustEnd(clap_host *host, clap_id param_id) { +void PluginHost::clapParamsAdjustEnd(const clap_host *host, clap_id param_id) { checkForMainThread(); auto h = fromHost(host); @@ -738,7 +738,7 @@ void PluginHost::clapParamsAdjustEnd(clap_host *host, clap_id param_id) { param.endAdjust(); } -void PluginHost::clapParamsAdjust(clap_host *host, clap_id param_id, clap_param_value value) { +void PluginHost::clapParamsAdjust(const clap_host *host, clap_id param_id, clap_param_value value) { checkForMainThread(); auto h = fromHost(host); @@ -775,7 +775,7 @@ void PluginHost::setParamValueByHost(PluginParam &param, clap_param_value value) void PluginHost::scanParams() { clapParamsRescan(&host_, CLAP_PARAM_RESCAN_ALL); } -void PluginHost::clapParamsRescan(clap_host *host, uint32_t flags) { +void PluginHost::clapParamsRescan(const clap_host *host, uint32_t flags) { checkForMainThread(); auto h = fromHost(host); @@ -1001,7 +1001,7 @@ void PluginHost::setQuickControlsSelectedPageByHost(clap_id page_id) { pluginQuickControls_->select_page(plugin_, page_id); } -void PluginHost::clapQuickControlsPagesChanged(clap_host *host) { +void PluginHost::clapQuickControlsPagesChanged(const clap_host *host) { checkForMainThread(); auto h = fromHost(host); @@ -1014,7 +1014,7 @@ void PluginHost::clapQuickControlsPagesChanged(clap_host *host) { h->scanQuickControls(); } -void PluginHost::clapQuickControlsSelectedPageChanged(clap_host *host, clap_id page_id) { +void PluginHost::clapQuickControlsSelectedPageChanged(const clap_host *host, clap_id page_id) { checkForMainThread(); auto h = fromHost(host); @@ -1039,7 +1039,7 @@ bool PluginHost::loadNativePluginPreset(const std::string &path) { return pluginPresetLoad_->load_from_file(plugin_, path.c_str()); } -void PluginHost::clapStateSetDirty(clap_host *host) { +void PluginHost::clapStateSetDirty(const clap_host *host) { checkForMainThread(); auto h = fromHost(host); diff --git a/examples/host/plugin-host.hh b/examples/host/plugin-host.hh @@ -72,20 +72,20 @@ signals: void quickControlsSelectedPageChanged(); private: - static PluginHost *fromHost(clap_host *host); + static PluginHost *fromHost(const clap_host *host); template <typename T> void initPluginExtension(const T *&ext, const char *id); /* clap host callbacks */ - static void clapLog(clap_host *host, clap_log_severity severity, const char *msg); + static void clapLog(const clap_host *host, clap_log_severity severity, const char *msg); - static bool clapIsMainThread(clap_host *host); - static bool clapIsAudioThread(clap_host *host); + static bool clapIsMainThread(const clap_host *host); + static bool clapIsAudioThread(const clap_host *host); - static void clapParamsAdjustBegin(clap_host *host, clap_id param_id); - static void clapParamsAdjustEnd(clap_host *host, clap_id param_id); - static void clapParamsAdjust(clap_host *host, clap_id param_id, clap_param_value plain_value); - static void clapParamsRescan(clap_host *host, uint32_t flags); + static void clapParamsAdjustBegin(const clap_host *host, clap_id param_id); + static void clapParamsAdjustEnd(const clap_host *host, clap_id param_id); + static void clapParamsAdjust(const clap_host *host, clap_id param_id, clap_param_value plain_value); + static void clapParamsRescan(const clap_host *host, uint32_t flags); void scanParams(); void scanParam(int32_t index); PluginParam &checkValidParamId(const std::string_view &function, @@ -102,24 +102,24 @@ private: void scanQuickControls(); void quickControlsSetSelectedPage(clap_id pageId); - static void clapQuickControlsPagesChanged(clap_host *host); - static void clapQuickControlsSelectedPageChanged(clap_host *host, clap_id page_id); - - static bool clapEventLoopRegisterTimer(clap_host *host, uint32_t period_ms, clap_id *timer_id); - static bool clapEventLoopUnregisterTimer(clap_host *host, clap_id timer_id); - static bool clapEventLoopRegisterFd(clap_host *host, clap_fd fd, uint32_t flags); - static bool clapEventLoopModifyFd(clap_host *host, clap_fd fd, uint32_t flags); - static bool clapEventLoopUnregisterFd(clap_host *host, clap_fd fd); + static void clapQuickControlsPagesChanged(const clap_host *host); + static void clapQuickControlsSelectedPageChanged(const clap_host *host, clap_id page_id); + + static bool clapEventLoopRegisterTimer(const clap_host *host, uint32_t period_ms, clap_id *timer_id); + static bool clapEventLoopUnregisterTimer(const clap_host *host, clap_id timer_id); + static bool clapEventLoopRegisterFd(const clap_host *host, clap_fd fd, uint32_t flags); + static bool clapEventLoopModifyFd(const clap_host *host, clap_fd fd, uint32_t flags); + static bool clapEventLoopUnregisterFd(const clap_host *host, clap_fd fd); void eventLoopSetFdNotifierFlags(clap_fd fd, uint32_t flags); - static bool clapThreadPoolRequestExec(clap_host *host, uint32_t num_tasks); + static bool clapThreadPoolRequestExec(const clap_host *host, uint32_t num_tasks); - static const void *clapExtension(clap_host *host, const char *extension); + static const void *clapExtension(const clap_host *host, const char *extension); /* clap host gui callbacks */ - static bool clapGuiResize(clap_host *host, int32_t width, int32_t height); + static bool clapGuiResize(const clap_host *host, int32_t width, int32_t height); - static void clapStateSetDirty(clap_host *host); + static void clapStateSetDirty(const clap_host *host); private: Engine &engine_; @@ -138,7 +138,7 @@ private: clap_host_state hostState_; const struct clap_plugin_entry * pluginEntry_ = nullptr; - clap_plugin * plugin_ = nullptr; + const clap_plugin * plugin_ = nullptr; const clap_plugin_params * pluginParams_ = nullptr; const clap_plugin_quick_controls * pluginQuickControls_ = nullptr; const clap_plugin_audio_ports * pluginAudioPorts_ = nullptr; diff --git a/examples/plugins/clap-entry.cc b/examples/plugins/clap-entry.cc @@ -9,20 +9,20 @@ #include "gain/gain.hh" struct PluginEntry { - using create_func = std::function<clap_plugin *(clap_host *)>; + using create_func = std::function<const clap_plugin *(const clap_host *)>; PluginEntry(const clap_plugin_descriptor *d, create_func &&func) : desc(d), create(std::move(func)) {} const clap_plugin_descriptor * desc; - std::function<clap_plugin *(clap_host *)> create; + std::function<const clap_plugin *(const clap_host *)> create; }; static std::vector<PluginEntry> g_plugins; template <typename T> static void addPlugin() { - g_plugins.emplace_back(T::descriptor(), [](clap_host *host) -> clap_plugin * { + g_plugins.emplace_back(T::descriptor(), [](const clap_host *host) -> const clap_plugin * { auto plugin = new T(host); return plugin->clapPlugin(); }); @@ -47,7 +47,7 @@ static const clap_plugin_descriptor *clap_get_plugin_descriptor(int32_t index) { return g_plugins[index].desc; } -static clap_plugin *clap_create_plugin(clap_host *host, const char *plugin_id) { +static const clap_plugin *clap_create_plugin(const clap_host *host, const char *plugin_id) { for (auto &entry : g_plugins) if (!strcmp(entry.desc->id, plugin_id)) return entry.create(host); diff --git a/examples/plugins/gain/gain.cc b/examples/plugins/gain/gain.cc @@ -22,7 +22,7 @@ namespace clap { return &desc; } - Gain::Gain(clap_host *host) : Plugin(descriptor(), host) {} + Gain::Gain(const clap_host *host) : Plugin(descriptor(), host) {} bool Gain::activate(int sample_rate) { channelCount_ = trackChannelCount(); @@ -51,8 +51,8 @@ namespace clap { strncpy(info.name, "main", sizeof(info.name)); info.is_main = true; info.is_cv = false; - info.supports_64_bits = false; - info.supports_in_place = true; + info.sample_size = 32; + info.in_place = true; info.channel_count = channelCount_; info.channel_map = CLAP_CHMAP_UNSPECIFIED; diff --git a/examples/plugins/gain/gain.hh b/examples/plugins/gain/gain.hh @@ -7,7 +7,7 @@ namespace clap { class Gain final : public Plugin { public: - Gain(clap_host *host); + Gain(const clap_host *host); static const clap_plugin_descriptor *descriptor(); diff --git a/examples/plugins/plugin.cc b/examples/plugins/plugin.cc @@ -8,7 +8,7 @@ namespace clap { - Plugin::Plugin(const clap_plugin_descriptor *desc, clap_host *host) : host_(host) { + Plugin::Plugin(const clap_plugin_descriptor *desc, const clap_host *host) : host_(host) { plugin_.plugin_data = this; plugin_.desc = desc; plugin_.init = Plugin::clapInit; @@ -26,7 +26,7 @@ namespace clap { ///////////////////// // clap_plugin interface - bool Plugin::clapInit(clap_plugin *plugin) { + bool Plugin::clapInit(const clap_plugin *plugin) { auto &self = from(plugin); self.plugin_.extension = Plugin::clapExtension; @@ -43,13 +43,13 @@ namespace clap { return self.init(); } - void Plugin::clapDestroy(clap_plugin *plugin) { + void Plugin::clapDestroy(const clap_plugin *plugin) { auto &self = from(plugin); self.ensureMainThread("clap_plugin.destroy"); delete &from(plugin); } - bool Plugin::clapActivate(clap_plugin *plugin, int sample_rate) { + bool Plugin::clapActivate(const clap_plugin *plugin, int sample_rate) { auto &self = from(plugin); self.ensureMainThread("clap_plugin.activate"); @@ -88,7 +88,7 @@ namespace clap { return true; } - void Plugin::clapDeactivate(clap_plugin *plugin) { + void Plugin::clapDeactivate(const clap_plugin *plugin) { auto &self = from(plugin); self.ensureMainThread("clap_plugin.deactivate"); @@ -103,7 +103,7 @@ namespace clap { self.deactivate(); } - bool Plugin::clapStartProcessing(clap_plugin *plugin) { + bool Plugin::clapStartProcessing(const clap_plugin *plugin) { auto &self = from(plugin); self.ensureAudioThread("clap_plugin.start_processing"); @@ -121,7 +121,7 @@ namespace clap { return self.isProcessing_; } - void Plugin::clapStopProcessing(clap_plugin *plugin) { + void Plugin::clapStopProcessing(const clap_plugin *plugin) { auto &self = from(plugin); self.ensureAudioThread("clap_plugin.stop_processing"); @@ -139,8 +139,7 @@ namespace clap { self.isProcessing_ = false; } - clap_process_status Plugin::clapProcess(struct clap_plugin *plugin, - const clap_process *process) { + clap_process_status Plugin::clapProcess(const clap_plugin *plugin, const clap_process *process) { auto &self = from(plugin); self.ensureAudioThread("clap_plugin.process"); @@ -158,7 +157,7 @@ namespace clap { return self.process(process); } - const void *Plugin::clapExtension(struct clap_plugin *plugin, const char *id) { + const void *Plugin::clapExtension(const clap_plugin *plugin, const char *id) { auto &self = from(plugin); self.ensureMainThread("clap_plugin.extension"); @@ -172,7 +171,7 @@ namespace clap { return from(plugin).extension(id); } - void Plugin::clapTrackInfoChanged(clap_plugin *plugin) { + void Plugin::clapTrackInfoChanged(const clap_plugin *plugin) { auto &self = from(plugin); self.ensureMainThread("clap_plugin_track_info.changed"); @@ -224,14 +223,14 @@ namespace clap { hasTrackInfo_ = hostTrackInfo_->get(host_, &trackInfo_); } - uint32_t Plugin::clapAudioPortsCount(clap_plugin *plugin, bool is_input) { + uint32_t Plugin::clapAudioPortsCount(const clap_plugin *plugin, bool is_input) { auto &self = from(plugin); self.ensureMainThread("clap_plugin_audio_ports.count"); return is_input ? self.inputAudioPorts_.size() : self.outputAudioPorts_.size(); } - bool Plugin::clapAudioPortsInfo(clap_plugin * plugin, + bool Plugin::clapAudioPortsInfo(const clap_plugin * plugin, uint32_t index, bool is_input, clap_audio_port_info *info) { @@ -344,7 +343,7 @@ namespace clap { /////////////// // Utilities // /////////////// - Plugin &Plugin::from(clap_plugin *plugin) { + Plugin &Plugin::from(const clap_plugin *plugin) { if (!plugin) { std::cerr << "called with a null clap_plugin pointer!" << std::endl; std::terminate(); @@ -387,7 +386,7 @@ namespace clap { uint32_t Plugin::compareAudioPortsInfo(const clap_audio_port_info &a, const clap_audio_port_info &b) noexcept { - if (a.supports_64_bits != b.supports_64_bits || a.supports_in_place != b.supports_in_place || + 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 @@ -10,10 +10,10 @@ namespace clap { class Plugin { public: - clap_plugin *clapPlugin() noexcept { return &plugin_; } + const clap_plugin *clapPlugin() noexcept { return &plugin_; } protected: - Plugin(const clap_plugin_descriptor *desc, clap_host *host); + Plugin(const clap_plugin_descriptor *desc, const clap_host *host); virtual ~Plugin() = default; // not copyable, not moveable @@ -74,7 +74,7 @@ namespace clap { /////////////// // Utilities // /////////////// - static Plugin &from(clap_plugin *plugin); + static Plugin &from(const clap_plugin *plugin); template <typename T> void initInterface(const T *&ptr, const char *id); @@ -125,7 +125,7 @@ namespace clap { clap_plugin_gui_x11 pluginGuiX11_; clap_plugin_event_loop pluginEventLoop_; - clap_host *const host_ = 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; @@ -147,23 +147,23 @@ namespace clap { clap_plugin plugin_; // clap_plugin - static bool clapInit(clap_plugin *plugin); - static void clapDestroy(clap_plugin *plugin); - static bool clapActivate(clap_plugin *plugin, int sample_rate); - static void clapDeactivate(clap_plugin *plugin); - static bool clapStartProcessing(clap_plugin *plugin); - static void clapStopProcessing(clap_plugin *plugin); - static clap_process_status clapProcess(struct clap_plugin *plugin, + static bool clapInit(const clap_plugin *plugin); + static void clapDestroy(const clap_plugin *plugin); + static bool clapActivate(const clap_plugin *plugin, int sample_rate); + static void clapDeactivate(const clap_plugin *plugin); + static bool clapStartProcessing(const clap_plugin *plugin); + static void clapStopProcessing(const clap_plugin *plugin); + static clap_process_status clapProcess(const clap_plugin * plugin, const clap_process *process); - static const void * clapExtension(struct clap_plugin *plugin, const char *id); + static const void * clapExtension(const clap_plugin *plugin, const char *id); // clap_plugin_track_info - static void clapTrackInfoChanged(clap_plugin *plugin); + static void clapTrackInfoChanged(const clap_plugin *plugin); void initTrackInfo(); // clap_plugin_audio_ports - static uint32_t clapAudioPortsCount(clap_plugin *plugin, bool is_input); - static bool clapAudioPortsInfo(clap_plugin * plugin, + static uint32_t clapAudioPortsCount(const clap_plugin *plugin, bool is_input); + static bool clapAudioPortsInfo(const clap_plugin * plugin, uint32_t index, bool is_input, clap_audio_port_info *info); diff --git a/include/clap/clap.h b/include/clap/clap.h @@ -109,7 +109,7 @@ typedef struct clap_host { // Query an extension. // [thread-safe] - const void *(*extension)(struct clap_host *host, const char *extension_id); + const void *(*extension)(const struct clap_host *host, const char *extension_id); } clap_host; //////////// @@ -170,29 +170,29 @@ typedef struct clap_plugin { // Must be called after creating the plugin. // If init returns false, the host must destroy the plugin instance. - bool (*init)(struct clap_plugin *plugin); + bool (*init)(const struct clap_plugin *plugin); /* Free the plugin and its resources. * It is not required to deactivate the plugin prior to this call. */ - void (*destroy)(struct clap_plugin *plugin); + void (*destroy)(const struct clap_plugin *plugin); /* activation/deactivation * [main-thread] */ - bool (*activate)(struct clap_plugin *plugin, int sample_rate); - void (*deactivate)(struct clap_plugin *plugin); + bool (*activate)(const struct clap_plugin *plugin, int sample_rate); + void (*deactivate)(const struct clap_plugin *plugin); // Set to true before processing, and to false before sending the plugin to sleep. // [audio-thread] - bool (*start_processing)(struct clap_plugin *plugin); - void (*stop_processing)(struct clap_plugin *plugin); + bool (*start_processing)(const struct clap_plugin *plugin); + void (*stop_processing)(const struct clap_plugin *plugin); /* process audio, events, ... * [audio-thread] */ - clap_process_status (*process)(struct clap_plugin *plugin, const clap_process *process); + clap_process_status (*process)(const struct clap_plugin *plugin, const clap_process *process); /* query an extension * [thread-safe] */ - const void *(*extension)(struct clap_plugin *plugin, const char *id); + const void *(*extension)(const struct clap_plugin *plugin, const char *id); } clap_plugin; ///////////////// @@ -221,7 +221,7 @@ struct clap_plugin_entry { * The plugin is not allowed to use the host callbacks in the create method. * Returns null in case of error. * [thread-safe] */ - clap_plugin *(*create_plugin)(clap_host *host, const char *plugin_id); + const clap_plugin *(*create_plugin)(const clap_host *host, const char *plugin_id); }; /* Entry point */ diff --git a/include/clap/ext/audio-ports.h b/include/clap/ext/audio-ports.h @@ -12,25 +12,27 @@ extern "C" { typedef struct clap_audio_port_info { clap_id id; // stable identifier char name[CLAP_NAME_SIZE]; // displayable name, i18n? - bool is_main; // there can only be 1 main input and output - bool is_cv; // control voltage - bool supports_64_bits; // 32 bit support is mandatory, the host chooses - // between 32 and 64. - bool supports_in_place; // if true the daw can use the same buffer for input - // and output, only for main input to main output - int32_t channel_count; + + uint32_t channel_count; clap_chmap channel_map; + uint32_t sample_size; // 32 for float and 64 for double + + bool is_main; // there can only be 1 main input and output + bool is_cv; // control voltage + bool in_place; // if true the daw can use the same buffer for input + // and output, only for main input to main output + } clap_audio_port_info; // The audio ports scan has to be done while the plugin is deactivated. typedef struct clap_plugin_audio_ports { // number of ports, for either input or output // [main-thread] - uint32_t (*count)(clap_plugin *plugin, bool is_input); + uint32_t (*count)(const clap_plugin *plugin, bool is_input); // get info about about an audio port. // [main-thread] - bool (*get_info)(clap_plugin *plugin, uint32_t index, bool is_input, clap_audio_port_info *info); + bool (*info)(const clap_plugin *plugin, uint32_t index, bool is_input, clap_audio_port_info *info); } clap_plugin_audio_ports; enum { @@ -43,9 +45,12 @@ enum { }; typedef struct clap_host_audio_ports { + // [main-thread] + uint32_t (*preferred_sample_size)(const clap_host *host); + // Rescan the full list of audio ports according to the flags. // [main-thread] - void (*rescan)(clap_host *host, uint32_t flags); + void (*rescan)(const clap_host *host, uint32_t flags); } clap_host_audio_ports; #ifdef __cplusplus diff --git a/include/clap/ext/draft/event-filter.h b/include/clap/ext/draft/event-filter.h @@ -13,12 +13,12 @@ extern "C" { typedef struct clap_plugin_event_filter { // Returns true if the plugin is interested in the given event type. // [audio-thread] - bool (*accepts)(clap_plugin *plugin, clap_event_type event_type); + bool (*accepts)(const clap_plugin *plugin, clap_event_type event_type); } clap_plugin_event_filter; typedef struct clap_host_event_filter { - void (*changed)(clap_host *host); + void (*changed)(const clap_host *host); } clap_host_event_filter; #ifdef __cplusplus diff --git a/include/clap/ext/draft/file-reference.h b/include/clap/ext/draft/file-reference.h @@ -30,30 +30,30 @@ typedef struct clap_file_reference { typedef struct clap_plugin_file_reference { // returns the number of file reference this plugin has // [main-thread] - uint32_t (*count)(clap_plugin *plugin); + uint32_t (*count)(const clap_plugin *plugin); // gets the file reference at index // returns true on success // [main-thread] - bool (*get)(clap_plugin *plugin, uint32_t index, clap_file_reference *file_reference); + bool (*get)(const clap_plugin *plugin, uint32_t index, clap_file_reference *file_reference); // [main-thread] - bool (*get_hash)(clap_plugin *plugin, clap_id resource_id, clap_hash hash, uint8_t *digest); + bool (*get_hash)(const clap_plugin *plugin, clap_id resource_id, clap_hash hash, uint8_t *digest); // updates the path to a file reference // [main-thread] - bool (*set)(clap_plugin *plugin, clap_id resource_id, const char *path); + bool (*set)(const clap_plugin *plugin, clap_id resource_id, const char *path); // [main-thread] - bool (*save_resources)(clap_plugin *plugin); + bool (*save_resources)(const clap_plugin *plugin); } clap_plugin_file_reference; typedef struct clap_host_file_reference { // informs the host that the file references have changed, the host should schedule a full rescan // [main-thread] - void (*changed)(clap_host *host); + void (*changed)(const clap_host *host); - void (*set_dirty)(clap_host *host , clap_id resource_id); + void (*set_dirty)(const clap_host *host , clap_id resource_id); } clap_host_file_reference; #ifdef __cplusplus diff --git a/include/clap/ext/draft/key-name.h b/include/clap/ext/draft/key-name.h @@ -17,17 +17,17 @@ typedef struct clap_note_name { typedef struct clap_plugin_note_name { // Return the number of note names // [main-thread] - int (*count)(clap_plugin *plugin); + int (*count)(const clap_plugin *plugin); // Returns true on success and stores the result into note_name // [main-thread] - bool (*get)(clap_plugin *plugin, int index, clap_note_name *note_name); + bool (*get)(const clap_plugin *plugin, int index, clap_note_name *note_name); } clap_plugin_note_name; typedef struct clap_host_note_name { // Informs the host that the note names has changed. // [main-thread] - void (*changed)(clap_host *host); + void (*changed)(const clap_host *host); } clap_host_note_name; #ifdef __cplusplus diff --git a/include/clap/ext/draft/preset-load.h b/include/clap/ext/draft/preset-load.h @@ -11,7 +11,7 @@ extern "C" { typedef struct clap_plugin_preset_load { // Loads a preset in the plugin native preset file format from a path. // [main-thread] - bool (*load_from_file)(clap_plugin *plugin, const char *path); + bool (*load_from_file)(const clap_plugin *plugin, const char *path); } clap_plugin_preset_load; #ifdef __cplusplus diff --git a/include/clap/ext/draft/quick-controls.h b/include/clap/ext/draft/quick-controls.h @@ -20,26 +20,26 @@ typedef struct clap_quick_controls_page { } clap_quick_controls_page; typedef struct clap_plugin_quick_controls { - int32_t (*page_count)(clap_plugin *plugin); + int32_t (*page_count)(const clap_plugin *plugin); // [main-thread] - bool (*get_page)(clap_plugin *plugin, int32_t page_index, clap_quick_controls_page *page); + bool (*get_page)(const clap_plugin *plugin, int32_t page_index, clap_quick_controls_page *page); // [main-thread] - void (*select_page)(clap_plugin *plugin, clap_id page_id); + void (*select_page)(const clap_plugin *plugin, clap_id page_id); // [main-thread] - clap_id (*get_selected_page)(clap_plugin *plugin); + clap_id (*get_selected_page)(const clap_plugin *plugin); } clap_host_plugin_info; typedef struct clap_host_quick_controls { // Informs the host that the quick controls pages has changed. // [main-thread] - void (*pages_changed)(clap_host *host); + void (*pages_changed)(const clap_host *host); // Informs the host that the user did change the selected page, from the plugin. // [main-thread] - void (*selected_page_changed)(clap_host *host, clap_id page_id); + void (*selected_page_changed)(const clap_host *host, clap_id page_id); } clap_host_quick_controls; #ifdef __cplusplus diff --git a/include/clap/ext/draft/thread-pool.h b/include/clap/ext/draft/thread-pool.h @@ -17,12 +17,12 @@ extern "C" { /// Simple example with N voices to process /// /// @code -/// void myplug_thread_pool_exec(clap_plugin *plugin, uint32_t voice_index) +/// void myplug_thread_pool_exec(const clap_plugin *plugin, uint32_t voice_index) /// { /// compute_voice(plugin, voice_index); /// } /// -/// void myplug_process(clap_plugin *plugin, const clap_process *process) +/// void myplug_process(const clap_plugin *plugin, const clap_process *process) /// { /// ... /// bool didComputeVoices = false; @@ -40,7 +40,7 @@ extern "C" { typedef struct clap_plugin_thread_pool { // Called by the thread pool - void (*exec)(clap_plugin *plugin, uint32_t task_index); + void (*exec)(const clap_plugin *plugin, uint32_t task_index); } clap_plugin_thread_pool; typedef struct clap_host_thread_pool { @@ -52,7 +52,7 @@ typedef struct clap_host_thread_pool { // The host should check that the plugin is within the process call, and if not, reject the exec // request. // [audio-thread] - bool (*request_exec)(clap_host *host, uint32_t num_tasks); + bool (*request_exec)(const clap_host *host, uint32_t num_tasks); } clap_host_thread_pool; #ifdef __cplusplus diff --git a/include/clap/ext/draft/track-info.h b/include/clap/ext/draft/track-info.h @@ -23,13 +23,13 @@ typedef struct clap_track_info { typedef struct clap_plugin_track_info { // [main-thread] - void (*changed)(clap_plugin *plugin); + void (*changed)(const clap_plugin *plugin); } clap_plugin_track_info; typedef struct clap_host_track_info { // Get info about the track the plugin belongs to. // [main-thread] - bool (*get)(clap_host *host, clap_track_info *info); + bool (*get)(const clap_host *host, clap_track_info *info); } clap_host_track_info; #ifdef __cplusplus diff --git a/include/clap/ext/draft/tuning.h b/include/clap/ext/draft/tuning.h @@ -16,7 +16,7 @@ typedef struct clap_host_tuning { // The plugin is not supposed to query it for each samples, // but at a rate that makes sense for low frequency modulations. // [audio-thread] - double (*key_freq)(clap_host *host, int32_t key, int32_t channel, int32_t frameIndex); + double (*key_freq)(const clap_host *host, int32_t key, int32_t channel, int32_t frameIndex); } clap_host_tuning; #ifdef __cplusplus diff --git a/include/clap/ext/draft/vst2-convert.h b/include/clap/ext/draft/vst2-convert.h @@ -13,19 +13,19 @@ typedef struct clap_plugin_vst2_convert { // Copies the name and VST2 plugin id that we can convert from. // Returns the lenght of the name. // [thread-safe] - int32_t (*get_vst2_plugin_id)(clap_plugin *plugin, + int32_t (*get_vst2_plugin_id)(const clap_plugin *plugin, uint32_t * vst2_plugin_id, char * name, uint32_t name_size); // Loads the plugin state from stream using the VST2 chunk. // [main-thread] - bool (*restore_vst2_state)(clap_plugin *plugin, clap_istream *stream); + bool (*restore_vst2_state)(const clap_plugin *plugin, clap_istream *stream); // converts the vst2 param id and normalized value to clap param id and // plain value. // [thread-safe] - bool (*convert_normalized_value)(clap_plugin * plugin, + bool (*convert_normalized_value)(const clap_plugin * plugin, uint32_t vst2_param_id, double vst2_normalized_value, clap_id * clap_param_id, @@ -34,7 +34,7 @@ typedef struct clap_plugin_vst2_convert { // converts the vst2 param id and plain value to clap param id and // plain value. // [thread-safe] - bool (*convert_plain_value)(clap_plugin * plugin, + bool (*convert_plain_value)(const clap_plugin * plugin, uint32_t vst2_param_id, double vst2_plain_value, clap_id * clap_param_id, diff --git a/include/clap/ext/draft/vst3-convert.h b/include/clap/ext/draft/vst3-convert.h @@ -12,16 +12,16 @@ extern "C" { typedef struct clap_plugin_vst3_convert { // Copies the name and VST3 plugin id that we can convert from. // [thread-safe] - void (*get_vst3_plugin_id)(clap_plugin *plugin, uint8_t *vst3_plugin_uuid); + void (*get_vst3_plugin_id)(const clap_plugin *plugin, uint8_t *vst3_plugin_uuid); // Loads the plugin state from stream using the vst3 chunk. // [main-thread] - bool (*restore_vst3_state)(clap_plugin *plugin, clap_istream *stream); + bool (*restore_vst3_state)(const clap_plugin *plugin, clap_istream *stream); // converts the VST3 param id and normalized value to clap param id and // normalized value. // [thread-safe] - bool (*convert_normalized_value)(clap_plugin * plugin, + bool (*convert_normalized_value)(const clap_plugin * plugin, uint32_t vst3_param_id, double vst3_normalized_value, clap_id * clap_param_id, @@ -30,7 +30,7 @@ typedef struct clap_plugin_vst3_convert { // converts the vst3 param id and plain value to clap param id and // plain value. // [thread-safe] - bool (*convert_plain_value)(clap_plugin * plugin, + bool (*convert_plain_value)(const clap_plugin * plugin, uint32_t vst3_param_id, double vst3_plain_value, clap_id * clap_param_id, diff --git a/include/clap/ext/event-loop.h b/include/clap/ext/event-loop.h @@ -23,27 +23,27 @@ enum { typedef struct clap_plugin_event_loop { // [main-thread] - void (*on_timer)(clap_plugin *plugin, clap_id timer_id); + void (*on_timer)(const clap_plugin *plugin, clap_id timer_id); // [main-thread] - void (*on_fd)(clap_plugin *plugin, clap_fd fd, uint32_t flags); + void (*on_fd)(const clap_plugin *plugin, clap_fd fd, uint32_t flags); } clap_plugin_event_loop; typedef struct clap_host_event_loop { // [main-thread] - bool (*register_timer)(clap_host *host, uint32_t period_ms, clap_id *timer_id); + bool (*register_timer)(const clap_host *host, uint32_t period_ms, clap_id *timer_id); // [main-thread] - bool (*unregister_timer)(clap_host *host, clap_id timer_id); + bool (*unregister_timer)(const clap_host *host, clap_id timer_id); // [main-thread] - bool (*register_fd)(clap_host *host, clap_fd fd, uint32_t flags); + bool (*register_fd)(const clap_host *host, clap_fd fd, uint32_t flags); // [main-thread] - bool (*modify_fd)(clap_host *host, clap_fd fd, uint32_t flags); + bool (*modify_fd)(const clap_host *host, clap_fd fd, uint32_t flags); // [main-thread] - bool (*unregister_fd)(clap_host *host, clap_fd fd); + bool (*unregister_fd)(const clap_host *host, clap_fd fd); } clap_host_event_loop; #ifdef __cplusplus diff --git a/include/clap/ext/gui-cocoa.h b/include/clap/ext/gui-cocoa.h @@ -10,7 +10,7 @@ extern "C" { typedef struct clap_plugin_gui_cocoa { // [main-thread] - bool (*attach)(clap_plugin *plugin, void *nsView); + bool (*attach)(const clap_plugin *plugin, void *nsView); } clap_plugin_gui_cocoa; #ifdef __cplusplus diff --git a/include/clap/ext/gui-free-standing.h b/include/clap/ext/gui-free-standing.h @@ -12,7 +12,7 @@ typedef struct clap_plugin_gui_free_standing { // Opens the plugin window as a free standing window, which means it is not // embedded in the host and managed by the plugin. // [main-thread] - bool (*open)(clap_plugin * plugin); + bool (*open)(const clap_plugin * plugin); } clap_plugin_gui_free_standing; #ifdef __cplusplus diff --git a/include/clap/ext/gui-win32.h b/include/clap/ext/gui-win32.h @@ -13,7 +13,7 @@ typedef void *clap_hwnd; typedef struct clap_plugin_gui_win32 { // [main-thread] - bool (*attach)(clap_plugin *plugin, clap_hwnd window); + bool (*attach)(const clap_plugin *plugin, clap_hwnd window); } clap_plugin_gui_win32; #ifdef __cplusplus diff --git a/include/clap/ext/gui-x11.h b/include/clap/ext/gui-x11.h @@ -11,7 +11,7 @@ extern "C" { typedef struct clap_plugin_gui_x11 { // Use the protocol XEmbed // [main-thread] - bool (*attach)(clap_plugin * plugin, + bool (*attach)(const clap_plugin * plugin, const char * display_name, unsigned long window); } clap_plugin_gui_x11; diff --git a/include/clap/ext/gui.h b/include/clap/ext/gui.h @@ -12,24 +12,24 @@ extern "C" { typedef struct clap_plugin_gui { // Get the size of the plugin UI. // [main-thread] - void (*get_size)(clap_plugin *plugin, int32_t *width, int32_t *height); + void (*get_size)(const clap_plugin *plugin, int32_t *width, int32_t *height); // Sets the GUI scaling factor. // [main-thread] - void (*set_scale)(clap_plugin *plugin, double scale); + void (*set_scale)(const clap_plugin *plugin, double scale); - void (*show)(clap_plugin *plugin); - void (*hide)(clap_plugin *plugin); + void (*show)(const clap_plugin *plugin); + void (*hide)(const clap_plugin *plugin); // [main-thread] - void (*close)(clap_plugin *plugin); + void (*close)(const clap_plugin *plugin); } clap_plugin_gui; typedef struct clap_host_gui { /* Request the host to resize the client area to width, height. * Return true on success, false otherwise. * [thread-safe] */ - bool (*resize)(clap_host *host, int32_t width, int32_t height); + bool (*resize)(const clap_host *host, int32_t width, int32_t height); } clap_host_gui; #ifdef __cplusplus diff --git a/include/clap/ext/latency.h b/include/clap/ext/latency.h @@ -13,14 +13,14 @@ extern "C" { typedef struct clap_plugin_latency { // Returns the plugin latency. // [main-thread] - uint32_t (*get_latency)(clap_plugin *plugin); + uint32_t (*get_latency)(const clap_plugin *plugin); } clap_plugin_latency; typedef struct clap_host_latency { // Tell the host that the latency changed. // The new latency will be effective after deactivation of the plugin. // [main-thread] - void (*changed)(clap_host *host, uint32_t new_latency); + void (*changed)(const clap_host *host, uint32_t new_latency); } clap_host_latency; #ifdef __cplusplus diff --git a/include/clap/ext/log.h b/include/clap/ext/log.h @@ -23,7 +23,7 @@ typedef int32_t clap_log_severity; typedef struct clap_host_log { // Log a message through the host. // [thread-safe] - void (*log)(clap_host *host, clap_log_severity severity, const char *msg); + void (*log)(const clap_host *host, clap_log_severity severity, const char *msg); } clap_host_log; #ifdef __cplusplus diff --git a/include/clap/ext/params.h b/include/clap/ext/params.h @@ -46,39 +46,39 @@ typedef struct clap_param_info { typedef struct clap_plugin_params { // Returns the number of parameters. // [main-thread] - int32_t (*count)(clap_plugin *plugin); + int32_t (*count)(const clap_plugin *plugin); // Copies the parameter's info to param_info and returns true on success. // [main-thread] - bool (*get_info)(clap_plugin *plugin, int32_t param_index, clap_param_info *param_info); + bool (*get_info)(const clap_plugin *plugin, int32_t param_index, clap_param_info *param_info); - bool (*get_enum_value)(clap_plugin * plugin, + bool (*get_enum_value)(const clap_plugin * plugin, clap_id param_id, int32_t value_index, clap_param_value *plain_value); // Gets the parameter plain value. // [main-thread] - bool (*get_value)(clap_plugin *plugin, clap_id param_id, clap_param_value *plain_value); + bool (*get_value)(const clap_plugin *plugin, clap_id param_id, clap_param_value *plain_value); // Sets the parameter plain value. // If the plupin is activated, then the host must send a param event // in the next process call to update the audio processor. // [main-thread] - bool (*set_value)(clap_plugin * plugin, + bool (*set_value)(const clap_plugin * plugin, clap_id param_id, clap_param_value plain_value, clap_param_value plain_modulated_value); // Formats the display text for the given parameter value. // [thread-safe,lock-wait-free] - bool (*value_to_text)(clap_plugin * plugin, + bool (*value_to_text)(const clap_plugin * plugin, clap_id param_id, clap_param_value plain_value, char * display, uint32_t size); - bool (*text_to_value)(clap_plugin * plugin, + bool (*text_to_value)(const clap_plugin * plugin, clap_id param_id, const char * display, clap_param_value *plain_value); @@ -129,20 +129,20 @@ enum { typedef struct clap_host_params { /* [main-thread] */ - void (*adjust_begin)(clap_host *host, clap_id param_id); + void (*adjust_begin)(const clap_host *host, clap_id param_id); // If the plugin is activated, the host must send a parameter update // in the next process call to update the audio processor. // Only for value changes that happens in the gui. // [main-thread] - void (*adjust)(clap_host *host, clap_id param_id, clap_param_value plain_value); + void (*adjust)(const clap_host *host, clap_id param_id, clap_param_value plain_value); /* [main-thread] */ - void (*adjust_end)(clap_host *host, clap_id param_id); + void (*adjust_end)(const clap_host *host, clap_id param_id); // Rescan the full list of parameters according to the flags. // [main-thread] - void (*rescan)(clap_host *host, uint32_t flags); + void (*rescan)(const clap_host *host, uint32_t flags); } clap_host_params; #ifdef __cplusplus diff --git a/include/clap/ext/render.h b/include/clap/ext/render.h @@ -21,7 +21,7 @@ typedef int32_t clap_plugin_render_mode; // pressure to process. typedef struct clap_plugin_render { // [main-thread] - void (*set_render_mode)(clap_plugin *plugin, clap_plugin_render_mode mode); + void (*set_render_mode)(const clap_plugin *plugin, clap_plugin_render_mode mode); } clap_plugin_render; #ifdef __cplusplus diff --git a/include/clap/ext/state.h b/include/clap/ext/state.h @@ -12,17 +12,17 @@ extern "C" { typedef struct clap_plugin_state { /* Saves the plugin state into stream. * [main-thread] */ - bool (*save)(clap_plugin *plugin, clap_ostream *stream); + bool (*save)(const clap_plugin *plugin, clap_ostream *stream); /* Loads the plugin state from stream. * [main-thread] */ - bool (*restore)(clap_plugin *plugin, clap_istream *stream); + bool (*restore)(const clap_plugin *plugin, clap_istream *stream); } clap_plugin_state; typedef struct clap_host_state { /* Tell the host that the plugin state has changed. * [thread-safe] */ - void (*set_dirty)(clap_host *host); + void (*set_dirty)(const clap_host *host); } clap_host_state; #ifdef __cplusplus diff --git a/include/clap/ext/thread-check.h b/include/clap/ext/thread-check.h @@ -13,11 +13,11 @@ extern "C" { typedef struct clap_host_thread_check { // Returns true if the "this" thread is the main thread. // [thread-safe] - bool (*is_main_thread)(clap_host *host); + bool (*is_main_thread)(const clap_host *host); // Returns true if the "this" thread is one of the audio threads. // [thread-safe] - bool (*is_audio_thread)(clap_host *host); + bool (*is_audio_thread)(const clap_host *host); } clap_host_thread_check; #ifdef __cplusplus