这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/plugin/vst3/Vst3Plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,24 @@ NS_HWM_BEGIN
using namespace Steinberg;

Vst3Plugin::Vst3Plugin(std::unique_ptr<Impl> pimpl,
std::unique_ptr<HostContext> host_context,
std::function<void(Vst3Plugin const *p)> on_destruction)
std::unique_ptr<HostContext> host_context)
: pimpl_(std::move(pimpl))
, host_context_(std::move(host_context))
{
host_context_->SetVst3Plugin(this);
on_destruction_ = on_destruction;
}

Vst3Plugin::~Vst3Plugin()
{
vpdls_.Invoke([this](auto *li) {
li->OnBeforeDestruction(this);
});

assert(IsEditorOpened() == false);

pimpl_.reset();

host_context_.reset();
on_destruction_(this);
}

FactoryInfo const & Vst3Plugin::GetFactoryInfo() const
Expand Down Expand Up @@ -296,12 +298,11 @@ void Vst3Plugin::LoadData(DumpData const &dump)
std::unique_ptr<Vst3Plugin>
CreatePlugin(IPluginFactory *factory,
FactoryInfo const &factory_info,
ClassInfo const &class_info,
std::function<void(Vst3Plugin const *p)> on_destruction)
ClassInfo const &class_info)
{
auto host_context = std::make_unique<Vst3Plugin::HostContext>(kAppName);
auto impl = std::make_unique<Vst3Plugin::Impl>(factory, factory_info, class_info, host_context->unknownCast());
auto plugin = std::make_unique<Vst3Plugin>(std::move(impl), std::move(host_context), on_destruction);
auto plugin = std::make_unique<Vst3Plugin>(std::move(impl), std::move(host_context));

return plugin;
}
Expand All @@ -311,4 +312,9 @@ Vst3Plugin::Vst3PluginListenerService & Vst3Plugin::GetVst3PluginListenerService
return host_context_->vpls_;
}

Vst3Plugin::Vst3PluginDestructionListenerService & Vst3Plugin::GetVst3PluginDestructionListenerService()
{
return vpdls_;
}

NS_HWM_END
22 changes: 18 additions & 4 deletions src/plugin/vst3/Vst3Plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,19 @@ struct Vst3PluginListener
{}

virtual void OnNotifyUnitByBusChange(Vst3Plugin *plugin)
{}
{}
};

struct Vst3PluginDestructionListener
: IListenerBase
{
protected:
Vst3PluginDestructionListener()
{}

public:
virtual void OnBeforeDestruction(Vst3Plugin *plugin)
{}
};

//! VST3のプラグインを表すクラス
Expand Down Expand Up @@ -177,8 +189,7 @@ class Vst3Plugin

public:
Vst3Plugin(std::unique_ptr<Impl> pimpl,
std::unique_ptr<HostContext> host_context,
std::function<void(Vst3Plugin const *p)> on_destruction);
std::unique_ptr<HostContext> host_context);

virtual ~Vst3Plugin();

Expand Down Expand Up @@ -278,10 +289,13 @@ class Vst3Plugin
using Vst3PluginListenerService = IListenerService<Vst3PluginListener>;
Vst3PluginListenerService & GetVst3PluginListenerService();

using Vst3PluginDestructionListenerService = IListenerService<Vst3PluginDestructionListener>;
Vst3PluginDestructionListenerService & GetVst3PluginDestructionListenerService();

private:
std::unique_ptr<Impl> pimpl_;
std::unique_ptr<HostContext> host_context_;
std::function<void(Vst3Plugin const *p)> on_destruction_;
ListenerService<Vst3PluginDestructionListener> vpdls_;
};

NS_HWM_END
21 changes: 11 additions & 10 deletions src/plugin/vst3/Vst3PluginFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ extern
std::unique_ptr<Vst3Plugin>
CreatePlugin(IPluginFactory *factory,
FactoryInfo const &factory_info,
ClassInfo const &info,
std::function<void(Vst3Plugin const *p)> on_destruction
ClassInfo const &info
);

FactoryInfo::FactoryInfo(PFactoryInfo const &info)
Expand Down Expand Up @@ -137,6 +136,7 @@ bool ClassInfo::is_instrument() const
}

class Vst3PluginFactory::Impl
: public Vst3PluginDestructionListener
{
public:
Impl(String module_path);
Expand All @@ -155,14 +155,16 @@ class Vst3PluginFactory::Impl
return factory_.get();
}

void OnVst3PluginIsCreated(Vst3Plugin const *p) {
loaded_plugins_.push_back(p);
void OnAfterConstruction(Vst3Plugin *plugin) {
loaded_plugins_.push_back(plugin);
plugin->GetVst3PluginDestructionListenerService().AddListener(this);
}
void OnVst3PluginIsDestructed(Vst3Plugin const *p) {
auto found = std::find(loaded_plugins_.begin(), loaded_plugins_.end(), p);

void OnBeforeDestruction(Vst3Plugin *plugin) override {
auto found = std::find(loaded_plugins_.begin(), loaded_plugins_.end(), plugin);
assert(found != loaded_plugins_.end());
loaded_plugins_.erase(found);
plugin->GetVst3PluginDestructionListenerService().RemoveListener(this);
}

UInt32 GetNumLoadedPlugins() const {
Expand Down Expand Up @@ -334,11 +336,10 @@ std::unique_ptr<Vst3Plugin>
{
auto p = CreatePlugin(pimpl_->GetFactory(),
pimpl_->GetFactoryInfo(),
GetComponentInfo(index),
[this](Vst3Plugin const *p) { pimpl_->OnVst3PluginIsDestructed(p); }
GetComponentInfo(index)
);
pimpl_->OnVst3PluginIsCreated(p.get());

pimpl_->OnAfterConstruction(p.get());
return p;
}

Expand Down