From 149be2f8f923adc0eaf6b77b65712c4cb0ebf460 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Tue, 12 Jan 2021 16:01:34 +0100 Subject: [PATCH] Add a function for copying channel contexts For proxying `IInfoListener::setChannelContextInfos`. --- .../serialization/vst3/attribute-list.cpp | 64 +++++++++++++++++++ .../serialization/vst3/attribute-list.h | 11 ++++ 2 files changed, 75 insertions(+) diff --git a/src/common/serialization/vst3/attribute-list.cpp b/src/common/serialization/vst3/attribute-list.cpp index 2e0ef421..f46676c7 100644 --- a/src/common/serialization/vst3/attribute-list.cpp +++ b/src/common/serialization/vst3/attribute-list.cpp @@ -16,6 +16,37 @@ #include "attribute-list.h" +#include "pluginterfaces/vst/ivstchannelcontextinfo.h" + +/** + * Keys for channel context attributes passed in + * `IInfoListener::setChannelContextInfos` that contain a string value. + */ +const static char* channel_context_string_keys[] = { + Steinberg::Vst::ChannelContext::kChannelUIDKey, + Steinberg::Vst::ChannelContext::kChannelNameKey, + Steinberg::Vst::ChannelContext::kChannelIndexNamespaceKey}; + +/** + * Keys for channel context attributes passed in + * `IInfoListener::setChannelContextInfos` that contain an integer value. + */ +const static char* channel_context_integer_keys[] = { + Steinberg::Vst::ChannelContext::kChannelUIDLengthKey, + Steinberg::Vst::ChannelContext::kChannelNameLengthKey, + Steinberg::Vst::ChannelContext::kChannelColorKey, + Steinberg::Vst::ChannelContext::kChannelIndexKey, + Steinberg::Vst::ChannelContext::kChannelIndexNamespaceOrderKey, + Steinberg::Vst::ChannelContext::kChannelIndexNamespaceLengthKey, + Steinberg::Vst::ChannelContext::kChannelPluginLocationKey}; + +/** + * Keys for channel context attributes passed in + * `IInfoListener::setChannelContextInfos` that contain a binary value. + */ +const static char* channel_context_binary_keys[] = { + Steinberg::Vst::ChannelContext::kChannelImageKey}; + YaAttributeList::YaAttributeList(){FUNKNOWN_CTOR} YaAttributeList::~YaAttributeList() { @@ -51,6 +82,39 @@ tresult YaAttributeList::write_back( return Steinberg::kResultOk; } +YaAttributeList YaAttributeList::read_channel_context( + Steinberg::Vst::IAttributeList* context) { + YaAttributeList attributes{}; + // Copy over all predefined channel context attributes. `IAttributeList` + // does not offer any interface to enumerate the stored keys. + Steinberg::Vst::String128 vst_string{0}; + for (const auto& key : channel_context_string_keys) { + vst_string[0] = 0; + if (context->getString(key, vst_string, sizeof(vst_string)) == + Steinberg::kResultOk) { + attributes.setString(key, vst_string); + } + } + + int64 vst_integer; + for (const auto& key : channel_context_integer_keys) { + if (context->getInt(key, vst_integer) == Steinberg::kResultOk) { + attributes.setInt(key, vst_integer); + } + } + + const void* vst_binary_ptr; + uint32 vst_binary_size; + for (const auto& key : channel_context_binary_keys) { + if (context->getBinary(key, vst_binary_ptr, vst_binary_size) == + Steinberg::kResultOk) { + attributes.setBinary(key, vst_binary_ptr, vst_binary_size); + } + } + + return attributes; +} + tresult PLUGIN_API YaAttributeList::setInt(AttrID id, int64 value) { attrs_int[id] = value; return Steinberg::kResultOk; diff --git a/src/common/serialization/vst3/attribute-list.h b/src/common/serialization/vst3/attribute-list.h index 81e43453..6c8c5c30 100644 --- a/src/common/serialization/vst3/attribute-list.h +++ b/src/common/serialization/vst3/attribute-list.h @@ -49,6 +49,17 @@ class YaAttributeList : public Steinberg::Vst::IAttributeList { */ tresult write_back(Steinberg::Vst::IAttributeList* stream) const; + /** + * Read the channel context info passed to + * `IInfoListener::setChannelContextInfos` into a `YaAttributeList`. We + * normally can't serialize any arbitrary `IAttributeList` because there's + * no way to enumerate the keys, but in this case the keys are fixed. This + * works in a similar was as reading preset meta data in + * `IStreamAttributes`. + */ + static YaAttributeList read_channel_context( + Steinberg::Vst::IAttributeList* context); + virtual tresult PLUGIN_API setInt(AttrID id, int64 value) override; virtual tresult PLUGIN_API getInt(AttrID id, int64& value) override; virtual tresult PLUGIN_API setFloat(AttrID id, double value) override;