forked from Sneeds-Feed-and-Seed/sneedacity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSnap.h
116 lines (88 loc) · 2.84 KB
/
Snap.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/**********************************************************************
Sneedacity: A Digital Audio Editor
Snap.h
Dominic Mazzoni
Create one of these objects at the beginning of a click/drag.
Then, given a time corresponding to the current mouse cursor
position, it will tell you the closest place to snap to.
**********************************************************************/
#ifndef __SNEEDACITY_SNAP__
#define __SNEEDACITY_SNAP__
#include <vector>
#include <wx/defs.h>
#include "widgets/NumericTextCtrl.h" // member variable
class SneedacityProject;
class Track;
class TrackList;
class ZoomInfo;
class wxDC;
const int kPixelTolerance = 4;
class SnapPoint
{
public:
explicit
SnapPoint(double t_ = 0.0, const Track *track_ = nullptr)
: t(t_), track(track_)
{
}
double t;
const Track *track;
};
using SnapPointArray = std::vector < SnapPoint > ;
struct SnapResults {
double timeSnappedTime{ 0.0 };
double outTime{ 0.0 };
wxInt64 outCoord{ -1 };
bool snappedPoint{ false };
bool snappedTime{ false };
bool Snapped() const { return snappedPoint || snappedTime; }
};
class SNEEDACITY_DLL_API SnapManager
{
public:
SnapManager(const SneedacityProject &project,
SnapPointArray candidates,
const ZoomInfo &zoomInfo,
bool noTimeSnap = false,
int pixelTolerance = kPixelTolerance);
SnapManager(const SneedacityProject &project,
const TrackList &tracks,
const ZoomInfo &zoomInfo,
bool noTimeSnap = false,
int pixelTolerance = kPixelTolerance);
~SnapManager();
// The track may be NULL.
// Returns true if the output time is not the same as the input.
// Pass rightEdge=true if this is the right edge of a selection,
// and false if it's the left edge.
SnapResults Snap(Track *currentTrack,
double t,
bool rightEdge);
static const TranslatableStrings &GetSnapLabels();
// The two coordinates need not be ordered:
static void Draw( wxDC *dc, wxInt64 snap0, wxInt64 snap1 );
private:
void Reinit();
void CondListAdd(double t, const Track *track);
double Get(size_t index);
wxInt64 PixelDiff(double t, size_t index);
size_t Find(double t, size_t i0, size_t i1);
size_t Find(double t);
bool SnapToPoints(Track *currentTrack, double t, bool rightEdge, double *outT);
private:
const SneedacityProject *mProject;
const ZoomInfo *mZoomInfo;
int mPixelTolerance;
bool mNoTimeSnap;
//! Two time points closer than this are considered the same
double mEpsilon{ 1 / 44100.0 };
SnapPointArray mCandidates;
SnapPointArray mSnapPoints;
// Info for snap-to-time
NumericConverter mConverter;
bool mSnapToTime{ false };
int mSnapTo{ 0 };
double mRate{ 0.0 };
NumericFormatSymbol mFormat{};
};
#endif