mirror of
https://github.com/cookiengineer/audacity
synced 2025-05-03 17:19:43 +02:00
Rewrite many iterations over tracks and channels in src/commands
This commit is contained in:
parent
23a85893a1
commit
c7ab9f2338
@ -76,20 +76,20 @@ bool CompareAudioCommand::GetSelection(const CommandContext &context, AudacityPr
|
||||
|
||||
// Get the selected tracks and check that there are at least two to
|
||||
// compare
|
||||
SelectedTrackListOfKindIterator iter(Track::Wave, proj.GetTracks());
|
||||
mTrack0 = (WaveTrack*)(iter.First());
|
||||
auto trackRange = proj.GetTracks()->Selected< const WaveTrack >();
|
||||
mTrack0 = *trackRange.first;
|
||||
if (mTrack0 == NULL)
|
||||
{
|
||||
context.Error(wxT("No tracks selected! Select two tracks to compare."));
|
||||
return false;
|
||||
}
|
||||
mTrack1 = (WaveTrack*)(iter.Next());
|
||||
mTrack1 = * ++ trackRange.first;
|
||||
if (mTrack1 == NULL)
|
||||
{
|
||||
context.Error(wxT("Only one track selected! Select two tracks to compare."));
|
||||
return false;
|
||||
}
|
||||
if (iter.Next() != NULL)
|
||||
if ( * ++ trackRange.first )
|
||||
{
|
||||
context.Status(wxT("More than two tracks selected - only the first two will be compared."));
|
||||
}
|
||||
|
@ -267,7 +267,7 @@ bool GetInfoCommand::SendTracks(const CommandContext & context)
|
||||
context.AddItem( t->GetEndTime(), "end" );
|
||||
context.AddItem( t->GetPan() , "pan");
|
||||
context.AddItem( t->GetGain() , "gain");
|
||||
context.AddItem( t->GetLinked() ? 2:1, "channels");
|
||||
context.AddItem( TrackList::Channels(t).size(), "channels");
|
||||
context.AddBool( t->GetSolo(), "solo" );
|
||||
context.AddBool( t->GetMute(), "mute");
|
||||
} );
|
||||
@ -280,28 +280,18 @@ bool GetInfoCommand::SendTracks(const CommandContext & context)
|
||||
bool GetInfoCommand::SendClips(const CommandContext &context)
|
||||
{
|
||||
TrackList *tracks = context.GetProject()->GetTracks();
|
||||
TrackListIterator iter(tracks);
|
||||
Track *t = iter.First();
|
||||
int i=0;
|
||||
context.StartArray();
|
||||
while (t) {
|
||||
if (t->GetKind() == Track::Wave) {
|
||||
WaveTrack *waveTrack = static_cast<WaveTrack*>(t);
|
||||
WaveClipPointers ptrs( waveTrack->SortedClipArray());
|
||||
for(WaveClip * pClip : ptrs ) {
|
||||
context.StartStruct();
|
||||
context.AddItem( (double)i, "track" );
|
||||
context.AddItem( pClip->GetStartTime(), "start" );
|
||||
context.AddItem( pClip->GetEndTime(), "end" );
|
||||
context.AddItem( pClip->GetColourIndex(), "color" );
|
||||
context.EndStruct();
|
||||
}
|
||||
for (auto waveTrack : tracks->Leaders<WaveTrack>()) {
|
||||
WaveClipPointers ptrs( waveTrack->SortedClipArray());
|
||||
for(WaveClip * pClip : ptrs ) {
|
||||
context.StartStruct();
|
||||
context.AddItem( (double)i, "track" );
|
||||
context.AddItem( pClip->GetStartTime(), "start" );
|
||||
context.AddItem( pClip->GetEndTime(), "end" );
|
||||
context.AddItem( pClip->GetColourIndex(), "color" );
|
||||
context.EndStruct();
|
||||
}
|
||||
// Skip second tracks of stereo...
|
||||
if( t->GetLinked() )
|
||||
t= iter.Next();
|
||||
if( t )
|
||||
t=iter.Next();
|
||||
i++;
|
||||
}
|
||||
context.EndArray();
|
||||
@ -312,43 +302,33 @@ bool GetInfoCommand::SendClips(const CommandContext &context)
|
||||
bool GetInfoCommand::SendEnvelopes(const CommandContext &context)
|
||||
{
|
||||
TrackList *tracks = context.GetProject()->GetTracks();
|
||||
TrackListIterator iter(tracks);
|
||||
Track *t = iter.First();
|
||||
int i=0;
|
||||
int j=0;
|
||||
context.StartArray();
|
||||
while (t) {
|
||||
if (t->GetKind() == Track::Wave) {
|
||||
WaveTrack *waveTrack = static_cast<WaveTrack*>(t);
|
||||
WaveClipPointers ptrs( waveTrack->SortedClipArray());
|
||||
for(WaveClip * pClip : ptrs ) {
|
||||
context.StartStruct();
|
||||
context.AddItem( (double)i, "track" );
|
||||
context.AddItem( (double)j, "clip" );
|
||||
context.AddItem( pClip->GetStartTime(), "start" );
|
||||
Envelope * pEnv = pClip->GetEnvelope();
|
||||
context.StartField( "points" );
|
||||
context.StartArray();
|
||||
double offset = pEnv->mOffset;
|
||||
for( size_t k=0;k<pEnv->mEnv.size(); k++)
|
||||
{
|
||||
context.StartStruct( );
|
||||
context.AddItem( pEnv->mEnv[k].GetT()+offset, "t" );
|
||||
context.AddItem( pEnv->mEnv[k].GetVal(), "y" );
|
||||
context.EndStruct();
|
||||
}
|
||||
context.EndArray();
|
||||
context.EndField();
|
||||
context.AddItem( pClip->GetEndTime(), "end" );
|
||||
for (auto waveTrack : tracks->Leaders<WaveTrack>()) {
|
||||
WaveClipPointers ptrs( waveTrack->SortedClipArray());
|
||||
for(WaveClip * pClip : ptrs ) {
|
||||
context.StartStruct();
|
||||
context.AddItem( (double)i, "track" );
|
||||
context.AddItem( (double)j, "clip" );
|
||||
context.AddItem( pClip->GetStartTime(), "start" );
|
||||
Envelope * pEnv = pClip->GetEnvelope();
|
||||
context.StartField( "points" );
|
||||
context.StartArray();
|
||||
double offset = pEnv->mOffset;
|
||||
for( size_t k=0;k<pEnv->mEnv.size(); k++)
|
||||
{
|
||||
context.StartStruct( );
|
||||
context.AddItem( pEnv->mEnv[k].GetT()+offset, "t" );
|
||||
context.AddItem( pEnv->mEnv[k].GetVal(), "y" );
|
||||
context.EndStruct();
|
||||
j++;
|
||||
}
|
||||
context.EndArray();
|
||||
context.EndField();
|
||||
context.AddItem( pClip->GetEndTime(), "end" );
|
||||
context.EndStruct();
|
||||
j++;
|
||||
}
|
||||
// Skip second tracks of stereo...
|
||||
if( t->GetLinked() )
|
||||
t= iter.Next();
|
||||
if( t )
|
||||
t=iter.Next();
|
||||
}
|
||||
context.EndArray();
|
||||
|
||||
|
@ -777,20 +777,14 @@ wxRect ScreenshotCommand::GetTrackRect( AudacityProject * pProj, TrackPanel * pa
|
||||
return rect;
|
||||
};
|
||||
|
||||
TrackListIterator iter(pProj->GetTracks());
|
||||
int count = 0;
|
||||
for (auto t = iter.First(); t; t = iter.Next()) {
|
||||
for (auto t : pProj->GetTracks()->Leaders()) {
|
||||
count += 1;
|
||||
if( count > n )
|
||||
{
|
||||
wxRect r = FindRectangle( *panel, *t );
|
||||
return r;
|
||||
}
|
||||
if( t->GetLinked() ){
|
||||
t = iter.Next();
|
||||
if( !t )
|
||||
break;
|
||||
}
|
||||
}
|
||||
return wxRect( 0,0,0,0);
|
||||
}
|
||||
|
@ -220,31 +220,30 @@ bool SelectTracksCommand::Apply(const CommandContext &context)
|
||||
if( !bHasFirstTrack )
|
||||
mFirstTrack = 0.0;
|
||||
|
||||
// Stereo second tracks count as 0.5 of a track.
|
||||
// Multiple channels count as fractions of a track.
|
||||
double last = mFirstTrack+mNumTracks;
|
||||
double first = mFirstTrack;
|
||||
bool bIsSecondChannel = false;
|
||||
TrackListIterator iter(tracks);
|
||||
Track *t = iter.First();
|
||||
while (t) {
|
||||
|
||||
for (auto t : tracks->Leaders()) {
|
||||
auto channels = TrackList::Channels(t);
|
||||
double term = 0.0;
|
||||
// Add 0.01 so we are free of rounding errors in comparisons.
|
||||
// Optionally add 0.5 for second track which counts as is half a track
|
||||
double track = index + 0.01 + (bIsSecondChannel ? 0.5 : 0.0);
|
||||
bool sel = first <= track && track <= last;
|
||||
if( mMode == 0 ){ // Set
|
||||
t->SetSelected(sel);
|
||||
constexpr double fudge = 0.01;
|
||||
for (auto channel : channels) {
|
||||
double track = index + fudge + term;
|
||||
bool sel = first <= track && track <= last;
|
||||
if( mMode == 0 ){ // Set
|
||||
t->SetSelected(sel);
|
||||
}
|
||||
else if( mMode == 1 && sel ){ // Add
|
||||
t->SetSelected(sel);
|
||||
}
|
||||
else if( mMode == 2 && sel ){ // Remove
|
||||
t->SetSelected(!sel);
|
||||
}
|
||||
term += (1.0 - fudge) / channels.size();
|
||||
}
|
||||
else if( mMode == 1 && sel ){ // Add
|
||||
t->SetSelected(sel);
|
||||
}
|
||||
else if( mMode == 2 && sel ){ // Remove
|
||||
t->SetSelected(!sel);
|
||||
}
|
||||
// Do second channel in stereo track too.
|
||||
bIsSecondChannel = t->GetLinked();
|
||||
if( !bIsSecondChannel )
|
||||
++index;
|
||||
t = iter.Next();
|
||||
++index;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -67,27 +67,21 @@ bool SetLabelCommand::Apply(const CommandContext & context)
|
||||
//wxString mode = GetString(wxT("Type"));
|
||||
AudacityProject * p = context.GetProject();
|
||||
TrackList *tracks = context.GetProject()->GetTracks();
|
||||
TrackListIterator iter(tracks);
|
||||
Track *t = iter.First();
|
||||
LabelStruct * pLabel = NULL;
|
||||
int i=0;
|
||||
int nn=0;
|
||||
|
||||
LabelTrack *labelTrack = nullptr;
|
||||
while (t && i<=mLabelIndex) {
|
||||
if (t->GetKind() == Track::Label) {
|
||||
labelTrack = static_cast<LabelTrack*>(t);
|
||||
if( labelTrack )
|
||||
{
|
||||
for (nn = 0;
|
||||
(nn< (int)labelTrack->mLabels.size()) && i<=mLabelIndex;
|
||||
nn++) {
|
||||
i++;
|
||||
pLabel = &labelTrack->mLabels[nn];
|
||||
}
|
||||
}
|
||||
LabelTrack *labelTrack {};
|
||||
for (auto lt : tracks->Any<LabelTrack>()) {
|
||||
if( i > mLabelIndex )
|
||||
break;
|
||||
labelTrack = lt;
|
||||
for (nn = 0;
|
||||
(nn< (int)labelTrack->mLabels.size()) && i<=mLabelIndex;
|
||||
nn++) {
|
||||
i++;
|
||||
pLabel = &labelTrack->mLabels[nn];
|
||||
}
|
||||
t = iter.Next();
|
||||
}
|
||||
|
||||
if ( (i< mLabelIndex) || (pLabel == NULL))
|
||||
|
@ -92,28 +92,26 @@ bool SetTrackBase::Apply(const CommandContext & context )
|
||||
{
|
||||
long i = 0;// track counter
|
||||
long j = 0;// channel counter
|
||||
TrackListIterator iter(context.GetProject()->GetTracks());
|
||||
Track *t = iter.First();
|
||||
bIsSecondChannel = false;
|
||||
while (t )
|
||||
auto tracks = context.GetProject()->GetTracks();
|
||||
for ( auto t : tracks->Leaders() )
|
||||
{
|
||||
bool bThisTrack =
|
||||
auto channels = TrackList::Channels(t);
|
||||
for ( auto channel : channels ) {
|
||||
bool bThisTrack =
|
||||
#ifdef USE_OWN_TRACK_SELECTION
|
||||
(bHasTrackIndex && (i==mTrackIndex)) ||
|
||||
(bHasChannelIndex && (j==mChannelIndex ) ) ||
|
||||
(!bHasTrackIndex && !bHasChannelIndex) ;
|
||||
#else
|
||||
t->GetSelected();
|
||||
channel->GetSelected();
|
||||
#endif
|
||||
|
||||
if( bThisTrack ){
|
||||
ApplyInner( context, t );
|
||||
if( bThisTrack ){
|
||||
ApplyInner( context, t );
|
||||
}
|
||||
++j; // count all channels
|
||||
}
|
||||
bIsSecondChannel = t->GetLinked();
|
||||
if( !bIsSecondChannel )
|
||||
++i;
|
||||
j++;
|
||||
t = iter.Next();
|
||||
++i; // count groups of channels
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user