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
10 changes: 5 additions & 5 deletions .github/workflows/pullreq.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ jobs:
# name: Windows gcc/minGW
# exe: .exe

- os: windows-latest
cmakeargs: -GNinja -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang
install_ninja: true
name: Windows clang
exe: .exe
# - os: windows-latest
# cmakeargs: -GNinja -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang
# install_ninja: true
# name: Windows clang
# exe: .exe

- os: ubuntu-latest
cmakeargs: -DCMAKE_CXX_COMPILER=g++-12 -DCMAKE_C_COMPILER=gcc-12 -DCLAP_HELPERS_TESTS_CXX_STANDARD=11
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,6 @@ ignore/
build/
out/
.DS_Store

# Meson
.meson-subproject*
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
cmake_minimum_required(VERSION 3.17)
cmake_policy(SET CMP0100 NEW) # handle .hh files
project(clap-helpers C CXX)
include(GNUInstallDirs)

option(CLAP_HELPERS_BUILD_TESTS "Build tests for the CLAP Helper" FALSE)
option(CLAP_HELPERS_DOWNLOAD_DEPENDENCIES "Resolve CLAP Targets with CPM if not defined" FALSE)
Expand Down Expand Up @@ -97,5 +98,5 @@ if (${CLAP_HELPERS_BUILD_TESTS})
)
endif()

install(DIRECTORY include DESTINATION ".")
install(FILES "cmake/clap-helpers-config.cmake" DESTINATION "lib/cmake/clap-helpers")
install(DIRECTORY "include/" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
install(FILES "cmake/clap-helpers-config.cmake" DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/clap-helpers")
4 changes: 2 additions & 2 deletions cmake/external/CPM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#
# SPDX-FileCopyrightText: Copyright (c) 2019-2023 Lars Melchior and contributors

set(CPM_DOWNLOAD_VERSION 0.38.6)
set(CPM_HASH_SUM "11c3fa5f1ba14f15d31c2fb63dbc8628ee133d81c8d764caad9a8db9e0bacb07")
set(CPM_DOWNLOAD_VERSION 0.42.0)
set(CPM_HASH_SUM "2020B4FC42DBA44817983E06342E682ECFC3D2F484A581F11CC5731FBE4DCE8A")

if(CPM_SOURCE_CACHE)
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
Expand Down
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
21 changes: 20 additions & 1 deletion include/clap/helpers/host.hh
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ namespace clap { namespace helpers {
virtual void requestCallback() noexcept = 0;

virtual bool enableDraftExtensions() const noexcept { return false; }
virtual const void* getExtension(const char* extensionId) const noexcept { return nullptr; }

// clap_host_audio_ports
virtual bool implementsAudioPorts() const noexcept { return false; }
Expand Down Expand Up @@ -107,6 +108,14 @@ namespace clap { namespace helpers {
virtual bool implementsThreadPool() const noexcept { return false; }
virtual bool threadPoolRequestExec(uint32_t numTasks) noexcept { return false; }

// clap_host_surround
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 @@ -173,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 @@ -186,6 +197,12 @@ namespace clap { namespace helpers {
// clap_host_thread_pool
static bool clapThreadPoolRequestExec(const clap_host *host, uint32_t num_tasks) noexcept;

// 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 @@ -199,5 +216,7 @@ namespace clap { namespace helpers {
static const clap_host_tail _hostTail;
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
37 changes: 37 additions & 0 deletions include/clap/helpers/host.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ namespace clap { namespace helpers {
clapThreadPoolRequestExec,
};

template <MisbehaviourHandler h, CheckingLevel l>
const clap_host_surround Host<h, l>::_hostSurround = {
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 @@ -132,6 +142,8 @@ namespace clap { namespace helpers {
const void *Host<h, l>::clapGetExtension(const clap_host_t *host,
const char *extension_id) noexcept {
auto &self = from(host);
if (auto ext = self.getExtension(extension_id))
return ext;
if (!std::strcmp(extension_id, CLAP_EXT_AUDIO_PORTS) && self.implementsAudioPorts())
return &_hostAudioPorts;
if (!std::strcmp(extension_id, CLAP_EXT_GUI) && self.implementsGui())
Expand All @@ -158,10 +170,15 @@ namespace clap { namespace helpers {
return &_hostThreadCheck;
if (!strcmp(extension_id, CLAP_EXT_THREAD_POOL) && self.implementsThreadPool())
return &_hostThreadPool;
if (!std::strcmp(extension_id, CLAP_EXT_SURROUND) && self.implementsSurround())
return &_hostSurround;

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

return nullptr;
}

Expand Down Expand Up @@ -394,6 +411,26 @@ namespace clap { namespace helpers {
return self.threadPoolRequestExec(num_tasks);
}

//--------------------//
// clap_host_surround //
//--------------------//
template <MisbehaviourHandler h, CheckingLevel l>
void Host<h, l>::clapSurroundChanged(const clap_host *host) noexcept {
auto &self = from(host);
self.ensureMainThread("surround.changed");
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
49 changes: 49 additions & 0 deletions include/clap/helpers/plugin.hh
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,18 @@ namespace clap { namespace helpers {
return false;
}

//----------------------//
// clap_plugin_surround //
//----------------------//
virtual bool implementsSurround() const noexcept { return false; }
virtual bool isChannelMaskSupported(uint64_t channel_mask) const noexcept { return false; }
virtual uint32_t getChannelMap(bool is_input,
uint32_t port_index,
uint8_t *channel_map,
uint32_t channel_map_capacity) const noexcept {
return 0;
}

//--------------------//
// clap_plugin_params //
//--------------------//
Expand Down Expand Up @@ -352,6 +364,21 @@ 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 webviewGetResource(const char *path,
char *mime,
uint32_t mime_capacity,
const clap_ostream_t *data_stream) {
return false;
}
virtual bool webviewReceive(const void *buffer, uint32_t size) const noexcept {
return false;
}

/////////////
// Logging //
/////////////
Expand Down Expand Up @@ -505,6 +532,15 @@ namespace clap { namespace helpers {
const clap_audio_port_configuration_request *requests,
uint32_t request_count) noexcept;

// clap_plugin_surround
static bool clapSurroundIsChannelMaskSupported(const clap_plugin_t *plugin,
uint64_t channel_mask) noexcept;
static uint32_t clapSurroundGetChannelMap(const clap_plugin_t *plugin,
bool is_input,
uint32_t port_index,
uint8_t *channel_map,
uint32_t channel_map_capacity) noexcept;

// clap_plugin_params
static uint32_t clapParamsCount(const clap_plugin *plugin) noexcept;
static bool clapParamsInfo(const clap_plugin *plugin,
Expand Down Expand Up @@ -656,11 +692,23 @@ 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 clapWebviewGetResource(const clap_plugin_t *plugin,
const char *path,
char *mime,
uint32_t mime_capacity,
const clap_ostream_t *data_stream);
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;
static const clap_plugin_audio_ports_activation _pluginAudioPortsActivation;
static const clap_plugin_configurable_audio_ports _pluginConfigurableAudioPorts;
static const clap_plugin_surround_t _pluginSurroundConfig;
static const clap_plugin_gui _pluginGui;
static const clap_plugin_latency _pluginLatency;
static const clap_plugin_note_name _pluginNoteName;
Expand All @@ -685,6 +733,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
Loading