Skip to content

Commit

Permalink
clap-validator sends non-sensical pointers (0x1) for output parameter…
Browse files Browse the repository at this point in the history
…s, disable audio-ports-config for this host
  • Loading branch information
Guillaume Piolat committed Nov 4, 2024
1 parent 527f729 commit 56bae56
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 48 deletions.
95 changes: 48 additions & 47 deletions clap/dplug/clap/client.d
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private:
CLAPHost _host;

// Which DAW is it?
DAW _daw;
DAW _daw = DAW.Unknown;

// Returned to the CLAP api, it's a sort of v-table.
clap_plugin_t _plugin;
Expand Down Expand Up @@ -488,25 +488,33 @@ private:
return &api;
}

if (streq(s, CLAP_EXT_AUDIO_PORTS_CONFIG) == 0)
{
__gshared clap_plugin_audio_ports_config_t api;
api.count = &plugin_ports_config_count;
api.get = &plugin_ports_config_get;
api.select = &plugin_ports_config_select;
return &api;
}
// clap-validator calls audio-ports-config with bad pointers.
bool useAudioPortsConfig = _daw != DAW.ClapValidator;

if ( streq(s, CLAP_EXT_AUDIO_PORTS_CONFIG_INFO)
|| streq(s, CLAP_EXT_AUDIO_PORTS_CONFIG_INFO_COMPAT) )
if (useAudioPortsConfig)
{
__gshared clap_plugin_audio_ports_config_info_t api;
api.current_config = &plugin_ports_current_config;
api.get = &plugin_ports_config_info_get;
return &api;
if (streq(s, CLAP_EXT_AUDIO_PORTS_CONFIG) == 0)
{
__gshared clap_plugin_audio_ports_config_t api;
api.count = &plugin_ports_config_count;
api.get = &plugin_ports_config_get;
api.select = &plugin_ports_config_select;
return &api;
}

if ( streq(s, CLAP_EXT_AUDIO_PORTS_CONFIG_INFO)
|| streq(s, CLAP_EXT_AUDIO_PORTS_CONFIG_INFO_COMPAT) )
{
__gshared clap_plugin_audio_ports_config_info_t api;
api.current_config = &plugin_ports_current_config;
api.get = &plugin_ports_config_info_get;
return &api;
}
}

if (streq(s, CLAP_EXT_NOTE_PORTS))
bool hasMIDI = _client.receivesMIDI() || _client.sendsMIDI();

if (hasMIDI && streq(s, CLAP_EXT_NOTE_PORTS))
{
__gshared clap_plugin_note_ports_t api;
api.count = &plugin_note_ports_count;
Expand Down Expand Up @@ -1138,14 +1146,11 @@ private:
mixin(GraphicsMutexLock);
IGraphics gr = _client.getGraphics();
int[2] AR = gr.getPreservedAspectRatio();
with(*hints)
{
can_resize_horizontally = gr.isResizeableHorizontally();
can_resize_vertically = gr.isResizeableVertically();
preserve_aspect_ratio = gr.isAspectRatioPreserved();
aspect_ratio_width = AR[0];
aspect_ratio_height = AR[1];
}
hints.can_resize_horizontally = gr.isResizeableHorizontally();
hints.can_resize_vertically = gr.isResizeableVertically();
hints.preserve_aspect_ratio = gr.isAspectRatioPreserved();
hints.aspect_ratio_width = AR[0];
hints.aspect_ratio_height = AR[1];
return true;
}

Expand Down Expand Up @@ -1329,32 +1334,28 @@ private:
return cast(uint) (legalIOs.length);
}

bool ports_config_get(uint index,
bool ports_config_get(uint index,
clap_audio_ports_config_t* config)
{
LegalIO[] legalIOs = _client.legalIOs();
if (index >= legalIOs.length)
return false;

LegalIO* io = &legalIOs[index];

with (config)
{
id = index;
// Call that "2-2" for stereo, etc
snprintf(name.ptr, CLAP_NAME_SIZE, "%d-%d",
io.numInputChannels, io.numOutputChannels);
int inChannels = io.numInputChannels;
int outChannels = io.numOutputChannels;
input_port_count = inChannels ? 1 : 0;
output_port_count = outChannels ? 1 : 0;
has_main_input = (inChannels != 0);
has_main_output = (outChannels != 0);
main_input_channel_count = inChannels;
main_output_channel_count = outChannels;
main_input_port_type = portTypeChans(inChannels);
main_output_port_type = portTypeChans(outChannels);
}
config.id = index;
// Call that "2-2" for stereo, etc
snprintf(config.name.ptr, CLAP_NAME_SIZE, "%d-%d",
io.numInputChannels, io.numOutputChannels);
int inChannels = io.numInputChannels;
int outChannels = io.numOutputChannels;
config.input_port_count = inChannels ? 1 : 0;
config.output_port_count = outChannels ? 1 : 0;
config.has_main_input = (inChannels != 0);
config.has_main_output = (outChannels != 0);
config.main_input_channel_count = inChannels;
config.main_output_channel_count = outChannels;
config.main_input_port_type = portTypeChans(inChannels);
config.main_output_port_type = portTypeChans(outChannels);
return true;
}

Expand Down Expand Up @@ -1779,16 +1780,16 @@ extern(C) static
return client.ports_config_count();
}

bool plugin_ports_config_get(const(clap_plugin_t)* plugin,
uint index,
clap_audio_ports_config_t* config)
bool plugin_ports_config_get(const(clap_plugin_t)* plugin,
uint index,
clap_audio_ports_config_t* config)
{
mixin(ClientCallback);
return client.ports_config_get(index, config);
}

bool plugin_ports_config_select(const(clap_plugin_t)* plugin,
clap_id config_id)
clap_id config_id)
{
mixin(ClientCallback);
return client.ports_config_select(config_id);
Expand Down
4 changes: 3 additions & 1 deletion client/dplug/client/daw.d
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ enum DAW
StudioOne,
VSTHost,
VST3TestHost,
Ardour
Ardour,
ClapValidator
// These hosts don't report the host name:
// EnergyXT2
// MiniHost
Expand Down Expand Up @@ -211,6 +212,7 @@ DAW identifyDAW(const(char*) s) pure nothrow @nogc
if (hasSubstring(s, "protools")) return DAW.ProTools;
if (hasSubstring(s, "ardour")) return DAW.Ardour;
if (hasSubstring(s, "standalone")) return DAW.Standalone;
if (hasSubstring(s, "clap-validator")) return DAW.ClapValidator;
return DAW.Unknown;
}

0 comments on commit 56bae56

Please sign in to comment.