diff --git a/src/common/serialization/vst3/attribute-list.cpp b/src/common/serialization/vst3/attribute-list.cpp index f46676c7..b56b259d 100644 --- a/src/common/serialization/vst3/attribute-list.cpp +++ b/src/common/serialization/vst3/attribute-list.cpp @@ -16,6 +16,8 @@ #include "attribute-list.h" +#include + #include "pluginterfaces/vst/ivstchannelcontextinfo.h" /** @@ -47,6 +49,31 @@ const static char* channel_context_integer_keys[] = { const static char* channel_context_binary_keys[] = { Steinberg::Vst::ChannelContext::kChannelImageKey}; +/** + * These are the meta data keys used for `IStreamAttributes`. We need to keep + * track of this because `IAttributeList` has no way to just iterate over the + * stored keys. We'll read these from the host if the host supports this + * interface, and if the plugin writes an attribute with one of these keys we'll + * write the value back to the host. + * + * TODO: There's also `Steinberg::Vst::PresetAttributes::kFilePathStringType` + * This would require translating between Windows and Unix style paths, + * which we can't easily do outside of Wine. If this ends up being + * important, then we'll have to shell out to `winepath` which is not + * ideal. On the Wine side we can just use the `wine_get_dos_file_name` + * and `wine_get_unix_file_name` functions instead. Requesting this should + * also use a 1024 character buffer. + */ +const static char* stream_meta_data_string_keys[] = { + Steinberg::Vst::PresetAttributes::kPlugInName, + Steinberg::Vst::PresetAttributes::kPlugInCategory, + Steinberg::Vst::PresetAttributes::kInstrument, + Steinberg::Vst::PresetAttributes::kStyle, + Steinberg::Vst::PresetAttributes::kCharacter, + Steinberg::Vst::PresetAttributes::kStateType, + Steinberg::Vst::PresetAttributes::kName, + Steinberg::Vst::PresetAttributes::kFileName}; + YaAttributeList::YaAttributeList(){FUNKNOWN_CTOR} YaAttributeList::~YaAttributeList() { @@ -115,6 +142,23 @@ YaAttributeList YaAttributeList::read_channel_context( return attributes; } +YaAttributeList YaAttributeList::read_stream_attributes( + Steinberg::Vst::IAttributeList* stream_attributes) { + YaAttributeList attributes{}; + // Copy over all predefined preset meta data. `IAttributeList` does not + // offer any interface to enumerate the stored keys. + Steinberg::Vst::String128 vst_string{0}; + for (const auto& key : stream_meta_data_string_keys) { + vst_string[0] = 0; + if (stream_attributes->getString(key, vst_string, sizeof(vst_string)) == + Steinberg::kResultOk) { + attributes.setString(key, vst_string); + } + } + + 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 6c8c5c30..0a527cbd 100644 --- a/src/common/serialization/vst3/attribute-list.h +++ b/src/common/serialization/vst3/attribute-list.h @@ -60,6 +60,14 @@ class YaAttributeList : public Steinberg::Vst::IAttributeList { static YaAttributeList read_channel_context( Steinberg::Vst::IAttributeList* context); + /** + * Read the the meta data attributes provided by `IBStraem`s that support + * `IStreamAttributes`. This works the same was as + * `YaAttributeList::read_channel_context`. + */ + static YaAttributeList read_stream_attributes( + Steinberg::Vst::IAttributeList* stream_attributes); + 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; diff --git a/src/common/serialization/vst3/bstream.cpp b/src/common/serialization/vst3/bstream.cpp index 57b0e009..312f8e4a 100644 --- a/src/common/serialization/vst3/bstream.cpp +++ b/src/common/serialization/vst3/bstream.cpp @@ -16,36 +16,9 @@ #include "bstream.h" -#include - #include #include -/** - * These are the meta data keys used for `IStreamAttributes`. We need to keep - * track of this because `IAttributeList` has no way to just iterate over the - * stored keys. We'll read these from the host if the host supports this - * interface, and if the plugin writes an attribute with one of these keys we'll - * write the value back to the host. - * - * TODO: There's also `Steinberg::Vst::PresetAttributes::kFilePathStringType` - * This would require translating between Windows and Unix style paths, - * which we can't easily do outside of Wine. If this ends up being - * important, then we'll have to shell out to `winepath` which is not - * ideal. On the Wine side we can just use the `wine_get_dos_file_name` - * and `wine_get_unix_file_name` functions instead. Requesting this should - * also use a 1024 character buffer. - */ -const static char* stream_meta_data_keys[] = { - Steinberg::Vst::PresetAttributes::kPlugInName, - Steinberg::Vst::PresetAttributes::kPlugInCategory, - Steinberg::Vst::PresetAttributes::kInstrument, - Steinberg::Vst::PresetAttributes::kStyle, - Steinberg::Vst::PresetAttributes::kCharacter, - Steinberg::Vst::PresetAttributes::kStateType, - Steinberg::Vst::PresetAttributes::kName, - Steinberg::Vst::PresetAttributes::kFileName}; - YaBStream::YaBStream(){FUNKNOWN_CTOR} YaBStream::YaBStream(Steinberg::IBStream* stream) { @@ -86,19 +59,12 @@ YaBStream::YaBStream(Steinberg::IBStream* stream) { file_name.emplace(tchar_pointer_to_u16string(vst_string)); } - attributes.emplace(); if (Steinberg::IPtr stream_attributes_list = stream_attributes->getAttributes()) { - // Copy over all predefined meta data keys. `IAttributeList` does - // not offer any interface to enumerate the stored keys. - for (const auto& key : stream_meta_data_keys) { - vst_string[0] = 0; - if (stream_attributes_list->getString(key, vst_string, - sizeof(vst_string)) == - Steinberg::kResultOk) { - attributes->setString(key, vst_string); - } - } + attributes.emplace(YaAttributeList::read_stream_attributes( + stream_attributes_list)); + } else { + attributes.emplace(); } } }