Skip to content

Commit

Permalink
CLAP 1.2.5 (#81)
Browse files Browse the repository at this point in the history
Add support for mini curve display.
  • Loading branch information
abique authored Feb 18, 2025
1 parent 93026e9 commit 6c4edba
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 4 deletions.
8 changes: 8 additions & 0 deletions include/clap/helpers/host-proxy.hh
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,13 @@ namespace clap { namespace helpers {
uint32_t max_concurrency_hint) const noexcept;
void *scratchMemoryAccess() const noexcept;

//////////////////////////////////
// clap_host_mini_curve_display //
//////////////////////////////////
bool canUseMiniCurveDisplay() const noexcept;
void miniCurveDisplaySetDynamic(bool is_dynamic) const noexcept;
void miniCurveDisplayChanged(uint32_t flags) const noexcept;

protected:
void ensureMainThread(const char *method) const noexcept;
void ensureAudioThread(const char *method) const noexcept;
Expand Down Expand Up @@ -235,5 +242,6 @@ namespace clap { namespace helpers {
const clap_host_preset_load *_hostPresetLoad = nullptr;
const clap_host_undo *_hostUndo = nullptr;
const clap_host_scratch_memory *_hostScratchMemory = nullptr;
const clap_host_mini_curve_display *_hostMiniCurveDisplay = nullptr;
};
}} // namespace clap::helpers
30 changes: 30 additions & 0 deletions include/clap/helpers/host-proxy.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ namespace clap { namespace helpers {
getExtension(_hostPresetLoad, CLAP_EXT_PRESET_LOAD);
getExtension(_hostUndo, CLAP_EXT_UNDO);
getExtension(_hostScratchMemory, CLAP_EXT_SCRATCH_MEMORY);
getExtension(_hostMiniCurveDisplay, CLAP_EXT_MINI_CURVE_DISPLAY);
}

template <MisbehaviourHandler h, CheckingLevel l>
Expand Down Expand Up @@ -776,4 +777,33 @@ namespace clap { namespace helpers {
return _hostScratchMemory->access(_host);
}

//////////////////////////////////
// clap_host_mini_curve_display //
//////////////////////////////////
template <MisbehaviourHandler h, CheckingLevel l>
bool HostProxy<h, l>::canUseMiniCurveDisplay() const noexcept {
if (!_hostMiniCurveDisplay)
return false;

if (_hostMiniCurveDisplay->set_dynamic && _hostMiniCurveDisplay->changed)
return true;

hostMisbehaving("clap_host_mini_curve_display is partially implemented!");
return false;
}

template <MisbehaviourHandler h, CheckingLevel l>
void HostProxy<h, l>::miniCurveDisplaySetDynamic(bool is_dynamic) const noexcept {
assert(canUseMiniCurveDisplay());
ensureMainThread("mini_curve_display.set_dynamic");
_hostMiniCurveDisplay->set_dynamic(_host, is_dynamic);
}

template <MisbehaviourHandler h, CheckingLevel l>
void HostProxy<h, l>::miniCurveDisplayChanged(uint32_t flags) const noexcept {
assert(canUseMiniCurveDisplay());
ensureMainThread("mini_curve_display.set_dynamic");
_hostMiniCurveDisplay->changed(_host, flags);
}

}} // namespace clap::helpers
25 changes: 25 additions & 0 deletions include/clap/helpers/plugin.hh
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,19 @@ namespace clap { namespace helpers {
virtual bool implementsGainAdjustmentMetering() const noexcept { return false; }
virtual double gainAdjustmentMeteringGet() noexcept { return 0; }

//--------------------------------//
// clap_plugin_mini_curve_display //
//--------------------------------//
virtual bool implementsMiniCurveDisplay() const noexcept { return false; }
virtual bool miniCurveDisplayRender(uint16_t *data, uint32_t data_size) noexcept {
return false;
}
virtual void miniCurveDisplaySetObserved(bool is_observed) noexcept {}
virtual bool
miniCurveDisplayGetAxisName(char *x_name, char *y_name, uint32_t name_capacity) noexcept {
return false;
}

/////////////
// Logging //
/////////////
Expand Down Expand Up @@ -626,6 +639,17 @@ namespace clap { namespace helpers {
// clap_plugin_gain_adjustment_metering
static double clapGainAdjustmentMeteringGet(const clap_plugin_t *plugin) noexcept;

// clap_plugin_mini_curve_display
static bool clapMiniCurveDisplayRender(const clap_plugin_t *plugin,
uint16_t *data,
uint32_t data_size) noexcept;
static void clapMiniCurveDisplaySetObserved(const clap_plugin_t *plugin,
bool is_observed) noexcept;
static bool clapMiniCurveDisplayGetAxisName(const clap_plugin_t *plugin,
char *x_name,
char *y_name,
uint32_t name_capacity) noexcept;

// interfaces
static const clap_plugin_audio_ports _pluginAudioPorts;
static const clap_plugin_audio_ports_config _pluginAudioPortsConfig;
Expand Down Expand Up @@ -654,6 +678,7 @@ namespace clap { namespace helpers {
static const clap_plugin_undo_context _pluginUndoContext;
static const clap_plugin_project_location _pluginProjectLocation;
static const clap_plugin_gain_adjustment_metering _pluginGainAdjustmentMetering;
static const clap_plugin_mini_curve_display _pluginMiniCurveDisplay;

// state
bool _wasInitialized = false;
Expand Down
68 changes: 66 additions & 2 deletions include/clap/helpers/plugin.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,13 @@ namespace clap { namespace helpers {
clapGainAdjustmentMeteringGet,
};

template <MisbehaviourHandler h, CheckingLevel l>
const clap_plugin_mini_curve_display Plugin<h, l>::_pluginMiniCurveDisplay = {
clapMiniCurveDisplayRender,
clapMiniCurveDisplaySetObserved,
clapMiniCurveDisplayGetAxisName,
};

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 @@ -542,6 +549,8 @@ namespace clap { namespace helpers {
if (!strcmp(id, CLAP_EXT_GAIN_ADJUSTMENT_METERING) &&
self.implementsGainAdjustmentMetering())
return &_pluginGainAdjustmentMetering;
if (!strcmp(id, CLAP_EXT_MINI_CURVE_DISPLAY) && self.implementsMiniCurveDisplay())
return &_pluginMiniCurveDisplay;
}

return self.extension(id);
Expand Down Expand Up @@ -1817,8 +1826,8 @@ namespace clap { namespace helpers {

template <MisbehaviourHandler h, CheckingLevel l>
void Plugin<h, l>::clapProjectLocationSet(const clap_plugin_t *plugin,
const clap_project_location_element_t *path,
uint32_t num_elements) noexcept {
const clap_project_location_element_t *path,
uint32_t num_elements) noexcept {
auto &self = from(plugin);
self.ensureMainThread("clap_plugin_location.set_location");

Expand Down Expand Up @@ -1857,6 +1866,61 @@ namespace clap { namespace helpers {
return gain;
}

//--------------------------------//
// clap_plugin_mini_curve_display //
//--------------------------------//
template <MisbehaviourHandler h, CheckingLevel l>
bool Plugin<h, l>::clapMiniCurveDisplayRender(const clap_plugin_t *plugin,
uint16_t *data,
uint32_t data_size) noexcept {
auto &self = from(plugin);
self.ensureMainThread("clap_plugin_mini_curve_display.render");

if (l >= CheckingLevel::Minimal) {
if (!data) {
self.hostMisbehaving(
"clap_plugin_mini_curve_display.render() called with null data pointer!!!");
return false;
}

if (data_size == 0) {
self.hostMisbehaving("clap_plugin_mini_curve_display.render() called an empty data "
"array, meaningless...");
return false;
}
}

return self.miniCurveDisplayRender(data, data_size);
}

template <MisbehaviourHandler h, CheckingLevel l>
void Plugin<h, l>::clapMiniCurveDisplaySetObserved(const clap_plugin_t *plugin,
bool is_observed) noexcept {
auto &self = from(plugin);
self.ensureMainThread("clap_plugin_mini_curve_display.set_observed");

self.miniCurveDisplaySetObserved(is_observed);
}

template <MisbehaviourHandler h, CheckingLevel l>
bool Plugin<h, l>::clapMiniCurveDisplayGetAxisName(const clap_plugin_t *plugin,
char *x_name,
char *y_name,
uint32_t name_capacity) noexcept {
auto &self = from(plugin);
self.ensureMainThread("clap_plugin_mini_curve_display.get_axis_name");

if (l >= CheckingLevel::Minimal) {
if (!x_name || !y_name) {
self.hostMisbehaving(
"clap_plugin_mini_curve_display.get_axis_name() called with null name pointer(s)");
return false;
}
}

return self.miniCurveDisplayGetAxisName(x_name, y_name, name_capacity);
}

/////////////
// Logging //
/////////////
Expand Down
4 changes: 2 additions & 2 deletions include/clap/helpers/version-check.hh
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

#include "clap/version.h"

#if CLAP_VERSION_LT(1,2,4)
static_assert(false, "Clap version must be at least 1.2.4");
#if CLAP_VERSION_LT(1,2,5)
static_assert(false, "Clap version must be at least 1.2.5");
#endif

#if CLAP_VERSION_GE(2,0,0)
Expand Down

0 comments on commit 6c4edba

Please sign in to comment.