Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions include/clap/helpers/host-proxy.hh
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,12 @@ namespace clap { namespace helpers {
bool miniCurveDisplayGetHints(uint32_t kind,
clap_mini_curve_display_curve_hints_t *hints) const noexcept;

////////////////////////////
// nl_clap_plugin_webview //
////////////////////////////
bool canUseWebview() const noexcept;
bool webviewSend(const void *buffer, uint32_t size) const noexcept;

protected:
void ensureMainThread(const char *method) const noexcept;
void ensureAudioThread(const char *method) const noexcept;
Expand Down Expand Up @@ -245,5 +251,6 @@ namespace clap { namespace helpers {
const clap_host_undo *_hostUndo = nullptr;
const clap_host_scratch_memory *_hostScratchMemory = nullptr;
const clap_host_mini_curve_display *_hostMiniCurveDisplay = nullptr;
const clap_host_webview *_hostWebview = nullptr;
};
}} // namespace clap::helpers
19 changes: 17 additions & 2 deletions include/clap/helpers/host-proxy.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ namespace clap { namespace helpers {
getExtension(_hostUndo, CLAP_EXT_UNDO);
getExtension(_hostScratchMemory, CLAP_EXT_SCRATCH_MEMORY);
getExtension(_hostMiniCurveDisplay, CLAP_EXT_MINI_CURVE_DISPLAY);
getExtension(_hostWebview, CLAP_EXT_WEBVIEW);
}

template <MisbehaviourHandler h, CheckingLevel l>
Expand Down Expand Up @@ -810,14 +811,28 @@ namespace clap { namespace helpers {
bool HostProxy<h, l>::miniCurveDisplayGetHints(
uint32_t kind, clap_mini_curve_display_curve_hints_t *hints) const noexcept {
assert(canUseMiniCurveDisplay());
ensureMainThread("mini_curve_display_get_hints");
ensureMainThread("mini_curve_display.get_hints");

if (!hints) {
pluginMisbehaving("mini_curve_display_get_hints() called with a null hints pointer");
pluginMisbehaving("mini_curve_display.get_hints() called with a null hints pointer");
return false;
}

return _hostMiniCurveDisplay->get_hints(_host, kind, hints);
}

////////////////////////
// clap_host_web_view //
////////////////////////
template <MisbehaviourHandler h, CheckingLevel l>
bool HostProxy<h, l>::canUseWebview() const noexcept {
return _hostWebview && _hostWebview->send;
}

template <MisbehaviourHandler h, CheckingLevel l>
bool HostProxy<h, l>::webviewSend(const void *buffer, uint32_t size) const noexcept {
assert(canUseWebview());
this->ensureMainThread("webview.send");
return _hostWebview->send(this->_host, buffer, size);
}
}} // namespace clap::helpers
12 changes: 11 additions & 1 deletion include/clap/helpers/host.hh
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ namespace clap { namespace helpers {
virtual bool implementsSurround() const noexcept { return false; }
virtual void surroundChanged() noexcept {}

// clap_host_webview
virtual bool implementsWebview() const noexcept { return false; }
virtual bool webviewSend(const void *buffer, uint32_t size) const noexcept { return false; }

/////////////////////
// Thread Checking //
/////////////////////
Expand Down Expand Up @@ -178,7 +182,9 @@ namespace clap { namespace helpers {
static void clapStateMarkDirty(const clap_host *host) noexcept;

// clap_host_timer_support
static bool clapTimerSupportRegisterTimer(const clap_host *host, uint32_t period_ms, clap_id *timer_id) noexcept;
static bool clapTimerSupportRegisterTimer(const clap_host *host,
uint32_t period_ms,
clap_id *timer_id) noexcept;
static bool clapTimerSupportUnregisterTimer(const clap_host *host, clap_id timer_id) noexcept;

// clap_host_tail
Expand All @@ -194,6 +200,9 @@ namespace clap { namespace helpers {
// clap_host_surround
static void clapSurroundChanged(const clap_host_t *host) noexcept;

// clap_host_webview
static bool clapWebviewSend(const clap_host_t *host, const void *buffer, uint32_t size);

// interfaces
static const clap_host_audio_ports _hostAudioPorts;
static const clap_host_gui _hostGui;
Expand All @@ -208,5 +217,6 @@ namespace clap { namespace helpers {
static const clap_host_thread_check _hostThreadCheck;
static const clap_host_thread_pool _hostThreadPool;
static const clap_host_surround _hostSurround;
static const clap_host_webview _hostWebview;
};
}} // namespace clap::helpers
17 changes: 17 additions & 0 deletions include/clap/helpers/host.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ namespace clap { namespace helpers {
clapSurroundChanged,
};

template <MisbehaviourHandler h, CheckingLevel l>
const clap_host_webview Host<h, l>::_hostWebview = {
clapWebviewSend,
};

template <MisbehaviourHandler h, CheckingLevel l>
Host<h, l>::Host(const char *name, const char *vendor, const char *url, const char *version)
: _host{
Expand Down Expand Up @@ -169,6 +174,8 @@ namespace clap { namespace helpers {
return &_hostSurround;

if (self.enableDraftExtensions()) {
if (!strcmp(extension_id, CLAP_EXT_WEBVIEW) && self.implementsWebview())
return &_hostWebview;
// put draft ext here
}

Expand Down Expand Up @@ -414,6 +421,16 @@ namespace clap { namespace helpers {
self.surroundChanged();
}

//-------------------//
// clap_host_webview //
//-------------------//
template <MisbehaviourHandler h, CheckingLevel l>
bool Host<h, l>::clapWebviewSend(const clap_host_t *host, const void *buffer, uint32_t size) {
auto &self = from(host);
self.ensureMainThread("webview.send");
return self.webviewSend(buffer, size);
}

/////////////////////
// Thread Checking //
/////////////////////
Expand Down
8 changes: 8 additions & 0 deletions include/clap/helpers/plugin-proxy.hh
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,13 @@ namespace clap { namespace helpers {
bool canUseGainAdjustmentMetering() const noexcept;
double gainAdjustmentMeteringGet() const noexcept;

/////////////////////////
// clap_plugin_webview //
/////////////////////////
bool canUseWebview() const noexcept;
int32_t webviewGetUri(char *uri, uint32_t uriCapacity) const noexcept;
bool webviewReceive(const void *buffer, uint32_t size) const noexcept;

protected:
/////////////////////
// Thread Checking //
Expand Down Expand Up @@ -181,6 +188,7 @@ namespace clap { namespace helpers {
const clap_plugin_project_location *_pluginProjectLocation = nullptr;
const clap_plugin_gain_adjustment_metering *_pluginGainAdjustmentMetering = nullptr;
const clap_plugin_mini_curve_display *_pluginMiniCurveDisplay = nullptr;
const clap_plugin_webview* _pluginWebview = nullptr;

// state
bool _isActive = false;
Expand Down
23 changes: 23 additions & 0 deletions include/clap/helpers/plugin-proxy.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace clap { namespace helpers {
getExtension(_pluginProjectLocation, CLAP_EXT_PROJECT_LOCATION);
getExtension(_pluginGainAdjustmentMetering, CLAP_EXT_GAIN_ADJUSTMENT_METERING);
getExtension(_pluginMiniCurveDisplay, CLAP_EXT_MINI_CURVE_DISPLAY);
getExtension(_pluginWebview, CLAP_EXT_WEBVIEW);
return true;
}

Expand Down Expand Up @@ -644,6 +645,28 @@ namespace clap { namespace helpers {
return gain;
}

/////////////////////////
// clap_plugin_webview //
/////////////////////////
template <MisbehaviourHandler h, CheckingLevel l>
bool PluginProxy<h, l>::canUseWebview() const noexcept {
return _pluginWebview && _pluginWebview->get_uri && _pluginWebview->receive;
}

template <MisbehaviourHandler h, CheckingLevel l>
int32_t PluginProxy<h, l>::webviewGetUri(char *uri, uint32_t uriCapacity) const noexcept {
assert(canUseWebview());
ensureMainThread("webview.get_uri");
return _pluginWebview->get_uri(&this->_plugin, uri, uriCapacity);
}

template <MisbehaviourHandler h, CheckingLevel l>
bool PluginProxy<h, l>::webviewReceive(const void *buffer, uint32_t size) const noexcept {
assert(canUseWebview());
ensureMainThread("webview.receive");
return _pluginWebview->receive(&this->_plugin, buffer, size);
}

/////////////////////
// Thread Checking //
/////////////////////
Expand Down
16 changes: 16 additions & 0 deletions include/clap/helpers/plugin.hh
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,15 @@ namespace clap { namespace helpers {
return false;
}

//---------------------//
// clap_plugin_webview //
//---------------------//
virtual bool implementsWebview() const noexcept { return false; }
virtual int32_t webviewGetUri(char *uri, uint32_t uriCapacity) const noexcept { return 0; }
virtual bool webviewReceive(const void *buffer, uint32_t size) const noexcept {
return false;
}

/////////////
// Logging //
/////////////
Expand Down Expand Up @@ -677,6 +686,12 @@ namespace clap { namespace helpers {
char *y_name,
uint32_t name_capacity) noexcept;

// clap_plugin_webview
static int32_t
clapWebviewGetUri(const clap_plugin_t *plugin, char *uri, uint32_t uri_capacity);
static bool
clapWebviewReceive(const clap_plugin_t *plugin, const void *buffer, uint32_t size);

// interfaces
static const clap_plugin_audio_ports _pluginAudioPorts;
static const clap_plugin_audio_ports_config _pluginAudioPortsConfig;
Expand Down Expand Up @@ -707,6 +722,7 @@ namespace clap { namespace helpers {
static const clap_plugin_project_location _pluginProjectLocation;
static const clap_plugin_gain_adjustment_metering _pluginGainAdjustmentMetering;
static const clap_plugin_mini_curve_display _pluginMiniCurveDisplay;
static const clap_plugin_webview _pluginWebview;

// state
bool _wasInitialized = false;
Expand Down
28 changes: 28 additions & 0 deletions include/clap/helpers/plugin.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@ namespace clap { namespace helpers {
clapMiniCurveDisplayGetAxisName,
};

template <MisbehaviourHandler h, CheckingLevel l>
const clap_plugin_webview Plugin<h, l>::_pluginWebview = {
clapWebviewGetUri,
clapWebviewReceive,
};

template <MisbehaviourHandler h, CheckingLevel l>
Plugin<h, l>::Plugin(const clap_plugin_descriptor *desc, const clap_host *host) : _host(host) {
_plugin.plugin_data = this;
Expand Down Expand Up @@ -562,6 +568,8 @@ namespace clap { namespace helpers {
return &_pluginGainAdjustmentMetering;
if (!strcmp(id, CLAP_EXT_MINI_CURVE_DISPLAY) && self.implementsMiniCurveDisplay())
return &_pluginMiniCurveDisplay;
if (!strcmp(id, CLAP_EXT_WEBVIEW) && self.implementsWebview())
return &_pluginWebview;
}

return nullptr;
Expand Down Expand Up @@ -1986,6 +1994,26 @@ namespace clap { namespace helpers {
return self.miniCurveDisplayGetAxisName(curve_index, x_name, y_name, name_capacity);
}

//--------------------------------//
// clap_plugin_mini_curve_display //
//--------------------------------//
template <MisbehaviourHandler h, CheckingLevel l>
int32_t
Plugin<h, l>::clapWebviewGetUri(const clap_plugin_t *plugin, char *uri, uint32_t uri_capacity) {
auto &self = from(plugin);
self.ensureMainThread("clap_plugin_webview.get_uri");
return self.webviewGetUri(uri, uri_capacity);
}

template <MisbehaviourHandler h, CheckingLevel l>
bool Plugin<h, l>::clapWebviewReceive(const clap_plugin_t *plugin,
const void *buffer,
uint32_t size) {
auto &self = from(plugin);
self.ensureMainThread("clap_plugin_webview.receive");
return self.webviewReceive(buffer, size);
}

/////////////
// Logging //
/////////////
Expand Down
Loading