Remove support for null pointers in setHostContext

Like the other functions, null pointers are never valid here so we
shouldn't bother passing them as it only increases complexity.
This commit is contained in:
Robbert van der Helm
2020-12-22 14:03:56 +01:00
parent 3b96ffa349
commit 9288cdcb59
5 changed files with 24 additions and 38 deletions
+1 -7
View File
@@ -342,13 +342,7 @@ bool Vst3Logger::log_request(bool is_host_vst,
bool Vst3Logger::log_request(bool is_host_vst,
const YaPluginFactory::SetHostContext& request) {
return log_request_base(is_host_vst, [&](auto& message) {
message << "IPluginFactory3::setHostContext(";
if (request.host_context_args) {
message << "<FUnknown*>";
} else {
message << "<nullptr>";
}
message << ")";
message << "IPluginFactory3::setHostContext(<FUnknown*>)";
});
}
@@ -162,15 +162,11 @@ class YaPluginFactory : public Steinberg::IPluginFactory3 {
struct SetHostContext {
using Response = UniversalTResult;
/**
* Arguments for creating a proxy host context object. If we got passed
* an null pointer we'll reflect that.
*/
std::optional<Vst3HostContextProxy::ConstructArgs> host_context_args;
Vst3HostContextProxy::ConstructArgs host_context_args;
template <typename S>
void serialize(S& s) {
s.ext(host_context_args, bitsery::ext::StdOptional{});
s.object(host_context_args);
}
};
@@ -100,25 +100,24 @@ YaPluginFactoryImpl::createInstance(Steinberg::FIDString cid,
tresult PLUGIN_API
YaPluginFactoryImpl::setHostContext(Steinberg::FUnknown* context) {
// We will create a proxy object that that supports all the same interfaces
// as `context`, and then we'll store `context` in this object. We can then
// use it to handle callbacks made by the Windows VST3 plugin to this
// context.
host_context = context;
if (context) {
// We will create a proxy object that that supports all the same
// interfaces as `context`, and then we'll store `context` in this
// object. We can then use it to handle callbacks made by the Windows
// VST3 plugin to this context.
host_context = context;
// Automatically converted smart pointers for when the plugin performs a
// callback later
host_application = host_context;
// Automatically converted smart pointers for when the plugin performs a
// callback later
host_application = host_context;
std::optional<Vst3HostContextProxy::ConstructArgs> host_context_args{};
if (host_context) {
host_context_args =
Vst3HostContextProxy::ConstructArgs(host_context, std::nullopt);
return bridge.send_message(YaPluginFactory::SetHostContext{
.host_context_args = Vst3HostContextProxy::ConstructArgs(
host_context, std::nullopt)});
} else {
bridge.logger.log(
"Null pointer passed to 'IPluginFactory3::setHostContext()'");
"WARNING: Null pointer passed to "
"'IPluginFactory3::setHostContext()'");
return Steinberg::kInvalidArgument;
}
return bridge.send_message(YaPluginFactory::SetHostContext{
.host_context_args = std::move(host_context_args)});
}
@@ -406,7 +406,8 @@ tresult PLUGIN_API Vst3PluginProxyImpl::initialize(FUnknown* context) {
.host_context_args = Vst3HostContextProxy::ConstructArgs(
host_context, instance_id())});
} else {
bridge.logger.log("Null pointer passed to 'IPluginBase::initialize()'");
bridge.logger.log(
"WARNING: Null pointer passed to 'IPluginBase::initialize()'");
return Steinberg::kInvalidArgument;
}
}
+4 -8
View File
@@ -443,18 +443,14 @@ void Vst3Bridge::run() {
},
[&](YaPluginFactory::SetHostContext& request)
-> YaPluginFactory::SetHostContext::Response {
if (request.host_context_args) {
plugin_factory_host_context =
Steinberg::owned(new Vst3HostContextProxyImpl(
*this, std::move(*request.host_context_args)));
} else {
plugin_factory_host_context = nullptr;
}
plugin_factory_host_context =
Steinberg::owned(new Vst3HostContextProxyImpl(
*this, std::move(request.host_context_args)));
Steinberg::FUnknownPtr<Steinberg::IPluginFactory3> factory_3(
module->getFactory().get());
assert(factory_3);
return factory_3->setHostContext(plugin_factory_host_context);
}});
}