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

Configurable audio ports support #65

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions include/clap/helpers/plugin-proxy.hh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ namespace clap { namespace helpers {
uint32_t audioPortsCount(bool isInput) const noexcept;
bool audioPortsGet(uint32_t index, bool isInput, clap_audio_port_info_t *info) const noexcept;

/////////////////////////////
// clap_plugin_configurable_audio_ports //
/////////////////////////////
bool canUseConfigurableAudioPorts() const noexcept;
bool configurableAudioPortsCanApplyConfiguration(clap_audio_port_configuration_request* requests, uint32_t requests_count) const noexcept;
bool configurableAudioPortsApplyConfiguration(clap_audio_port_configuration_request* requests, uint32_t requests_count) const noexcept;

/////////////////////
// clap_plugin_gui //
/////////////////////
Expand Down Expand Up @@ -154,6 +161,7 @@ namespace clap { namespace helpers {
const clap_plugin& _plugin;

const clap_plugin_audio_ports *_pluginAudioPorts = nullptr;
const clap_plugin_configurable_audio_ports *_pluginConfigurableAudioPorts = nullptr;
const clap_plugin_gui *_pluginGui = nullptr;
const clap_plugin_latency *_pluginLatency = nullptr;
const clap_plugin_note_ports *_pluginNotePorts = nullptr;
Expand Down
29 changes: 29 additions & 0 deletions include/clap/helpers/plugin-proxy.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace clap { namespace helpers {
return false;

getExtension(_pluginAudioPorts, CLAP_EXT_AUDIO_PORTS);
getExtension(_pluginConfigurableAudioPorts, CLAP_EXT_CONFIGURABLE_AUDIO_PORTS);
getExtension(_pluginGui, CLAP_EXT_GUI);
getExtension(_pluginLatency, CLAP_EXT_LATENCY);
getExtension(_pluginNotePorts, CLAP_EXT_NOTE_PORTS);
Expand Down Expand Up @@ -48,6 +49,7 @@ namespace clap { namespace helpers {
_plugin.destroy(&_plugin);

_pluginAudioPorts = nullptr;
_pluginConfigurableAudioPorts = nullptr;
_pluginGui = nullptr;
_pluginParams = nullptr;
_pluginPosixFdSupport = nullptr;
Expand Down Expand Up @@ -137,6 +139,33 @@ namespace clap { namespace helpers {
return _pluginAudioPorts->get(&_plugin, index, isInput, info);
}

/////////////////////////////
// clap_plugin_configurable_audio_ports //
/////////////////////////////
template<MisbehaviourHandler h, CheckingLevel l>
bool PluginProxy<h, l>::canUseConfigurableAudioPorts() const noexcept {
if(!_pluginConfigurableAudioPorts) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have to check that the methods aren't null pointers as well.

return false;
}
return true;
}

template<MisbehaviourHandler h, CheckingLevel l>
bool PluginProxy<h, l>::configurableAudioPortsCanApplyConfiguration(clap_audio_port_configuration_request *requests, uint32_t requests_count) const noexcept {
if(!_pluginConfigurableAudioPorts) return false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should call canUseConfigurableAudioPorts() here.

ensureMainThread("clap_plugin_configurable_audio_ports.can_apply_configuration");
return _pluginConfigurableAudioPorts->can_apply_configuration(&_plugin, requests, requests_count);
}

template<MisbehaviourHandler h, CheckingLevel l>
bool PluginProxy<h, l>::configurableAudioPortsApplyConfiguration(clap_audio_port_configuration_request *requests, uint32_t requests_count) const noexcept {
if(!_pluginConfigurableAudioPorts) return false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should call canUseConfigurableAudioPorts() here.

ensureMainThread("clap_plugin_configurable_audio_ports.apply_configuration");
return _pluginConfigurableAudioPorts->apply_configuration(&_plugin, requests, requests_count);
}



/////////////////////
// clap_plugin_gui //
/////////////////////
Expand Down
21 changes: 21 additions & 0 deletions include/clap/helpers/plugin.hh
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,18 @@ namespace clap { namespace helpers {
return false;
}

//------------------------------------//
// clap_configurable_audio_ports //
//------------------------------------//
virtual bool implementsConfigurableAudioPorts() const noexcept { return false; };
virtual bool configurableAudioPortsCanApplyConfiguration(const clap_audio_port_configuration_request* requests,
uint32_t requests_count) noexcept {
return false;
}
virtual bool configurableAudioPortsApplyConfiguration(const clap_audio_port_configuration_request* requests,
uint32_t requests_count) noexcept {
return false;
}
//--------------------//
// clap_plugin_params //
//--------------------//
Expand Down Expand Up @@ -427,6 +439,14 @@ namespace clap { namespace helpers {
bool is_active,
uint32_t sample_size) noexcept;

static bool clapConfigurableAudioPortsCanApplyConfiguration(const clap_plugin_t* plugin,
const clap_audio_port_configuration_request* requests,
uint32_t requests_count) noexcept;

static bool clapConfigurableAudioPortsApplyConfiguration(const clap_plugin_t* plugin,
const clap_audio_port_configuration_request* requests,
uint32_t requests_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 +572,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
38 changes: 38 additions & 0 deletions include/clap/helpers/plugin.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ 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 +478,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 @@ -783,6 +791,36 @@ namespace clap { namespace helpers {
return self.audioPortsActivationSetActive(is_input, port_index, is_active, sample_size);
}

template<MisbehaviourHandler h, CheckingLevel l>
bool Plugin<h, l>::clapConfigurableAudioPortsCanApplyConfiguration(const clap_plugin_t *plugin, const clap_audio_port_configuration_request *requests, uint32_t requests_count) noexcept {
auto& self = from(plugin);
self.ensureMainThread("clap_plugin_configurable_audio_ports.can_apply_configuration");
if(l >= CheckingLevel::Minimal) {
if(self.isActive()) {
self.hostMisbehaving(
"it is illegal to call clap_plugin_configurable_audio_ports.can_apply_configuration "
"if the plugin is active"
);
}
}
return self.configurableAudioPortsCanApplyConfiguration(requests, requests_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 requests_count) noexcept {
auto& self = from(plugin);
self.ensureMainThread("clap_plugin_configurable_audio_ports.apply_configuration");
if(l >= CheckingLevel::Minimal) {
if(self.isActive()) {
self.hostMisbehaving(
"it is illegal to call clap_plugin_configurable_audio_ports.apply_configuration "
"if the plugin is active"
);
}
}
return self.configurableAudioPortsApplyConfiguration(requests, requests_count);
}

template <MisbehaviourHandler h, CheckingLevel l>
uint32_t Plugin<h, l>::clapParamsCount(const clap_plugin *plugin) noexcept {
auto &self = from(plugin);
Expand Down
Loading