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 AUDACITY_DLL_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
84 // The two coordinates need not be ordered:
85 static void Draw( wxDC *dc, wxInt64 snap0, wxInt64 snap1 );
86
87private:
88
89 void Reinit();
90 void CondListAdd(double t, const Track *track);
91 double Get(size_t index);
92 wxInt64 PixelDiff(double t, size_t index);
93 size_t Find(double t, size_t i0, size_t i1);
94 size_t Find(double t);
95 bool SnapToPoints(Track *currentTrack, double t, bool rightEdge, double *outT);
96
97private:
98
103
105 double mEpsilon{ 1 / 44100.0 };
108
109 // Info for snap-to-time
110 bool mSnapToTime{ false };
111
112 Identifier mSnapTo {};
113 double mRate{ 0.0 };
115};
116
117#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
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
An explicitly nonlocalized string, not meant for the user to see.
Definition: Identifier.h:22
const AudacityProject * mProject
Definition: Snap.h:99
SnapPointArray mCandidates
Definition: Snap.h:106
SnapPointArray mSnapPoints
Definition: Snap.h:107
bool mNoTimeSnap
Definition: Snap.h:102
int mPixelTolerance
Definition: Snap.h:101
const ZoomInfo * mZoomInfo
Definition: Snap.h:100
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:123
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Definition: Track.h:987
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:196
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