Browse Source

Fix edge cases detected by clap validator

Signed-off-by: falkTX <falktx@falktx.com>
pull/443/head
falkTX 1 year ago
parent
commit
07436d430a
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
5 changed files with 34 additions and 27 deletions
  1. +22
    -12
      distrho/src/DistrhoPluginCLAP.cpp
  2. +3
    -2
      distrho/src/DistrhoPluginVST3.cpp
  3. +1
    -1
      examples/CVPort/Makefile
  4. +6
    -0
      examples/CairoUI/DistrhoPluginInfo.h
  5. +2
    -12
      examples/CairoUI/Makefile

+ 22
- 12
distrho/src/DistrhoPluginCLAP.cpp View File

@@ -957,13 +957,13 @@ public:
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:
@@ -971,9 +971,10 @@ public:
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:
@@ -984,7 +985,7 @@ public:
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:
@@ -1232,11 +1233,13 @@ public:

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));
}
}

@@ -1504,7 +1507,7 @@ public:

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);
}

@@ -1517,6 +1520,7 @@ public:
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)
@@ -1524,14 +1528,15 @@ public:
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
@@ -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
};
@@ -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);



+ 3
- 2
distrho/src/DistrhoPluginVST3.cpp View File

@@ -943,6 +943,7 @@ public:
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)
@@ -959,7 +960,7 @@ public:
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)
{
@@ -1245,7 +1246,7 @@ public:
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);


+ 1
- 1
examples/CVPort/Makefile View File

@@ -23,7 +23,7 @@ include ../../Makefile.plugins.mk
# --------------------------------------------------------------
# Enable all possible plugin types

TARGETS = jack lv2_dsp
TARGETS = jack lv2_sep

all: $(TARGETS)



+ 6
- 0
examples/CairoUI/DistrhoPluginInfo.h View File

@@ -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


+ 2
- 12
examples/CairoUI/Makefile View File

@@ -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)



Loading…
Cancel
Save