From 9746a6362526605560da40533032a9299e9bf3f9 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Tue, 6 Oct 2020 23:33:28 +0200 Subject: [PATCH] VST3: implement ChannelContext::IInfoListener --- libs/ardour/ardour/vst3_plugin.h | 5 +++ libs/ardour/vst3_host.cc | 3 ++ libs/ardour/vst3_plugin.cc | 71 ++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+) diff --git a/libs/ardour/ardour/vst3_plugin.h b/libs/ardour/ardour/vst3_plugin.h index 8215a55ae1..364950076b 100644 --- a/libs/ardour/ardour/vst3_plugin.h +++ b/libs/ardour/ardour/vst3_plugin.h @@ -181,6 +181,11 @@ private: bool midi_controller (int32_t, int16_t, Vst::CtrlNumber, Vst::ParamID &id); bool live_midi_cc (int32_t, int16_t, Vst::CtrlNumber); + void setup_info_listener (); + void stripable_property_changed (PBD::PropertyChange const&); + + PBD::ScopedConnectionList _strip_connections; + boost::shared_ptr _module; std::vector _connections; diff --git a/libs/ardour/vst3_host.cc b/libs/ardour/vst3_host.cc index 507e22a6f1..31f93cbe46 100644 --- a/libs/ardour/vst3_host.cc +++ b/libs/ardour/vst3_host.cc @@ -58,6 +58,7 @@ DEF_CLASS_IID (Vst::IProgramListData) DEF_CLASS_IID (Vst::IStreamAttributes) DEF_CLASS_IID (Vst::IUnitData) DEF_CLASS_IID (Vst::IUnitInfo) +DEF_CLASS_IID (Vst::ChannelContext::IInfoListener) #if SMTG_OS_LINUX DEF_CLASS_IID (Linux::IRunLoop); @@ -315,7 +316,9 @@ PlugInterfaceSupport::PlugInterfaceSupport () addPlugInterfaceSupported (INoteExpressionController::iid); //---VST 3.6.5-------------------------------- +#endif addPlugInterfaceSupported (ChannelContext::IInfoListener::iid); +#if 0 addPlugInterfaceSupported (IPrefetchableSupport::iid); addPlugInterfaceSupported (IAutomationState::iid); diff --git a/libs/ardour/vst3_plugin.cc b/libs/ardour/vst3_plugin.cc index d1d5ba8378..8f27340ff1 100644 --- a/libs/ardour/vst3_plugin.cc +++ b/libs/ardour/vst3_plugin.cc @@ -35,6 +35,7 @@ #include "ardour/audio_buffer.h" #include "ardour/audioengine.h" #include "ardour/session.h" +#include "ardour/stripable.h" #include "ardour/tempo.h" #include "ardour/utils.h" #include "ardour/vst3_module.h" @@ -1462,6 +1463,11 @@ void VST3PI::set_owner (SessionObject* o) { _owner = o; + if (!o) { + _strip_connections.drop_connections (); + return; + } + setup_info_listener (); } int32 @@ -2254,6 +2260,71 @@ VST3PI::save_state (RAMStream& stream) return entries.size () > 0; } +/* ****************************************************************************/ + +void +VST3PI::stripable_property_changed (PBD::PropertyChange const&) +{ + FUnknownPtr il (_controller); + Stripable* s = dynamic_cast (_owner); + assert (il && s); + + IPtr al (new HostAttributeList ()); + + Vst::String128 tmp; + utf8_to_tchar (tmp, _owner->name(), 128); + al->setInt (Vst::ChannelContext::kChannelNameLengthKey, _owner->name().size()); + al->setString (Vst::ChannelContext::kChannelNameKey, tmp); + + utf8_to_tchar (tmp, _owner->id().to_s(), 128); + al->setInt (Vst::ChannelContext::kChannelNameLengthKey, _owner->id().to_s().size()); + al->setString (Vst::ChannelContext::kChannelUIDKey, tmp); + + std::string ns; + int order_key; + if (s->is_master ()) { + ns = _("Master"); + order_key = 2; + } else if (s->is_monitor ()) { + ns = _("Monitor"); + order_key = 3; + } else { + ns = _("Track"); + order_key = 1; + } + + al->setInt (Vst::ChannelContext::kChannelIndexNamespaceOrderKey, order_key); + al->setInt (Vst::ChannelContext::kChannelIndexKey, 1 + s->presentation_info ().order()); + + utf8_to_tchar (tmp, ns, 128); + al->setInt (Vst::ChannelContext::kChannelIndexNamespaceLengthKey, ns.size()); + al->setString (Vst::ChannelContext::kChannelIndexNamespaceKey, tmp); + + uint32_t rgba = s->presentation_info ().color(); + Vst::ChannelContext::ColorSpec argb = ((rgba >> 8) & 0xffffff) | ((rgba & 0xff) << 24); + al->setInt (Vst::ChannelContext::kChannelColorKey, argb); + + al->setInt (Vst::ChannelContext::kChannelPluginLocationKey, Vst::ChannelContext::kPreVolumeFader); // XXX + + il->setChannelContextInfos (al); +} + +void +VST3PI::setup_info_listener () +{ + FUnknownPtr il (_controller); + if (!il) { + return; + } + Stripable* s = dynamic_cast (_owner); + + s->PropertyChanged.connect_same_thread (_strip_connections, boost::bind (&VST3PI::stripable_property_changed, this, _1)); + s->presentation_info().PropertyChanged.connect_same_thread (_strip_connections, boost::bind (&VST3PI::stripable_property_changed, this, _1)); + + /* send initial change */ + stripable_property_changed (PropertyChange ()); +} + /* **************************************************************************** * GUI */