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