sfizz/plugins/vst/SfizzVstUpdates.cpp

67 lines
1.7 KiB
C++
Raw Normal View History

2021-02-04 02:48:49 +01:00
// SPDX-License-Identifier: BSD-2-Clause
// This code is part of the sfizz library and is licensed under a BSD 2-clause
// license. You should have receive a LICENSE.md file along with the code.
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
#include "SfizzVstUpdates.h"
2021-04-11 19:39:27 +02:00
#include <algorithm>
2021-02-04 02:48:49 +01:00
#include <cstring>
2021-04-28 17:19:42 +02:00
void QueuedUpdates::enqueue(IPtr<FObject> update)
2021-02-04 02:48:49 +01:00
{
2021-04-28 17:19:42 +02:00
std::lock_guard<std::mutex> lock(mutex_);
for (std::pair<IDependent* const, List>& item : updates_)
item.second.push_back(update);
2021-02-04 02:48:49 +01:00
}
2021-04-28 17:19:42 +02:00
auto QueuedUpdates::getUpdates(IDependent* dep) -> List
2021-02-04 02:48:49 +01:00
{
2021-04-28 17:19:42 +02:00
std::lock_guard<std::mutex> lock(mutex_);
List list;
auto it = updates_.find(dep);
if (it != updates_.end())
std::swap(list, it->second);
return list;
2021-02-04 02:48:49 +01:00
}
2021-04-28 17:19:42 +02:00
void QueuedUpdates::addDependent(IDependent* dep)
2021-02-04 02:48:49 +01:00
{
2021-04-28 17:19:42 +02:00
std::lock_guard<std::mutex> lock(mutex_);
FObject::addDependent(dep);
updates_.emplace(dep, List());
2021-02-04 02:48:49 +01:00
}
2021-02-23 09:27:20 +01:00
2021-04-28 17:19:42 +02:00
void QueuedUpdates::removeDependent(IDependent* dep)
2021-02-23 09:27:20 +01:00
{
2021-04-28 17:19:42 +02:00
std::lock_guard<std::mutex> lock(mutex_);
FObject::removeDependent(dep);
updates_.erase(dep);
2021-02-23 09:27:20 +01:00
}
2021-04-28 17:19:42 +02:00
///
bool OSCUpdate::saveToAttributes(Vst::IAttributeList* attrs) const
2021-02-23 09:27:20 +01:00
{
return attrs->setBinary("Data", data(), size()) == kResultTrue;
}
bool OSCUpdate::loadFromAttributes(Vst::IAttributeList* attrs)
{
const void* data;
uint32 size;
if (attrs->getBinary("Data", data, size) != kResultTrue)
return false;
const uint8* data8 = reinterpret_cast<const uint8*>(data);
data_.assign(data8, data8 + size);
return true;
2021-02-23 09:27:20 +01:00
}
2021-04-28 17:19:42 +02:00
///
NoteUpdate::NoteUpdate(const Item* items, uint32 count)
2021-02-23 09:27:20 +01:00
{
2021-04-28 17:19:42 +02:00
Item* copy = new Item[count];
std::copy_n(items, count, copy);
events_.reset(copy);
2021-02-23 09:27:20 +01:00
count_ = count;
}