mirror of
https://github.com/cookiengineer/audacity
synced 2025-06-15 15:49:36 +02:00
fixing sort by time bug and refactoring sort by name code. Also making name sort semi case sensitive.
This commit is contained in:
parent
b52315f111
commit
26b59b363b
@ -1965,40 +1965,54 @@ double AudacityProject::GetTime(Track *t)
|
|||||||
return stime;
|
return stime;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudacityProject::OnSortTime()
|
//sort based on flags. see Project.h for sort flags
|
||||||
|
void AudacityProject::SortTracks(int flags)
|
||||||
{
|
{
|
||||||
int ndx;
|
int ndx;
|
||||||
|
int cmpValue;
|
||||||
wxArrayPtrVoid warr, marr;
|
wxArrayPtrVoid arr;
|
||||||
TrackListIterator iter(mTracks);
|
TrackListIterator iter(mTracks);
|
||||||
Track *track = iter.First();
|
Track *track = iter.First();
|
||||||
|
bool lastTrackLinked = false;
|
||||||
|
//sort by linked tracks. Assumes linked track follows owner in list.
|
||||||
while (track) {
|
while (track) {
|
||||||
if (track->GetKind() == Track::Wave) {
|
if(lastTrackLinked) {
|
||||||
for (ndx = 0; ndx < (int)warr.GetCount(); ndx++) {
|
//insert after the last track since this track should be linked to it.
|
||||||
if (GetTime(track) < GetTime((Track *) warr[ndx])) {
|
ndx++;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
warr.Insert(track, ndx);
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for (ndx = 0; ndx < (int)marr.GetCount(); ndx++) {
|
for (ndx = 0; ndx < (int)arr.GetCount(); ndx++) {
|
||||||
if (GetTime(track) < GetTime((Track *) marr[ndx])) {
|
if(flags & kAudacitySortByName){
|
||||||
|
//do case insensitive sort - cmpNoCase returns less than zero if the string is 'less than' its argument
|
||||||
|
//also if we have case insensitive equality, then we need to sort by case as well
|
||||||
|
//We sort 'b' before 'B' accordingly. We uncharacteristically use greater than for the case sensitive
|
||||||
|
//compare because 'b' is greater than 'B' in ascii.
|
||||||
|
cmpValue = track->GetName().CmpNoCase(((Track *) arr[ndx])->GetName());
|
||||||
|
if (cmpValue < 0 ||
|
||||||
|
(0 == cmpValue && track->GetName().CompareTo(((Track *) arr[ndx])->GetName()) > 0) )
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//sort by time otherwise
|
||||||
|
else if(flags & kAudacitySortByTime){
|
||||||
|
if (GetTime(track) < GetTime((Track *) arr[ndx]))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
marr.Insert(track, ndx);
|
|
||||||
}
|
}
|
||||||
|
arr.Insert(track, ndx);
|
||||||
|
|
||||||
|
lastTrackLinked = track->GetLinked();
|
||||||
track = iter.RemoveCurrent();
|
track = iter.RemoveCurrent();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ndx = 0; ndx < (int)marr.GetCount(); ndx++) {
|
for (ndx = 0; ndx < (int)arr.GetCount(); ndx++) {
|
||||||
mTracks->Add((Track *)marr[ndx]);
|
mTracks->Add((Track *)arr[ndx]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (ndx = 0; ndx < (int)warr.GetCount(); ndx++) {
|
void AudacityProject::OnSortTime()
|
||||||
mTracks->Add((Track *)warr[ndx]);
|
{
|
||||||
}
|
SortTracks(kAudacitySortByTime);
|
||||||
|
|
||||||
PushState(_("Tracks sorted by time"), _("Sort By Time"));
|
PushState(_("Tracks sorted by time"), _("Sort By Time"));
|
||||||
|
|
||||||
@ -2007,27 +2021,7 @@ void AudacityProject::OnSortTime()
|
|||||||
|
|
||||||
void AudacityProject::OnSortName()
|
void AudacityProject::OnSortName()
|
||||||
{
|
{
|
||||||
int ndx;
|
SortTracks(kAudacitySortByName);
|
||||||
|
|
||||||
wxArrayPtrVoid arr;
|
|
||||||
TrackListIterator iter(mTracks);
|
|
||||||
Track *track = iter.First();
|
|
||||||
//Assumes that linked channels have the same name.
|
|
||||||
//if this is not true a crash will occur during redraw after the sort.
|
|
||||||
while (track) {
|
|
||||||
for (ndx = 0; ndx < (int)arr.GetCount(); ndx++) {
|
|
||||||
//do case insensitive sort - cmpNoCase returns less than zero if the string is 'less than' its argument
|
|
||||||
if (track->GetName().CmpNoCase(((Track *) arr[ndx])->GetName()) < 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
arr.Insert(track, ndx);
|
|
||||||
track = iter.RemoveCurrent();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (ndx = 0; ndx < (int)arr.GetCount(); ndx++) {
|
|
||||||
mTracks->Add((Track *)arr[ndx]);
|
|
||||||
}
|
|
||||||
|
|
||||||
PushState(_("Tracks sorted by name"), _("Sort By Name"));
|
PushState(_("Tracks sorted by name"), _("Sort By Name"));
|
||||||
|
|
||||||
|
@ -499,6 +499,12 @@ class AUDACITY_DLL_API AudacityProject: public wxFrame,
|
|||||||
bool IsTimerRecordCancelled(){return mTimerRecordCanceled;}
|
bool IsTimerRecordCancelled(){return mTimerRecordCanceled;}
|
||||||
void ResetTimerRecordFlag(){mTimerRecordCanceled=false;}
|
void ResetTimerRecordFlag(){mTimerRecordCanceled=false;}
|
||||||
private:
|
private:
|
||||||
|
//sort method used by OnSortName and OnSortTime
|
||||||
|
//currently only supported flags are kAudacitySortByName and kAudacitySortByName
|
||||||
|
//in the future we might have 0x01 as sort ascending and we can bit or it
|
||||||
|
#define kAudacitySortByTime (1 << 1)
|
||||||
|
#define kAudacitySortByName (1 << 2)
|
||||||
|
void SortTracks(int flags);
|
||||||
|
|
||||||
int mAudioIOToken;
|
int mAudioIOToken;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user