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