Audacity 3.2.0
TimeTrackView.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3Audacity: A Digital Audio Editor
4
5TimeTrackView.cpp
6
7Paul Licameli split from TrackPanel.cpp
8
9**********************************************************************/
10
11#include "TimeTrackView.h"
12#include "TimeTrack.h"
13
14#include "TimeTrackControls.h"
15
17#include "AColor.h"
18#include "AllThemeResources.h"
19#include "Envelope.h"
20#include "../../../EnvelopeEditor.h"
21#include "../../../HitTestResult.h"
22#include "Theme.h"
23#include "../../../TrackArtist.h"
24#include "../../../TrackPanelDrawingContext.h"
25#include "../../../TrackPanelMouseEvent.h"
26#include "ViewInfo.h"
27#include "../../../widgets/Ruler.h"
28#include "../../../widgets/LinearUpdater.h"
29#include "../../../widgets/TimeFormat.h"
30
31#include "../../ui/EnvelopeHandle.h"
32
33#include <wx/dc.h>
34
36
37TimeTrackView::TimeTrackView(const std::shared_ptr<Track> &pTrack)
38 : CommonChannelView{ pTrack, 0 }
39{
40}
41
43{
44}
45
46std::vector<UIHandlePtr> TimeTrackView::DetailedHitTest
47(const TrackPanelMouseState &st,
48 const AudacityProject *pProject, int, bool)
49{
50 std::vector<UIHandlePtr> results;
52 ( mEnvelopeHandle, st.state, st.rect, pProject,
53 std::static_pointer_cast< TimeTrack >( FindTrack() ) );
54 if (result)
55 results.push_back(result);
56 return results;
57}
58
61 return [](TimeTrack &track, size_t) {
62 return std::make_shared<TimeTrackView>(track.SharedPointer());
63 };
64}
65
66std::shared_ptr<ChannelVRulerControls> TimeTrackView::DoGetVRulerControls()
67{
68 return
69 std::make_shared<TimeTrackVRulerControls>(shared_from_this());
70}
71
72namespace {
74( TrackPanelDrawingContext &context, const wxRect & r,
75 const TimeTrack &track, Ruler &ruler )
76{
77 auto &dc = context.dc;
78 const auto artist = TrackArtist::Get( context );
79 const auto &zoomInfo = *artist->pZoomInfo;
80
81 bool highlight = false;
82#ifdef EXPERIMENTAL_TRACK_PANEL_HIGHLIGHTING
83 auto target = dynamic_cast<EnvelopeHandle*>(context.target.get());
84 highlight = target && target->GetEnvelope() == track.GetEnvelope();
85#endif
86
87 double min = zoomInfo.PositionToTime(0);
88 double max = zoomInfo.PositionToTime(r.width);
89 if (min > max)
90 {
91 wxASSERT(false);
92 min = max;
93 }
94
95 AColor::UseThemeColour( &dc, clrUnselected );
96 dc.DrawRectangle(r);
97
98 //copy this rectangle away for future use.
99 wxRect mid = r;
100
101 // Draw the Ruler
102 ruler.SetBounds(r.x, r.y, r.x + r.width - 1, r.y + r.height - 1);
103 ruler.SetRange(min, max);
104 ruler.SetFlip(true); // tick marks at top of track.
105 ruler.Invalidate(); // otherwise does not redraw.
106 ruler.SetTickColour( theTheme.Colour( clrTrackPanelText ));
107 ruler.Draw(dc, track.GetEnvelope());
108
109 Doubles envValues{ size_t(mid.width) };
111 0, 0, envValues.get(), mid.width, 0, zoomInfo);
112
113 wxPen &pen = highlight ? AColor::uglyPen : AColor::envelopePen;
114 dc.SetPen( pen );
115
116 auto rangeLower = track.GetRangeLower(), rangeUpper = track.GetRangeUpper();
117 double logLower = log(std::max(1.0e-7, rangeLower)),
118 logUpper = log(std::max(1.0e-7, rangeUpper));
119
120 for (int x = 0; x < mid.width; x++)
121 {
122 double y;
123 if ( track.GetDisplayLog() )
124 y = (double)mid.height * (logUpper - log(envValues[x])) / (logUpper - logLower);
125 else
126 y = (double)mid.height * (rangeUpper - envValues[x]) / (rangeUpper - rangeLower);
127 int thisy = r.y + (int)y;
128 AColor::Line(dc, mid.x + x, thisy - 1, mid.x + x, thisy+2);
129 }
130}
131
133 const TimeTrack &track, Ruler &ruler,
134 const wxRect & rect)
135{
136 // Ruler and curve...
137 DrawHorzRulerAndCurve( context, rect, track, ruler );
138
139 // ... then the control points
140 wxRect envRect = rect;
141 envRect.height -= 2;
142 double lower = track.GetRangeLower(), upper = track.GetRangeUpper();
143 const auto artist = TrackArtist::Get( context );
144 const auto dbRange = artist->mdBrange;
145 if(track.GetDisplayLog()) {
146 // MB: silly way to undo the work of GetWaveYPos while still getting a logarithmic scale
147 lower = LINEAR_TO_DB(std::max(1.0e-7, lower)) / dbRange + 1.0;
148 upper = LINEAR_TO_DB(std::max(1.0e-7, upper)) / dbRange + 1.0;
149 }
151 context, envRect,
152 track.GetDisplayLog(), dbRange, lower, upper, false );
153}
154}
155
158 const wxRect &rect, unsigned iPass )
159{
160 if ( iPass == TrackArtist::PassTracks ) {
161 const auto pTrack = FindTrack();
162 const auto pList = pTrack->GetOwner();
163 if (!pList)
164 // Track isn't owned by a list. Can't proceed!
165 return;
166 const auto pProject = pList->GetOwner();
167 if (!pProject)
168 // List isn't owned by a project. Can't proceed!
169 // But this shouldn't happen when drawing it
170 return;
171
172 auto &zoomInfo = ViewInfo::Get(*pProject);
174 updater.SetData(&zoomInfo);
175
176 // Just using a stack-local Ruler object. Observe the "Invalidate"
177 // call above which has long been done with every redraw.
178 // Avoiding invalidation with every draw, and making the ruler persistent
179 // between drawings, would require that it be invalidated whenever the
180 // user drags points, or the time selection changes -- really too much
181 // work.
183 ruler.SetLabelEdges(false);
184
185 const auto tt = std::static_pointer_cast<const TimeTrack>(
186 pTrack->SubstitutePendingChangedTrack());
187 DrawTimeTrack(context, *tt, ruler, rect);
188 }
189 CommonChannelView::Draw(context, rect, iPass);
190}
int min(int a, int b)
#define LINEAR_TO_DB(x)
Definition: MemoryX.h:562
THEME_API Theme theTheme
Definition: Theme.cpp:82
DEFINE_ATTACHED_VIRTUAL_OVERRIDE(DoGetTimeTrackView)
static CustomUpdaterValue updater
static void Line(wxDC &dc, wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
Definition: AColor.cpp:187
static wxPen uglyPen
Definition: AColor.h:141
static wxPen envelopePen
Definition: AColor.h:115
static void UseThemeColour(wxDC *dc, int iBrush, int iPen=-1, int alpha=255)
Definition: AColor.cpp:372
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
Implements some hit-testing shared by many ChannelView subtypes.
static void GetEnvelopeValues(const Envelope &env, double aligned_time, double sampleDur, double *buffer, int bufferLen, int leftOffset, const ZoomInfo &zoomInfo)
Get many envelope points for pixel columns at once, but don't assume uniform time per pixel.
std::shared_ptr< Track > FindTrack()
void SetData(RulerUpdater::Labels majorLabels, RulerUpdater::Labels minorLabels, RulerUpdater::Labels minorMinorLabels)
Definition: CustomUpdater.h:27
static void DrawPoints(const Envelope &env, TrackPanelDrawingContext &context, const wxRect &r, bool dB, double dBRange, float zoomMin, float zoomMax, bool mirrored, int origin=0)
static UIHandlePtr TimeTrackHitTest(std::weak_ptr< EnvelopeHandle > &holder, const wxMouseState &state, const wxRect &rect, const AudacityProject *pProject, const std::shared_ptr< TimeTrack > &tt)
Envelope * GetEnvelope() const
Used to display a Ruler.
Definition: Ruler.h:34
void SetTickColour(const wxColour &colour)
Definition: Ruler.h:135
void SetFlip(bool flip)
Definition: Ruler.cpp:192
void Draw(wxDC &dc) const
Definition: Ruler.cpp:441
void SetLabelEdges(bool labelEdges)
Definition: Ruler.cpp:179
void SetBounds(int left, int top, int right, int bottom)
Definition: Ruler.cpp:304
void SetRange(double min, double max)
Definition: Ruler.cpp:152
void Invalidate()
Definition: Ruler.cpp:317
wxColour & Colour(int iIndex)
static const TimeFormat & Instance()
Definition: TimeFormat.cpp:15
A kind of Track used to 'warp time'.
Definition: TimeTrack.h:24
BoundedEnvelope * GetEnvelope()
Definition: TimeTrack.h:83
bool GetDisplayLog() const
Definition: TimeTrack.h:94
double GetRangeLower() const
Definition: TimeTrack.cpp:112
double GetRangeUpper() const
Definition: TimeTrack.cpp:117
~TimeTrackView() override
std::weak_ptr< EnvelopeHandle > mEnvelopeHandle
Definition: TimeTrackView.h:36
std::vector< UIHandlePtr > DetailedHitTest(const TrackPanelMouseState &state, const AudacityProject *pProject, int currentTool, bool bMultiTool) override
void Draw(TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass) override
std::shared_ptr< ChannelVRulerControls > DoGetVRulerControls() override
TimeTrackView(const TimeTrackView &)=delete
static TrackArtist * Get(TrackPanelDrawingContext &)
Definition: TrackArtist.cpp:69
std::shared_ptr< Subclass > SharedPointer()
Definition: Track.h:160
virtual void Draw(TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass)
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
void DrawTimeTrack(TrackPanelDrawingContext &context, const TimeTrack &track, Ruler &ruler, const wxRect &rect)
void DrawHorzRulerAndCurve(TrackPanelDrawingContext &context, const wxRect &r, const TimeTrack &track, Ruler &ruler)
For defining overrides of the method.