From 2a3eb6dc88cc91a54fa608214e66fa730536fe9d Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Fri, 17 Mar 2023 15:46:34 +0100 Subject: [PATCH] VST3: match pin-mapping with VST speaker-arrangement This enables all channels left of the last connected pin for each given bus. e.g. when using just the 2nd (right) input of a given bus, the plugin is configure in stereo mode, with the 1st (left) input being fed with silence. VST3 does not have a "right-channel mono" configuration. It is also preferable to have Ardour do the pin/channel mapping. --- libs/ardour/vst3_plugin.cc | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/libs/ardour/vst3_plugin.cc b/libs/ardour/vst3_plugin.cc index 574898d063..883fb61d8d 100644 --- a/libs/ardour/vst3_plugin.cc +++ b/libs/ardour/vst3_plugin.cc @@ -2137,15 +2137,18 @@ VST3PI::enable_io (std::vector const& ins, std::vector const& outs) while (sa_in.size () < (VSTSpeakerArrangements::size_type) _n_bus_in) { bool enable = false; + int32_t const n_chn = _bus_info_in[sa_in.size ()].n_chn; Vst::SpeakerArrangement sa = 0; _bus_info_in[sa_in.size ()].n_used_chn = 0; - for (int i = 0; i < _bus_info_in[sa_in.size ()].n_chn; ++i) { - if (ins[cnt++]) { + /* use all channels before the last connected one */ + for (int32_t i = n_chn - 1; i >= 0; --i) { + if (ins[cnt + i] || enable) { sa |= (uint64_t)1 << i; ++_bus_info_in[sa_in.size ()].n_used_chn; enable = true; } } + cnt += n_chn; /* special case for Left only == Mono */ if (sa == 1 /*Vst::SpeakerArr::kSpeakerL */) { sa = Vst::SpeakerArr::kMono; /* 1 << 19 */ @@ -2158,16 +2161,18 @@ VST3PI::enable_io (std::vector const& ins, std::vector const& outs) cnt = 0; while (sa_out.size () < (VSTSpeakerArrangements::size_type) _n_bus_out) { - bool enable = false; + bool enable = false; + int32_t const n_chn = _bus_info_out[sa_out.size ()].n_chn; Vst::SpeakerArrangement sa = 0; _bus_info_out[sa_out.size ()].n_used_chn = 0; - for (int i = 0; i < _bus_info_out[sa_out.size ()].n_chn; ++i) { - if (outs[cnt++]) { + for (int32_t i = n_chn - 1; i >= 0; --i) { + if (outs[cnt + i] || enable) { sa |= (uint64_t)1 << i; ++_bus_info_out[sa_out.size ()].n_used_chn; enable = true; } } + cnt += n_chn; /* special case for Left only == Mono */ if (sa == 1 /*Vst::SpeakerArr::kSpeakerL */) { sa = Vst::SpeakerArr::kMono; /* 1 << 19 */