mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-25 16:48:44 +02:00
Rewrite LabelTrack::SortLabels
This commit is contained in:
parent
15bb2f0434
commit
8fefea6d36
@ -2805,48 +2805,42 @@ bool LabelTrack::IsGoodLabelEditKey(const wxKeyEvent & evt)
|
|||||||
/// sort (with a linear search) is a reasonable choice.
|
/// sort (with a linear search) is a reasonable choice.
|
||||||
void LabelTrack::SortLabels()
|
void LabelTrack::SortLabels()
|
||||||
{
|
{
|
||||||
int i,j;
|
const auto begin = mLabels.begin();
|
||||||
LabelStruct * pTemp;
|
const auto nn = (int)mLabels.size();
|
||||||
for (i = 1; i < (int)mLabels.Count(); i++)
|
int i = 1;
|
||||||
|
while (true)
|
||||||
{
|
{
|
||||||
j=i-1;
|
// Find the next disorder
|
||||||
while( (j>=0) && (mLabels[j]->getT0() >
|
while (i < nn && mLabels[i - 1]->getT0() <= mLabels[i]->getT0())
|
||||||
mLabels[i]->getT0()) )
|
++i;
|
||||||
{
|
if (i >= nn)
|
||||||
j--;
|
break;
|
||||||
}
|
|
||||||
j++;
|
|
||||||
if( j<i)
|
|
||||||
{
|
|
||||||
// Remove at i and insert at j.
|
|
||||||
// Don't use DeleteLabel() since just moving it.
|
|
||||||
pTemp = mLabels[i];
|
|
||||||
mLabels.RemoveAt( i );
|
|
||||||
mLabels.Insert(pTemp, j);
|
|
||||||
|
|
||||||
// Various indecese need to be updated with the moved items...
|
// Where must element i sink to? At most i - 1, maybe less
|
||||||
if( mMouseOverLabelLeft <=i )
|
int j = i - 2;
|
||||||
{
|
while( (j >= 0) && (mLabels[j]->getT0() > mLabels[i]->getT0()) )
|
||||||
if( mMouseOverLabelLeft == i )
|
--j;
|
||||||
mMouseOverLabelLeft=j;
|
++j;
|
||||||
else if( mMouseOverLabelLeft >= j)
|
|
||||||
mMouseOverLabelLeft++;
|
// Now fix the disorder
|
||||||
|
std::rotate(
|
||||||
|
begin + j,
|
||||||
|
begin + i,
|
||||||
|
begin + i + 1
|
||||||
|
);
|
||||||
|
|
||||||
|
// Various indices need to be updated with the moved items...
|
||||||
|
auto update = [=](int &index) {
|
||||||
|
if( index <= i ) {
|
||||||
|
if( index == i )
|
||||||
|
index = j;
|
||||||
|
else if( index >= j)
|
||||||
|
++index;
|
||||||
}
|
}
|
||||||
if( mMouseOverLabelRight <=i )
|
};
|
||||||
{
|
update(mMouseOverLabelLeft);
|
||||||
if( mMouseOverLabelRight == i )
|
update(mMouseOverLabelRight);
|
||||||
mMouseOverLabelRight=j;
|
update(mSelIndex);
|
||||||
else if( mMouseOverLabelRight >= j)
|
|
||||||
mMouseOverLabelRight++;
|
|
||||||
}
|
|
||||||
if( mSelIndex <=i )
|
|
||||||
{
|
|
||||||
if( mSelIndex == i )
|
|
||||||
mSelIndex=j;
|
|
||||||
else if( mSelIndex >= j)
|
|
||||||
mSelIndex++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user