Add a function for copying channel contexts

For proxying `IInfoListener::setChannelContextInfos`.
This commit is contained in:
Robbert van der Helm
2021-01-12 16:01:34 +01:00
parent 87b270273f
commit 149be2f8f9
2 changed files with 75 additions and 0 deletions
@@ -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;
@@ -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;