G2.1: save full instrument state to disk (path/type/preset/transport)
This commit is contained in:
@@ -549,6 +549,44 @@ void Vst3Instrument::captureState() {
|
||||
#endif
|
||||
}
|
||||
|
||||
// G2.1: base64 encode (RFC 4648). Small, dependency-free.
|
||||
static std::string base64Encode(const uint8_t* data, size_t len) {
|
||||
static const char* tbl = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
std::string out;
|
||||
out.reserve(((len + 2) / 3) * 4);
|
||||
for (size_t i = 0; i < len; i += 3) {
|
||||
uint32_t n = (uint32_t)data[i] << 16;
|
||||
if (i + 1 < len) n |= (uint32_t)data[i + 1] << 8;
|
||||
if (i + 2 < len) n |= (uint32_t)data[i + 2];
|
||||
out += tbl[(n >> 18) & 63];
|
||||
out += tbl[(n >> 12) & 63];
|
||||
out += (i + 1 < len) ? tbl[(n >> 6) & 63] : '=';
|
||||
out += (i + 2 < len) ? tbl[n & 63] : '=';
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
std::string Vst3Instrument::serializeState() const {
|
||||
#ifndef HAVE_VST3SDK
|
||||
return std::string();
|
||||
#else
|
||||
if (savedComponentState_.empty() && savedControllerState_.empty())
|
||||
return std::string();
|
||||
std::vector<uint8_t> blob;
|
||||
auto append32 = [&blob](uint32_t v) {
|
||||
blob.push_back((uint8_t)(v >> 24));
|
||||
blob.push_back((uint8_t)(v >> 16));
|
||||
blob.push_back((uint8_t)(v >> 8));
|
||||
blob.push_back((uint8_t)v);
|
||||
};
|
||||
append32((uint32_t)savedComponentState_.size());
|
||||
blob.insert(blob.end(), savedComponentState_.begin(), savedComponentState_.end());
|
||||
append32((uint32_t)savedControllerState_.size());
|
||||
blob.insert(blob.end(), savedControllerState_.begin(), savedControllerState_.end());
|
||||
return base64Encode(blob.data(), blob.size());
|
||||
#endif
|
||||
}
|
||||
|
||||
// G0.4: restore the captured state onto the freshly loaded instance.
|
||||
void Vst3Instrument::restoreState() {
|
||||
#ifndef HAVE_VST3SDK
|
||||
|
||||
Reference in New Issue
Block a user