From 204765ec0ce6f68ff7c3695f731c974622d5087d Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Sat, 26 Dec 2020 22:37:45 +0100 Subject: [PATCH] Implement IUnitInfo::getProgramName --- src/common/logging/vst3.cpp | 21 +++++++++ src/common/logging/vst3.h | 3 ++ src/common/serialization/vst3.h | 3 +- .../serialization/vst3/plugin/unit-info.h | 47 +++++++++++++++++-- .../bridges/vst3-impls/plugin-proxy.cpp | 12 +++-- src/wine-host/bridges/vst3.cpp | 11 +++++ 6 files changed, 88 insertions(+), 9 deletions(-) diff --git a/src/common/logging/vst3.cpp b/src/common/logging/vst3.cpp index 8ca1ef0d..76b6e327 100644 --- a/src/common/logging/vst3.cpp +++ b/src/common/logging/vst3.cpp @@ -462,6 +462,15 @@ bool Vst3Logger::log_request(bool is_host_vst, }); } +bool Vst3Logger::log_request(bool is_host_vst, + const YaUnitInfo::GetProgramName& request) { + return log_request_base(is_host_vst, [&](auto& message) { + message << request.instance_id + << ": IUnitInfo::getProgramName(listId = " << request.list_id + << ", programIndex = " << request.program_index << ", &name)"; + }); +} + bool Vst3Logger::log_request( bool is_host_vst, const YaAudioProcessor::SetBusArrangements& request) { @@ -883,6 +892,18 @@ void Vst3Logger::log_response( }); } +void Vst3Logger::log_response( + bool is_host_vst, + const YaUnitInfo::GetProgramNameResponse& response) { + log_response_base(is_host_vst, [&](auto& message) { + message << response.result.string(); + if (response.result == Steinberg::kResultOk) { + message << ", \"" << VST3::StringConvert::convert(response.name) + << "\""; + } + }); +} + void Vst3Logger::log_response( bool is_host_vst, const YaAudioProcessor::GetBusArrangementResponse& response) { diff --git a/src/common/logging/vst3.h b/src/common/logging/vst3.h index 697975cf..cf60d46c 100644 --- a/src/common/logging/vst3.h +++ b/src/common/logging/vst3.h @@ -112,6 +112,7 @@ class Vst3Logger { bool log_request(bool is_host_vst, const YaUnitInfo::GetUnitInfo&); bool log_request(bool is_host_vst, const YaUnitInfo::GetProgramListCount&); bool log_request(bool is_host_vst, const YaUnitInfo::GetProgramListInfo&); + bool log_request(bool is_host_vst, const YaUnitInfo::GetProgramName&); bool log_request(bool is_host_vst, const YaAudioProcessor::SetBusArrangements&); @@ -168,6 +169,8 @@ class Vst3Logger { void log_response(bool is_host_vst, const YaUnitInfo::GetUnitInfoResponse&); void log_response(bool is_host_vst, const YaUnitInfo::GetProgramListInfoResponse&); + void log_response(bool is_host_vst, + const YaUnitInfo::GetProgramNameResponse&); void log_response(bool is_host_vst, const YaAudioProcessor::GetBusArrangementResponse&); diff --git a/src/common/serialization/vst3.h b/src/common/serialization/vst3.h index 279f2e90..233e4534 100644 --- a/src/common/serialization/vst3.h +++ b/src/common/serialization/vst3.h @@ -103,7 +103,8 @@ using ControlRequest = std::variant; + YaUnitInfo::GetProgramListInfo, + YaUnitInfo::GetProgramName>; template void serialize(S& s, ControlRequest& payload) { diff --git a/src/common/serialization/vst3/plugin/unit-info.h b/src/common/serialization/vst3/plugin/unit-info.h index 21846b83..6ff6f454 100644 --- a/src/common/serialization/vst3/plugin/unit-info.h +++ b/src/common/serialization/vst3/plugin/unit-info.h @@ -81,7 +81,7 @@ class YaUnitInfo : public Steinberg::Vst::IUnitInfo { /** * The response code and returned unit information for a call to - * `IUnitInfo::getUnitInfo(unit_index)`. + * `IUnitInfo::getUnitInfo(unit_index, &info)`. */ struct GetUnitInfoResponse { UniversalTResult result; @@ -95,8 +95,8 @@ class YaUnitInfo : public Steinberg::Vst::IUnitInfo { }; /** - * Message to pass through a call to `IUnitInfo::getUnitInfo(unit_index)` to - * the Wine plugin host. + * Message to pass through a call to `IUnitInfo::getUnitInfo(unit_index, + * &info)` to the Wine plugin host. */ struct GetUnitInfo { using Response = GetUnitInfoResponse; @@ -135,7 +135,7 @@ class YaUnitInfo : public Steinberg::Vst::IUnitInfo { /** * The response code and returned unit information for a call to - * `IUnitInfo::getProgramListInfo(list_index)`. + * `IUnitInfo::getProgramListInfo(list_index, &info)`. */ struct GetProgramListInfoResponse { UniversalTResult result; @@ -150,7 +150,8 @@ class YaUnitInfo : public Steinberg::Vst::IUnitInfo { /** * Message to pass through a call to - * `IUnitInfo::getProgramListInfo(list_index)` to the Wine plugin host. + * `IUnitInfo::getProgramListInfo(list_index, &info)` to the Wine plugin + * host. */ struct GetProgramListInfo { using Response = GetProgramListInfoResponse; @@ -169,6 +170,42 @@ class YaUnitInfo : public Steinberg::Vst::IUnitInfo { virtual tresult PLUGIN_API getProgramListInfo( int32 listIndex, Steinberg::Vst::ProgramListInfo& info /*out*/) override = 0; + + /** + * The response code and returned name for a call to + * `IUnitInfo::getProgramName(list_id, program_index, &name)`. + */ + struct GetProgramNameResponse { + UniversalTResult result; + std::u16string name; + + template + void serialize(S& s) { + s.object(result); + s.text2b(name, std::extent_v); + } + }; + + /** + * Message to pass through a call to `IUnitInfo::getProgramName(list_id, + * program_index, &name)` to the Wine plugin host. + */ + struct GetProgramName { + using Response = GetProgramNameResponse; + + native_size_t instance_id; + + Steinberg::Vst::ProgramListID list_id; + int32 program_index; + + template + void serialize(S& s) { + s.value8b(instance_id); + s.value4b(list_id); + s.value4b(program_index); + } + }; + virtual tresult PLUGIN_API getProgramName(Steinberg::Vst::ProgramListID listId, int32 programIndex, diff --git a/src/plugin/bridges/vst3-impls/plugin-proxy.cpp b/src/plugin/bridges/vst3-impls/plugin-proxy.cpp index 7c182ad5..01ce3d98 100644 --- a/src/plugin/bridges/vst3-impls/plugin-proxy.cpp +++ b/src/plugin/bridges/vst3-impls/plugin-proxy.cpp @@ -478,9 +478,15 @@ tresult PLUGIN_API Vst3PluginProxyImpl::getProgramName(Steinberg::Vst::ProgramListID listId, int32 programIndex, Steinberg::Vst::String128 name /*out*/) { - // TODO: Implement - bridge.logger.log("TODO: IUnitInfo::getProgramName()"); - return Steinberg::kNotImplemented; + const GetProgramNameResponse response = bridge.send_message( + YaUnitInfo::GetProgramName{.instance_id = instance_id(), + .list_id = listId, + .program_index = programIndex}); + + std::copy(response.name.begin(), response.name.end(), name); + name[response.name.size()] = 0; + + return response.result; } tresult PLUGIN_API Vst3PluginProxyImpl::getProgramInfo( diff --git a/src/wine-host/bridges/vst3.cpp b/src/wine-host/bridges/vst3.cpp index 66ee170b..cc561337 100644 --- a/src/wine-host/bridges/vst3.cpp +++ b/src/wine-host/bridges/vst3.cpp @@ -596,6 +596,17 @@ void Vst3Bridge::run() { return YaUnitInfo::GetProgramListInfoResponse{.result = result, .info = info}; }, + [&](const YaUnitInfo::GetProgramName& request) + -> YaUnitInfo::GetProgramName::Response { + Steinberg::Vst::String128 name{0}; + const tresult result = + object_instances[request.instance_id] + .unit_info->getProgramName(request.list_id, + request.program_index, name); + + return YaUnitInfo::GetProgramNameResponse{ + .result = result, .name = tchar_pointer_to_u16string(name)}; + }, }); }