mirror of
https://github.com/cookiengineer/audacity
synced 2025-08-16 08:34:10 +02:00
No extra indirection accessing SnapPoint
This commit is contained in:
parent
e0c88b1e53
commit
1758f85451
33
src/Snap.cpp
33
src/Snap.cpp
@ -21,9 +21,9 @@
|
||||
|
||||
WX_DEFINE_USER_EXPORTED_OBJARRAY(TrackClipArray);
|
||||
|
||||
static int CompareSnapPoints(SnapPoint *s1, SnapPoint *s2)
|
||||
inline bool operator < (SnapPoint s1, SnapPoint s2)
|
||||
{
|
||||
return (s1->t - s2->t > 0? 1 : -1);
|
||||
return s1.t < s2.t;
|
||||
}
|
||||
|
||||
SnapManager::SnapManager(TrackList *tracks,
|
||||
@ -32,8 +32,7 @@ SnapManager::SnapManager(TrackList *tracks,
|
||||
const TrackArray *trackExclusions,
|
||||
bool noTimeSnap,
|
||||
int pixelTolerance)
|
||||
: mConverter(NumericConverter::TIME),
|
||||
mSnapPoints(CompareSnapPoints)
|
||||
: mConverter(NumericConverter::TIME)
|
||||
{
|
||||
mTracks = tracks;
|
||||
mZoomInfo = zoomInfo;
|
||||
@ -57,10 +56,6 @@ SnapManager::SnapManager(TrackList *tracks,
|
||||
|
||||
SnapManager::~SnapManager()
|
||||
{
|
||||
for (size_t i = 0, cnt = mSnapPoints.GetCount(); i < cnt; ++i)
|
||||
{
|
||||
delete mSnapPoints[i];
|
||||
}
|
||||
}
|
||||
|
||||
void SnapManager::Reinit()
|
||||
@ -80,12 +75,7 @@ void SnapManager::Reinit()
|
||||
mRate = rate;
|
||||
mFormat = format;
|
||||
|
||||
// Clear snap points
|
||||
for (size_t i = 0, cnt = mSnapPoints.GetCount(); i < cnt; ++i)
|
||||
{
|
||||
delete mSnapPoints[i];
|
||||
}
|
||||
mSnapPoints.Clear();
|
||||
mSnapPoints.clear();
|
||||
|
||||
// Grab time-snapping prefs (unless otherwise requested)
|
||||
mSnapToTime = false;
|
||||
@ -99,7 +89,7 @@ void SnapManager::Reinit()
|
||||
}
|
||||
|
||||
// Add a SnapPoint at t=0
|
||||
mSnapPoints.Add(new SnapPoint(0.0, NULL));
|
||||
mSnapPoints.push_back(SnapPoint{});
|
||||
|
||||
TrackListIterator iter(mTracks);
|
||||
for (Track *track = iter.First(); track; track = iter.Next())
|
||||
@ -162,6 +152,9 @@ void SnapManager::Reinit()
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
// Sort all by time
|
||||
std::sort(mSnapPoints.begin(), mSnapPoints.end());
|
||||
}
|
||||
|
||||
// Adds to mSnapPoints, filtering by TimeConverter
|
||||
@ -174,14 +167,14 @@ void SnapManager::CondListAdd(double t, Track *track)
|
||||
|
||||
if (!mSnapToTime || mConverter.GetValue() == t)
|
||||
{
|
||||
mSnapPoints.Add(new SnapPoint(t, track));
|
||||
mSnapPoints.push_back(SnapPoint{ t, track });
|
||||
}
|
||||
}
|
||||
|
||||
// Return the time of the SnapPoint at a given index
|
||||
double SnapManager::Get(size_t index)
|
||||
{
|
||||
return mSnapPoints[index]->t;
|
||||
return mSnapPoints[index].t;
|
||||
}
|
||||
|
||||
// Returns the difference in time between t and the point at a given index
|
||||
@ -213,7 +206,7 @@ size_t SnapManager::Find(double t, size_t i0, size_t i1)
|
||||
// Find the SnapPoint nearest to time t
|
||||
size_t SnapManager::Find(double t)
|
||||
{
|
||||
size_t cnt = mSnapPoints.GetCount();
|
||||
size_t cnt = mSnapPoints.size();
|
||||
size_t index = Find(t, 0, cnt);
|
||||
|
||||
// At this point, either index is the closest, or the next one
|
||||
@ -242,7 +235,7 @@ bool SnapManager::SnapToPoints(Track *currentTrack,
|
||||
{
|
||||
*outT = t;
|
||||
|
||||
size_t cnt = mSnapPoints.GetCount();
|
||||
size_t cnt = mSnapPoints.size();
|
||||
if (cnt == 0)
|
||||
{
|
||||
return false;
|
||||
@ -284,7 +277,7 @@ bool SnapManager::SnapToPoints(Track *currentTrack,
|
||||
size_t countInThisTrack = 0;
|
||||
for (i = left; i <= right; ++i)
|
||||
{
|
||||
if (mSnapPoints[i]->track == currentTrack)
|
||||
if (mSnapPoints[i].track == currentTrack)
|
||||
{
|
||||
indexInThisTrack = i;
|
||||
countInThisTrack++;
|
||||
|
@ -57,16 +57,17 @@ const int kPixelTolerance = 4;
|
||||
class SnapPoint
|
||||
{
|
||||
public:
|
||||
SnapPoint(double t, Track *track)
|
||||
explicit
|
||||
SnapPoint(double t_ = 0.0, Track *track_ = nullptr)
|
||||
: t(t_), track(track_)
|
||||
{
|
||||
this->t = t;
|
||||
this->track = track;
|
||||
}
|
||||
|
||||
double t;
|
||||
Track *track;
|
||||
};
|
||||
|
||||
WX_DEFINE_SORTED_ARRAY(SnapPoint *, SnapPointArray);
|
||||
using SnapPointArray = std::vector < SnapPoint > ;
|
||||
|
||||
class SnapManager
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user