mirror of
https://github.com/cookiengineer/audacity
synced 2025-08-16 08:34:10 +02:00
Fix up label behavior, clean up reverse effect
This commit is contained in:
parent
7945e8723d
commit
10892c33e5
@ -36,25 +36,20 @@ bool EffectReverse::Process()
|
|||||||
//Track::All is needed because Reverse should move the labels too
|
//Track::All is needed because Reverse should move the labels too
|
||||||
this->CopyInputTracks(Track::All); // Set up mOutputTracks.
|
this->CopyInputTracks(Track::All); // Set up mOutputTracks.
|
||||||
bool bGoodResult = true;
|
bool bGoodResult = true;
|
||||||
|
Track *lastGroup = NULL; // First track of group of last acted-on WaveTrack
|
||||||
|
TrackGroupIterator gIt(mOutputTracks);
|
||||||
|
|
||||||
TrackListIterator iter(mOutputTracks);
|
TrackListIterator iter(mOutputTracks);
|
||||||
Track *t = iter.First();
|
Track *t = iter.First();
|
||||||
int count = 0;
|
int count = 0;
|
||||||
double lt0 = -2.0; // -2.0 = not initialized yet; -1.0 = is not possible to reverse labels
|
|
||||||
double lt1 = -2.0;
|
|
||||||
while (t) {
|
while (t) {
|
||||||
if (t->GetKind() == Track::Wave) {
|
if (t->GetKind() == Track::Wave) {
|
||||||
WaveTrack *track = (WaveTrack*)t;
|
WaveTrack *track = (WaveTrack*)t;
|
||||||
|
|
||||||
// Since leading and trailing whitespaces should also be considered for reversal
|
|
||||||
// t0 and t1 must always be equal to mT0 and mT1
|
|
||||||
double t0 = mT0;
|
|
||||||
double t1 = mT1;
|
|
||||||
|
|
||||||
if (track->GetSelected()) {
|
if (track->GetSelected()) {
|
||||||
if (t1 > t0) {
|
if (mT1 > mT0) {
|
||||||
sampleCount start = track->TimeToLongSamples(t0);
|
sampleCount start = track->TimeToLongSamples(mT0);
|
||||||
sampleCount end = track->TimeToLongSamples(t1);
|
sampleCount end = track->TimeToLongSamples(mT1);
|
||||||
sampleCount len = (sampleCount)(end - start);
|
sampleCount len = (sampleCount)(end - start);
|
||||||
|
|
||||||
if (!ProcessOneWave(count, track, start, len))
|
if (!ProcessOneWave(count, track, start, len))
|
||||||
@ -62,39 +57,19 @@ bool EffectReverse::Process()
|
|||||||
bGoodResult = false;
|
bGoodResult = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
//if this is the first selected track in the group we can define the label
|
|
||||||
//region to be reversed without any more verifications
|
// Update grouping variables
|
||||||
if (lt0 == -2.0) {
|
lastGroup = gIt.First(t);
|
||||||
lt0 = t0;
|
|
||||||
lt1 = t1;
|
|
||||||
}
|
|
||||||
//track has not the same selection result (after checking start and end of the track as the first track)
|
|
||||||
//it's not possible to know how to reverse the label in this situation.
|
|
||||||
else if ((lt0 != t0) || (lt1 != t1)) {
|
|
||||||
lt0 = -1.0;
|
|
||||||
lt1 = -1.0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//if the track is not selected but has no content inside the selected region, there is no problem.
|
|
||||||
//otherwise we should not change the labels.
|
|
||||||
else if (t1 > t0) {
|
|
||||||
lt0 = -1.0;
|
|
||||||
lt1 = -1.0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (t->GetKind() == Track::Label) {
|
else if (t->GetKind() == Track::Label) {
|
||||||
AudacityProject *p = GetActiveProject();
|
AudacityProject *p = GetActiveProject();
|
||||||
//if we can reverse the label
|
if ((p && p->IsSticky() && gIt.First(t) == lastGroup) ||
|
||||||
if (lt0 != -1.0 && p && p->IsSticky()) {
|
t->GetSelected())
|
||||||
|
{
|
||||||
LabelTrack *track = (LabelTrack*)t;
|
LabelTrack *track = (LabelTrack*)t;
|
||||||
track->ChangeLabelsOnReverse(lt0, lt1);
|
track->ChangeLabelsOnReverse(mT0, mT1);
|
||||||
}
|
|
||||||
//otherwise we set the region to the not initialized state -2.0 to begin the process in the next group
|
|
||||||
else {
|
|
||||||
lt0 = -2.0;
|
|
||||||
lt1 = -2.0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
t = iter.Next();
|
t = iter.Next();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user