diff --git a/CHANGELOG.md b/CHANGELOG.md index a4b55521..79b4df57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,12 @@ Versioning](https://semver.org/spec/v2.0.0.html). - The `editor_double_embed` option added in yabridge 1.4.0 has been removed as the `editor_coordinate_hack` option supersedes it. +### Changed + +- VST3 Data (SysEx) events now use the same small buffer optimization we use for + VST2 SysEx events. This avoids allocations when a VST3 plugin sends or + receives a SysEx event. + ### Fixed - Fixed _New Sonic Arts' Vice_ plugin freezing when loading the plugin. This diff --git a/src/common/serialization/vst3/event-list.cpp b/src/common/serialization/vst3/event-list.cpp index 756cc002..cc9e0b42 100644 --- a/src/common/serialization/vst3/event-list.cpp +++ b/src/common/serialization/vst3/event-list.cpp @@ -24,9 +24,12 @@ YaDataEvent::YaDataEvent(const Steinberg::Vst::DataEvent& event) noexcept : type(event.type), buffer(event.bytes, event.bytes + event.size) {} Steinberg::Vst::DataEvent YaDataEvent::get() const noexcept { - return Steinberg::Vst::DataEvent{.size = static_cast(buffer.size()), - .type = type, - .bytes = buffer.data()}; + static_assert(sizeof(decltype(buffer)::value_type) == sizeof(uint8)); + + return Steinberg::Vst::DataEvent{ + .size = static_cast(buffer.size()), + .type = type, + .bytes = reinterpret_cast(buffer.data())}; } YaNoteExpressionTextEvent::YaNoteExpressionTextEvent() noexcept {} diff --git a/src/common/serialization/vst3/event-list.h b/src/common/serialization/vst3/event-list.h index 1fc84020..ec31e493 100644 --- a/src/common/serialization/vst3/event-list.h +++ b/src/common/serialization/vst3/event-list.h @@ -31,7 +31,7 @@ /** * A wrapper around `DataEvent` for serialization purposes, as this event - * contains a heap array. + * contains a heap array. This would presumably be used for SysEx. */ struct YaDataEvent { YaDataEvent() noexcept; @@ -50,12 +50,18 @@ struct YaDataEvent { Steinberg::Vst::DataEvent get() const noexcept; uint32 type; - std::vector buffer; + + /** + * We'll just abuse the standard library's Small String Optimization to + * avoid allocations for small messages, just like we do for VST2 SysEx + * events. + */ + std::string buffer; template void serialize(S& s) { s.value4b(type); - s.container1b(buffer, 1 << 16); + s.text1b(buffer, 1 << 16); } };