sfizz/plugins/vst/SfizzVstUpdates.cpp

59 lines
1.4 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
///
OSCUpdate::OSCUpdate(const uint8* data, uint32 size)
2021-02-23 09:27:20 +01:00
{
2021-04-28 17:19:42 +02:00
uint8* copy = new uint8[size];
std::copy_n(data, size, copy);
data_.reset(copy);
size_ = size;
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;
}