Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add base implementation of configurable audio ports extension #64

Merged
merged 5 commits into from
Jun 18, 2024
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
28 changes: 28 additions & 0 deletions include/clap/helpers/plugin.hh
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,19 @@ namespace clap { namespace helpers {
return false;
}

//--------------------------------------//
// clap_plugin_configurable_audio_ports //
//--------------------------------------//
virtual bool implementsConfigurableAudioPorts() const noexcept { return false; }
virtual bool configurableAudioPortsCanApplyConfiguration(const clap_audio_port_configuration_request *requests,
uint32_t request_count) const noexcept {
return false;
}
virtual bool configurableAudioPortsApplyConfiguration(const clap_audio_port_configuration_request *requests,
uint32_t request_count) noexcept {
return false;
}

//--------------------//
// clap_plugin_params //
//--------------------//
Expand Down Expand Up @@ -315,6 +328,12 @@ namespace clap { namespace helpers {
void ensureAudioThread(const char *method) const noexcept;
void ensureParamThread(const char *method) const noexcept;

////////////////////
// General Checks //
////////////////////
void ensureIsInactive(const char *methodName) const noexcept;
Schroedingers-Cat marked this conversation as resolved.
Show resolved Hide resolved
void ensureIsActive(const char *methodName) const noexcept;

///////////////
// Utilities //
///////////////
Expand Down Expand Up @@ -427,6 +446,14 @@ namespace clap { namespace helpers {
bool is_active,
uint32_t sample_size) noexcept;

// clap_plugin_configurable_audio_ports
static bool clapConfigurableAudioPortsCanApplyConfiguration(const clap_plugin_t *plugin,
const clap_audio_port_configuration_request *requests,
uint32_t request_count) noexcept;
static bool clapConfigurableAudioPortsApplyConfiguration(const clap_plugin_t *plugin,
const clap_audio_port_configuration_request *requests,
uint32_t request_count) noexcept;

// clap_plugin_params
static uint32_t clapParamsCount(const clap_plugin *plugin) noexcept;
static bool clapParamsInfo(const clap_plugin *plugin,
Expand Down Expand Up @@ -552,6 +579,7 @@ namespace clap { namespace helpers {
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_gui _pluginGui;
static const clap_plugin_latency _pluginLatency;
static const clap_plugin_note_name _pluginNoteName;
Expand Down
84 changes: 84 additions & 0 deletions include/clap/helpers/plugin.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ namespace clap { namespace helpers {
clapAudioPortsActivationSetActive,
};

template <MisbehaviourHandler h, CheckingLevel l>
const clap_plugin_configurable_audio_ports Plugin<h, l>::_pluginConfigurableAudioPorts = {
clapConfigurableAudioPortsCanApplyConfiguration,
clapConfigurableAudioPortsApplyConfiguration,
};


template <MisbehaviourHandler h, CheckingLevel l>
const clap_plugin_params Plugin<h, l>::_pluginParams = {
clapParamsCount,
Expand Down Expand Up @@ -472,6 +479,8 @@ namespace clap { namespace helpers {
return &_pluginAudioPortsActivation;
if (!strcmp(id, CLAP_EXT_AUDIO_PORTS_CONFIG) && self.implementsAudioPortsConfig())
return &_pluginAudioPortsConfig;
if (!strcmp(id, CLAP_EXT_CONFIGURABLE_AUDIO_PORTS) && self.implementsConfigurableAudioPorts())
return &_pluginConfigurableAudioPorts;
if (!strcmp(id, CLAP_EXT_PARAMS) && self.implementsParams())
return &_pluginParams;
if ((!strcmp(id, CLAP_EXT_PARAM_INDICATION) ||
Expand Down Expand Up @@ -791,6 +800,52 @@ namespace clap { namespace helpers {
return self.paramsCount();
}

//--------------------------------------//
// clap_plugin_configurable_audio_ports //
//--------------------------------------//

template <MisbehaviourHandler h, CheckingLevel l>
bool Plugin<h, l>::clapConfigurableAudioPortsCanApplyConfiguration(
const clap_plugin_t *plugin,
const clap_audio_port_configuration_request *requests,
uint32_t request_count) noexcept {
Schroedingers-Cat marked this conversation as resolved.
Show resolved Hide resolved
auto &self = from(plugin);
auto methodName = "clap_plugin_configurable_audio_ports.can_apply_configuration";
self.ensureMainThread(methodName);
self.ensureIsInactive(methodName);

return self.configurableAudioPortsCanApplyConfiguration(requests, request_count);
}

template <MisbehaviourHandler h, CheckingLevel l>
bool Plugin<h, l>::clapConfigurableAudioPortsApplyConfiguration(
const clap_plugin_t *plugin,
const clap_audio_port_configuration_request *requests,
uint32_t request_count) noexcept {
auto &self = from(plugin);
auto methodName = "clap_plugin_configurable_audio_ports.apply_configuration";
self.ensureMainThread(methodName);
self.ensureIsInactive(methodName);

bool canApplyConfiguration;
if (l >= CheckingLevel::Minimal) {
canApplyConfiguration =
self.configurableAudioPortsCanApplyConfiguration(requests, request_count);
}

bool applyConfigurationSuccess =
self.configurableAudioPortsApplyConfiguration(requests, request_count);

if (l >= CheckingLevel::Minimal && canApplyConfiguration != applyConfigurationSuccess) {
self._host.pluginMisbehaving(
"Plugin's functions clap_plugin_configurable_audio_ports.can_apply_configuration and "
"clap_plugin_configurable_audio_ports.apply_configuration returned different values "
"for the same configuration.");
}

return applyConfigurationSuccess;
}

//--------------------//
// clap_plugin_params //
//--------------------//
Expand Down Expand Up @@ -1793,6 +1848,35 @@ namespace clap { namespace helpers {
hostMisbehaving(msg.str());
}

////////////////////
// General Checks //
////////////////////
template <MisbehaviourHandler h, CheckingLevel l>
void Plugin<h, l>::ensureIsInactive(const char *methodName) const noexcept {
if (l == CheckingLevel::None)
return;

if (!isActive())
return;

std::ostringstream msg;
msg << "it is illegal to call " << methodName << "() while the plugin is active!";
hostMisbehaving(msg.str());
}

template <MisbehaviourHandler h, CheckingLevel l>
void Plugin<h, l>::ensureIsActive(const char *methodName) const noexcept {
if (l == CheckingLevel::None)
return;

if (isActive())
return;

std::ostringstream msg;
msg << "it is illegal to call " << methodName << "() while the plugin is not active!";
hostMisbehaving(msg.str());
}

///////////////
// Utilities //
///////////////
Expand Down
Loading