mirror of
https://github.com/cookiengineer/audacity
synced 2025-05-02 16:49:41 +02:00
Use std::vector for wave track locations
This commit is contained in:
parent
60eeac0b10
commit
05f5375e4a
@ -1480,8 +1480,7 @@ void TrackArtist::DrawWaveform(WaveTrack *track,
|
||||
// Update cache for locations, e.g. cutlines and merge points
|
||||
track->UpdateLocationsCache();
|
||||
|
||||
for (int i = 0; i<track->GetNumCachedLocations(); i++) {
|
||||
WaveTrack::Location loc = track->GetCachedLocation(i);
|
||||
for (const auto loc : track->GetCachedLocations()) {
|
||||
const int xx = zoomInfo.TimeToPosition(loc.pos);
|
||||
if (xx >= 0 && xx < rect.width) {
|
||||
dc.SetPen(*wxGREY_PEN);
|
||||
|
@ -6655,11 +6655,12 @@ namespace {
|
||||
int FindMergeLine(WaveTrack *track, double time)
|
||||
{
|
||||
const double tolerance = 0.5 / track->GetRate();
|
||||
for (int ii = 0, nn = track->GetNumCachedLocations(); ii < nn; ++ii) {
|
||||
WaveTrack::Location loc = track->GetCachedLocation(ii);
|
||||
int ii = 0;
|
||||
for (const auto loc: track->GetCachedLocations()) {
|
||||
if (loc.typ == WaveTrackLocation::locationMergePoint &&
|
||||
fabs(time - loc.pos) < tolerance)
|
||||
return ii;
|
||||
++ii;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@ -6731,7 +6732,7 @@ bool TrackPanel::HandleTrackLocationMouseEvent(WaveTrack * track, wxRect &rect,
|
||||
// Don't assume correspondence of merge points across channels!
|
||||
int idx = FindMergeLine(linked, pos);
|
||||
if (idx >= 0) {
|
||||
WaveTrack::Location location = linked->GetCachedLocation(idx);
|
||||
WaveTrack::Location location = linked->GetCachedLocations()[idx];
|
||||
if (!linked->MergeClips(location.clipidx1, location.clipidx2))
|
||||
return false;
|
||||
}
|
||||
@ -6770,10 +6771,8 @@ bool TrackPanel::HandleTrackLocationMouseEvent(WaveTrack * track, wxRect &rect,
|
||||
|
||||
bool TrackPanel::IsOverCutline(WaveTrack * track, wxRect &rect, wxMouseEvent &event)
|
||||
{
|
||||
for (int i=0; i<track->GetNumCachedLocations(); i++)
|
||||
for (auto loc: track->GetCachedLocations())
|
||||
{
|
||||
WaveTrack::Location loc = track->GetCachedLocation(i);
|
||||
|
||||
const double x = mViewInfo->TimeToPosition(loc.pos);
|
||||
if (x >= 0 && x < rect.width)
|
||||
{
|
||||
|
@ -108,9 +108,6 @@ WaveTrack::WaveTrack(DirManager *projDirManager, sampleFormat format, double rat
|
||||
mDisplayMin = -1.0;
|
||||
mDisplayMax = 1.0;
|
||||
mSpectrumMin = mSpectrumMax = -1; // so values will default to settings
|
||||
mDisplayNumLocations = 0;
|
||||
mDisplayLocations = NULL;
|
||||
mDisplayNumLocationsAllocated = 0;
|
||||
mLastScaleType = -1;
|
||||
mLastdBRange = -1;
|
||||
mAutoSaveIdent = 0;
|
||||
@ -150,9 +147,7 @@ void WaveTrack::Init(const WaveTrack &orig)
|
||||
mDisplayMax = orig.mDisplayMax;
|
||||
mSpectrumMin = orig.mSpectrumMin;
|
||||
mSpectrumMax = orig.mSpectrumMax;
|
||||
mDisplayNumLocations = 0;
|
||||
mDisplayLocations = NULL;
|
||||
mDisplayNumLocationsAllocated = 0;
|
||||
mDisplayLocationsCache.clear();
|
||||
}
|
||||
|
||||
void WaveTrack::Merge(const Track &orig)
|
||||
@ -181,8 +176,6 @@ WaveTrack::~WaveTrack()
|
||||
for (WaveClipList::compatibility_iterator it=GetClipIterator(); it; it=it->GetNext())
|
||||
delete it->GetData();
|
||||
mClips.Clear();
|
||||
if (mDisplayLocations)
|
||||
delete [] mDisplayLocations;
|
||||
|
||||
delete mpSpectrumSettings;
|
||||
delete mpWaveformSettings;
|
||||
@ -2437,33 +2430,26 @@ void WaveTrack::UpdateLocationsCache()
|
||||
|
||||
FillSortedClipArray(clips);
|
||||
|
||||
mDisplayNumLocations = 0;
|
||||
mDisplayLocationsCache.clear();
|
||||
|
||||
// Count number of display locations
|
||||
int num = 0;
|
||||
for (i = 0; i < clips.GetCount(); i++)
|
||||
{
|
||||
WaveClip* clip = clips.Item(i);
|
||||
|
||||
mDisplayNumLocations += clip->GetCutLines()->GetCount();
|
||||
num += clip->GetCutLines()->GetCount();
|
||||
|
||||
if (i > 0 && fabs(clips.Item(i - 1)->GetEndTime() -
|
||||
clip->GetStartTime()) < WAVETRACK_MERGE_POINT_TOLERANCE)
|
||||
mDisplayNumLocations++;
|
||||
++num;
|
||||
}
|
||||
|
||||
if (mDisplayNumLocations == 0)
|
||||
if (num == 0)
|
||||
return;
|
||||
|
||||
// Alloc necessary number of display locations
|
||||
if (mDisplayNumLocations > mDisplayNumLocationsAllocated)
|
||||
{
|
||||
// Only realloc, if we need more space than before. Otherwise
|
||||
// just use block from before.
|
||||
if (mDisplayLocations)
|
||||
delete[] mDisplayLocations;
|
||||
mDisplayLocations = new Location[mDisplayNumLocations];
|
||||
mDisplayNumLocationsAllocated = mDisplayNumLocations;
|
||||
}
|
||||
mDisplayLocationsCache.reserve(num);
|
||||
|
||||
// Add all display locations to cache
|
||||
int curpos = 0;
|
||||
@ -2477,9 +2463,10 @@ void WaveTrack::UpdateLocationsCache()
|
||||
it = it->GetNext())
|
||||
{
|
||||
// Add cut line expander point
|
||||
mDisplayLocations[curpos].typ = WaveTrackLocation::locationCutLine;
|
||||
mDisplayLocations[curpos].pos =
|
||||
clip->GetOffset() + it->GetData()->GetOffset();
|
||||
mDisplayLocationsCache.push_back(WaveTrackLocation{
|
||||
clip->GetOffset() + it->GetData()->GetOffset(),
|
||||
WaveTrackLocation::locationCutLine
|
||||
});
|
||||
curpos++;
|
||||
}
|
||||
|
||||
@ -2491,16 +2478,18 @@ void WaveTrack::UpdateLocationsCache()
|
||||
< WAVETRACK_MERGE_POINT_TOLERANCE)
|
||||
{
|
||||
// Add merge point
|
||||
mDisplayLocations[curpos].typ = WaveTrackLocation::locationMergePoint;
|
||||
mDisplayLocations[curpos].pos = clips.Item(i-1)->GetEndTime();
|
||||
mDisplayLocations[curpos].clipidx1 = mClips.IndexOf(previousClip);
|
||||
mDisplayLocations[curpos].clipidx2 = mClips.IndexOf(clip);
|
||||
mDisplayLocationsCache.push_back(WaveTrackLocation{
|
||||
clips.Item(i - 1)->GetEndTime(),
|
||||
WaveTrackLocation::locationMergePoint,
|
||||
mClips.IndexOf(previousClip),
|
||||
mClips.IndexOf(clip)
|
||||
});
|
||||
curpos++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
wxASSERT(curpos == mDisplayNumLocations);
|
||||
wxASSERT(curpos == num);
|
||||
}
|
||||
|
||||
// Expand cut line (that is, re-insert audio, then DELETE audio saved in cut line)
|
||||
|
@ -375,9 +375,8 @@ class AUDACITY_DLL_API WaveTrack final : public Track {
|
||||
// Cache special locations (e.g. cut lines) for later speedy access
|
||||
void UpdateLocationsCache();
|
||||
|
||||
// Get number of cached locations
|
||||
int GetNumCachedLocations() { return mDisplayNumLocations; }
|
||||
Location GetCachedLocation(int index) { return mDisplayLocations[index]; }
|
||||
// Get cached locations
|
||||
const std::vector<Location> &GetCachedLocations() const { return mDisplayLocationsCache; }
|
||||
|
||||
// Expand cut line (that is, re-insert audio, then DELETE audio saved in cut line)
|
||||
bool ExpandCutLine(double cutLinePosition, double* cutlineStart = NULL, double* cutlineEnd = NULL);
|
||||
@ -477,9 +476,7 @@ class AUDACITY_DLL_API WaveTrack final : public Track {
|
||||
WaveTrackDisplay mDisplay;
|
||||
int mLastScaleType; // last scale type choice
|
||||
int mLastdBRange;
|
||||
int mDisplayNumLocations;
|
||||
int mDisplayNumLocationsAllocated;
|
||||
Location* mDisplayLocations;
|
||||
mutable std::vector <Location> mDisplayLocationsCache;
|
||||
|
||||
//
|
||||
// Protected methods
|
||||
|
@ -18,6 +18,13 @@ struct WaveTrackLocation {
|
||||
locationMergePoint
|
||||
};
|
||||
|
||||
explicit
|
||||
WaveTrackLocation
|
||||
(double pos_ = 0.0, LocationType typ_ = locationCutLine,
|
||||
int clipidx1_ = -1, int clipidx2_ = -1)
|
||||
: pos(pos_), typ(typ_), clipidx1(clipidx1_), clipidx2(clipidx2_)
|
||||
{}
|
||||
|
||||
// Position of track location
|
||||
double pos;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user