Audacity 3.2.0
Snap.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 Snap.h
6
7 Dominic Mazzoni
8
9 Create one of these objects at the beginning of a click/drag.
10 Then, given a time corresponding to the current mouse cursor
11 position, it will tell you the closest place to snap to.
12
13**********************************************************************/
14
15#ifndef __AUDACITY_SNAP__
16#define __AUDACITY_SNAP__
17
18#include <vector>
19#include <wx/defs.h>
21
22class AudacityProject;
23class Track;
24class TrackList;
25class ZoomInfo;
26class wxDC;
27
28const int kPixelTolerance = 4;
29
31{
32public:
33 explicit
34 SnapPoint(double t_ = 0.0, const Track *track_ = nullptr)
35 : t(t_), track(track_)
36 {
37 }
38
39 double t;
40 const Track *track;
41};
42
43using SnapPointArray = std::vector < SnapPoint > ;
44
46 double timeSnappedTime{ 0.0 };
47 double outTime{ 0.0 };
48 wxInt64 outCoord{ -1 };
49 bool snappedPoint{ false };
50 bool snappedTime{ false };
51
52 bool Snapped() const { return snappedPoint || snappedTime; }
53};
54
55class SNAPPING_API SnapManager
56{
57public:
60 SnapPointArray candidates,
61 const ZoomInfo &zoomInfo,
62 bool noTimeSnap = false,
63 int pixelTolerance = kPixelTolerance);
64
68 const TrackList &tracks,
69 const ZoomInfo &zoomInfo,
70 SnapPointArray candidates = {},
71 bool noTimeSnap = false,
72 int pixelTolerance = kPixelTolerance);
73
75
76 // The track may be NULL.
77 // Returns true if the output time is not the same as the input.
78 // Pass rightEdge=true if this is the right edge of a selection,
79 // and false if it's the left edge.
80 SnapResults Snap(Track *currentTrack,
81 double t,
82 bool rightEdge);
83
84private:
85
86 void Reinit();
87 void CondListAdd(double t, const Track *track);
88 double Get(size_t index);
89 wxInt64 PixelDiff(double t, size_t index);
90 size_t Find(double t, size_t i0, size_t i1);
91 size_t Find(double t);
92 bool SnapToPoints(Track *currentTrack, double t, bool rightEdge, double *outT);
93
94private:
95
100
102 double mEpsilon{ 1 / 44100.0 };
105
106 // Info for snap-to-time
107 bool mSnapToTime{ false };
108
109 Identifier mSnapTo {};
110 double mRate{ 0.0 };
112};
113
114#endif
const int kPixelTolerance
Definition: Snap.h:28
std::vector< SnapPoint > SnapPointArray
Definition: Snap.h:43
const auto tracks
const auto project
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
An explicitly nonlocalized string, not meant for the user to see.
Definition: Identifier.h:22
const AudacityProject * mProject
Definition: Snap.h:96
SnapPointArray mCandidates
Definition: Snap.h:103
SnapPointArray mSnapPoints
Definition: Snap.h:104
bool mNoTimeSnap
Definition: Snap.h:99
int mPixelTolerance
Definition: Snap.h:98
const ZoomInfo * mZoomInfo
Definition: Snap.h:97
Definition: Snap.h:31
double t
Definition: Snap.h:39
const Track * track
Definition: Snap.h:40
SnapPoint(double t_=0.0, const Track *track_=nullptr)
Definition: Snap.h:34
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:110
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Definition: Track.h:850
PROJECT_FILE_IO_API wxString Find(const FilePath &path)
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:202
bool snappedTime
Definition: Snap.h:50
double outTime
Definition: Snap.h:47
double timeSnappedTime
Definition: Snap.h:46
wxInt64 outCoord
Definition: Snap.h:48
bool Snapped() const
Definition: Snap.h:52
bool snappedPoint
Definition: Snap.h:49