sfizz/plugins/vst/SfizzVstUpdates.cpp

69 lines
1.3 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>
OSCUpdate::~OSCUpdate()
{
clear();
}
void OSCUpdate::clear()
{
if (allocated_)
delete[] reinterpret_cast<const uint8_t*>(data_);
data_ = nullptr;
size_ = 0;
allocated_ = false;
}
2021-02-04 09:04:23 +01:00
void OSCUpdate::setMessage(const void* data, uint32_t size, bool copy)
2021-02-04 02:48:49 +01:00
{
clear();
if (copy) {
uint8_t *buffer = new uint8_t[size];
std::memcpy(buffer, data, size);
data = buffer;
}
data_ = data;
size_ = size;
allocated_ = copy;
}
2021-02-23 09:27:20 +01:00
///
NoteUpdate::~NoteUpdate()
{
clear();
}
void NoteUpdate::clear()
{
if (allocated_)
delete[] events_;
events_ = nullptr;
count_ = 0;
allocated_ = false;
}
void NoteUpdate::setEvents(const std::pair<uint32_t, float>* events, uint32_t count, bool copy)
{
clear();
if (copy) {
auto *buffer = new std::pair<uint32_t, float>[count];
2021-04-11 19:39:27 +02:00
std::copy_n(events, count, buffer);
2021-02-23 09:27:20 +01:00
events = buffer;
}
events_ = events;
count_ = count;
allocated_ = copy;
}