|
| 1 | +/* Copyright (c) 2025 pkv <[email protected]> |
| 2 | + * This file is part of obs-vst3. |
| 3 | + * |
| 4 | + * Portions are derived from EasyVst (https://github.com/iffyloop/EasyVst), |
| 5 | + * licensed under Public Domain (Unlicense) or MIT No Attribution. |
| 6 | + * |
| 7 | + * This file uses the Steinberg VST3 SDK, which is licensed under MIT license. |
| 8 | + * See https://github.com/steinbergmedia/vst3sdk for details. |
| 9 | + * |
| 10 | + * This file and all modifications by pkv <[email protected]> are licensed under |
| 11 | + * the GNU General Public License, version 3 or later, to comply with the SDK license. |
| 12 | + */ |
| 13 | +#include "VST3HostApp.h" |
| 14 | +#include "VST3Plugin.h" |
| 15 | + |
| 16 | +using namespace Steinberg; |
| 17 | +using namespace Vst; |
| 18 | + |
| 19 | +VST3HostApp::VST3HostApp() |
| 20 | +{ |
| 21 | + addPlugInterfaceSupported(IComponent::iid); |
| 22 | + addPlugInterfaceSupported(IAudioProcessor::iid); |
| 23 | + addPlugInterfaceSupported(IEditController::iid); |
| 24 | + addPlugInterfaceSupported(IConnectionPoint::iid); |
| 25 | +} |
| 26 | + |
| 27 | +VST3HostApp::~VST3HostApp() noexcept {FUNKNOWN_DTOR} |
| 28 | + |
| 29 | +/* IComponentHandler methods */ |
| 30 | +tresult PLUGIN_API VST3HostApp::beginEdit(ParamID) |
| 31 | +{ |
| 32 | + return kResultOk; |
| 33 | +} |
| 34 | + |
| 35 | +tresult PLUGIN_API VST3HostApp::performEdit(ParamID id, ParamValue valueNormalized) |
| 36 | +{ |
| 37 | + if (guiToDsp) |
| 38 | + guiToDsp->push({id, valueNormalized}); |
| 39 | + return kResultOk; |
| 40 | +} |
| 41 | + |
| 42 | +tresult PLUGIN_API VST3HostApp::endEdit(ParamID) |
| 43 | +{ |
| 44 | + return kResultOk; |
| 45 | +} |
| 46 | + |
| 47 | +tresult PLUGIN_API VST3HostApp::restartComponent(int32 flags) |
| 48 | +{ |
| 49 | + if (!plugin) |
| 50 | + return kInvalidArgument; |
| 51 | + |
| 52 | + if ((flags & kReloadComponent) || (flags & kLatencyChanged)) { |
| 53 | + std::unique_lock<std::mutex> lk(plugin->obsVst3Struct->plugin_state_mutex); |
| 54 | + os_atomic_set_bool(&plugin->obsVst3Struct->bypass, true); |
| 55 | + |
| 56 | + if (plugin->audioEffect) |
| 57 | + plugin->audioEffect->setProcessing(false); |
| 58 | + |
| 59 | + if (plugin->vstPlug) { |
| 60 | + plugin->vstPlug->setActive(false); |
| 61 | + plugin->vstPlug->setActive(true); |
| 62 | + } |
| 63 | + |
| 64 | + if (plugin->audioEffect) |
| 65 | + plugin->audioEffect->setProcessing(true); |
| 66 | + |
| 67 | + uint32 latency = plugin->audioEffect ? plugin->audioEffect->getLatencySamples() : 0; |
| 68 | + infovst3plugin("Latency of the plugin is %u samples", latency); |
| 69 | + |
| 70 | + os_atomic_set_bool(&plugin->obsVst3Struct->bypass, false); |
| 71 | + return kResultOk; |
| 72 | + } |
| 73 | + |
| 74 | + return kNotImplemented; |
| 75 | +} |
| 76 | + |
| 77 | +/* IHostApplication methods */ |
| 78 | +tresult PLUGIN_API VST3HostApp::getName(String128 name) |
| 79 | +{ |
| 80 | + std::memset(name, 0, sizeof(String128)); |
| 81 | +#if defined(_WIN32) |
| 82 | + const char *src = "OBS VST3 Host"; |
| 83 | + MultiByteToWideChar(CP_UTF8, 0, src, -1, (wchar_t *)name, 128); |
| 84 | +#else |
| 85 | + std::u16string src = u"OBS VST3 Host"; |
| 86 | + src.copy(name, src.size()); |
| 87 | +#endif |
| 88 | + return kResultOk; |
| 89 | +} |
| 90 | + |
| 91 | +tresult PLUGIN_API VST3HostApp::createInstance(TUID cid, TUID _iid, void **obj) |
| 92 | +{ |
| 93 | + if (FUnknownPrivate::iidEqual(cid, IMessage::iid) && FUnknownPrivate::iidEqual(_iid, IMessage::iid)) { |
| 94 | + *obj = new HostMessage; |
| 95 | + return kResultTrue; |
| 96 | + } |
| 97 | + if (FUnknownPrivate::iidEqual(cid, IAttributeList::iid) && |
| 98 | + FUnknownPrivate::iidEqual(_iid, IAttributeList::iid)) { |
| 99 | + if (auto al = HostAttributeList::make()) { |
| 100 | + *obj = al.take(); |
| 101 | + return kResultTrue; |
| 102 | + } |
| 103 | + return kOutOfMemory; |
| 104 | + } |
| 105 | + *obj = nullptr; |
| 106 | + return kResultFalse; |
| 107 | +} |
| 108 | + |
| 109 | +/* IUnitHandler methods */ |
| 110 | +tresult PLUGIN_API VST3HostApp::notifyUnitSelection(UnitID) |
| 111 | +{ |
| 112 | + return kResultTrue; |
| 113 | +} |
| 114 | + |
| 115 | +tresult PLUGIN_API VST3HostApp::notifyProgramListChange(ProgramListID, int32) |
| 116 | +{ |
| 117 | + return kResultTrue; |
| 118 | +} |
| 119 | + |
| 120 | +/* IPlugInterfaceSupport methods */ |
| 121 | +tresult PLUGIN_API VST3HostApp::isPlugInterfaceSupported(const TUID _iid) |
| 122 | +{ |
| 123 | + auto uid = FUID::fromTUID(_iid); |
| 124 | + if (std::find(mFUIDArray.begin(), mFUIDArray.end(), uid) != mFUIDArray.end()) |
| 125 | + return kResultTrue; |
| 126 | + return kResultFalse; |
| 127 | +} |
| 128 | + |
| 129 | +/* FUnknown methods */ |
| 130 | +tresult PLUGIN_API VST3HostApp::queryInterface(const TUID _iid, void **obj) |
| 131 | +{ |
| 132 | + if (FUnknownPrivate::iidEqual(_iid, IHostApplication::iid)) { |
| 133 | + *obj = static_cast<IHostApplication *>(this); |
| 134 | + return kResultOk; |
| 135 | + } |
| 136 | + if (FUnknownPrivate::iidEqual(_iid, IPlugInterfaceSupport::iid)) { |
| 137 | + *obj = static_cast<IPlugInterfaceSupport *>(this); |
| 138 | + return kResultOk; |
| 139 | + } |
| 140 | +#ifdef __linux__ |
| 141 | + if (runLoop && FUnknownPrivate::iidEqual(_iid, Linux::IRunLoop::iid)) { |
| 142 | + *obj = static_cast<Linux::IRunLoop *>(runLoop); |
| 143 | + return kResultOk; |
| 144 | + } |
| 145 | +#endif |
| 146 | + *obj = nullptr; |
| 147 | + return kNoInterface; |
| 148 | +} |
0 commit comments