reVeno/Source/Veno/VenoInstance.cpp

56 lines
1.5 KiB
C++
Raw Normal View History

2020-06-13 10:56:20 +02:00
//
// Created by versustune on 09.06.20.
//
#include "VenoInstance.h"
#include <utility>
#include "Utils/Logger.h"
std::unordered_map<std::string, std::shared_ptr<VenoInstance>> VenoInstance::instances;
VenoInstance::VenoInstance (std::string id)
{
m_id = std::move (id);
m_synthInstance = std::make_shared<SynthInstance> (id);
audioBuffer = std::make_shared<VenoBuffer> ();
2020-06-13 10:56:20 +02:00
}
VenoInstance::~VenoInstance ()
{
m_synthInstance.reset ();
audioBuffer.reset ();
2020-06-13 10:56:20 +02:00
}
std::shared_ptr<VenoInstance> VenoInstance::createInstance (const std::string& id)
{
auto instance = std::make_shared<VenoInstance> (id);
instances.insert (std::pair<std::string, std::shared_ptr<VenoInstance>> (id, instance));
VeNo::Logger::debugMessage ("Created VenoInstance with id: " + id);
2020-06-13 10:56:20 +02:00
return instance;
}
// will return the instance or a empty new on... can find out because the id is fucked!
std::shared_ptr<VenoInstance> VenoInstance::getInstance (const std::string& id)
{
if (instances.find (id) != instances.end ())
{
2020-06-13 10:56:20 +02:00
return instances[id];
}
return createInstance (id);
2020-06-13 10:56:20 +02:00
}
const std::shared_ptr<SynthInstance>& VenoInstance::getSynthInstance () const
{
2020-06-13 10:56:20 +02:00
return m_synthInstance;
}
void VenoInstance::deleteInstance (const std::string& processId)
{
if (instances.find (processId) != instances.end ())
{
instances[processId].reset ();
instances.erase (processId);
VeNo::Logger::debugMessage ("Removed VenoInstance with id: " + processId);
2020-06-13 10:56:20 +02:00
}
}