1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-05-02 08:39:46 +02:00

Define TrackList::GroupChannels()

This commit is contained in:
Paul Licameli 2018-09-19 14:32:41 -04:00
parent 31d46ae624
commit 7e6a543473
2 changed files with 63 additions and 0 deletions

View File

@ -38,6 +38,7 @@ and TimeTrack.
#include "DirManager.h"
#include "Experimental.h"
#include "InconsistencyException.h"
#include "TrackPanel.h" // for TrackInfo
@ -724,6 +725,58 @@ Track *TrackList::Add(std::shared_ptr<TrackKind> &&t)
template Track *TrackList::Add<Track>(std::shared_ptr<Track> &&);
template Track *TrackList::Add<WaveTrack>(std::shared_ptr<WaveTrack> &&);
void TrackList::GroupChannels(
Track &track, size_t groupSize, bool resetChannels )
{
// If group size is more than two, for now only the first two channels
// are grouped as stereo, and any others remain mono
auto list = track.mList.lock();
if ( groupSize > 0 && list.get() == this ) {
auto iter = track.mNode.first;
auto after = iter;
auto end = this->ListOfTracks::end();
auto count = groupSize;
for ( ; after != end && count--; ++after )
;
if ( count == 0 ) {
auto unlink = [&] ( Track &tr ) {
if ( tr.GetLinked() ) {
if ( resetChannels ) {
auto link = tr.GetLink();
if ( link )
link->SetChannel( Track::MonoChannel );
}
tr.SetLinked( false );
}
if ( resetChannels )
tr.SetChannel( Track::MonoChannel );
};
// Disassociate previous tracks -- at most one
auto pLeader = this->FindLeader( &track );
if ( *pLeader && *pLeader != &track )
unlink( **pLeader );
// First disassociate given and later tracks, then reassociate them
for ( auto iter2 = iter; iter2 != after; ++iter2 )
unlink( **iter2 );
if ( groupSize > 1 ) {
const auto channel = *iter++;
channel->SetLinked( true );
channel->SetChannel( Track::LeftChannel );
(*iter++)->SetChannel( Track::RightChannel );
while (iter != after)
(*iter++)->SetChannel( Track::MonoChannel );
}
return;
}
}
// *this does not contain the track or sufficient following channels
// or group size is zero
throw InconsistencyException{};
}
auto TrackList::Replace(Track * t, ListOfTracks::value_type &&with) ->
ListOfTracks::value_type
{

View File

@ -1318,6 +1318,16 @@ public:
template<typename TrackKind>
Track *Add(std::shared_ptr<TrackKind> &&t);
/** \brief Define a group of channels starting at the given track
*
* @param track and (groupSize - 1) following tracks must be in this
* list. They will be disassociated from any groups they already belong to.
* @param groupSize must be at least 1.
* @param resetChannels if true, disassociated channels will be marked Mono.
*/
void GroupChannels(
Track &track, size_t groupSize, bool resetChannels = true );
/// Replace first track with second track, give back a holder
/// Give the replacement the same id as the replaced
ListOfTracks::value_type Replace(Track * t, ListOfTracks::value_type &&with);