Don't cache IHostApplication::getName()

As it turns out there are only two or three functions where we can do
this. It also breaks logging, and this function will probably only be
called once anyways. More consistency is always better.
This commit is contained in:
Robbert van der Helm
2020-12-19 18:28:16 +01:00
parent 01d84b0029
commit 63ae5f330c
13 changed files with 124 additions and 41 deletions
@@ -20,34 +20,8 @@ YaHostApplication::ConstructArgs::ConstructArgs() {}
YaHostApplication::ConstructArgs::ConstructArgs(
Steinberg::IPtr<Steinberg::FUnknown> object)
: supported(false) {
if (auto host_application =
Steinberg::FUnknownPtr<Steinberg::Vst::IHostApplication>(object)) {
supported = true;
// `IHostApplication::getName`
Steinberg::Vst::String128 name_array;
if (host_application->getName(name_array) == Steinberg::kResultOk) {
name = tchar_pointer_to_u16string(name_array);
}
}
}
: supported(
Steinberg::FUnknownPtr<Steinberg::Vst::IHostApplication>(object)) {}
YaHostApplication::YaHostApplication(const ConstructArgs&& args)
: arguments(std::move(args)) {}
tresult PLUGIN_API YaHostApplication::getName(Steinberg::Vst::String128 name) {
// TODO: This is now not being logged at all. It's probably better if we
// just drop these two functions that output cached data directly.
// They'll only be used once or twice anyways.
if (arguments.name) {
// Terminate with a null byte. There are no nice functions for copying
// UTF-16 strings (because who would use those?).
std::copy(arguments.name->begin(), arguments.name->end(), name);
name[arguments.name->size()] = 0;
return Steinberg::kResultOk;
} else {
return Steinberg::kNotImplemented;
}
}
@@ -51,18 +51,9 @@ class YaHostApplication : public Steinberg::Vst::IHostApplication {
*/
bool supported;
/**
* For `IHostApplication::getName`.
*/
std::optional<std::u16string> name;
template <typename S>
void serialize(S& s) {
s.value1b(supported);
s.ext(name, bitsery::ext::StdOptional{},
[](S& s, std::u16string& name) {
s.text2b(name, std::extent_v<Steinberg::Vst::String128>);
});
}
};
@@ -74,7 +65,46 @@ class YaHostApplication : public Steinberg::Vst::IHostApplication {
inline bool supported() const { return arguments.supported; }
tresult PLUGIN_API getName(Steinberg::Vst::String128 name) override;
/**
* The response code and resulting value for a call to
* `IHostApplication::getName()`.
*/
struct GetNameResponse {
UniversalTResult result;
std::u16string name;
template <typename S>
void serialize(S& s) {
s.object(result);
s.text2b(name, std::extent_v<Steinberg::Vst::String128>);
}
};
/**
* Message to pass through a call to `IHostApplication::getName()` to the
* host context provided by the host.
*/
struct GetName {
using Response = GetNameResponse;
/**
* The object instance whose host context to call this function to. Of
* empty, then the function will be called on the factory's host context
* instead.
*/
std::optional<native_size_t> owner_instance_id;
template <typename S>
void serialize(S& s) {
s.ext(owner_instance_id, bitsery::ext::StdOptional{},
[](S& s, native_size_t& instance_id) {
s.value8b(instance_id);
});
}
};
virtual tresult PLUGIN_API
getName(Steinberg::Vst::String128 name) override = 0;
virtual tresult PLUGIN_API createInstance(Steinberg::TUID cid,
Steinberg::TUID _iid,
void** obj) override = 0;