Implement all event types

This commit is contained in:
Robbert van der Helm
2020-12-15 17:44:26 +01:00
parent d8c51d885b
commit f33b749172
6 changed files with 115 additions and 7 deletions
+21 -1
View File
@@ -19,7 +19,7 @@
#include "base.h"
std::u16string tchar_string_to_u16string(const Steinberg::Vst::TChar* string) {
std::u16string tchar_pointer_to_u16string(const Steinberg::Vst::TChar* string) {
#ifdef __WINE__
// This is great, thanks Steinberg
static_assert(sizeof(Steinberg::Vst::TChar) == sizeof(char16_t));
@@ -29,6 +29,26 @@ std::u16string tchar_string_to_u16string(const Steinberg::Vst::TChar* string) {
#endif
}
std::u16string tchar_pointer_to_u16string(const Steinberg::Vst::TChar* string,
uint32 length) {
#ifdef __WINE__
static_assert(sizeof(Steinberg::Vst::TChar) == sizeof(char16_t));
return std::u16string(reinterpret_cast<const char16_t*>(string), length);
#else
return std::u16string(static_cast<const char16_t*>(string), length);
#endif
}
const Steinberg::Vst::TChar* u16string_to_tchar_pointer(
const std::u16string& string) {
#ifdef __WINE__
static_assert(sizeof(Steinberg::Vst::TChar) == sizeof(char16_t));
return reinterpret_cast<const Steinberg::Vst::TChar*>(string.c_str());
#else
return static_cast<const Steinberg::Vst::TChar*>(string.c_str());
#endif
}
UniversalTResult::UniversalTResult() : universal_result(Value::kResultFalse) {}
UniversalTResult::UniversalTResult(tresult native_result)
+17 -3
View File
@@ -29,8 +29,8 @@
// we'll need for all of our interfaces
using Steinberg::TBool, Steinberg::int8, Steinberg::int16, Steinberg::int32,
Steinberg::int64, Steinberg::uint8, Steinberg::uint32, Steinberg::uint64,
Steinberg::tresult;
Steinberg::int64, Steinberg::uint8, Steinberg::uint16, Steinberg::uint32,
Steinberg::uint64, Steinberg::tresult;
/**
* Both `TUID` (`int8_t[16]`) and `FIDString` (`char*`) are hard to work with
@@ -57,7 +57,21 @@ constexpr size_t max_vector_stream_size = 50 << 20;
* Convert a UTF-16 C-style string to an `std::u16string`. Who event invented
* UTF-16?
*/
std::u16string tchar_string_to_u16string(const Steinberg::Vst::TChar* string);
std::u16string tchar_pointer_to_u16string(const Steinberg::Vst::TChar* string);
/**
* Same as the above, but with a fixed string length.
*
* @overload
*/
std::u16string tchar_pointer_to_u16string(const Steinberg::Vst::TChar* string,
uint32 length);
/**
* Convert an `std::u16string` back to a null terminated `TChar*` string.
*/
const Steinberg::Vst::TChar* u16string_to_tchar_pointer(
const std::u16string& string);
/**
* Empty struct for when we have send a response to some operation without any
@@ -0,0 +1,72 @@
// yabridge: a Wine VST bridge
// Copyright (C) 2020 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 "event-list.h"
YaDataEvent::YaDataEvent() {}
YaDataEvent::YaDataEvent(const Steinberg::Vst::DataEvent& event)
: type(event.type), buffer(event.bytes, event.bytes + event.size) {}
Steinberg::Vst::DataEvent YaDataEvent::get() const {
return Steinberg::Vst::DataEvent{.size = static_cast<uint32>(buffer.size()),
.type = type,
.bytes = buffer.data()};
}
YaNoteExpressionTextEvent::YaNoteExpressionTextEvent() {}
YaNoteExpressionTextEvent::YaNoteExpressionTextEvent(
const Steinberg::Vst::NoteExpressionTextEvent& event)
: type_id(event.typeId),
note_id(event.noteId),
text(tchar_pointer_to_u16string(event.text, event.textLen)) {}
Steinberg::Vst::NoteExpressionTextEvent YaNoteExpressionTextEvent::get() const {
return Steinberg::Vst::NoteExpressionTextEvent{
.typeId = type_id,
.noteId = note_id,
.textLen = static_cast<uint32>(text.size()),
.text = u16string_to_tchar_pointer(text)};
}
YaChordEvent::YaChordEvent() {}
YaChordEvent::YaChordEvent(const Steinberg::Vst::ChordEvent& event)
: root(event.root),
bass_note(event.bassNote),
text(tchar_pointer_to_u16string(event.text, event.textLen)) {}
Steinberg::Vst::ChordEvent YaChordEvent::get() const {
return Steinberg::Vst::ChordEvent{
.root = root,
.bassNote = bass_note,
.textLen = static_cast<uint16>(text.size()),
.text = u16string_to_tchar_pointer(text)};
}
YaScaleEvent::YaScaleEvent() {}
YaScaleEvent::YaScaleEvent(const Steinberg::Vst::ScaleEvent& event)
: root(event.root),
text(tchar_pointer_to_u16string(event.text, event.textLen)) {}
Steinberg::Vst::ScaleEvent YaScaleEvent::get() const {
return Steinberg::Vst::ScaleEvent{
.root = root,
.textLen = static_cast<uint16>(text.size()),
.text = u16string_to_tchar_pointer(text)};
}
+2 -2
View File
@@ -45,12 +45,12 @@ struct YaDataEvent {
Steinberg::Vst::DataEvent get() const;
uint32 type;
std::vector<uint8> data;
std::vector<uint8> buffer;
template <typename S>
void serialize(S& s) {
s.value4b(type);
s.container1b(data, 1 << 16);
s.container1b(buffer, 1 << 16);
}
};
@@ -24,7 +24,7 @@ YaHostApplication::ConstructArgs::ConstructArgs(
: component_instance_id(component_instance_id) {
Steinberg::Vst::String128 name_array;
if (context->getName(name_array) == Steinberg::kResultOk) {
name = tchar_string_to_u16string(name_array);
name = tchar_pointer_to_u16string(name_array);
}
}