Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix edge cases detected by clap validator
Signed-off-by: falkTX <falktx@falktx.com>
  • Loading branch information
falkTX committed Sep 29, 2023
1 parent 50a55c6 commit 07436d4
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 27 deletions.
34 changes: 22 additions & 12 deletions distrho/src/DistrhoPluginCLAP.cpp
Expand Up @@ -957,23 +957,24 @@ class PluginCLAP : ClapEventQueue
case CLAP_EVENT_NOTE_ON:
#if DISTRHO_PLUGIN_WANT_MIDI_INPUT
// BUG: even though we only report CLAP_NOTE_DIALECT_MIDI as supported, Bitwig sends us this anyway
addNoteEvent(static_cast<const clap_event_note_t*>(static_cast<const void*>(event)), true);
addNoteEvent(reinterpret_cast<const clap_event_note_t*>(event), true);
#endif
break;
case CLAP_EVENT_NOTE_OFF:
#if DISTRHO_PLUGIN_WANT_MIDI_INPUT
// BUG: even though we only report CLAP_NOTE_DIALECT_MIDI as supported, Bitwig sends us this anyway
addNoteEvent(static_cast<const clap_event_note_t*>(static_cast<const void*>(event)), false);
addNoteEvent(reinterpret_cast<const clap_event_note_t*>(event), false);
#endif
break;
case CLAP_EVENT_NOTE_CHOKE:
case CLAP_EVENT_NOTE_END:
case CLAP_EVENT_NOTE_EXPRESSION:
break;
case CLAP_EVENT_PARAM_VALUE:
DISTRHO_SAFE_ASSERT_UINT2_BREAK(event->size == sizeof(clap_event_param_value),
event->size, sizeof(clap_event_param_value));
setParameterValueFromEvent(static_cast<const clap_event_param_value*>(static_cast<const void*>(event)));
DISTRHO_SAFE_ASSERT_UINT2_BREAK(event->size == sizeof(clap_event_param_value_t),
event->size, sizeof(clap_event_param_value_t));
if (event->space_id == 0)
setParameterValueFromEvent(reinterpret_cast<const clap_event_param_value_t*>(event));
break;
case CLAP_EVENT_PARAM_MOD:
case CLAP_EVENT_PARAM_GESTURE_BEGIN:
Expand All @@ -984,7 +985,7 @@ class PluginCLAP : ClapEventQueue
DISTRHO_SAFE_ASSERT_UINT2_BREAK(event->size == sizeof(clap_event_midi_t),
event->size, sizeof(clap_event_midi_t));
#if DISTRHO_PLUGIN_WANT_MIDI_INPUT
addMidiEvent(static_cast<const clap_event_midi_t*>(static_cast<const void*>(event)));
addMidiEvent(reinterpret_cast<const clap_event_midi_t*>(event));
#endif
break;
case CLAP_EVENT_MIDI_SYSEX:
Expand Down Expand Up @@ -1232,11 +1233,13 @@ class PluginCLAP : ClapEventQueue

if (event->type != CLAP_EVENT_PARAM_VALUE)
continue;
if (event->space_id != 0)
continue;

DISTRHO_SAFE_ASSERT_UINT2_BREAK(event->size == sizeof(clap_event_param_value),
event->size, sizeof(clap_event_param_value));

setParameterValueFromEvent(static_cast<const clap_event_param_value*>(static_cast<const void*>(event)));
setParameterValueFromEvent(reinterpret_cast<const clap_event_param_value_t*>(event));
}
}

Expand Down Expand Up @@ -1504,7 +1507,7 @@ class PluginCLAP : ClapEventQueue

for (int32_t wrtntotal = 0, wrtn; wrtntotal < size; wrtntotal += wrtn)
{
wrtn = stream->write(stream, buffer, size - wrtntotal);
wrtn = stream->write(stream, buffer + wrtntotal, size - wrtntotal);
DISTRHO_SAFE_ASSERT_INT_RETURN(wrtn > 0, wrtn, false);
}

Expand All @@ -1517,21 +1520,23 @@ class PluginCLAP : ClapEventQueue
ClapUI* const ui = fUI.get();
#endif
String key, value;
bool empty = true;
bool hasValue = false;
bool fillingKey = true; // if filling key or value
char queryingType = 'i'; // can be 'n', 's' or 'p' (none, states, parameters)

char buffer[512], orig;
buffer[sizeof(buffer)-1] = '\xff';

