Audacity  2.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 <wx/string.h>
22 
23 class AudacityProject;
24 class Track;
25 class TrackArray;
26 class TrackClipArray;
27 class WaveClip;
28 class WaveTrack;
29 class TrackList;
30 class ZoomInfo;
31 class wxDC;
32 
33 class TrackClip
34 {
35 public:
36  TrackClip(Track *t, WaveClip *c);
37 
38  ~TrackClip();
39 
44  std::shared_ptr<WaveClip> holder;
45 };
46 
47 class TrackClipArray : public std::vector < TrackClip > {};
48 
49 enum
50 {
54 };
55 
56 const int kPixelTolerance = 4;
57 
58 class SnapPoint
59 {
60 public:
61  explicit
62  SnapPoint(double t_ = 0.0, const Track *track_ = nullptr)
63  : t(t_), track(track_)
64  {
65  }
66 
67  double t;
68  const Track *track;
69 };
70 
71 using SnapPointArray = std::vector < SnapPoint > ;
72 
73 struct SnapResults {
74  double timeSnappedTime{ 0.0 };
75  double outTime{ 0.0 };
76  wxInt64 outCoord{ -1 };
77  bool snappedPoint{ false };
78  bool snappedTime{ false };
79 
80  bool Snapped() const { return snappedPoint || snappedTime; }
81 };
82 
84 {
85 public:
86  SnapManager(const TrackList *tracks,
87  const ZoomInfo *zoomInfo,
88  const TrackClipArray *clipExclusions = NULL,
89  const TrackArray *trackExclusions = NULL,
90  bool noTimeSnap = false,
91  int pixelTolerance = kPixelTolerance);
92  ~SnapManager();
93 
94  // The track may be NULL.
95  // Returns true if the output time is not the same as the input.
96  // Pass rightEdge=true if this is the right edge of a selection,
97  // and false if it's the left edge.
98  SnapResults Snap(Track *currentTrack,
99  double t,
100  bool rightEdge);
101 
102  static wxArrayString GetSnapLabels();
103  static wxArrayString GetSnapValues();
104  static const wxString & GetSnapValue(int index);
105  static int GetSnapIndex(const wxString & value);
106 
107  // The two coordinates need not be ordered:
108  static void Draw( wxDC *dc, wxInt64 snap0, wxInt64 snap1 );
109 
110 private:
111 
112  void Reinit();
113  void CondListAdd(double t, const Track *track);
114  double Get(size_t index);
115  wxInt64 PixelDiff(double t, size_t index);
116  size_t Find(double t, size_t i0, size_t i1);
117  size_t Find(double t);
118  bool SnapToPoints(Track *currentTrack, double t, bool rightEdge, double *outT);
119 
120 private:
121 
125  const TrackArray *mTrackExclusions;
129 
130  double mEpsilon;
132 
133  // Info for snap-to-time
136 
137  int mSnapTo;
138  double mRate;
139  wxString mFormat;
140 };
141 
142 #endif
A list of TrackListNode items.
Definition: Track.h:550
std::shared_ptr< WaveClip > holder
Definition: Snap.h:44
double mEpsilon
Definition: Snap.h:130
Definition: Snap.h:58
const TrackList * mTracks
Definition: Snap.h:123
bool mSnapToTime
Definition: Snap.h:135
Definition: Snap.h:33
double Get(size_t index)
Definition: Snap.cpp:186
wxString mFormat
Definition: Snap.h:139
SnapResults Snap(Track *currentTrack, double t, bool rightEdge)
Definition: Snap.cpp:324
bool Snapped() const
Definition: Snap.h:80
const int kPixelTolerance
Definition: Snap.h:56
Definition: ViewInfo.h:31
bool snappedPoint
Definition: Snap.h:77
static int GetSnapIndex(const wxString &value)
Definition: Snap.cpp:400
wxInt64 PixelDiff(double t, size_t index)
Definition: Snap.cpp:192
Definition: Snap.h:51
bool SnapToPoints(Track *currentTrack, double t, bool rightEdge, double *outT)
Definition: Snap.cpp:242
~SnapManager()
Definition: Snap.cpp:68
const ZoomInfo * mZoomInfo
Definition: Snap.h:126
wxInt64 outCoord
Definition: Snap.h:76
const Track * track
Definition: Snap.h:68
static void Draw(wxDC *dc, wxInt64 snap0, wxInt64 snap1)
Definition: Snap.cpp:415
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:161
const AudacityProject * mProject
Definition: Snap.h:122
NumericConverter provides the advanced formatting control used in the selection bar of Audacity...
Definition: NumericTextCtrl.h:53
SnapPointArray mSnapPoints
Definition: Snap.h:131
This allows multiple clips to be a part of one WaveTrack.
Definition: WaveClip.h:177
Track * track
Definition: Snap.h:40
WaveTrack * dstTrack
Definition: Snap.h:42
void Reinit()
Definition: Snap.cpp:72
A Track that contains audio waveform data.
Definition: WaveTrack.h:76
Fundamental data object of Audacity, placed in the TrackPanel. Classes derived form it include the Wa...
Definition: Track.h:85
const TrackArray * mTrackExclusions
Definition: Snap.h:125
int mPixelTolerance
Definition: Snap.h:127
double mRate
Definition: Snap.h:138
Definition: Snap.h:53
SnapManager(const TrackList *tracks, const ZoomInfo *zoomInfo, const TrackClipArray *clipExclusions=NULL, const TrackArray *trackExclusions=NULL, bool noTimeSnap=false, int pixelTolerance=kPixelTolerance)
Definition: Snap.cpp:40
double t
Definition: Snap.h:67
Definition: Snap.h:47
std::vector< SnapPoint > SnapPointArray
Definition: Snap.h:71
size_t Find(double t, size_t i0, size_t i1)
Definition: Snap.cpp:200
Definition: Snap.h:83
~TrackClip()
Definition: Snap.cpp:35
SnapPoint(double t_=0.0, const Track *track_=nullptr)
Definition: Snap.h:62
const TrackClipArray * mClipExclusions
Definition: Snap.h:124
Definition: Snap.h:52
static wxArrayString GetSnapLabels()
Definition: Snap.cpp:366
bool snappedTime
Definition: Snap.h:78
void CondListAdd(double t, const Track *track)
Definition: Snap.cpp:172
int mSnapTo
Definition: Snap.h:137
static wxArrayString GetSnapValues()
Definition: Snap.cpp:377
TrackClip(Track *t, WaveClip *c)
Definition: Snap.cpp:28
WaveClip * clip
Definition: Snap.h:43
bool mNoTimeSnap
Definition: Snap.h:128
double outTime
Definition: Snap.h:75
Definition: Snap.h:73
static const wxString & GetSnapValue(int index)
Definition: Snap.cpp:388
Track * origTrack
Definition: Snap.h:41
NumericConverter mConverter
Definition: Snap.h:134
double timeSnappedTime
Definition: Snap.h:74