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
+25
View File
@@ -487,6 +487,19 @@ bool Vst3Logger::log_request(
});
}
bool Vst3Logger::log_request(bool is_host_vst,
const YaHostApplication::GetName& request) {
return log_request_base(is_host_vst, [&](auto& message) {
// This can be called either from a plugin object or from the plugin's
// plugin factory
if (request.owner_instance_id) {
message << *request.owner_instance_id << ": ";
}
message << "IHostApplication::getName(&name)";
});
}
void Vst3Logger::log_response(bool is_host_vst, const Ack&) {
log_response_base(is_host_vst, [&](auto& message) { message << "ACK"; });
}
@@ -644,3 +657,15 @@ void Vst3Logger::log_response(bool is_host_vst, const Configuration&) {
log_response_base(is_host_vst,
[&](auto& message) { message << "<Configuration>"; });
}
void Vst3Logger::log_response(
bool is_host_vst,
const YaHostApplication::GetNameResponse& response) {
log_response_base(is_host_vst, [&](auto& message) {
message << response.result.string();
if (response.result == Steinberg::kResultOk) {
std::string value = VST3::StringConvert::convert(response.name);
message << ", \"" << value << "\"";
}
});
}
+4
View File
@@ -115,6 +115,7 @@ class Vst3Logger {
bool log_request(bool is_host_vst, const YaComponentHandler::EndEdit&);
bool log_request(bool is_host_vst,
const YaComponentHandler::RestartComponent&);
bool log_request(bool is_host_vst, const YaHostApplication::GetName&);
void log_response(bool is_host_vst, const Ack&);
void log_response(
@@ -138,6 +139,9 @@ class Vst3Logger {
void log_response(bool is_host_vst, const YaPluginFactory::ConstructArgs&);
void log_response(bool is_host_vst, const Configuration&);
void log_response(bool is_host_vst,
const YaHostApplication::GetNameResponse&);
template <typename T>
void log_response(bool is_host_vst, const PrimitiveWrapper<T>& value) {
// For logging all primitive return values other than `tresult`
+2 -1
View File
@@ -110,7 +110,8 @@ using CallbackRequest = std::variant<WantsConfiguration,
YaComponentHandler::BeginEdit,
YaComponentHandler::PerformEdit,
YaComponentHandler::EndEdit,
YaComponentHandler::RestartComponent>;
YaComponentHandler::RestartComponent,
YaHostApplication::GetName>;
template <typename S>
void serialize(S& s, CallbackRequest& payload) {
@@ -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;