Audacity  3.0.3
ZoomInfo.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  ZoomInfo.h
6 
7  Paul Licameli split from ViewInfo.h
8 
9 **********************************************************************/
10 
11 #ifndef __AUDACITY_ZOOM_INFO__
12 #define __AUDACITY_ZOOM_INFO__
13 
14 #include "ClientData.h" // to inherit
15 #include "Prefs.h" // to inherit
16 
17 #ifdef __GNUC__
18 #define CONST
19 #else
20 #define CONST const
21 #endif
22 
23 class AudacityProject;
24 
25 // See big pictorial comment in TrackPanel.cpp for explanation of these numbers
26 enum : int {
27  // Constants related to x coordinates in the track panel
30 
35 
37 };
38 
39 // The subset of ViewInfo information (other than selection)
40 // that is sufficient for purposes of TrackArtist,
41 // and for computing conversions between track times and pixel positions.
42 class AUDACITY_DLL_API ZoomInfo /* not final */
43  // Note that ViewInfo inherits from ZoomInfo but there are no virtual functions.
44  // That's okay if we pass always by reference and never copy, suffering "slicing."
45  : public ClientData::Base
46  , protected PrefsListener
47 {
48 public:
49  ZoomInfo(double start, double pixelsPerSecond);
50  ~ZoomInfo();
51 
52  // Be sure we don't slice
53  ZoomInfo(const ZoomInfo&) PROHIBITED;
54  ZoomInfo& operator= (const ZoomInfo&) PROHIBITED;
55 
56  void UpdatePrefs() override;
57 
58  int vpos; // vertical scroll pos
59 
60  double h; // h pos in secs
61 
62 protected:
63  double zoom; // pixels per second
64 
65 public:
66  float dBr; // decibel scale range
67 
68  // do NOT use this once to convert a pixel width to a duration!
69  // Instead, call twice to convert start and end times,
70  // and take the difference.
71  // origin specifies the pixel corresponding to time h
72  double PositionToTime(wxInt64 position,
73  wxInt64 origin = 0
74  , bool ignoreFisheye = false
75  ) const;
76 
77  // do NOT use this once to convert a duration to a pixel width!
78  // Instead, call twice to convert start and end positions,
79  // and take the difference.
80  // origin specifies the pixel corresponding to time h
81  wxInt64 TimeToPosition(double time,
82  wxInt64 origin = 0
83  , bool ignoreFisheye = false
84  ) const;
85 
86  // This always ignores the fisheye. Use with caution!
87  // You should prefer to call TimeToPosition twice, for endpoints, and take the difference!
88  double TimeRangeToPixelWidth(double timeRange) const;
89 
90  double OffsetTimeByPixels(double time, wxInt64 offset, bool ignoreFisheye = false) const
91  {
92  return PositionToTime(offset + TimeToPosition(time, ignoreFisheye), ignoreFisheye);
93  }
94 
95  int GetWidth() const { return mWidth; }
96  void SetWidth( int width ) { mWidth = width; }
97 
98  int GetVRulerWidth() const { return mVRulerWidth; }
99  void SetVRulerWidth( int width ) { mVRulerWidth = width; }
100  int GetVRulerOffset() const { return kTrackInfoWidth + kLeftMargin; }
101  int GetLabelWidth() const { return GetVRulerOffset() + GetVRulerWidth(); }
102  int GetLeftOffset() const { return GetLabelWidth() + 1;}
103 
105  {
106  return
107  std::max( 0, GetWidth() - ( GetLeftOffset() + kRightMargin ) );
108  }
109 
110  // Returns the time corresponding to the pixel column one past the track area
111  // (ignoring any fisheye)
112  double GetScreenEndTime() const
113  {
114  auto width = GetTracksUsableWidth();
115  return PositionToTime(width, 0, true);
116  }
117 
118  bool ZoomInAvailable() const;
119  bool ZoomOutAvailable() const;
120 
121  static double GetDefaultZoom()
122  { return 44100.0 / 512.0; }
123 
124 
125  // Limits zoom to certain bounds
126  void SetZoom(double pixelsPerSecond);
127 
128  // This function should not be used to convert positions to times and back
129  // Use TimeToPosition and PositionToTime and OffsetTimeByPixels instead
130  double GetZoom() const;
131 
132  static double GetMaxZoom( );
133  static double GetMinZoom( );
134 
135  // Limits zoom to certain bounds
136  // multipliers above 1.0 zoom in, below out
137  void ZoomBy(double multiplier);
138 
139  struct Interval {
140  CONST wxInt64 position; CONST double averageZoom; CONST bool inFisheye;
141  Interval(wxInt64 p, double z, bool i)
142  : position(p), averageZoom(z), inFisheye(i) {}
143  };
144  typedef std::vector<Interval> Intervals;
145 
146  // Find an increasing sequence of pixel positions. Each is the start
147  // of an interval, or is the end position.
148  // Each of the disjoint intervals should be drawn
149  // separately.
150  // It is guaranteed that there is at least one entry and the position of the
151  // first entry equals origin.
152  // @param origin specifies the pixel position corresponding to time ViewInfo::h.
153  void FindIntervals
154  (double rate, Intervals &results, wxInt64 width, wxInt64 origin = 0) const;
155 
159 
161  };
163  { return HIDDEN; } // stub
164 
165  // Return true if the mouse position is anywhere in the fisheye
166  // origin specifies the pixel corresponding to time h
167  bool InFisheye(wxInt64 /*position*/, wxInt64 WXUNUSED(origin = 0)) const
168  {return false;} // stub
169 
170  // These accessors ignore the fisheye hiding state.
171  // Inclusive:
172  wxInt64 GetFisheyeLeftBoundary(wxInt64 WXUNUSED(origin = 0)) const
173  {return 0;} // stub
174  // Exclusive:
175  wxInt64 GetFisheyeRightBoundary(wxInt64 WXUNUSED(origin = 0)) const
176  {return 0;} // stub
177 
178  int mWidth{ 0 };
179  int mVRulerWidth{ 36 };
180 };
181 
182 #endif
CONST
#define CONST
Definition: ZoomInfo.h:20
ZoomInfo::vpos
int vpos
Definition: ZoomInfo.h:58
kLeftInset
@ kLeftInset
Definition: ZoomInfo.h:31
ZoomInfo::OffsetTimeByPixels
double OffsetTimeByPixels(double time, wxInt64 offset, bool ignoreFisheye=false) const
Definition: ZoomInfo.h:90
ZoomInfo::GetFisheyeLeftBoundary
wxInt64 GetFisheyeLeftBoundary(wxInt64 WXUNUSED(origin=0)) const
Definition: ZoomInfo.h:172
ZoomInfo::GetVRulerOffset
int GetVRulerOffset() const
Definition: ZoomInfo.h:100
ZoomInfo::GetDefaultZoom
static double GetDefaultZoom()
Definition: ZoomInfo.h:121
ZoomInfo::GetWidth
int GetWidth() const
Definition: ZoomInfo.h:95
ZoomInfo::Interval::Interval
Interval(wxInt64 p, double z, bool i)
Definition: ZoomInfo.h:141
ZoomInfo
Definition: ZoomInfo.h:47
kBorderThickness
@ kBorderThickness
Definition: ZoomInfo.h:28
kShadowThickness
@ kShadowThickness
Definition: ZoomInfo.h:29
ClientData::Base
A convenient default parameter for class template Site.
Definition: ClientData.h:28
ZoomInfo::SetVRulerWidth
void SetVRulerWidth(int width)
Definition: ZoomInfo.h:99
TrackInfo::UpdatePrefs
AUDACITY_DLL_API void UpdatePrefs(wxWindow *pParent)
kRightInset
@ kRightInset
Definition: ZoomInfo.h:32
ZoomInfo::GetVRulerWidth
int GetVRulerWidth() const
Definition: ZoomInfo.h:98
ClientData.h
Utility ClientData::Site to register hooks into a host class that attach client data.
ZoomInfo::Interval
Definition: ZoomInfo.h:139
PrefsListener
Definition: Prefs.h:388
ZoomInfo::GetLeftOffset
int GetLeftOffset() const
Definition: ZoomInfo.h:102
ZoomInfo::ZoomInfo
ZoomInfo(const ZoomInfo &) PROHIBITED
ZoomInfo::InFisheye
bool InFisheye(wxInt64, wxInt64 WXUNUSED(origin=0)) const
Definition: ZoomInfo.h:167
ZoomInfo::GetScreenEndTime
double GetScreenEndTime() const
Definition: ZoomInfo.h:112
ZoomInfo::NUM_STATES
@ NUM_STATES
Definition: ZoomInfo.h:160
ZoomInfo::PINNED
@ PINNED
Definition: ZoomInfo.h:158
ZoomInfo::HIDDEN
@ HIDDEN
Definition: ZoomInfo.h:157
ZoomInfo::FisheyeState
FisheyeState
Definition: ZoomInfo.h:156
ZoomInfo::GetFisheyeRightBoundary
wxInt64 GetFisheyeRightBoundary(wxInt64 WXUNUSED(origin=0)) const
Definition: ZoomInfo.h:175
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:112
ZoomInfo::GetFisheyeState
FisheyeState GetFisheyeState() const
Definition: ZoomInfo.h:162
kRightMargin
@ kRightMargin
Definition: ZoomInfo.h:34
ZoomInfo::GetLabelWidth
int GetLabelWidth() const
Definition: ZoomInfo.h:101
ZoomInfo::Interval::position
CONST wxInt64 position
Definition: ZoomInfo.h:140
Prefs.h
ZoomInfo::GetTracksUsableWidth
int GetTracksUsableWidth() const
Definition: ZoomInfo.h:104
ZoomInfo::zoom
double zoom
Definition: ZoomInfo.h:63
ZoomInfo::Intervals
std::vector< Interval > Intervals
Definition: ZoomInfo.h:144
kTrackInfoWidth
@ kTrackInfoWidth
Definition: ZoomInfo.h:36
ZoomInfo::dBr
float dBr
Definition: ZoomInfo.h:66
ZoomInfo::h
double h
Definition: ZoomInfo.h:60
kLeftMargin
@ kLeftMargin
Definition: ZoomInfo.h:33
ZoomInfo::SetWidth
void SetWidth(int width)
Definition: ZoomInfo.h:96