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