mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-13 20:09:59 +02:00
Create Vst3HostContextProxy from YaHostApplication
This is quite a huge refactor, but note everything is consistent (and we're going to need one or two more of these `Vst3*Proxy` objects). Right now nothing extends `IHostApplication`, but this way it will be trivial to add support for more host context interfaces.
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
// yabridge: a Wine VST bridge
|
||||
// Copyright (C) 2020 Robbert van der Helm
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include "host-application.h"
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
YaHostApplication::YaHostApplication(const ConstructArgs&& args)
|
||||
: arguments(std::move(args)) {}
|
||||
|
||||
tresult PLUGIN_API YaHostApplication::getName(Steinberg::Vst::String128 name) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
// yabridge: a Wine VST bridge
|
||||
// Copyright (C) 2020 Robbert van der Helm
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
#include <bitsery/ext/std_optional.h>
|
||||
#include <bitsery/traits/string.h>
|
||||
#include <pluginterfaces/vst/ivsthostapplication.h>
|
||||
|
||||
#include "../../common.h"
|
||||
#include "../base.h"
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
|
||||
|
||||
/**
|
||||
* Wraps around `IHostApplication` for serialization purposes. This is
|
||||
* instantiated as part of `Vst3HostContextProxy`.
|
||||
*/
|
||||
class YaHostApplication : public Steinberg::Vst::IHostApplication {
|
||||
public:
|
||||
/**
|
||||
* These are the arguments for creating a `YaHostApplication`.
|
||||
*/
|
||||
struct ConstructArgs {
|
||||
ConstructArgs();
|
||||
|
||||
/**
|
||||
* Check whether an existing implementation implements
|
||||
* `IHostApplication` and read arguments from it.
|
||||
*/
|
||||
ConstructArgs(Steinberg::IPtr<Steinberg::FUnknown> object);
|
||||
|
||||
/**
|
||||
* Whether the object supported this interface.
|
||||
*/
|
||||
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>);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Instantiate this instance with arguments read from another interface
|
||||
* implementation.
|
||||
*/
|
||||
YaHostApplication(const ConstructArgs&& args);
|
||||
|
||||
inline bool supported() const { return arguments.supported; }
|
||||
|
||||
tresult PLUGIN_API getName(Steinberg::Vst::String128 name) override;
|
||||
virtual tresult PLUGIN_API createInstance(Steinberg::TUID cid,
|
||||
Steinberg::TUID _iid,
|
||||
void** obj) override = 0;
|
||||
|
||||
protected:
|
||||
ConstructArgs arguments;
|
||||
};
|
||||
|
||||
#pragma GCC diagnostic pop
|
||||
Reference in New Issue
Block a user