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>
20#include "widgets/NumericTextCtrl.h" // member variable
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:
59 SnapManager(const AudacityProject &project,
60 SnapPointArray candidates,
61 const ZoomInfo &zoomInfo,
62 bool noTimeSnap = false,
63 int pixelTolerance = kPixelTolerance);
64
67 SnapManager(const AudacityProject &project,
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 static const TranslatableStrings &GetSnapLabels();
85
86 // The two coordinates need not be ordered:
87 static void Draw( wxDC *dc, wxInt64 snap0, wxInt64 snap1 );
88
89private:
90
91 void Reinit();
92 void CondListAdd(double t, const Track *track);
93 double Get(size_t index);
94 wxInt64 PixelDiff(double t, size_t index);
95 size_t Find(double t, size_t i0, size_t i1);
96 size_t Find(double t);
97 bool SnapToPoints(Track *currentTrack, double t, bool rightEdge, double *outT);
98
99private:
100
105
107 double mEpsilon{ 1 / 44100.0 };
110
111 // Info for snap-to-time
113 bool mSnapToTime{ false };
114
115 int mSnapTo{ 0 };
116 double mRate{ 0.0 };
118};
119
120#endif
const int kPixelTolerance
Definition: Snap.h:28
std::vector< SnapPoint > SnapPointArray
Definition: Snap.h:43
std::vector< TranslatableString > TranslatableStrings
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:89
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
NumericConverter provides the advanced formatting control used in the selection bar of Audacity.
NumericConverter mConverter
Definition: Snap.h:112
const AudacityProject * mProject
Definition: Snap.h:101
SnapPointArray mCandidates
Definition: Snap.h:108
SnapPointArray mSnapPoints
Definition: Snap.h:109
bool mNoTimeSnap
Definition: Snap.h:104
int mPixelTolerance
Definition: Snap.h:103
const ZoomInfo * mZoomInfo
Definition: Snap.h:102
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:225
A flat linked list of tracks supporting Add, Remove, Clear, and Contains, serialization of the list o...
Definition: Track.h:1330
wxString Find(const FilePath &path)
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:26
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