plugin_host新增mempool提高缓存命中率
This commit is contained in:
@@ -17,14 +17,24 @@ struct host_param_info {
|
||||
float max_value;
|
||||
};
|
||||
|
||||
enum class plugin_host_type {
|
||||
vst2,
|
||||
vst3,
|
||||
au,
|
||||
aax,
|
||||
lv2,
|
||||
internal,
|
||||
};
|
||||
|
||||
class CORE_API plugin_host {
|
||||
friend class window_manager;
|
||||
public:
|
||||
plugin_host() : id(gen_uid()) {
|
||||
plugin_host(plugin_host_type in_type) : id(gen_uid()), type_(in_type) {
|
||||
}
|
||||
virtual ~plugin_host();
|
||||
|
||||
uint64_t get_uid() const { return id; }
|
||||
[[nodiscard]] uint64_t get_uid() const { return id; }
|
||||
[[nodiscard]] plugin_host_type get_type() const { return type_; }
|
||||
|
||||
virtual bool load_plugin(const char* path) = 0;
|
||||
|
||||
@@ -82,4 +92,5 @@ protected:
|
||||
private:
|
||||
bool editor_opened = false;
|
||||
const uint64_t id = 0;
|
||||
plugin_host_type type_;
|
||||
};
|
||||
|
||||
@@ -25,9 +25,10 @@ void plugin_host_manager::release(singleton_release_guard& release_guard) {
|
||||
release_guard.require_release<audio_device_manager>();
|
||||
|
||||
for (const plugin_host* host: plugin_hosts_) {
|
||||
delete host;
|
||||
free_plugin_host(host);
|
||||
}
|
||||
plugin_hosts_.clear();
|
||||
instrument_plugins_.clear();
|
||||
}
|
||||
|
||||
plugin_host *plugin_host_manager::create_effect_plugin_host(const char *path) {
|
||||
@@ -60,7 +61,7 @@ void plugin_host_manager::remove_instrument_plugin_host(plugin_host* host) {
|
||||
}
|
||||
|
||||
plugin_host* plugin_host_manager::load_plugin(const char* path) {
|
||||
auto host = new vst2_plugin_host();
|
||||
auto host = alloc_plugin_host<vst2_plugin_host>();
|
||||
try {
|
||||
host->load_plugin(path);
|
||||
} catch (std::exception& e) {
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
#include "misc/delegates.h"
|
||||
#include "misc/singleton/singleton.h"
|
||||
#include "taskflow/taskflow.hpp"
|
||||
#include "plugin_host.h"
|
||||
#include "mempool.h"
|
||||
#include <unordered_map>
|
||||
|
||||
class plugin_host;
|
||||
class mixer_track;
|
||||
|
||||
class CORE_API plugin_host_manager : public singleton_t<plugin_host_manager> {
|
||||
@@ -12,7 +14,6 @@ public:
|
||||
void begin_release(singleton_release_guard& release_guard) override;
|
||||
void release(singleton_release_guard& release_guard) override;
|
||||
|
||||
|
||||
plugin_host* create_effect_plugin_host(const char* path);
|
||||
plugin_host* create_instrument_plugin_host(const char* path);
|
||||
void remove_instrument_plugin_host(plugin_host* host);
|
||||
@@ -30,8 +31,18 @@ private:
|
||||
void register_instrument_plugin(plugin_host* host);
|
||||
void on_mixer_track_removed(mixer_track* track);
|
||||
|
||||
template <typename T>
|
||||
T* alloc_plugin_host() {
|
||||
auto* host = plugin_host_map_[T::type].template alloc<T>();
|
||||
return host;
|
||||
}
|
||||
template <typename T>
|
||||
void free_plugin_host(T* host) {
|
||||
plugin_host_map_[host->get_type()].free(host);
|
||||
}
|
||||
std::vector<plugin_host*> instrument_plugins_{};
|
||||
std::vector<plugin_host*> plugin_hosts_{};
|
||||
std::unordered_map<plugin_host_type, mempool<>> plugin_host_map_;
|
||||
|
||||
void update_taskflow(uint32_t in_frames);
|
||||
tf::Taskflow taskflow_;
|
||||
|
||||
@@ -148,7 +148,7 @@ VstIntPtr vst_master_callback(AEffect* effect, VstInt32 opcode, VstInt32 index,
|
||||
|
||||
typedef AEffect*(*vst_plugin_entry_proc)(audioMasterCallback AudioMaster);
|
||||
|
||||
vst2_plugin_host::vst2_plugin_host() {
|
||||
vst2_plugin_host::vst2_plugin_host() : plugin_host(type) {
|
||||
effect_ = nullptr;
|
||||
library_ = nullptr;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
class vst2_plugin_host : public plugin_host {
|
||||
public:
|
||||
static VstTimeInfo vst_time_info;
|
||||
static constexpr auto type = plugin_host_type::vst2;
|
||||
vst2_plugin_host();
|
||||
~vst2_plugin_host() override;
|
||||
bool load_plugin(const char* path) override;
|
||||
|
||||
Reference in New Issue
Block a user