Move VectorStream to a new YaBStream

We'll have to extend this with `IStreamAttributes` for VST 3.6.0 preset
meta data.
This commit is contained in:
Robbert van der Helm
2021-01-10 15:11:19 +01:00
parent 8ac39a3bf6
commit 9b62386099
13 changed files with 291 additions and 244 deletions
+2
View File
@@ -137,6 +137,7 @@ vst3_plugin_sources = [
'src/common/serialization/vst3/plugin/xml-representation-controller.cpp',
'src/common/serialization/vst3/attribute-list.cpp',
'src/common/serialization/vst3/base.cpp',
'src/common/serialization/vst3/bstream.cpp',
'src/common/serialization/vst3/component-handler-proxy.cpp',
'src/common/serialization/vst3/connection-point-proxy.cpp',
'src/common/serialization/vst3/context-menu-proxy.cpp',
@@ -210,6 +211,7 @@ if with_vst3
'src/common/serialization/vst3/plugin/xml-representation-controller.cpp',
'src/common/serialization/vst3/attribute-list.cpp',
'src/common/serialization/vst3/base.cpp',
'src/common/serialization/vst3/bstream.cpp',
'src/common/serialization/vst3/component-handler-proxy.cpp',
'src/common/serialization/vst3/connection-point-proxy.cpp',
'src/common/serialization/vst3/context-menu-proxy.cpp',
+10 -10
View File
@@ -55,16 +55,16 @@ VST3 host interfaces are implemented as follows:
The following host interfaces are passed as function arguments and are thus also
implemented for serialization purposes:
| yabridge class | Interfaces | Notes |
| --------------------- | -------------------- | --------------------------------------------------------------------- |
| `YaAttributeList` | `IAttributeList` | |
| `YaContextMenuTarget` | `IContextMenuTarget` | Used in `YaContextMenu` to proxy specific menu items |
| `YaEventList` | `IEventList` | Comes with a lot of serialization wrappers around the related structs |
| `YaMessage` | `IMessage` | |
| `YaMessagePtr` | `IMessage` | Should be used in inter process communication to exchange messages |
| `YaParameterChanges` | `IParameterChanges` | |
| `YaParamValueQueue` | `IParamValueQueue` | |
| `VectorStream` | `IBStream` | Used for serializing data streams |
| yabridge class | Interfaces | Notes |
| --------------------- | ----------------------------- | --------------------------------------------------------------------- |
| `YaAttributeList` | `IAttributeList` | |
| `YaBStream` | `IBStream`, `ISizeableStream` | Used for serializing data streams |
| `YaContextMenuTarget` | `IContextMenuTarget` | Used in `YaContextMenu` to proxy specific menu items |
| `YaEventList` | `IEventList` | Comes with a lot of serialization wrappers around the related structs |
| `YaMessage` | `IMessage` | |
| `YaMessagePtr` | `IMessage` | Should be used in inter process communication to exchange messages |
| `YaParameterChanges` | `IParameterChanges` | |
| `YaParamValueQueue` | `IParamValueQueue` | |
And finally `YaProcessData` uses the above along with `YaAudioBusBuffers` to
wrap around `ProcessData`.
-156
View File
@@ -172,159 +172,3 @@ UniversalTResult::Value UniversalTResult::to_universal_result(
break;
}
}
VectorStream::VectorStream(){FUNKNOWN_CTOR}
VectorStream::VectorStream(Steinberg::IBStream* stream) {
FUNKNOWN_CTOR
if (!stream) {
throw std::runtime_error("Null pointer passed to VectorStream()");
}
if (stream->seek(0, Steinberg::IBStream::IStreamSeekMode::kIBSeekEnd) !=
Steinberg::kResultOk) {
throw std::runtime_error(
"IBStream passed to VectorStream() does not suport seeking to end");
}
// Now that we're at the end of the stream we know how large the buffer
// should be
int64 size;
assert(stream->tell(&size) == Steinberg::kResultOk);
int32 num_bytes_read = 0;
buffer.resize(size);
assert(stream->seek(0, Steinberg::IBStream::IStreamSeekMode::kIBSeekSet) ==
Steinberg::kResultOk);
assert(stream->read(buffer.data(), size, &num_bytes_read) ==
Steinberg::kResultOk);
assert(num_bytes_read == 0 || num_bytes_read == size);
}
VectorStream::~VectorStream() {
FUNKNOWN_DTOR
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdelete-non-virtual-dtor"
IMPLEMENT_REFCOUNT(VectorStream)
#pragma GCC diagnostic pop
tresult PLUGIN_API VectorStream::queryInterface(Steinberg::FIDString _iid,
void** obj) {
QUERY_INTERFACE(_iid, obj, Steinberg::FUnknown::iid, Steinberg::IBStream)
QUERY_INTERFACE(_iid, obj, Steinberg::IBStream::iid, Steinberg::IBStream)
QUERY_INTERFACE(_iid, obj, Steinberg::ISizeableStream::iid,
Steinberg::ISizeableStream)
*obj = nullptr;
return Steinberg::kNoInterface;
}
tresult VectorStream::write_back(Steinberg::IBStream* stream) const {
if (!stream) {
return Steinberg::kInvalidArgument;
}
// A `stream->seek(0, kIBSeekSet)` breaks restoring states in Bitwig. Not
// sure if Bitwig is prepending a header or if this is expected behaviour.
int32 num_bytes_written = 0;
if (stream->write(const_cast<uint8_t*>(buffer.data()), buffer.size(),
&num_bytes_written) == Steinberg::kResultOk) {
// Some implementations will return `kResultFalse` when writing 0 bytes
assert(num_bytes_written == 0 ||
static_cast<size_t>(num_bytes_written) == buffer.size());
}
return Steinberg::kResultOk;
}
size_t VectorStream::size() const {
return buffer.size();
}
tresult PLUGIN_API VectorStream::read(void* buffer,
int32 numBytes,
int32* numBytesRead) {
if (!buffer || numBytes < 0) {
return Steinberg::kInvalidArgument;
}
size_t bytes_to_read = std::min(static_cast<size_t>(numBytes),
this->buffer.size() - seek_position);
std::copy_n(&this->buffer[seek_position], bytes_to_read,
reinterpret_cast<uint8_t*>(buffer));
seek_position += bytes_to_read;
if (numBytesRead) {
*numBytesRead = bytes_to_read;
}
return Steinberg::kResultOk;
}
tresult PLUGIN_API VectorStream::write(void* buffer,
int32 numBytes,
int32* numBytesWritten) {
if (!buffer || numBytes < 0) {
return Steinberg::kInvalidArgument;
}
if (seek_position + numBytes > this->buffer.size()) {
this->buffer.resize(seek_position + numBytes);
}
std::copy_n(reinterpret_cast<uint8_t*>(buffer), numBytes,
this->buffer.begin() + seek_position);
seek_position += numBytes;
if (numBytesWritten) {
*numBytesWritten = numBytes;
}
return Steinberg::kResultOk;
}
tresult PLUGIN_API VectorStream::seek(int64 pos, int32 mode, int64* result) {
switch (mode) {
case kIBSeekSet:
seek_position = pos;
break;
case kIBSeekCur:
seek_position += pos;
break;
case kIBSeekEnd:
seek_position = this->buffer.size() + pos;
break;
default:
return Steinberg::kInvalidArgument;
break;
}
if (result) {
*result = seek_position;
}
return Steinberg::kResultOk;
}
tresult PLUGIN_API VectorStream::tell(int64* pos) {
if (pos) {
*pos = seek_position;
return Steinberg::kResultOk;
} else {
return Steinberg::kInvalidArgument;
}
}
tresult PLUGIN_API VectorStream::getStreamSize(int64& size) {
size = seek_position;
return Steinberg::kResultOk;
}
tresult PLUGIN_API VectorStream::setStreamSize(int64 size) {
buffer.resize(size);
return Steinberg::kResultOk;
}
-65
View File
@@ -22,7 +22,6 @@
#include <pluginterfaces/base/ftypes.h>
#include <pluginterfaces/base/funknown.h>
#include <pluginterfaces/base/ibstream.h>
#include <pluginterfaces/vst/vsttypes.h>
// Yet Another layer of includes, but these are some VST3-specific typedefs that
@@ -165,67 +164,3 @@ class UniversalTResult {
Value universal_result;
};
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
/**
* Serialize an `IBStream` into an `std::vector<uint8_t>`, and allow the
* receiving side to use it as an `IBStream` again. `ISizeableStream` is defined
* but then for whatever reason never used, but we'll implement it anyways.
*/
class VectorStream : public Steinberg::IBStream,
public Steinberg::ISizeableStream {
public:
VectorStream();
/**
* Read an existing stream.
*
* @throw std::runtime_error If we couldn't read from the stream.
*/
VectorStream(Steinberg::IBStream* stream);
virtual ~VectorStream();
DECLARE_FUNKNOWN_METHODS
/**
* Write the vector buffer back to an IBStream. After writing the seek
* position will be left at the end of the stream.
*/
tresult write_back(Steinberg::IBStream* stream) const;
/**
* Return the buffer's, used in the logging messages.
*/
size_t size() const;
// From `IBstream`
tresult PLUGIN_API read(void* buffer,
int32 numBytes,
int32* numBytesRead = nullptr) override;
tresult PLUGIN_API write(void* buffer,
int32 numBytes,
int32* numBytesWritten = nullptr) override;
tresult PLUGIN_API seek(int64 pos,
int32 mode,
int64* result = nullptr) override;
tresult PLUGIN_API tell(int64* pos) override;
// From `ISizeableStream`
tresult PLUGIN_API getStreamSize(int64& size) override;
tresult PLUGIN_API setStreamSize(int64 size) override;
template <typename S>
void serialize(S& s) {
s.container1b(buffer, max_vector_stream_size);
// The seek position should always be initialized at 0
}
private:
std::vector<uint8_t> buffer;
size_t seek_position = 0;
};
#pragma GCC diagnostic pop
+176
View File
@@ -0,0 +1,176 @@
// yabridge: a Wine VST bridge
// Copyright (C) 2020-2021 Robbert van der Helm
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "bstream.h"
#include <cassert>
#include <stdexcept>
YaBStream::YaBStream(){FUNKNOWN_CTOR}
YaBStream::YaBStream(Steinberg::IBStream* stream) {
FUNKNOWN_CTOR
if (!stream) {
throw std::runtime_error("Null pointer passed to YaBStream()");
}
if (stream->seek(0, Steinberg::IBStream::IStreamSeekMode::kIBSeekEnd) !=
Steinberg::kResultOk) {
throw std::runtime_error(
"IBStream passed to YaBStream() does not suport seeking to end");
}
// Now that we're at the end of the stream we know how large the buffer
// should be
int64 size;
assert(stream->tell(&size) == Steinberg::kResultOk);
int32 num_bytes_read = 0;
buffer.resize(size);
assert(stream->seek(0, Steinberg::IBStream::IStreamSeekMode::kIBSeekSet) ==
Steinberg::kResultOk);
assert(stream->read(buffer.data(), size, &num_bytes_read) ==
Steinberg::kResultOk);
assert(num_bytes_read == 0 || num_bytes_read == size);
}
YaBStream::~YaBStream() {
FUNKNOWN_DTOR
}
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdelete-non-virtual-dtor"
IMPLEMENT_REFCOUNT(YaBStream)
#pragma GCC diagnostic pop
tresult PLUGIN_API YaBStream::queryInterface(Steinberg::FIDString _iid,
void** obj) {
QUERY_INTERFACE(_iid, obj, Steinberg::FUnknown::iid, Steinberg::IBStream)
QUERY_INTERFACE(_iid, obj, Steinberg::IBStream::iid, Steinberg::IBStream)
QUERY_INTERFACE(_iid, obj, Steinberg::ISizeableStream::iid,
Steinberg::ISizeableStream)
*obj = nullptr;
return Steinberg::kNoInterface;
}
tresult YaBStream::write_back(Steinberg::IBStream* stream) const {
if (!stream) {
return Steinberg::kInvalidArgument;
}
// A `stream->seek(0, kIBSeekSet)` breaks restoring states in Bitwig. Not
// sure if Bitwig is prepending a header or if this is expected behaviour.
int32 num_bytes_written = 0;
if (stream->write(const_cast<uint8_t*>(buffer.data()), buffer.size(),
&num_bytes_written) == Steinberg::kResultOk) {
// Some implementations will return `kResultFalse` when writing 0 bytes
assert(num_bytes_written == 0 ||
static_cast<size_t>(num_bytes_written) == buffer.size());
}
return Steinberg::kResultOk;
}
size_t YaBStream::size() const {
return buffer.size();
}
tresult PLUGIN_API YaBStream::read(void* buffer,
int32 numBytes,
int32* numBytesRead) {
if (!buffer || numBytes < 0) {
return Steinberg::kInvalidArgument;
}
size_t bytes_to_read = std::min(static_cast<size_t>(numBytes),
this->buffer.size() - seek_position);
std::copy_n(&this->buffer[seek_position], bytes_to_read,
reinterpret_cast<uint8_t*>(buffer));
seek_position += bytes_to_read;
if (numBytesRead) {
*numBytesRead = bytes_to_read;
}
return Steinberg::kResultOk;
}
tresult PLUGIN_API YaBStream::write(void* buffer,
int32 numBytes,
int32* numBytesWritten) {
if (!buffer || numBytes < 0) {
return Steinberg::kInvalidArgument;
}
if (seek_position + numBytes > this->buffer.size()) {
this->buffer.resize(seek_position + numBytes);
}
std::copy_n(reinterpret_cast<uint8_t*>(buffer), numBytes,
this->buffer.begin() + seek_position);
seek_position += numBytes;
if (numBytesWritten) {
*numBytesWritten = numBytes;
}
return Steinberg::kResultOk;
}
tresult PLUGIN_API YaBStream::seek(int64 pos, int32 mode, int64* result) {
switch (mode) {
case kIBSeekSet:
seek_position = pos;
break;
case kIBSeekCur:
seek_position += pos;
break;
case kIBSeekEnd:
seek_position = this->buffer.size() + pos;
break;
default:
return Steinberg::kInvalidArgument;
break;
}
if (result) {
*result = seek_position;
}
return Steinberg::kResultOk;
}
tresult PLUGIN_API YaBStream::tell(int64* pos) {
if (pos) {
*pos = seek_position;
return Steinberg::kResultOk;
} else {
return Steinberg::kInvalidArgument;
}
}
tresult PLUGIN_API YaBStream::getStreamSize(int64& size) {
size = seek_position;
return Steinberg::kResultOk;
}
tresult PLUGIN_API YaBStream::setStreamSize(int64 size) {
buffer.resize(size);
return Steinberg::kResultOk;
}
+85
View File
@@ -0,0 +1,85 @@
// yabridge: a Wine VST bridge
// Copyright (C) 2020-2021 Robbert van der Helm
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma once
#include <pluginterfaces/base/ibstream.h>
#include "base.h"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
/**
* Serialize an `IBStream` into an `std::vector<uint8_t>`, and allow the
* receiving side to use it as an `IBStream` again. `ISizeableStream` is defined
* but then for whatever reason never used, but we'll implement it anyways.
*/
class YaBStream : public Steinberg::IBStream,
public Steinberg::ISizeableStream {
public:
YaBStream();
/**
* Read an existing stream.
*
* @throw std::runtime_error If we couldn't read from the stream.
*/
YaBStream(Steinberg::IBStream* stream);
virtual ~YaBStream();
DECLARE_FUNKNOWN_METHODS
/**
* Write the vector buffer back to an IBStream. After writing the seek
* position will be left at the end of the stream.
*/
tresult write_back(Steinberg::IBStream* stream) const;
/**
* Return the buffer's, used in the logging messages.
*/
size_t size() const;
// From `IBstream`
tresult PLUGIN_API read(void* buffer,
int32 numBytes,
int32* numBytesRead = nullptr) override;
tresult PLUGIN_API write(void* buffer,
int32 numBytes,
int32* numBytesWritten = nullptr) override;
tresult PLUGIN_API seek(int64 pos,
int32 mode,
int64* result = nullptr) override;
tresult PLUGIN_API tell(int64* pos) override;
// From `ISizeableStream`
tresult PLUGIN_API getStreamSize(int64& size) override;
tresult PLUGIN_API setStreamSize(int64 size) override;
template <typename S>
void serialize(S& s) {
s.container1b(buffer, max_vector_stream_size);
// The seek position should always be initialized at 0
}
private:
std::vector<uint8_t> buffer;
size_t seek_position = 0;
};
#pragma GCC diagnostic pop
+2 -2
View File
@@ -214,7 +214,7 @@ class Vst3PluginProxy : public YaAudioPresentationLatency,
native_size_t instance_id;
VectorStream state;
YaBStream state;
template <typename S>
void serialize(S& s) {
@@ -229,7 +229,7 @@ class Vst3PluginProxy : public YaAudioPresentationLatency,
*/
struct GetStateResponse {
UniversalTResult result;
VectorStream updated_state;
YaBStream updated_state;
template <typename S>
void serialize(S& s) {
@@ -21,6 +21,7 @@
#include "../../common.h"
#include "../base.h"
#include "../bstream.h"
#include "../component-handler-proxy.h"
#include "../plug-view-proxy.h"
@@ -73,7 +74,7 @@ class YaEditController : public Steinberg::Vst::IEditController {
native_size_t instance_id;
VectorStream state;
YaBStream state;
template <typename S>
void serialize(S& s) {
@@ -20,6 +20,7 @@
#include "../../common.h"
#include "../base.h"
#include "../bstream.h"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
@@ -89,7 +90,7 @@ class YaProgramListData : public Steinberg::Vst::IProgramListData {
*/
struct GetProgramDataResponse {
UniversalTResult result;
VectorStream data;
YaBStream data;
template <typename S>
void serialize(S& s) {
@@ -136,7 +137,7 @@ class YaProgramListData : public Steinberg::Vst::IProgramListData {
Steinberg::Vst::ProgramListID list_id;
int32 program_index;
VectorStream data;
YaBStream data;
template <typename S>
void serialize(S& s) {
@@ -20,6 +20,7 @@
#include "../../common.h"
#include "../base.h"
#include "../bstream.h"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
@@ -88,7 +89,7 @@ class YaUnitData : public Steinberg::Vst::IUnitData {
*/
struct GetUnitDataResponse {
UniversalTResult result;
VectorStream data;
YaBStream data;
template <typename S>
void serialize(S& s) {
@@ -129,7 +130,7 @@ class YaUnitData : public Steinberg::Vst::IUnitData {
native_size_t instance_id;
Steinberg::Vst::UnitID unit_id;
VectorStream data;
YaBStream data;
template <typename S>
void serialize(S& s) {
@@ -20,6 +20,7 @@
#include "../../common.h"
#include "../base.h"
#include "../bstream.h"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
@@ -420,7 +421,7 @@ class YaUnitInfo : public Steinberg::Vst::IUnitInfo {
int32 list_or_unit_id;
int32 program_index;
VectorStream data;
YaBStream data;
template <typename S>
void serialize(S& s) {
@@ -20,6 +20,7 @@
#include "../../common.h"
#include "../base.h"
#include "../bstream.h"
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
@@ -75,7 +76,7 @@ class YaXmlRepresentationController
*/
struct GetXmlRepresentationStreamResponse {
UniversalTResult result;
VectorStream stream;
YaBStream stream;
template <typename S>
void serialize(S& s) {
+4 -4
View File
@@ -172,7 +172,7 @@ void Vst3Bridge::run() {
},
[&](Vst3PluginProxy::GetState& request)
-> Vst3PluginProxy::GetState::Response {
VectorStream stream{};
YaBStream stream{};
tresult result;
// This same function is defined in both `IComponent` and
@@ -741,7 +741,7 @@ void Vst3Bridge::run() {
},
[&](const YaProgramListData::GetProgramData& request)
-> YaProgramListData::GetProgramData::Response {
VectorStream data{};
YaBStream data{};
const tresult result =
object_instances[request.instance_id]
.program_list_data->getProgramData(
@@ -763,7 +763,7 @@ void Vst3Bridge::run() {
},
[&](const YaUnitData::GetUnitData& request)
-> YaUnitData::GetUnitData::Response {
VectorStream data{};
YaBStream data{};
const tresult result =
object_instances[request.instance_id]
.unit_data->getUnitData(request.unit_id, &data);
@@ -898,7 +898,7 @@ void Vst3Bridge::run() {
[&](YaXmlRepresentationController::GetXmlRepresentationStream&
request) -> YaXmlRepresentationController::
GetXmlRepresentationStream::Response {
VectorStream stream{};
YaBStream stream{};
const tresult result =
object_instances[request.instance_id]
.xml_representation_controller