Generate a unique ID and store the new component

This commit is contained in:
Robbert van der Helm
2020-12-08 17:59:59 +01:00
parent 5eb1fe2de2
commit e099255b92
2 changed files with 35 additions and 12 deletions
+10 -12
View File
@@ -56,20 +56,14 @@ void Vst3Bridge::run() {
Steinberg::IPtr<Steinberg::Vst::IComponent> component =
module->getFactory()
.createInstance<Steinberg::Vst::IComponent>(args.cid);
// TODO: Next steps are:
// - Generate a new unique ID using an atomic size_t and
// fetch-and-add.
// - Add an `std::map<size_t,
// Steinberg::IPtr<Steinberg::Vst::IComponent>`
// to this class and add `component` with the generated
// ID to that.
// - Add that ID to `YaComponent` and set it in the object
// we create here.
if (component) {
// TODO: Generate a unique instance ID
std::lock_guard lock(component_instances_mutex);
const size_t instance_id = generate_instance_id();
component_instances[instance_id] = std::move(component);
return std::make_optional<YaComponent::Arguments>(
component, 420691337);
component, instance_id);
} else {
return std::nullopt;
}
@@ -78,3 +72,7 @@ void Vst3Bridge::run() {
return *plugin_factory;
}});
}
size_t Vst3Bridge::generate_instance_id() {
return current_instance_id.fetch_add(1);
}