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
+25
View File
@@ -59,6 +59,13 @@ class Vst3Bridge : public HostBridge {
void run() override;
private:
/**
* Generate a nique instance identifier using an atomic fetch-and-add. This
* is used to be able to refer to specific instances created for
* `IPluginFactory::createInstance()`.
*/
size_t generate_instance_id();
/**
* The IO context used for event handling so that all events and window
* message handling can be performed from a single thread, even when hosting
@@ -90,4 +97,22 @@ class Vst3Bridge : public HostBridge {
* information during its initialization.
*/
std::unique_ptr<YaPluginFactory> plugin_factory;
/**
* Used to assign unique identifier to instances created for
* `IPluginFactory::createInstance()`.
*
* @related enerate_instance_id
*/
std::atomic_size_t current_instance_id;
// Below are managed instances we created for
// `IPluginFactory::createInstance()`. The keys in all of these maps are the
// unique identifiers we generated for them so we can identify specific
// instances. The mutexes are used for operations that insert or remove
// items, and not for regular access.
std::map<size_t, Steinberg::IPtr<Steinberg::Vst::IComponent>>
component_instances;
std::mutex component_instances_mutex;
};