for (int32_t terminated = 0, read; terminated == 0;)
for (int32_t terminated = 0; terminated == 0;)
{
read = stream->read(stream, buffer, sizeof(buffer)-1);
const int32_t read = stream->read(stream, buffer, sizeof(buffer)-1);
DISTRHO_SAFE_ASSERT_INT_RETURN(read >= 0, read, false);

if (read == 0)
return true;
return !empty;

empty = false;
for (int32_t i = 0; i < read; ++i)
{
// found terminator, stop here
Expand Down Expand Up @@ -2502,6 +2507,8 @@ static const clap_plugin_descriptor_t* CLAP_ABI clap_get_plugin_descriptor(const
DISTRHO_PLUGIN_CLAP_FEATURES,
#elif DISTRHO_PLUGIN_IS_SYNTH
"instrument",
#else
"audio-effect",
#endif
nullptr
};
Expand All @@ -2528,8 +2535,11 @@ static const clap_plugin_descriptor_t* CLAP_ABI clap_get_plugin_descriptor(const

static const clap_plugin_t* CLAP_ABI clap_create_plugin(const clap_plugin_factory_t* const factory,
const clap_host_t* const host,
const char*)
const char* const plugin_id)
{
if (plugin_id == nullptr || std::strcmp(plugin_id, DISTRHO_PLUGIN_CLAP_ID) != 0)
return nullptr;

clap_plugin_t* const pluginptr = static_cast<clap_plugin_t*>(std::malloc(sizeof(clap_plugin_t)));
DISTRHO_SAFE_ASSERT_RETURN(pluginptr != nullptr, nullptr);

Expand Down
5 changes: 3 additions & 2 deletions distrho/src/DistrhoPluginVST3.cpp
Expand Up @@ -943,6 +943,7 @@ class PluginVst3
const bool connectedToUI = fConnectionFromCtrlToView != nullptr && fConnectedToUI;
#endif
String key, value;
bool empty = true;
bool hasValue = false;
bool fillingKey = true; // if filling key or value
char queryingType = 'i'; // can be 'n', 's' or 'p' (none, states, parameters)
Expand All @@ -959,7 +960,7 @@ class PluginVst3
DISTRHO_SAFE_ASSERT_INT_RETURN(read > 0, read, V3_INTERNAL_ERR);

if (read == 0)
return V3_OK;
return empty ? V3_INVALID_ARG : V3_OK;

for (int32_t i = 0; i < read; ++i)
{
Expand Down Expand Up @@ -1245,7 +1246,7 @@ class PluginVst3
for (int32_t wrtntotal = 0, wrtn; wrtntotal < size; wrtntotal += wrtn)
{
wrtn = 0;
res = v3_cpp_obj(stream)->write(stream, const_cast<char*>(buffer), size - wrtntotal, &wrtn);
res = v3_cpp_obj(stream)->write(stream, const_cast<char*>(buffer) + wrtntotal, size - wrtntotal, &wrtn);

DISTRHO_SAFE_ASSERT_INT_RETURN(res == V3_OK, res, res);
DISTRHO_SAFE_ASSERT_INT_RETURN(wrtn > 0, wrtn, V3_INTERNAL_ERR);
Expand Down
2 changes: 1 addition & 1 deletion examples/CVPort/Makefile
Expand Up @@ -23,7 +23,7 @@ include ../../Makefile.plugins.mk
# --------------------------------------------------------------
# Enable all possible plugin types

TARGETS = jack lv2_dsp
TARGETS = jack lv2_sep

all: $(TARGETS)

Expand Down
6 changes: 6 additions & 0 deletions examples/CairoUI/DistrhoPluginInfo.h
Expand Up @@ -39,6 +39,12 @@
*/
#define DISTRHO_PLUGIN_URI "http://distrho.sf.net/examples/CairoUI"

/**
The plugin id when exporting in CLAP format, in reverse URI form.
@note This macro is required when building CLAP plugins
*/
#define DISTRHO_PLUGIN_CLAP_ID "studio.kx.distrho.examples.cairo-ui"

/**
Wherever the plugin has a custom %UI.
@see DISTRHO_UI_USE_NANOVG
Expand Down
14 changes: 2 additions & 12 deletions examples/CairoUI/Makefile
Expand Up @@ -29,21 +29,11 @@ include ../../Makefile.plugins.mk
# --------------------------------------------------------------
# Enable all possible plugin types

ifeq ($(HAVE_CAIRO),true)

TARGETS += jack

ifneq ($(MACOS_OR_WINDOWS),true)
ifeq ($(HAVE_LIBLO),true)
TARGETS += clap
TARGETS += dssi
endif # HAVE_LIBLO
endif # MACOS_OR_WINDOWS

TARGETS += jack
TARGETS += lv2_sep
TARGETS += vst2
TARGETS += vst3

endif # HAVE_CAIRO

all: $(TARGETS)

Expand Down

0 comments on commit 07436d4

Please sign in to comment.