From 518df314ebca6b8fad99c628a996d246614fd319 Mon Sep 17 00:00:00 2001 From: Paul Licameli Date: Thu, 13 Sep 2018 10:17:59 -0400 Subject: [PATCH] Rewrite GetLink(ed) in vamp effects --- src/effects/vamp/VampEffect.cpp | 40 ++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/src/effects/vamp/VampEffect.cpp b/src/effects/vamp/VampEffect.cpp index bb6e95b12..e326594c3 100644 --- a/src/effects/vamp/VampEffect.cpp +++ b/src/effects/vamp/VampEffect.cpp @@ -299,25 +299,25 @@ bool VampEffect::Init() { mRate = 0.0; - for (auto left : inputTracks()->Leaders< const WaveTrack >() ) - { - if (mRate == 0.0) - { - mRate = left->GetRate(); - } - - if (left->GetLinked()) - { - auto right = static_cast( left->GetLink() ); + // PRL: this loop checked that channels of a track have the same rate, + // but there was no check that all tracks have one rate, and only the first + // is remembered in mRate. Is that correct? + for (auto leader : inputTracks()->Leaders()) { + auto channelGroup = TrackList::Channels( leader ); + auto rate = (*channelGroup.first++) -> GetRate(); + for(auto channel : channelGroup) { + if (rate != channel->GetRate()) // PRL: Track rate might not match individual clip rates. // So is this check not adequate? - if (left->GetRate() != right->GetRate()) - { - Effect::MessageBox(_("Sorry, Vamp Plug-ins cannot be run on stereo tracks where the individual channels of the track do not match.")); - return false; + { + // TODO: more-than-two-channels-message + Effect::MessageBox(_("Sorry, Vamp Plug-ins cannot be run on stereo tracks where the individual channels of the track do not match.")); + return false; } } + if (mRate == 0.0) + mRate = rate; } if (mRate <= 0.0) @@ -361,22 +361,26 @@ bool VampEffect::Process() std::vector> addedTracks; - for (auto left : inputTracks()->Leaders< const WaveTrack >() ) + for (auto leader : inputTracks()->Leaders()) { + auto channelGroup = TrackList::Channels(leader); + auto left = *channelGroup.first++; + sampleCount lstart, rstart = 0; sampleCount len; GetSamples(left, &lstart, &len); unsigned channels = 1; - const WaveTrack *right{}; - if (left->GetLinked()) + const WaveTrack *right = *channelGroup.first++; + if (right) { - right = static_cast< const WaveTrack* >( left->GetLink() ); channels = 2; GetSamples(right, &rstart, &len); } + // TODO: more-than-two-channels + size_t step = mPlugin->getPreferredStepSize(); size_t block = mPlugin->getPreferredBlockSize();