Pass through host provided IBStream objects

So if the host supports IStreamAttributes, we can also provide objects
that support the same itnerface to the plugin.
This commit is contained in:
Robbert van der Helm
2021-01-10 16:57:36 +01:00
parent 9b603a964c
commit 8971a65825
9 changed files with 65 additions and 50 deletions
+16 -16
View File
@@ -30,25 +30,25 @@ YaBStream::YaBStream(Steinberg::IBStream* stream) {
throw std::runtime_error("Null pointer passed to YaBStream()");
}
if (stream->seek(0, Steinberg::IBStream::IStreamSeekMode::kIBSeekEnd) !=
// Copy any existing contents, used for `IComponent::setState` and similar
// methods
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);
}
// 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);
// Starting at VST 3.6.0 streams provided by the host may contain context
// based meta data
if (Steinberg::FUnknownPtr<Steinberg::Vst::IStreamAttributes>
+5
View File
@@ -39,6 +39,11 @@ class YaBStream : public Steinberg::IBStream,
public Steinberg::ISizeableStream,
public Steinberg::Vst::IStreamAttributes {
public:
/**
* This constructor should only be used by bitsery for serialization. The
* other constructor will check whether the `IBstream*` provided by the host
* supports stream attributes and configures the object accordingly.
*/
YaBStream();
/**
+7 -4
View File
@@ -225,31 +225,34 @@ class Vst3PluginProxy : public YaAudioPresentationLatency,
/**
* The response code and written state for a call to
* `{IComponent,IEditController}::getState(state)`.
* `{IComponent,IEditController}::getState(&state)`.
*/
struct GetStateResponse {
UniversalTResult result;
YaBStream updated_state;
YaBStream state;
template <typename S>
void serialize(S& s) {
s.object(result);
s.object(updated_state);
s.object(state);
}
};
/**
* Message to pass through a call to
* `{IComponent,IEditController}::getState(state)` to the Wine plugin host.
* `{IComponent,IEditController}::getState(&state)` to the Wine plugin host.
*/
struct GetState {
using Response = GetStateResponse;
native_size_t instance_id;
YaBStream state;
template <typename S>
void serialize(S& s) {
s.value8b(instance_id);
s.object(state);
}
};
@@ -111,12 +111,14 @@ class YaProgramListData : public Steinberg::Vst::IProgramListData {
Steinberg::Vst::ProgramListID list_id;
int32 program_index;
YaBStream data;
template <typename S>
void serialize(S& s) {
s.value8b(instance_id);
s.value4b(list_id);
s.value4b(program_index);
s.object(data);
}
};
@@ -108,11 +108,13 @@ class YaUnitData : public Steinberg::Vst::IUnitData {
native_size_t instance_id;
Steinberg::Vst::UnitID unit_id;
YaBStream data;
template <typename S>
void serialize(S& s) {
s.value8b(instance_id);
s.value4b(unit_id);
s.object(data);
}
};
@@ -96,11 +96,13 @@ class YaXmlRepresentationController
native_size_t instance_id;
Steinberg::Vst::RepresentationInfo info;
YaBStream stream;
template <typename S>
void serialize(S& s) {
s.value8b(instance_id);
s.object(info);
s.object(stream);
}
};