Add vst support for message<->update conversion
This commit is contained in:
parent
3986bc782b
commit
0d63c7ee5f
4 changed files with 74 additions and 11 deletions
|
|
@ -33,6 +33,7 @@ add_library(sfizz-vst3-core STATIC EXCLUDE_FROM_ALL
|
|||
SfizzVstState.h
|
||||
SfizzVstParameters.h
|
||||
SfizzVstUpdates.h
|
||||
SfizzVstUpdates.hpp
|
||||
SfizzVstUpdates.cpp
|
||||
SfizzVstIDs.h
|
||||
OrderedEventProcessor.h
|
||||
|
|
|
|||
|
|
@ -40,12 +40,20 @@ void QueuedUpdates::removeDependent(IDependent* dep)
|
|||
}
|
||||
|
||||
///
|
||||
OSCUpdate::OSCUpdate(const uint8* data, uint32 size)
|
||||
bool OSCUpdate::saveToAttributes(Vst::IAttributeList* attrs) const
|
||||
{
|
||||
uint8* copy = new uint8[size];
|
||||
std::copy_n(data, size, copy);
|
||||
data_.reset(copy);
|
||||
size_ = size;
|
||||
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;
|
||||
}
|
||||
|
||||
///
|
||||
|
|
|
|||
|
|
@ -6,14 +6,32 @@
|
|||
|
||||
#pragma once
|
||||
#include "SfizzVstState.h"
|
||||
#include <public.sdk/source/vst/vstcomponentbase.h>
|
||||
#include <pluginterfaces/vst/ivstmessage.h>
|
||||
#include <base/source/fobject.h>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <cstring>
|
||||
#include <cstdint>
|
||||
|
||||
/**
|
||||
* @brief Update which is convertible with Vst::IMessage back and forth.
|
||||
*/
|
||||
template <class T> class IConvertibleToMessage {
|
||||
public:
|
||||
virtual ~IConvertibleToMessage() {}
|
||||
|
||||
IPtr<Vst::IMessage> convertToMessage(Vst::ComponentBase* sender) const;
|
||||
static IPtr<T> convertFromMessage(Vst::IMessage& message);
|
||||
|
||||
protected:
|
||||
virtual bool saveToAttributes(Vst::IAttributeList* attrs) const = 0;
|
||||
virtual bool loadFromAttributes(Vst::IAttributeList* attrs) = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Update which notifies a FIFO queue of one-time updates
|
||||
*/
|
||||
|
|
@ -37,17 +55,21 @@ private:
|
|||
/**
|
||||
* @brief Update which notifies a single OSC message
|
||||
*/
|
||||
class OSCUpdate : public Steinberg::FObject {
|
||||
class OSCUpdate : public Steinberg::FObject,
|
||||
public IConvertibleToMessage<OSCUpdate> {
|
||||
public:
|
||||
OSCUpdate(const uint8* data, uint32 size);
|
||||
const uint8* data() const noexcept { return data_.get(); }
|
||||
uint32_t size() const noexcept { return size_; }
|
||||
OSCUpdate() = default;
|
||||
OSCUpdate(const uint8* data, uint32 size) : data_(data, data + size) {}
|
||||
const uint8* data() const noexcept { return data_.data(); }
|
||||
uint32_t size() const noexcept { return static_cast<uint32_t>(data_.size()); }
|
||||
|
||||
bool saveToAttributes(Vst::IAttributeList* attrs) const override;
|
||||
bool loadFromAttributes(Vst::IAttributeList* attrs) override;
|
||||
|
||||
OBJ_METHODS(OSCUpdate, FObject)
|
||||
|
||||
private:
|
||||
std::unique_ptr<uint8[]> data_;
|
||||
uint32 size_ = 0;
|
||||
std::vector<uint8> data_;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
@ -163,3 +185,5 @@ private:
|
|||
SfizzPlayState state_ {};
|
||||
mutable std::mutex mutex_;
|
||||
};
|
||||
|
||||
#include "SfizzVstUpdates.hpp"
|
||||
|
|
|
|||
30
plugins/vst/SfizzVstUpdates.hpp
Normal file
30
plugins/vst/SfizzVstUpdates.hpp
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
// 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
|
||||
|
||||
#pragma once
|
||||
#include "SfizzVstUpdates.h"
|
||||
|
||||
template <class T>
|
||||
IPtr<Vst::IMessage> IConvertibleToMessage<T>::convertToMessage(Vst::ComponentBase* sender) const
|
||||
{
|
||||
IPtr<Vst::IMessage> message = owned(sender->allocateMessage());
|
||||
message->setMessageID(static_cast<const T*>(this)->isA());
|
||||
if (!saveToAttributes(message->getAttributes()))
|
||||
return nullptr;
|
||||
return message;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
IPtr<T> IConvertibleToMessage<T>::convertFromMessage(Vst::IMessage& message)
|
||||
{
|
||||
IPtr<T> object;
|
||||
if (!strcmp(T::getFClassID(), message.getMessageID())) {
|
||||
object = owned(new T);
|
||||
if (!object->loadFromAttributes(message.getAttributes()))
|
||||
object = nullptr;
|
||||
}
|
||||
return object;
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue